fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <locale>
  4. #include <exception>
  5. #include <algorithm>
  6. #include <functional>
  7. #include <cstdint>
  8.  
  9. class Stud
  10. {
  11. public:
  12. std::string surname;
  13. uint32_t semester;
  14. uint32_t marks[4];
  15.  
  16. constexpr static uint32_t min_semester = 1;
  17. constexpr static uint32_t max_semester = 20;
  18. constexpr static uint32_t min_mark = 0;
  19. constexpr static uint32_t max_mark = 10;
  20.  
  21. public:
  22. Stud() noexcept
  23. : surname("<-unknown->"), semester(min_semester)
  24. {
  25. std::fill_n(marks, 4, Stud::min_mark);
  26. }
  27.  
  28. void get() const;
  29. Stud(const Stud &St);
  30. void exam ();
  31. ~Stud() noexcept {}
  32. };
  33.  
  34. void Stud::exam()
  35. {
  36. std::cout << "Фамилия студента ";
  37. std::cin >> surname;
  38. if ( std::any_of( std::begin(surname), std::end(surname), std::not1(std::cref(::isalpha)) ) )
  39. throw std::runtime_error("Names can only contain letters");
  40.  
  41. do {
  42. std::cout << "Семестр студента ";
  43. std::cin.clear();
  44. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  45. } while ( !(std::cin >> semester) || semester < Stud::min_semester || semester > Stud::max_semester );
  46.  
  47. for (uint32_t i = 0; i < 4u; ++i) {
  48. do {
  49. std::cout << "Введите " << i + 1 << " оценку - ";
  50. std::cin.clear();
  51. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  52. } while ( !(std::cin >> marks[i]) || marks[i] < Stud::min_mark || marks[i] > Stud::max_mark );
  53. }
  54. std::cout << "=======ВВОД ЗАКОНЧЕН=======" << std::endl;
  55. }
  56.  
  57.  
  58. void Stud::get() const
  59. {
  60. std::cout << "Фамилия - " << surname << " " << std::endl;
  61. std::cout << "Оценки:" << std::endl;
  62. for (int i = 0; i < 4; i++)
  63. std::cout << "Оценка " << i + 1 << " равна " << marks[i] << std::endl;
  64. std::cout << "Семестр " << semester << std::endl;
  65. std::cout << "=====ВЫВОД ЗАКОНЧЕН========" << std::endl;
  66. }
  67.  
  68. Stud::Stud(const Stud &St)
  69. : surname(St.surname), semester(St.semester)
  70. {
  71. std::copy_n(St.marks, 4, marks);
  72. }
  73.  
  74. int main() {
  75. setlocale(LC_ALL, "RUS");
  76. Stud FIRST_TRY;
  77. FIRST_TRY.exam();
  78. FIRST_TRY.get();
  79. std::cout << "=====КОПИЯ СТУДЕНТА========" << std::endl;
  80. Stud SECOND_TRY(FIRST_TRY);
  81. SECOND_TRY.get();
  82. Stud STUDENTS_ARRAY[2];
  83. STUDENTS_ARRAY[0] = FIRST_TRY;
  84. STUDENTS_ARRAY[1] = SECOND_TRY;
  85. std::cout << "=====МАССИВ СТУДЕНТОВ======" << std::endl;
  86. for (int i = 0; i < 2; i++)
  87. STUDENTS_ARRAY[i].get();
  88. system("pause");
  89. return 0;
  90. }
  91.  
Success #stdin #stdout #stderr 0s 5052KB
stdin
Surname
5
1
2
3
4
5
stdout
Фамилия студента Семестр студента Введите 1 оценку - Введите 2 оценку - Введите 3 оценку - Введите 4 оценку - =======ВВОД ЗАКОНЧЕН=======
Фамилия - Surname 
Оценки:
Оценка 1 равна 1
Оценка 2 равна 2
Оценка 3 равна 3
Оценка 4 равна 4
Семестр 5
=====ВЫВОД ЗАКОНЧЕН========
=====КОПИЯ СТУДЕНТА========
Фамилия - Surname 
Оценки:
Оценка 1 равна 1
Оценка 2 равна 2
Оценка 3 равна 3
Оценка 4 равна 4
Семестр 5
=====ВЫВОД ЗАКОНЧЕН========
=====МАССИВ СТУДЕНТОВ======
Фамилия - Surname 
Оценки:
Оценка 1 равна 1
Оценка 2 равна 2
Оценка 3 равна 3
Оценка 4 равна 4
Семестр 5
=====ВЫВОД ЗАКОНЧЕН========
Фамилия - Surname 
Оценки:
Оценка 1 равна 1
Оценка 2 равна 2
Оценка 3 равна 3
Оценка 4 равна 4
Семестр 5
=====ВЫВОД ЗАКОНЧЕН========
stderr
sh: pause: not found