#include <iostream>
#include <string>
#include <locale>
#include <exception>
#include <algorithm>
#include <functional>
#include <cstdint>
class Stud
{
public:
std::string surname;
uint32_t semester;
uint32_t marks[4];
constexpr static uint32_t min_semester = 1;
constexpr static uint32_t max_semester = 20;
constexpr static uint32_t min_mark = 0;
constexpr static uint32_t max_mark = 10;
public:
Stud() noexcept
: surname("<-unknown->"), semester(min_semester)
{
std::fill_n(marks, 4, Stud::min_mark);
}
void get() const;
Stud(const Stud &St);
void exam ();
~Stud() noexcept {}
};
void Stud::exam()
{
std::cout << "Фамилия студента ";
std::cin >> surname;
if ( std::any_of( std::begin(surname), std::end(surname), std::not1(std::cref(::isalpha)) ) )
throw std::runtime_error("Names can only contain letters");
do {
std::cout << "Семестр студента ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} while ( !(std::cin >> semester) || semester < Stud::min_semester || semester > Stud::max_semester );
for (uint32_t i = 0; i < 4u; ++i) {
do {
std::cout << "Введите " << i + 1 << " оценку - ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} while ( !(std::cin >> marks[i]) || marks[i] < Stud::min_mark || marks[i] > Stud::max_mark );
}
std::cout << "=======ВВОД ЗАКОНЧЕН=======" << std::endl;
}
void Stud::get() const
{
std::cout << "Фамилия - " << surname << " " << std::endl;
std::cout << "Оценки:" << std::endl;
for (int i = 0; i < 4; i++)
std::cout << "Оценка " << i + 1 << " равна " << marks[i] << std::endl;
std::cout << "Семестр " << semester << std::endl;
std::cout << "=====ВЫВОД ЗАКОНЧЕН========" << std::endl;
}
Stud::Stud(const Stud &St)
: surname(St.surname), semester(St.semester)
{
std::copy_n(St.marks, 4, marks);
}
int main() {
setlocale(LC_ALL, "RUS");
Stud FIRST_TRY;
FIRST_TRY.exam();
FIRST_TRY.get();
std::cout << "=====КОПИЯ СТУДЕНТА========" << std::endl;
Stud SECOND_TRY(FIRST_TRY);
SECOND_TRY.get();
Stud STUDENTS_ARRAY[2];
STUDENTS_ARRAY[0] = FIRST_TRY;
STUDENTS_ARRAY[1] = SECOND_TRY;
std::cout << "=====МАССИВ СТУДЕНТОВ======" << std::endl;
for (int i = 0; i < 2; i++)
STUDENTS_ARRAY[i].get();
system("pause");
return 0;
}