Advertisement
awsmpshk

Untitled

May 17th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. struct Student
  7. {
  8.   int group;
  9.   string F, I, O;
  10.   int year, marks[5];
  11.  
  12.   Student scanInfo(ifstream& in)
  13.   {
  14.     in >> group >> F >> I >> O >> year;
  15.     for (int i = 0; i < 5; ++i) in >> marks[i];
  16.   }
  17.  
  18.   void printInfo(ofstream& out)
  19.   {
  20.     out << group << " " << F << " " << I << " " << O << " ";
  21.     for (int i = 0; i < 5; ++i)
  22.     {
  23.       out << marks[i] << " ";
  24.     }
  25.   }
  26. };
  27.  
  28. // Пузырёк
  29. int main()
  30. {
  31.   ifstream in("input.txt");
  32.   ofstream out("output.txt");
  33.   int index = 0;
  34.   Student* base = new Student[100];
  35.   while (in.peek() != EOF)
  36.   {
  37.     base[index].scanInfo(in);
  38.     index++;
  39.   }
  40.   for (int i = 0; i < index - 1; i++)
  41.   {
  42.     for (int j = 0; j < index - i - 1; j++)
  43.     {
  44.       double cur_sum = (base[j].marks[0] + base[j].marks[1] + base[j].marks[2] + base[j].marks[3] + base[j].marks[4]) / 5;
  45.       double next_sum = (base[j + 1].marks[0] + base[j + 1].marks[1] + base[j + 1].marks[2] + base[j + 1].marks[3] + base[j + 1].marks[4]) / 5;
  46.       if (cur_sum < next_sum)
  47.       {
  48.           Student tmp = base[j];
  49.           base[j] = base[j + 1];
  50.           base[j+1] = tmp;
  51.       }
  52.     }
  53.   }
  54.   for (int i = 0; i < index; ++i)
  55.   {
  56.     double sum = (base[i].marks[0] + base[i].marks[1] + base[i].marks[2] + base[i].marks[3] + base[i].marks[4]) / 5;
  57.     base[i].printInfo(out);
  58.     out << sum << endl;
  59.   }
  60.   in.close();
  61.   out.close();
  62.   return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement