Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Письмак_ЗВІТ_з_практики.doc
Скачиваний:
1
Добавлен:
01.05.2025
Размер:
2 Мб
Скачать
☆
      1. Результати тестування програм

Програма №1 :

Рис.7. Вікно програми в роботі

Програма №2 :

Рис.8. Вікно програми в роботі

Програма №3 :

Рис.9. Вікно програми в роботі

Програма №4 :

Рис.10. Вікно програми в роботі

Програма №5 :

Рис.11. Вікно програми в роботі

    1. Стандартна бібліотека шаблонів stl. Алгоритми та діопазони

      1. Умови задач:

  1. Знайти об'єкт із значенням 23 в масиві цілих чисел за допомогою алгоритму find та повернути номер його позиції. Підрахувати кількість входжень цього числа в масиві.

  2. Вивести всі входження слова «тор» зі словника, що завантажується з текстового файлу.

  3. Відсортувати елементи масиву в зростаючому порядку за допомогою бінарного предикату greater.

  4. Визначити, чи є слово паліндромом за допомогою equal.

  5. Стерти всі елементи цілочисельного вектору, значення яких перевищують 77.

      1. Лістинги програм

  1. :

#include <iostream.h>

#include <conio.h>

int main()

{

int search_value;

int ia[ 6 ] = { 27, 210, 12, 47, 142, 83 };

int i,pos;

for (i=0;i<6;i++)

cout << ia[i] << endl;

cout << "enter search value: ";

cin >> search_value;

int *presult = find( &ia[0], &ia[6], search_value );

for (i=0;i<6;i++){

if (ia[i] == search_value)

pos = i+1;

}

cout << "The value " << search_value

<< ( presult == &ia[6]

? " is not present" : " is present" )

<< endl;

cout << "Position "<< pos << endl;

//for (i=0;i<6;i++)

//if (ia[i] == search_value)

// pos = i;

getch();

}

  1. :

#include <stdio.h>

#include <iostream>

#include <string.h>

#include <conio.h>

#include <windows.h>

int main()

{

char mass [80][80];

char slovo[80];

int i=0;

int a;

int k;

FILE *f;

f=fopen("f.txt", "r");

if(f==NULL) printf("fail f.txt ne otkrit\n");

while(!feof(f))

{

fscanf(f,"%s",&mass[i]);

printf("%s\n", mass[i]);

i++;

}

a=i;

printf("\n slovo: ");

gets(slovo);

if(slovo!=0)

{

for(i=0;i<a;i++)

{

if(strcmp(slovo,mass[i])==0)

{

printf("\n index - %d",i);

getch();

return 0;

}

}

if(strcmp(slovo,mass[k])!=0)printf("takogo slova net");

}

//printf("slova net");

getch();

}

  1. :

#include <iostream.h>

#include <algorithm>

#include <vector>

#include <vcl.h>

using namespace std;

main(){

int key = 3;

int arr[] = {3,2,1,4,5,6};

vector<int> sortedVector (arr, arr+6);

vector<int>::iterator it;

sort(sortedVector.begin(), sortedVector.begin() + key);

sort(sortedVector.begin() + key, sortedVector.end(), greater<int>());

for (it = sortedVector.begin(); it != sortedVector.end(); ++it)

cout << " " << *it;

cout << endl;

system ("pause");

return 0;

}

  1. :

#include <iostream>

#include <stdlib>

#include <string>

#include <algorithm>

using namespace std;

int main(void)

{

string str, tmp;

cout << "enter str: ";

cin >> str;

tmp = str;

reverse(str.begin(), str.end());

cout << (equal(str.begin(), str.end(), str.rbegin()) ? "yes\n" : "no\n");

system("pause");

return 0;

}

  1. :

#include <iostream>

#include<stdlib>

#include <vector>

#include <algorithm> // sort, max_element, random_shuffle, remove_if, lower_bound

#include <functional> // greater, bind2nd

using namespace std;

int main()

{

vector<int> numbers(10);

for (int i = 0; i < 10; i++)

{

numbers[i] = rand()%100-1;

cout << numbers[i] << " ";

}

random_shuffle(numbers.begin(), numbers.end());

numbers.erase(remove_if(numbers.begin(), numbers.end(),

bind2nd(greater<int>(), 77)), numbers.end() );

cout << "\nNew Vector:" << endl;

// Печатаем оставшиеся

for (vector<int>::const_iterator it = numbers.begin(); it != numbers.end(); ++it) {

cout << *it << ' ';

}

system("pause");

return 0;

}