Advertisement
kxcoze

cringe_unknown

Jun 28th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct CIVILIAN {
  6.     char surname[13];
  7.     char district[15];
  8.     char social[15];
  9.     double value;
  10. };
  11.  
  12. using namespace std;
  13.  
  14. int main() {
  15.     setlocale(LC_ALL, "Rus");
  16.     int max = 0;
  17.     short choise;
  18.     FILE *fp;
  19.     CIVILIAN *group = new CIVILIAN;
  20.     bool k = false;
  21.     do {
  22.         cout << "\nМЕНЮ: \n";
  23.         cout << "1.Добавить вкладчика.\n";
  24.         cout << "2.Таблица вкладчиков.\n";
  25.         cout << "3.Служащие вкладчики.\n";
  26.         cout << "0.Выход.\n";
  27.         cout << "Выбор : ";
  28.         cin >> choise;
  29.         if (choise == 1) {
  30.             system("cls");
  31.             fp = fopen("test.dat", "ab");
  32.             cin.ignore();
  33.             cout << "Фамилия : ";
  34.             cin.getline(group->surname, 13);
  35.             cout << "Район : ";
  36.             cin.getline(group->district, 15);
  37.             cout << "Соц.положение : ";
  38.             cin.getline(group->social, 15);
  39.             cout << "величина вклада : ";
  40.             cin >> group->value;
  41.             k = true;
  42.             fwrite(group, sizeof(CIVILIAN), 1, fp);
  43.             fclose(fp);
  44.             system("cls");
  45.         }
  46.         if ((choise == 2) && (k)) {
  47.             system("cls");
  48.             max = 0;
  49.             int pc = 0;
  50.             fp = fopen("test.dat", "rb");
  51.             while (!feof(fp)) {
  52.                 fread(group, sizeof(CIVILIAN), 1, fp);
  53.                 if (!feof(fp)) {
  54.                     cout << "ТАБЛИЦА О ВКЛАДЧИКАХ ::\n";
  55.                     cout << "\tФамилия : " << group->surname << endl;
  56.                     cout << "\tРайон : " << group->district << endl;
  57.                     if (strcmp(group->social, "Служащий") == 0) pc++;
  58.                     cout << "\tСоц.положение : " << group->social << endl;
  59.                     cout << "\tВеличина вклада : " << group->value << endl;
  60.                     cout << "\nКоличество служащих : " << pc << endl;
  61.                 }
  62.             }
  63.             system("pause");
  64.             fclose(fp);
  65.         }
  66.         if ((choise == 3) && (k)) {
  67.             fp = fopen("test.dat", "rb");
  68.             while (fread(group, sizeof(CIVILIAN), 1, fp) == 1) {
  69.                 if (strcmp(group->social, "Служащий") == 0) {
  70.                     cout << "ТАБЛИЦА О ВКЛАДЧИКАХ ::\n";
  71.                     cout << "\tФамилия : " << group->surname << endl;
  72.                     cout << "\tРайон : " << group->district << endl;
  73.                     cout << "\tСоц.положение : " << group->social << endl;
  74.                     cout << "\tВеличина вклада : " << group->value << endl;
  75.                 }
  76.             }
  77.             fclose(fp);
  78.         }
  79.     } while (choise);
  80.  
  81.     delete group;
  82.     system("pause");
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement