include iostream include cstdio include cstring using namespace std co

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int size = 3;
struct lalka {
char name[50];
char surname[50];
int mobile;
int birth;}
lalka_name[size];
int menu();
void enter(), display();
int main()
{
int choice;
for (;;)
{
choice = menu();
switch (choice)
{
case 'e': enter();
break;
case 'd': display();
break;
case 'q': return 0;
}
}
}
int menu()
{
char choice;
do
{
cout << "(E)nter\n";
cout << "(Q)uit\n";
cin >> choice;
} while (!strchr("eq", tolower(choice)));
return tolower(choice);
}
void enter()
{
int i;
for(i = 0; i < size; i++)
{
if(!*lalka_name[i].name)
break;
}
if (i == size)
{
cout << "The list is full.\n"; //массив заполнен
}
while (i < size)
{
cout << "\nName: ";
cin >> lalka_name[i].name;
cout << "Surname: ";
cin >> lalka_name[i].surname;
cout << "Telephone number: ";
cin >> lalka_name[i].mobile;
cout << "Date of birth: ";
cin >> lalka_name[i].birth;
i++;
}
for (i = 1; i < size; i++) //сортировка по номеру телефона
for (int j = i; j < 3 && lalka_name[j - 1].mobile> lalka_name[j].mobile; j--)
swap(lalka_name[j - 1], lalka_name[j]);
cout << "\n";
display();
}
void display()//вывод информации о человеке с искомой фамилией
{
cout << "\nInformation: ";
for (int p = 0; p < size; p++)
{
cout << "\nName: " << lalka_name[p].name<< ". Surname: " << lalka_name[p].surname<< ". Mobile: " << lalka_name[p].mobile << ". Date of birth: "<< lalka_name[p].birth;
//<< ". Day of birth: " << lalka_name[0].birth << ". Month of birth: " << lalka_name[1].birth << ". Year of birth: " << lalka_name[2].birth;
}
char search[30];
cout << "\nName to find\n";
cin >> search;
cin.clear();
cin.sync();
cout << "\nName: " << search << "\n";
bool q = true;
for (int t = 0; t < size; t++)
{
if (!strcmp(search, lalka_name[t].name))
{
cout << "\nName: " << lalka_name[t].name<< ". Surname: " << lalka_name[t].surname<< ". Mobile: " << lalka_name[t].mobile << ". Date of birth: " << lalka_name[t].birth;
// << ". Day of birth: " << lalka_name[0].birth << ". Month of birth: " << lalka_name[1].birth << ". Year of birth: " << lalka_name[2].birth<< "\n\n\n";
q = false;
}
}
if (q) cout << "There's not any person with the name " << search << " found\n\n\n";
}