Advertisement
kxcoze

satie_15_2

Jun 25th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string>
  4. #include <windows.h>
  5. #include <conio.h>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. struct CIVILIAN {
  11.     char surname[13];
  12.     char district[15];
  13.     char social[15];
  14.     double value;
  15. };
  16.  
  17. short menu();
  18. void input(CIVILIAN* x, int &pc, int &max);
  19. void inputInFile(CIVILIAN* x, int &pc, int &max);
  20. void list();
  21. void list2(int &pc, int &max);
  22.  
  23. int main() {
  24.     SetConsoleCP(1251);
  25.     SetConsoleOutputCP(1251);
  26.     setlocale(LC_ALL, "Rus");
  27.     int max = 0, pc = 0;
  28.     short choice;
  29.     CIVILIAN *group = new CIVILIAN;
  30.  
  31.     do {
  32.         choice = menu();
  33.         switch (choice) {
  34.         case 1:
  35.             system("cls");
  36.             inputInFile(group, pc, max);
  37.             _getch();
  38.             system("cls");
  39.             break;
  40.         case 2:
  41.             system("cls");
  42.             list();
  43.             _getch();
  44.             system("cls");
  45.             break;
  46.         case 3:
  47.             system("cls");
  48.             list2(pc, max);
  49.             _getch();
  50.             system("cls");
  51.             break;
  52.         case 0:
  53.             cout << "Goodbye!" << endl;
  54.             system("pause");
  55.             break;
  56.         default:
  57.             cout << "Error!" << endl;
  58.             cout << "\n\nPress Enter..." << endl;
  59.             _getch();
  60.             system("cls");
  61.             break;
  62.         }
  63.     } while (choice);
  64.  
  65.     delete group;
  66.     system("pause");
  67.     return 0;
  68. }
  69.  
  70. short menu() {
  71.     short m;
  72.     cout << " МЕНЮ \n";
  73.     cout << " Введите [1] чтобы добавить вкладчика \n";
  74.     cout << " Введите [2] для просмотра введенных данных о вкладчиках \n";
  75.     cout << " Введите [3] для просмотра введенных данных о служащих вкладчиках \n";
  76.     cout << " Введите [0] для выхода \n";
  77.     cout << " Пункт: ";
  78.     cin >> m;
  79.     return m;
  80. }
  81.  
  82. void inputInFile(CIVILIAN* x, int &pc, int &max) {
  83.     input(x, pc, max);
  84.     FILE* pFile;
  85.     fopen_s(&pFile, "datebase.dat", "a+");
  86.     system("pause");
  87.     cout << "\n\nФамилия вкладчика: " << x->surname << endl;
  88.     cout << "Район: " << x->district << endl;
  89.     cout << "Социальное положение: " << x->social << endl;
  90.     cout << "Величина вклада: " << x->value << endl;
  91.     fwrite(x, sizeof(CIVILIAN), 1, pFile);
  92.     cout << "Ваши данные теперь находятся в файле.";
  93.     fclose(pFile);
  94. }
  95.  
  96. void input(CIVILIAN* x, int &pc, int &max) {
  97.     cin.ignore();
  98.  
  99.     cout << "Фамилия вкладчика: ";
  100.     cin.getline(x->surname, 13);
  101.    
  102.     cout << "Район: ";
  103.     cin.getline(x->district, 15);
  104.    
  105.     cout << "Социальное положение: ";
  106.     cin.getline(x->social, 15);
  107.    
  108.  
  109.     cout << "Величина вклада: ";
  110.     cin >> x->value;
  111.  
  112.     if (strcmp(x->social, "Служащий") == 0) {
  113.         pc++;
  114.         max += x->value;
  115.     }
  116. }
  117.  
  118. void list() {
  119.     CIVILIAN* group = new CIVILIAN;
  120.     FILE* pFile;
  121.     int i = 1;
  122.     fopen_s(&pFile, "datebase.dat", "r+");
  123.  
  124.     cout << "ТАБЛИЦА О ВКЛАДЧИКАХ:\n";
  125.     while (!feof(pFile)) {
  126.         fread(group, sizeof(CIVILIAN), 1, pFile);
  127.         if (!feof(pFile)) {
  128.             cout << i++ << ": " << endl;
  129.             cout << "\tФамилия: " << group->surname << endl;
  130.             cout << "\tРайон: " << group->district << endl;
  131.             cout << "\tСоц.положение: " << group->social << endl;
  132.             cout << "\tВеличина вклада: " << group->value << endl;
  133.         }
  134.     }
  135.  
  136.     system("pause");
  137.     delete group;
  138.     fclose(pFile);
  139. }
  140.  
  141. void list2(int &pc, int &max) {
  142.     CIVILIAN* group = new CIVILIAN;
  143.     FILE* pFile;
  144.     int i = 1;
  145.     fopen_s(&pFile, "datebase.dat", "r+");
  146.  
  147.     cout << "ТАБЛИЦА О CЛУЖАЩИХ ВКЛАДЧИКАХ:\n";
  148.     while (fread(group, sizeof(CIVILIAN), 1, pFile) == 1) {
  149.         if (strcmp(group->social, "Служащий") == 0) {
  150.             cout << i++ << ": " << endl;
  151.             cout << "\tФамилия: " << group->surname << endl;
  152.             cout << "\tРайон: " << group->district << endl;
  153.             cout << "\tСоц.положение: " << group->social << endl;
  154.             cout << "\tВеличина вклада: " << group->value << endl;
  155.         }
  156.     }
  157.     cout << "Количество служащих: " << pc << endl;
  158.     cout << "Суммарный вклад служащих: " << max << endl;
  159.  
  160.     delete group;
  161.     fclose(pFile);
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement