#include <iostream>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <functional>
#include <limits>
#include <clocale>
class Stud
{
public:
std::string surname;
std::size_t semester;
std::size_t marks[4];
static std::size_t const min_semester = 1;
static std::size_t const max_semester = 20;
static std::size_t const min_mark = 0;
static std::size_t const max_mark = 10;
public:
Stud()
: surname("<-unknown->"), semester(min_semester)
{
std::fill_n(marks, 4, Stud::min_mark);
}
void get() const;
Stud(const Stud &St);
void exam ();
~Stud() {}
};
void Stud::exam()
{
std::cout << "Фамилия студента ";
std::cin >> surname;
if ( std::find_if( surname.begin(), surname.end(), std::not1(std::ptr_fun(::isalpha)) ) != surname.end())
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 (std::size_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(St.marks, St.marks + 4, marks);
}
int main() {
std::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();
std::system("pause");
return 0;
}