Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h> // SetConsoleCP, SetConsoleOutputCP
- #include <locale.h>
- #include <conio.h>
- #include <algorithm>
- #include <array>
- using namespace std;
- class Student {
- private:
- array<int, 3> score;
- int numberScorebook;
- string lastName;
- // int scoreAverage;
- public:
- Student() {}
- Student(string lastName, int numberScorebook, array<int, 3> score) {
- this->lastName = lastName;
- this->numberScorebook = numberScorebook;
- this->score = score;
- }
- void AddItemArray(Student* students, int size, int scoreSize)
- {
- array<int, 3> myarray1 = { 8, 6, 4 };
- array<int, 3> myarray2 = { 2, 1, 4 };
- array<int, 3> myarray3 = { 1, 2, 3 };
- array<int, 3> myarray4 = { 10, 6, 7 };
- array<int, 3> myarray5 = { 4, 2, 2 };
- array<int, 3> myarray6 = { 3, 4, 5 };
- students[0] = Student("Якимчук", 1, myarray1);
- students[1] = Student("Богданець", 2, myarray2);
- students[2] = Student("Мельник", 3, myarray3);
- students[3] = Student("Ступка", 4, myarray4);
- students[4] = Student("Макарець", 5, myarray5);
- students[5] = Student("Власик", 6, myarray6);
- }
- void GetArray(Student* students, int size, int scoreSize) {
- int temp[3];// = new int[scoreSize];
- int index = 0;
- for (int i = 0; i < size; i++)
- {
- cout << "Прізвище - " << students[i].lastName << ". Номер залікової книжки - " << students[i].numberScorebook << ". Оцінки - ";
- for (int j = 0; j < scoreSize; j++)
- {
- cout << students[i].score[j] << " ";
- }
- cout << endl;
- }
- }
- void AverageScore(Student* students, int size, int scoreSize) {
- //Double for loop
- //Bubble sort
- for (int i = 0; i < size - 1; i++) {
- for (int j = 0; j < size - 1; j++) {
- double averageScore1 = 0;
- double averageScore2 = 0;
- double sum1 = 0;
- double sum2 = 0;
- //averageScore for student[j]
- for (int k = 0; k < scoreSize; k++) {
- sum1 += students[j].score[k];
- }
- averageScore1 = sum1 / scoreSize;
- //averageScore for student[j+1]
- for (int k = 0; k < scoreSize; k++) {
- sum2 += students[j + 1].score[k];
- }
- averageScore2 = sum2 / scoreSize;
- if (averageScore2 > averageScore1) {
- Student temp = students[j + 1];
- students[j + 1] = students[j];
- students[j] = temp;
- }
- }
- }
- if (size > 5) size = 5;
- cout << endl << size << " студентів з найбільшим середнім балом:" << endl;
- GetArray(students, size, 3);
- }
- };
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- const int size = 6;
- Student c[size];
- c->AddItemArray(c, size, 3);
- c->GetArray(c, size, 3);
- c->AverageScore(c, size, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment