Advertisement
Toliak

sus

Oct 12th, 2018
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. struct Subject {
  8.     string name;
  9.     unsigned short mark;
  10. };
  11.  
  12. struct Student {
  13.     string name;        // imya
  14.     string subname;     // otchestvo
  15.     string surname;     // familiya
  16.     Subject session[5];
  17. };
  18.  
  19. inline string maincraft(size_t s) {
  20.     const static string PATTERN = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
  21.     string str;
  22.     for (size_t i = 0; i < s; i++) {
  23.         str += PATTERN[rand() % PATTERN.length()];
  24.     }
  25.     return str;
  26. }
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30.     string subjectNames[] = { "Q", "W", "E", "R", "Bratishkin stream" };
  31.     std::cout << "Available subjects: (ID: Name)" << endl;
  32.     for (size_t i = 0; i < 5; i++ ) {
  33.         std::cout << i << ": " << subjectNames[i] << endl;
  34.     }
  35.     cout << endl;
  36.  
  37.     Student students[10];
  38.     cout << "Student ID Name Surname Subname Subjects(,,,,)" << endl;
  39.     for (size_t i = 0; i < 10; i++)
  40.     {
  41.         Student& s = students[i];
  42.         s.name = maincraft(5);
  43.         s.surname = maincraft(10);
  44.         s.subname = maincraft(6);
  45.         cout << "Student " << i
  46.             << " " << s.name
  47.             << " " << s.surname
  48.             << " " << s.subname;
  49.  
  50.         for (size_t j = 0; j < 5; j++) {
  51.             s.session[j].name = subjectNames[j];
  52.             s.session[j].mark = rand() % 6;
  53.             cout << " " << s.session[j].mark;
  54.         }
  55.         cout << endl;
  56.     }
  57.  
  58.     size_t subjectIndex;
  59.     std::cout << endl << "Enter subject ID: ";
  60.     std::cin >> subjectIndex;
  61.    
  62.     unsigned int sum = 0;
  63.     for (size_t i = 0; i < 10; i++) {
  64.         Student& s = students[i];
  65.         sum += s.session[subjectIndex].mark;
  66.     }
  67.  
  68.     std::cout << "Average: " << sum / 10. << std::endl;
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement