Advertisement
alexdmin

8.2

May 15th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. using namespace std;
  5. const int n = 100;
  6. fstream infile;
  7. fstream outfile;
  8. class studenty {
  9. public:
  10.     struct student {
  11.         string name;
  12.         int kurs;
  13.         int mark;
  14.     };
  15.     student u[n];
  16.     int l;
  17.     void vvod() {
  18.         int i, k;
  19.         cout << "Введите количество студентов" << endl;
  20.         cin >> k;
  21.         this->l = k;
  22.         for (i = 0; i < k; i++) {
  23.             cout << "Student №" << i + 1 << endl;
  24.             cout << "Имя" << endl;
  25.             cin >> u[i].name;
  26.             cout << "Курс" << endl;
  27.             cin >> u[i].kurs;
  28.             cout << "Оценка" << endl;
  29.             cin >> u[i].mark;
  30.         }
  31.     }
  32.     void update() {
  33.         int i = 0;
  34.         infile.open("file1.bin");
  35.         while (!infile.eof()) {
  36.             infile >> u[i].name;
  37.             infile >> u[i].kurs;
  38.             infile >> u[i].mark;
  39.             i++;
  40.         }
  41.         this->l = i;
  42.         infile.close();
  43.     }
  44.     void sohr() {
  45.         int i;
  46.  
  47.         outfile.open("file2.bin", ios::binary | ios::out);
  48.         for (i = 0; i < 6; i++) {
  49.             outfile << u[i].name;
  50.             outfile << u[i].kurs;
  51.             outfile << u[i].mark;
  52.             outfile.write(reinterpret_cast <char*> (&u), sizeof(&u));
  53.         }
  54.         //outfile.write(reinterpret_cast <char*> (&u), sizeof(int));
  55.         outfile.close();
  56.     }
  57.     void vyvod() {
  58.         int i;
  59.         for (i = 0; i < 6; i++) {
  60.             cout << "Student №" << i + 1 << endl;
  61.             cout << "Имя" << endl;
  62.             cout << u[i].name << endl;
  63.             cout << "Курс" << endl;
  64.             cout << u[i].kurs << endl;
  65.             cout << "Оценка" << endl;
  66.             cout << u[i].mark << endl;
  67.         }
  68.     }
  69. };
  70. int main()
  71. {
  72.     setlocale(LC_ALL, "rus");
  73.     int i, k, num = 0;
  74.     studenty b;
  75.     b.vvod();
  76.     b.sohr();
  77.     cout << "Enter kurs" << endl;
  78.     cin >> k;
  79.     b.update();
  80.     b.sohr();
  81.     for (i = 0; i < b.l; i++) {
  82.         if (b.u[i].kurs == k && b.u[i].mark < 4) num++;
  83.     }
  84.     cout << endl << "Количество неуспевающих студентов на k курсе:" <<  num+4 << endl;
  85.     b.vyvod();
  86.     system("pause");
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement