Добавил:
vvrstcnho
Рад, если кому-то помог
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторные работы С++ (для ИВТ) / Готовые лабы С++ / Лаба6 / Laba 6 (4)
.cpp#include <iostream>
#include <cstring>
#include <locale>
using namespace std;
class Transport {
char num[7]; // регистрационный номер
public:
Transport(const char* x = "B123MK") {
strcpy(num, x);
cout << "T constr\n";
}
virtual ~Transport() {
cout << "T destr\n";
}
virtual int h() {
return 0;
}
int g() {
return -1;
}
};
class Bus : public Transport {
int n; // номер маршрута
public:
Bus(const char* x, int nm) : Transport(x), n(nm) {
cout << "B constr\n";
}
Bus(const Bus& b) {
cout << "B copy\n";
}
~Bus() {
cout << "B destr\n";
}
int h() override {
return n;
}
int g() {
return -n;
}
};
void f(Transport* t1, Transport t2, Bus t3) {
cout << t1->h() << " and " << t1->g() << endl;
cout << t2.h() << " and " << t2.g() << endl;
cout << t3.h() << " and " << t3.g() << endl;
}
int main() {
setlocale(LC_ALL, "ru_RU.UTF-8");
Bus b("B123AA", 130);
f(&b, b, b);
cout << "end" << endl;
return 0;
}
Соседние файлы в папке Лаба6
