students-1.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Твой исходный файл
  2. #include <iostream>
  3. #include <string>
  4. #include <windows.h>
  5. using namespace std;
  6. struct Student
  7. {
  8. int mark;
  9. string name;
  10. };
  11. struct School
  12. {
  13. int number;
  14. };
  15. struct Score
  16. {
  17. double score;
  18. };
  19. class Journal
  20. {
  21. private:
  22. Student* students;
  23. School* schools;
  24. Score* scores;
  25. int NumberOfStudents = 0;
  26. int NOS = 0;
  27. int KolS = 0;
  28. int StudentData = 0;
  29. int AverageScore = 0;
  30. public:
  31. void NumOfSchool(int nos, int num)
  32. {
  33. NOS = nos;
  34. schools = new School[NOS];
  35. schools[KolS].number = num;
  36. KolS++;
  37. }
  38. void NumberOfStds(int kol)
  39. {
  40. NumberOfStudents = kol;
  41. students = new Student[NumberOfStudents];
  42. }
  43. void SetStds(string name, int mark)
  44. {
  45. students[StudentData].name = name;
  46. students[StudentData].mark = mark;
  47. StudentData++;
  48. }
  49. void SaR(double as)
  50. {
  51. scores = new Score[NOS];
  52. scores[AverageScore].score = as;
  53. }
  54. string Spisok()
  55. {
  56. string b;
  57. for (int i = 0; i < KolS; i++) {
  58. b = b + "Школа №: " + to_string(schools[i].number) + "\n";
  59. }
  60. return b;
  61. }
  62. string SpisokSt()
  63. {
  64. string sp;
  65. for (int i = 0; i < NumberOfStudents; i++) {
  66. sp = sp + " Фамилия: " + students[i].name + " Оценка: " + to_string(students[i].mark)+"\n";
  67. }
  68. return sp;
  69. }
  70. string AverScore()
  71. {
  72. string h;
  73. for (int i = 0; i < KolS; i++) {
  74. h = h + " Средний балл: " + to_string(scores[i].score)+"\n";
  75. }
  76. return h;
  77. }
  78. void Idol()
  79. {
  80. cout << "Фамилия ученика с баллом выше среднего: "<<"\n";
  81. string u;
  82. for (int i = 0; i < KolS; i++) {
  83. for (int j = 0; j < NumberOfStudents; j++) {
  84. if (scores[i].score < students[j].mark) {
  85. u = u +" | "+students[j].name+" | "+"\n";
  86. }
  87. }
  88. cout << u << "\n";
  89. }
  90. }
  91. };
  92. int main()
  93. {
  94. SetConsoleCP(1251);
  95. SetConsoleOutputCP(1251);
  96. setlocale(LC_ALL, "rus");
  97. int kolschool;
  98. int kolstudents;
  99. int numofschool;
  100. string familia;
  101. int mark;
  102. double averagescore = 0;
  103. cout << "Введите количество школ: ";
  104. cin >> kolschool;
  105. Journal* journals = new Journal[kolschool];
  106. for (int i = 0; i < kolschool; i++) {
  107. cout << "\nВведите номер школы: ";
  108. cin >> numofschool;
  109. journals[i].NumOfSchool(kolschool,numofschool);
  110. cout << "Введите количество учеников: ";
  111. cin >> kolstudents;
  112. journals[i].NumberOfStds(kolstudents);
  113. for (int j = 0; j < kolstudents; j++) {
  114. cout << "\nВведите фамилию для " << j + 1 << " ученика : ";
  115. cin >> familia;
  116. cout << "Введите оценку для " << j + 1 << " ученика : ";
  117. cin >> mark;
  118. journals[i].SetStds(familia, mark);
  119. averagescore += mark;
  120. }
  121. averagescore = averagescore / kolstudents;
  122. journals[i].SaR(averagescore);
  123. averagescore = 0;
  124. }
  125. for (int i = 0; i < kolschool; i++) {
  126. cout << "\n" << journals[i].Spisok();
  127. cout << "\n" << journals[i].SpisokSt();
  128. cout << "\n" << journals[i].AverScore();
  129. journals[i].Idol();
  130. }
  131. }