Добавил:
vvrstcnho
Рад, если кому-то помог
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторные работы С++ (для ИВТ) / Готовые лабы С++ / Лаба5 / Laba 5 (1)
.cpp#include <iostream>
#include <string>
#include <locale>
using namespace std;
class Person {
protected:
string name;
int age;
public:
Person(const string& n, int a) : name(n), age(a) {}
virtual void print() const {
cout << "Имя: " << name << ", Возраст: " << age;
}
virtual ~Person() {}
};
class Student : public Person {
string group;
double gpa;
public:
Student(const string& n, int a, const string& g, double gpa_val)
: Person(n, a), group(g), gpa(gpa_val) {}
void print() const override {
Person::print();
cout << ", Группа: " << group << ", Средний балл: " << gpa << endl;
}
};
class Teacher : public Person {
string department;
string position;
public:
Teacher(const string& n, int a, const string& dep, const string& pos)
: Person(n, a), department(dep), position(pos) {}
void print() const override {
Person::print();
cout << ", Кафедра: " << department << ", Должность: " << position << endl;
}
};
int main() {
setlocale(LC_ALL, "ru_RU.UTF-8");
Student student("Иван Петров", 20, "ИС-21", 4.5);
Teacher teacher("Мария Сидорова", 45, "Информатики", "Доцент");
cout << "Студент: ";
student.print();
cout << "Преподаватель: ";
teacher.print();
return 0;
}
Соседние файлы в папке Лаба5
