Advertisement
mashlukashova

Untitled

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