Vla_DOS

Untitled

Sep 20th, 2022 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>  // SetConsoleCP, SetConsoleOutputCP
  3. #include <locale.h>
  4. #include <conio.h>
  5. #include <algorithm>
  6. #include <array>
  7.  
  8. using namespace std;
  9. #define і i
  10.  
  11. class Student {
  12. private:
  13.     array<int, 3> score;
  14.     int numberScorebook;
  15.     string lastName;
  16. public:
  17.     Student(){}
  18.  
  19.     Student(string lastName, int numberScorebook, array<int, 3> score) {
  20.         this->lastName = lastName;
  21.         this->numberScorebook = numberScorebook;
  22.         this->score = score;
  23.     }
  24.  
  25.     void AddItemArray(Student* students, int size, int scoreSize)
  26.     {
  27.         array<int, 3> myarray1 = { 8, 6, 4 };
  28.         array<int, 3> myarray2 = { 2, 1, 4 };
  29.         students[0] = Student("q", 1, myarray1);
  30.         students[1] = Student("w", 2, myarray2);
  31.         //int* score = new int[scoreSize];
  32.         //int numberScorebook;
  33.         //string lastName;
  34.         //int j = 0;
  35.         //for (int i = 0; i < size; i++)
  36.         //{
  37.         //    cout << "Прізвище: ";
  38.         //    cin >> lastName;
  39.  
  40.         //    cout << "Номер залікової книжки: ";
  41.         //    cin >> numberScorebook;
  42.  
  43.         //    cout << "Оцінки: ";
  44.         //    for (j = 0; j < scoreSize; j++)
  45.         //    {
  46.         //        cin >> score[j];
  47.         //    }
  48.         //    j = 0;
  49.         //    students[i] = Student(lastName, numberScorebook, score);
  50.         //}
  51.     }
  52.  
  53.     void GetArray(Student* students, int size, int scoreSize) {
  54.  
  55.         int temp[3];// = new int[scoreSize];
  56.         int index = 0;
  57.         for (int i = 0; i < size; i++)
  58.         {
  59.             cout << "Прізвище - " << students[i].lastName << ". Номер залікової книжки - " << students[i].numberScorebook << ". Оцінки - ";
  60.             for (int j = 0; j < scoreSize; j++)
  61.             {
  62.                
  63.                 cout << students[i].score[j] << " ";
  64.             }
  65.             cout << endl;
  66.         }
  67.     }
  68.  
  69.     void AverageScore(Student* students, int size, int scoreSize) {
  70.         int* tempScore = new int[scoreSize];
  71.         int* tempAverage = new int[size];
  72.         int index = 0;
  73.         int averageScore = 0, sum = 0;
  74.         int j = 0;
  75.         for (int i = 0; i < size; i++)
  76.         {
  77.             cout << "Прізвище - " << students[i].lastName << ". Номер залікової книжки - " << students[i].numberScorebook << ". Оцінки - ";
  78.  
  79.             for (j = 0; j < scoreSize; j++)
  80.             {
  81.                 tempScore[j] = students[i].score[j];
  82.                 cout << tempScore[j] << " ";
  83.                 sum += tempScore[j];
  84.             }
  85.             //j = 0;
  86.             averageScore = sum / scoreSize;
  87.             tempAverage[i] += averageScore;
  88.             // if(students[i].score[j])
  89.  
  90.  
  91.             cout << endl;
  92.         }
  93.         sort(tempAverage, tempAverage + size);
  94.         for (int i = 0; i < size; i++)
  95.         {
  96.             for (j = 0; j < scoreSize; j++)
  97.             {
  98.                 //tempScore[j] = students[i].score[j];
  99.                 cout << tempScore[j] << " ";
  100.                 sum += tempScore[j];
  101.             }
  102.         }
  103.     }
  104.    
  105.  
  106. };
  107.  
  108. int main() {
  109.     SetConsoleCP(1251);
  110.     SetConsoleOutputCP(1251);
  111.     const int size = 2;
  112.     Student c[size];//= new Student[size];
  113.  
  114.  
  115.     c->AddItemArray(c, size, 3);
  116.  
  117.     c->GetArray(c, size, 3);
  118.  
  119.     c->AverageScore(c, size, 3);
  120.     c->GetArray(c, size, 3);
  121.  
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment