mashlukashova

Untitled

Mar 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. const int kolichestvo = 2;
  8. const int D = 3;
  9. const int n = 2;
  10.  
  11. struct ZNAK {
  12.     char name[20];
  13.     char surname[30];
  14.     string znak;
  15.     int date[D];
  16. };
  17. void meny(int &n);
  18.  
  19. void fank2(int *A);
  20.  
  21. void search(ZNAK *m, const int kolichestvo);
  22.  
  23. void fank(ZNAK *A,const int n);
  24.  
  25. void fillstruct(ZNAK *m, const int kolichestvo, const int D);
  26.  
  27. void showstruct(ZNAK *m, const int kolichestvo, const int D);
  28.  
  29. int main(){
  30.     setlocale(LC_ALL, "rus");
  31.     int choice = 0;
  32.     ZNAK m[kolichestvo];
  33.    
  34.     //fillstruct(m, kolichestvo, D);
  35.      //meny(choice);
  36.     while (choice != 4) {
  37.        // cin >> choice;
  38.         meny(choice);
  39.         if (choice == 1) {
  40.     fillstruct(m, kolichestvo, D);
  41.               fank(m, n);
  42.             }
  43.        
  44.        
  45.         if (choice == 3) {
  46.             for (int i = 0; i < n; i++) {
  47.                 cout << m[i].name << " ";
  48.                 cout << m[i].surname << " "<<endl;
  49.                 cout << m[i].znak << endl;
  50.                 for (int j = 0; j < 3; j++) {
  51.                     cout << m[i].date[j] << " ";
  52.                 }
  53.                 cout << endl;
  54.             }
  55.            
  56.         }
  57.         if (choice == 2) {
  58.             search(m, kolichestvo);
  59.             system ("pause");
  60.         }
  61.     if (choice == 4) break;
  62.     }
  63.         cout << "Завершение программы...";
  64.     }
  65.  
  66.  
  67.  
  68. void meny(int &n) {
  69.     system("cls");
  70.     cout << setw(15) << "****Меню****"<<endl<<endl;
  71.     cout << setw(3) << "1) Ввести данные" << endl;
  72.     cout << setw(3) << "2) найти человека " << endl;
  73.     cout << setw(3) << "3) Вывести данные" << endl;
  74.     cout << setw(3) << "4) Выход" << endl;
  75.     cin >> n;
  76. }
  77.  
  78.  
  79. void fillstruct(ZNAK *m, const int kolichestvo, const int D){
  80.     for (int i = 0; i < kolichestvo; i++){
  81.         cout << "input name and surname: ";
  82.         cin >> m[i].name;
  83.         cin >> m[i].surname;
  84.        
  85.         cout << "input Zodiac sign: ";
  86.         cin >> m[i].znak;
  87.        
  88.         cout << "input date: ";
  89.         fank2(m[i].date);
  90.     }
  91. }
  92.  
  93. void fank2(int *A) {
  94.     for (int i=0; i < 3; i++) {
  95.         cin >> A[i];
  96.     }
  97. }
  98.  
  99. void fank(ZNAK *A,const int n)
  100. {
  101.     ZNAK P;
  102.     for(int i=0;i<n;i++){
  103.         for (int j = 0; j < n; j++) {
  104.             if (A[i].date[3] > A[j].date[3]||
  105.                 (A[i].date[3] == A[j].date[3]&& A[i].date[2] > A[j].date[2])||
  106.                 (A[i].date[3] == A[j].date[3] && A[i].date[2] == A[j].date[2]&& A[i].date[1] > A[j].date[1])) {
  107.                 P = A[j];
  108.                 A[j] = A[i];
  109.                 A[i] = P;
  110.             }
  111.         }
  112.     }
  113. }
  114.  
  115.  
  116. /*void search(ZNAK *m, const int kolichestvo){
  117.     char surname_temp[20];
  118.     int temp = 0;
  119.     cout << "input surname temp: " << endl;
  120.     cin.getline(surname_temp, 20);
  121.     for(int i = 0; i < kolichestvo; i++){
  122.         if (m[i].surname == surname_temp) {
  123.             cout << m[i].name << " "<< m[i].surname << endl << m[i].znak << endl;
  124.             for (int j = 0; j < 3; j++){
  125.                 cout << m[i].date[j] << " ";
  126.             }
  127.             cout << endl;
  128.             break;
  129.         }
  130.         temp ++;
  131.     }
  132.     if (temp == kolichestvo) cout << " no pearsons " << endl;
  133.  
  134. }*/
  135.  
  136. void search(ZNAK *m, const int kolichestvo){
  137.     char surname1[20];
  138.    
  139.     for ( int l = 0; l < 20; l++ )
  140.         surname1[l]=NULL;
  141.    
  142.     cout<<"Enter needed surname: ";
  143.     cin >> surname1;
  144.    
  145.     bool r = false;
  146.    
  147.     for ( int k = 0; k < kolichestvo; k++ )
  148.     {
  149.         bool b = true;
  150.         int l = 0;
  151.        
  152.         while ( surname1[l] != NULL)
  153.         { if (surname1[l] != m[k].surname[l]) b = false; l++;
  154.         }
  155.         if (surname1[l] != m[k].surname[l]) b = false;
  156.        
  157.         if ( b == true  )
  158.         {
  159.             cout << m[k].name << " " << m[k].surname << endl << m[k].znak << endl;
  160.             for (int j = 0; j < 3; j++){
  161.                
  162.                 cout << m[k].date[j] << " ";
  163.             }
  164.             cout << endl;
  165.             cout<<"--------------------------------------------------"<<endl;
  166.             r = true;
  167.         }
  168.     }
  169.     if ( r == false ) cout<<"No match person"<<endl;
  170.     system("pause");
  171.    
  172. }
Add Comment
Please, Sign In to add comment