YT_o4ka

Untitled

Apr 26th, 2022
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. struct predm {
  8.     char name[20];
  9.     int mark;
  10. };
  11. struct session {
  12.     int predm_co;
  13.     predm p[10];
  14. };
  15.  
  16. struct student {
  17.     char fam[20];
  18.     char im[20];
  19.     char ot[20];
  20.     int b_day;
  21.     int b_month;
  22.     int b_year;
  23.     int year_apply;
  24.     char kaf[20];
  25.     char group[20];
  26.     int zachetka;
  27.     int sess_co;
  28.     session s[10];
  29. };
  30.  
  31. class input {
  32. public:
  33.     // int count;
  34.     // void in_count() { cout << "введите число студентов"; cin >> count; }
  35.     char key;
  36.     void switcher_in() {
  37.    
  38.         cout << " ---МЕНЮ---\n Введите k для ввода информации о студенте \n Для выхода введите e \n Для просмотра информации, которую вы ввели, нажмите r"<< endl;
  39.         cin >> key;
  40.     }
  41. };
  42.  
  43.  
  44.  
  45. class f : public virtual input {
  46.    
  47. public:
  48.     FILE* ou;
  49.     int s = 0;
  50.  
  51.     void f_in() {
  52.     fopen_s(&ou, "flilk", "wb");
  53.     struct student chel;
  54.     for (; 1;) {
  55.         cout << "\n вы собираетесь вводить ? Для продолжения выберите нужный вариант \n 1 -  для продолжения ввода \n 0 - для выхода 1/0\n";
  56.         cin >> s;
  57.         if (!s) break;
  58.         cout << "Введите имя, фамилию и отчество студента " << endl;
  59.         cin >> chel.im >> chel.fam >> chel.ot;
  60.         cout << "Введите дату рожедния студента, день, месяц и год " << endl;
  61.         cin >> chel.b_day >> chel.b_month >> chel.b_year;
  62.         cout << "Введите кафедру, номер груммы и номер зачётки студента " << endl;
  63.         cin >> chel.kaf >> chel.group >> chel.zachetka;
  64.         cout << "Введите количество СЕССИЙ, по которым вы хотите ввести информацию по данному студенту " << endl;
  65.         cin >> chel.sess_co;
  66.         for (int i = 0; i < chel.sess_co; i++) {
  67.             cout << "Введите количество предметов в "<< chel.sess_co<< " сессии, по которым вы хотите ввести данные этой сессии " << endl;
  68.             cin >> chel.s[i].predm_co;
  69.             for (int j = 0; j < chel.s[i].predm_co; j++) {
  70.                 cout << "Введите название предмета, а затем оценку по нему" << endl;
  71.                 cin >> chel.s[i].p[j].name >> chel.s[i].p[j].mark;
  72.             }
  73.         }
  74.            
  75.     }
  76.     cout << "Введёная вами информация сохраняется в файл";
  77.         fwrite(&chel, sizeof(chel), 1, ou);
  78.         fclose(ou);
  79.         cout << "Введённая вами информация была успешно осхранена в файл";
  80.     }
  81. };
  82. class read : public virtual f{
  83. public:
  84.     void f_read() {
  85.         struct student chel;
  86.         fopen_s(&ou, "flilk", "rb");
  87.         fread(&chel, sizeof(chel), 1, ou);
  88.         while (!feof(ou)) {
  89.             cout << " ФИО студента " << chel.im << "  " << chel.fam << "  " << chel.ot << endl;
  90.             cout << " Дата рождения студента " << chel.b_day << "  " << chel.b_month << "  " << chel.b_year << endl;
  91.             cout << " Кафедра, номер группы и зачётки " << chel.kaf << "  " << chel.group << "  " << chel.zachetka << endl;
  92.             cout << " Количество ссесий " << chel.sess_co << endl;
  93.             for (int i = 0; i < chel.sess_co; i++) {
  94.                 cout << " Количество предметов данной сессии " << endl;
  95.                 cout << chel.s[i].predm_co << endl;
  96.                 for (int j = 0; j < chel.s[i].predm_co; j++) {
  97.                     cout << "Название предмета и оценка" << endl;
  98.                     cout << chel.s[i].p[j].name <<"  " << chel.s[i].p[j].mark << endl;
  99.                 }
  100.             }
  101.             fread(&chel, sizeof(chel), 1, ou);
  102.         }
  103.  
  104.     }
  105. };
  106.  
  107. int main()
  108. {
  109.     SetConsoleCP(1251);
  110.     SetConsoleOutputCP(1251);
  111.  
  112.     read func;
  113.     func.switcher_in();
  114.     while (func.key != 'e') {
  115.         switch (func.key) {
  116.         case 'k': {func.f_in(); break; }
  117.         case 'r': func.f_read();
  118.         }
  119.         func.switcher_in();
  120.     }
  121.     //func.f_save();
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment