Advertisement
xotohop

struct_table

Apr 15th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #define SIZE 4
  4.  
  5. using namespace std;
  6.  
  7. struct node
  8. {
  9.     string group;
  10.     string surname;
  11.     short subjects[5];
  12. };
  13.  
  14. int main()
  15. {
  16.     node table[SIZE];
  17.  
  18.     for (int i = 0; i < SIZE; i++)
  19.     {
  20.         cout << "Group: "; cin >> table[i].group;
  21.         cout << "Surname: "; cin >> table[i].surname;
  22.         for (int n = 0; n < 5; n++)
  23.         {
  24.             table[i].subjects[n] = rand() % 3 + 2;
  25.             cout << "Subject " << n + 1 << ": " << table[i].subjects[n] << endl;
  26.         }
  27.     }
  28.    
  29.     cout << endl << "Underperforming students" << endl;
  30.    
  31.     for (int i = 0; i < SIZE; i++)
  32.     {
  33.         int debt = 0;
  34.         for (int n = 0; n < 5; n++)
  35.             if (table[i].subjects[n] == 2)
  36.                 debt++;
  37.         if (debt)
  38.         {
  39.             cout << table[i].group << " ";
  40.             cout << table[i].surname << endl;
  41.             cout << "Debts: " << debt << endl << endl;
  42.         }
  43.         debt = 0;
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement