1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
| // 4.1.cpp: главный файл проекта.
//#include <stdafx.h>
#include <iostream>
#include <string.h>
#include <locale>
//#include <conio.h>
using namespace std;
class car {
private:
char *drive;
int speed;
public:
car(char *, int);
virtual ~car();
void show_car(void);
car(const car &s);
};
car::car(char *drive, int speed) { // конструктор с параметрами
strcpy(car::drive, drive);
car::speed= speed;
};
void car::show_car(void) {
cout << " Привод=" << drive<<endl;
cout << " Скорость=" << speed<<" км/ч"<<endl;
};
car::~car(){ //деструктор
cout<<"деструктор удалил "<<speed<<"привод"<<endl;
//_getch();
};
car::car(const car &s) { // конструктор копирования
strcpy(drive, s.drive);
speed=s.speed;
}
class pas_transport{
private:
char* trans_m;
int pas_cap;
public:
pas_transport( char*, int);
void show_pas_transport(void);
virtual ~pas_transport();
};
pas_transport::pas_transport(char* trans_m, int pas_cap){// конструктор с параметрами
strcpy(pas_transport::trans_m, trans_m);
pas_transport::pas_cap=pas_cap;
}
pas_transport::~pas_transport(){//деструктор
cout<<"деструктор уничтожил коробку передач "<<trans_m<<endl;
//_getch();
}
// ввод/вывод
void pas_transport::show_pas_transport(void) {
cout << " Коробка передач="<<trans_m<<endl;
cout << " Пассажировместимость="<<pas_cap<<" человек"<<endl;
};
class bus:public car, public pas_transport {
private:
int length, weigth, heigth;
public:
bus(char*,int, char*, int, int, int, int);
void show_bus(void);
};
bus::bus(char* drive,int speed, char* trans_m,int pas_cap, int length, int weigth, int heigth):car(drive, speed), pas_transport(trans_m, pas_cap)
{
bus::length=length;
bus::weigth=weigth;
bus::heigth=heigth;
};
void bus::show_bus(void){
cout<<" Длина="<<length<<" м "<<endl;
cout<<" ширина="<<weigth<<" м"<<endl;
cout<<" Высота"<<heigth<<" м "<<endl;
show_car(); show_pas_transport();
}
int main() {
setlocale(0, "");
bus my_pc(" ДВС", 80, "РКП", 16, 20, 3, 4);
my_pc.show_bus();
// _getch();
} |