Advertisement
Aleksandr_Grigoryev

Клык

Mar 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. const int WordLength = 21;
  9. const int SurnameLength = 16;
  10. const int NumberStudent = 15;
  11. const int NumberExams = 9;
  12. struct date
  13. {
  14.     int Day;
  15.     int Month;
  16.     int Year;
  17. };
  18. struct student
  19. {
  20.     char Surname[WordLength];
  21.     int Points;
  22. };
  23. struct exam
  24. {
  25.     int GroupNumber;
  26.     char SubjectName[WordLength];
  27.     char Surname[SurnameLength];
  28.     date Date;
  29.     student Students[15];
  30. };
  31. void A(string filename)
  32. {
  33.     exam Exam;
  34.     ifstream fin(filename, ios::binary);
  35.     int count = 0;
  36.     for (int i = 0; i < NumberExams; i++)
  37.     {
  38.         fin.read((char*)&Exam, sizeof(exam));
  39.         if (strcmp(Exam.SubjectName, "Информатика") == 0)
  40.         {
  41.             bool t = true;
  42.             for (int i = 0; i < NumberStudent && t; i++)
  43.             {
  44.                 if (Exam.Students[i].Points < 71) // Успешно >=71
  45.                 {
  46.                     t = false;
  47.                 }
  48.             }
  49.             if (t)
  50.                 count++;
  51.         }
  52.     }
  53.     cout << "Количество групп " << count;
  54.     cout << endl << endl;
  55. }
  56.  
  57.  
  58.  
  59. int main()
  60. {
  61.     setlocale(LC_ALL, "Russian");
  62.     ifstream fin("input.txt");
  63.     if (!fin.is_open())
  64.     {
  65.         cout << "Файл не найден ";
  66.     }
  67.     else
  68.     {
  69.         ofstream fout("input.bin", ios::binary);
  70.         while (fin.peek() != EOF)
  71.         {
  72.             exam Exam;
  73.             fin >> Exam.GroupNumber;
  74.             fin >> Exam.SubjectName;
  75.             fin >> Exam.Surname;
  76.             string str;
  77.             fin >> str;
  78.             int chislo = 0;
  79.             for (int i = 0; i < str.size(); i++)
  80.             {
  81.                 if (str[i] != '.')
  82.                 {
  83.                     chislo = chislo * 10 + str[i] - '0';
  84.                 }
  85.                 if (i == 3)
  86.                 {
  87.                     Exam.Date.Day = chislo;
  88.                     chislo = 0;
  89.                 }
  90.                 if (i == 6)
  91.                 {
  92.                     Exam.Date.Month = chislo;
  93.                     chislo = 0;
  94.                 }
  95.                 if (i == 8)
  96.                 {
  97.                     Exam.Date.Year = chislo;
  98.                 }
  99.             }
  100.             for (int i = 0; i < 15; i++)
  101.             {
  102.                 fin >> Exam.Students[i].Surname;
  103.                 fin >> Exam.Students[i].Points;
  104.             }
  105.             fout.write((char*)&Exam, sizeof(exam));
  106.         }
  107.         fin.close();
  108.         fout.close();
  109.         cout.setf(ios::left);
  110.         A("input.bin");
  111.    
  112.     }
  113.     system("pause");
  114.     return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement