Advertisement
Vla_DOS

16.2

Feb 23rd, 2023
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <Windows.h>
  5. #include <fstream>
  6. #include <sstream>
  7.  
  8. using namespace std;
  9.  
  10. struct Student
  11. {
  12.     string name;
  13.     int mark[4];
  14.  
  15. };
  16.  
  17. void PrintStudent(Student std);
  18. void PrintTable(Student stds[], int size);
  19. Student BestStudent(Student stds[], int size);
  20. void SaveData(Student stds[], int size);
  21. void LoadData(Student stds[], int size);
  22. int main()
  23. {
  24.     int size = 4;
  25.  
  26.     Student* stds = new Student[size];
  27.     SaveData(stds, size);
  28.     LoadData(stds, size);
  29.     cout << setw(11) << "# " << setw(15) << "Full name" << setw(13) << "  Math  " << setw(12) << "Programming" << setw(8) << " OS " << setw(13) << "Algebra &" << endl;
  30.     cout << setw(10) << " " << setw(16) << "         " << setw(13) << "          " << setw(12) << "      " << setw(8) << "    " << setw(13) << "Geometry" << endl;
  31.     cout << "         _______________________________________________________________" << endl;
  32.     PrintTable(stds, size);
  33.     BestStudent(stds, size);
  34.     delete[]stds;
  35. }
  36.  
  37. void PrintStudent(Student std)
  38. {
  39.     string name = "";
  40.     for (auto c : std.name)
  41.     {
  42.         if (c == '_') {
  43.             c = ' ';
  44.         }
  45.         name += c;
  46.     }
  47.     cout << setw(15) << name << setw(8);
  48.     for (int i = 0; i < 4; i++)
  49.     {
  50.         cout << std.mark[i] << setw(11);
  51.     }
  52.     cout << endl;
  53.  
  54. }
  55.  
  56. void PrintTable(Student stds[], int size)
  57. {
  58.     for (int i = 0; i < size; i++)
  59.     {
  60.         cout << setw(10) << i + 1 << ". ";
  61.         PrintStudent(stds[i]);
  62.     }
  63.  
  64.  
  65. }
  66. void SaveData(Student stds[], int size) {
  67.    
  68.     Student std = { "Ivanchuk_S.O", {4,5,3,4} };
  69.     Student std_1 = { "Panachenko_I.A", {5,4,4,5} };
  70.     Student std_2 = { "Zayec_I.M", {3,4,4,4} };
  71.     Student std_3 = { "Kravchenko_I.I",{3,5,4,5} };
  72.     stds[0] = std;
  73.     stds[1] = std_1;
  74.     stds[2] = std_2;
  75.     stds[3] = std_3;
  76.  
  77.     ofstream outfile("Out.txt");
  78.     for (int i = 0; i < size; ++i){
  79.         outfile << stds[i].name << " " ;
  80.         for (int j = 0; j < 4; ++j) {
  81.             outfile << stds[i].mark[j] << " ";
  82.         }
  83.         outfile << endl;
  84.     }
  85.     outfile.close();
  86. }
  87.  
  88. void LoadData(Student stds[], int size) {
  89.  
  90.     ifstream inputFile("Out.txt");
  91.  
  92.     if (!inputFile.is_open())
  93.     {
  94.         cout << "Помилка відкриття файлу!" << endl;
  95.     }
  96.  
  97.  
  98.     for (int i = 0; i < size; i++)
  99.     {
  100.         inputFile >> stds[i].name;
  101.         for (int j = 0; j < 4; j++)
  102.         {
  103.             inputFile >> stds[i].mark[j];
  104.         }
  105.     }
  106.     inputFile.close();
  107. }
  108.  
  109. Student BestStudent(Student stds[], int size)
  110. {
  111.     Student best = stds[0];
  112.     for (int i = 0; i < size; i++)
  113.     {
  114.  
  115.         if (stds[i].mark[1] > best.mark[1])
  116.         {
  117.             best = stds[i];
  118.         }
  119.     }
  120.     cout << "Best Student: " << endl;
  121.     for (int i = 0; i < size; i++)
  122.     {
  123.         if (stds[i].mark[1] == best.mark[1])
  124.         {
  125.             cout << stds[i].name << endl;
  126.         }
  127.     }
  128.     return best;
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement