Untitled

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <string.h> #include<stdlib.h> using namespace std; typedef struct serviceman { char firstname[56]; char lastname[56]; char patronymic[56]; char nationality[56]; char position[56]; char ranks[56]; }; typedef struct adress { short postcode; char country[56]; char region[56]; char district[56]; char city[56]; char street[56]; short house; short apartment; }; typedef struct birth_day { short day; short month; short year; bool isCorrect() { bool result = false; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: { if ((day <= 31) && (day > 0)) result = true; break; } case 4: case 6: case 9: case 11: { if ((day <= 30) && (day > 0)) result = true; break; } case 2: { if (year % 4 != 0) { if ((day <= 28) && (day > 0)) result = true; } else if (year % 400 == 0) { if ((day <= 29) && (day > 0)) result = true; } else if ((year % 100 == 0) && (year % 400 != 0)) { if ((day == 28) && (day > 0)) result = true; } else if ((year % 4 == 0) && (year % 100 != 0)) if ((day <= 29) && (day > 0)) result = true; break; } default: result = false; } return result; } }; typedef struct allbase { serviceman objserviceman; adress objadress; birth_day objbirth; }; void fil_struct(short vvod,allbase *obj) { for (size_t i = 0; i < vvod; i++) { bool k = false; cout << "введите имя" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objserviceman.firstname,56); cout << "введите фамилию" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objserviceman.lastname,56); cout << "введите отчество" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objserviceman.patronymic,56); cout << "введите национальность" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objserviceman.nationality,56); cout << "введите должность" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objserviceman.position,56); cout << "введите звание" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objserviceman.ranks,56); do { cout << "введите дату рождения\nдень" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin>>obj[i].objbirth.day; cin.ignore(std::cin.rdbuf()->in_avail()); cout << "месяц" << endl; cin>>obj[i].objbirth.month; cout << "год" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin>>obj[i].objbirth.year; k = obj[i].objbirth.isCorrect(); } while (k == false); cout << "введите почтовый индекс" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin>>obj[i].objadress.postcode; cout << "введите страну" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objadress.country,56); cout << "введите регион" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objadress.region,56); cout << "введите район" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objadress.district,56); cout << "введите город" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objadress.city,56); cout << "введите улицу" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin.getline(obj[i].objadress.street,56); cout << "введите номер дома" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin >> obj[i].objadress.house; cout << "введите номкр квартиры" << endl; cin.ignore(std::cin.rdbuf()->in_avail()); cin>>obj[i].objadress.apartment; } } void View_struct(short *vvod, allbase* obj) { system("cls"); for (size_t i = 0; i < *vvod; i++) { cout<<"_______________________"<<endl; cout << "имя : " << obj[i].objserviceman.firstname << endl; cout << "фамилия : " << obj[i].objserviceman.lastname << endl; cout << "отчество : " << obj[i].objserviceman.patronymic << endl; cout << "национальность : " << obj[i].objserviceman.nationality << endl; cout << "должность : " << obj[i].objserviceman.position << endl; cout << "звание : " << obj[i].objserviceman.ranks << endl; cout << "дата рождения : " << obj[i].objbirth.day << "." << obj[i].objbirth.month << "." << obj[i].objbirth.year << endl; cout << "почтовый индекс : " << obj[i].objadress.postcode<<endl; cout << "страна : " << obj[i].objadress.country<<endl; cout << "регион : " << obj[i].objadress.region << endl; cout << "район : " << obj[i].objadress.district << endl; cout << "город : " << obj[i].objadress.city << endl; cout << "улица : " << obj[i].objadress.street << endl; cout << "дом : " << obj[i].objadress.house << endl; cout << "квартира : " << obj[i].objadress.apartment << endl; cout << "_______________________"<<endl; } } allbase* add_str(short vvod, allbase* obj) { if (vvod == 0) { obj = new allbase[vvod + 1]; } else { allbase* obj1 = new allbase[vvod + 1]; for (size_t i = 0; i < vvod; i++) { obj1[i] = obj[i]; } delete[]obj; obj = obj1; } return obj; } void SortFirstName(allbase* Massive, int Dimension) { allbase Temp; for (size_t i = 0; i <= Dimension; i++) { for (size_t q = Dimension - 1; q > i; q--) { if (strcmp(Massive[q].objserviceman.firstname, Massive[q - 1].objserviceman.firstname) < 0) { Temp = Massive[q]; Massive[q] = Massive[q - 1]; Massive[q - 1] = Temp; } } } } int main() { setlocale(0, ""); short vvod=0; cout << "сколько структур создать ?"<<endl; cin >> vvod; allbase *obj =0; short yesornot = 0; for (size_t i = 0; i < vvod; i++) { obj = add_str(i, obj); fil_struct(i, obj); } do { yesornot = 0; cout << "Продолжить ввод данных (1 - да, 0 - нет): "; cin >> yesornot; cin.get(); if (yesornot == 1) { obj = add_str(vvod, obj); fil_struct(vvod, obj); vvod++; } else { fil_struct(vvod,obj); } } while (yesornot != 0); View_struct(&vvod,obj); cout << "хотите искать структуры по параметрам(1 - да, 0 - нет) ?" << endl; yesornot = 0; do { cin >> yesornot; cin.get(); if (yesornot == 1) { } } while (yesornot != 0); yesornot = 0; cout << "хотите упорядочить массив по имени(1 - да, 0 - нет) ?" << endl; cin >> yesornot; cin.get(); if (yesornot == 1) { SortFirstName(obj, vvod); View_struct(&vvod, obj); } return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines