Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #define MARKS_NUM 10
- using namespace std;
- class Tman
- {
- protected:
- string name;
- string surname;
- string patronymic;
- int dayOfBirth;
- int mounthOfBirth;
- int yearOfBirth;
- public:
- Tman()
- {
- this->name = "";
- this->surname = "";
- this->patronymic = "";
- this->dayOfBirth = 0;
- this->mounthOfBirth = 0;
- this->yearOfBirth = 0;
- }
- Tman(string newSurname, string newName, string newPatronymic,
- int newDayOfBirth, int newMounthOfBirth, int newYearOfBirth)
- {
- this->name = newName;
- this->surname = newSurname;
- this->patronymic = newPatronymic;
- this->dayOfBirth = newDayOfBirth;
- this->mounthOfBirth = newMounthOfBirth;
- this->yearOfBirth = newYearOfBirth;
- }
- int modifyMan()
- {
- cout<<"Новая фамилия ";
- cin>>this->surname;
- cout<<"Новое имя ";
- cin>>this->name;
- cout<<"Новое отчество ";
- cin>>this->patronymic;
- cout<<"Новый день рождения ";
- cin>>this->dayOfBirth;
- cout<<"Новый месяц рождения ";
- cin>>this->mounthOfBirth;
- cout<<"Новый год рождения ";
- cin>>this->yearOfBirth;
- return 0;
- }
- friend ostream &operator<<(ostream &stream, Tman* obj);
- friend istream &operator>>(istream &stream, Tman** obj);
- };
- istream &operator>>(istream &stream, Tman** obj)
- {
- *obj = new Tman;
- cout<<"Введите имя ";
- cin>>(*obj)->name;
- cout<<"Введите фамилию ";
- cin>>(*obj)->surname;
- cout<<"Введите отчество ";
- cin>>(*obj)->patronymic;
- cout<<"Введите день рождения ";
- cin>>(*obj)->dayOfBirth;
- cout<<"Введите месяц рождения ";
- cin>>(*obj)->mounthOfBirth;
- cout<<"Введите год рождения ";
- cin>>(*obj)->yearOfBirth;
- return stream;
- }
- ostream &operator<<(ostream &stream, Tman* obj)
- {
- cout<<"Фамилия "<<obj->surname<<" Имя "<<obj->name<<" Отчество "<<obj->patronymic<<endl;
- cout<<"Дата рождения: "<<obj->dayOfBirth<<"-"<<obj->mounthOfBirth<<"-"<<obj->yearOfBirth<<endl;
- return stream;
- }
- class Tstudent: Tman
- {
- private:
- int kurs;
- string groupName;
- int marks[MARKS_NUM];
- public:
- Tstudent()
- {
- this->kurs = -1;
- this->groupName = "";
- for(int i=0;i<MARKS_NUM;i++)
- this->marks[i] = 0;
- }
- Tstudent(string newSurname, string newName, string newPatronymic,
- int newDayOfBirth, int newMounthOfBirth, int newYearOfBirth,
- int newKurs, string newGroupName, int newMarks[MARKS_NUM]):
- Tman(newSurname,newName,newPatronymic,
- newDayOfBirth,newMounthOfBirth,newYearOfBirth)
- {
- this->kurs = newKurs;
- this->groupName = newGroupName;
- for(int i=0;i<MARKS_NUM;i++)
- this->marks[i] = newMarks[i];
- }
- float avgMarks()
- {
- int sum = 0;
- for(int i=0;i<MARKS_NUM;i++)
- sum+=this->marks[i];
- return sum/MARKS_NUM;
- }
- int modifyStudent()
- {
- this->modifyMan();
- cout<<"Введите новый курс ";
- cin>>this->kurs;
- cout<<"Введите новую группу ";
- cin>>this->groupName;
- cout<<"Введите новые оценки"<<endl;
- for(int i=0;i<MARKS_NUM;i++)
- cin>>this->marks[i];
- return 0;
- }
- friend ostream &operator<<(ostream &stream, Tstudent* obj);
- friend istream &operator>>(istream &stream, Tstudent** obj);
- };
- istream &operator>>(istream &stream, Tstudent** obj)
- {
- *obj = new Tstudent;
- cout<<"Введите имя ";
- cin>>(*obj)->name;
- cout<<"Введите фамилию ";
- cin>>(*obj)->surname;
- cout<<"Введите отчество ";
- cin>>(*obj)->patronymic;
- cout<<"Введите день рождения ";
- cin>>(*obj)->dayOfBirth;
- cout<<"Введите месяц рождения ";
- cin>>(*obj)->mounthOfBirth;
- cout<<"Введите год рождения ";
- cin>>(*obj)->yearOfBirth;
- cout<<"Введите номер курса ";
- cin>>(*obj)->kurs;
- cout<<"Введите название группы ";
- cin>>(*obj)->groupName;
- cout<<"Введите "<<MARKS_NUM<<" оценок"<<endl;
- for(int i=0;i<MARKS_NUM;i++)
- cin>>(*obj)->marks[i];
- return stream;
- }
- ostream &operator<<(ostream &stream, Tstudent* obj)
- {
- cout<<"Фамилия "<<obj->surname<<" Имя "<<obj->name<<" Отчество "<<obj->patronymic<<endl;
- cout<<"Дата рождения: "<<obj->dayOfBirth<<"-"<<obj->mounthOfBirth<<"-"<<obj->yearOfBirth<<endl;
- cout<<"Курс: "<<obj->kurs<<endl;
- cout<<"Группа: "<<obj->groupName<<endl;
- cout<<"Оценки: ";
- for(int i=0;i<MARKS_NUM;i++)
- cout<<obj->marks[i]<<" ";
- cout<<endl;
- return stream;
- }
- int main()
- {
- setlocale(LC_ALL,"RU");
- Tman* man = new Tman("ivanov","ivan","ivanovich",1,1,1991);
- cout<<man;
- int mark[MARKS_NUM] = {5,4,5,4,5,4,5,4,5,4};
- Tstudent* student = new Tstudent("petrov","petr","petrovich",1,1,1996,3,"PMII",mark);
- cout<<student;
- cout<<"Средний балл: "<<student->avgMarks()<<endl;
- cout<<"Изменение информации о человеке"<<endl;
- man->modifyMan();
- cout<<"Изменение информации о студенте"<<endl;
- student->modifyStudent();
- cout<<man;
- cout<<student;
- cout<<"Средний балл: "<<student->avgMarks();
- Tman* newMan = new Tman;
- Tstudent* newStudent = new Tstudent;
- cin>>&newMan;
- cin>>&newStudent;
- cout<<newMan;
- cout<<newStudent;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement