Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
 
Рейтинг 4.77/48: Рейтинг темы: голосов - 48, средняя оценка - 4.77
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562

C++ ООП

27.06.2010, 00:26. Показов 9197. Ответов 36
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Просьба дать какую-нибудь интересную программу, дабы теста на курс ООП. Чтобы не из книжки, а реально придуманная про программистом, или начинающим) Зоопарк как предложили парню недавно не предлагать, ибо будет неинтересно) Заранее спасибо. Мне нужна только задача, а не сама программа)
0
IT_Exp
Эксперт
34794 / 4073 / 2104
Регистрация: 17.06.2006
Сообщений: 32,602
Блог
27.06.2010, 00:26
Ответы с готовыми решениями:

ООП
Привет всем, народ дайте какую-нибудь интересную задачку на ООП, (однообразные задачи из учебников достали уже), чтоб она затрагивала как...

ООП
Всем привет! Если можно, не могли бы вы ответить на пару вопросов по ООП, а то что-то не могу понять. Вопросы: Зачем используются такие...

ооп
Нада книгу по ооп, такую что бы было все разжевано максимально. Так, что бы я за минимум времени и усилий разобрался.

36
27.06.2010, 22:40
Студворк — интернет-сервис помощи студентам

Не по теме:

Цитата Сообщение от Хохол Посмотреть сообщение
какой нить мерс да запорожец, пусть они оба умеют делать какоенить действие (виртуальный метод класса car), но по-разному (две различные реализации в соответствующих классах).
Ага... В мерине сигнализация с пульта включается, а в запорожце собаку в салоне запирают... :D

1
Эксперт С++
 Аватар для Хохол
476 / 444 / 34
Регистрация: 20.11.2009
Сообщений: 1,293
27.06.2010, 22:47
Ну так пропишем это в реализации!
0
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
27.06.2010, 22:58  [ТС]
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//Классы
#include <iostream>
const std::string CarName("Car");
const std::string TruckName("Truck");
const std::string CarFuel("Benzin");
const std::string TruckFuel("Dizel");
const std::string ExitFer("Не вылетает");
const std::string ExitLada("Через лобовое стекло");
const int CarNum=4;
const int TruckNum=2;
class Transport
{
protected:
        std::string name;//Название транс средства
        double max_speed;//Максимальная скорость
        int num;//Колличество пассажиров
        int year;//Год выпуска
public:
        Transport(std::string _name, double _max_speed, int _num, int _year):name(_name),max_speed(_max_speed),
                num(_num), year(_year){}
        virtual ~Transport(){}
        virtual std::string GetName() const=0;
        double GetSpeed() const{return max_speed;}
        virtual int GetNum() const=0;
        int GetYear() const{return year;}
};
class Auto:public Transport
{
protected:
        std::string fuel;//Топливо
        std::string mark;//Страна
        std::string country;//Производитель
public:
        Auto(std::string _fuel, std::string _mark, std::string _country, std::string _name, double _max_speed,
                int _num, int _year):Transport(_name,_max_speed,_num,_year),fuel(_fuel),mark(_mark),country(_country){}
        virtual ~Auto(){}
        virtual std::string GetFuel() const=0;
        std::string GetMark() const{return mark;}
        std::string GetCountry() const{return country;};
};
class Car:public Auto
{
protected:
        double run;//Пробег
        double volume;// Объем багажника
        std::string exit;//Выход пилота при аварии
public:
        Car (double _run, double _volume, std::string _exit, std::string _name, double _max_speed, int _num, int _year,
                std::string _fuel, std::string _mark, std::string _country):Auto(_fuel,_mark,_country,_name,
                _max_speed,_num,_year),run(_run),volume(_volume),exit(_exit){}
        ~Car(){}
        virtual void SetInfo(std::string _name, double _max_speed, int _num, int _year, std::string _fuel,
            std::string _mark, std::string _country, double _run, double _volume, std::string Exit);
        virtual std::string ExitPilot(){return exit;}
        virtual std::string GetName() const {return CarName;}
        virtual int GetNum() const {return CarNum;}
        virtual std::string GetFuel() const {return CarFuel;}
        double GetRun() const {return run;}
        double GetVolume() const {return volume;}
        friend std::ostream& operator<<(std::ostream&, Car&);
        friend std::istream& operator>>(std::istream&, Car&);
};
class Ferrari:public Car
{
public:
    Ferrari(double _run, double _volume,std::string _exit, std::string _name, double _max_speed, int _num, int _year, 
        std::string _fuel, std::string _mark, std::string _country):Car(_run,_volume, _exit, _name,_max_speed,_num,
        _year,_fuel,_mark,_country){}
    ~Ferrari(){}
    std::string ExitPilot(){return ExitFer;}
};
class Lada:public Car
{
public:
    Lada(double _run, double _volume,std::string _exit, std::string _name, double _max_speed, int _num, int _year, 
        std::string _fuel, std::string _mark, std::string _country):Car(_run,_volume, _exit, _name,_max_speed,_num,
        _year,_fuel,_mark,_country){}
    ~Lada(){}
    std::string ExitPilot(){return ExitLada;}
};
class Truck:public Auto
{
private:
    double cargo;//Грузоподъемность
    std::string goods;//Что перевозит
    std::string Body_type;//Тип кузова
public:
    Truck(double _cargo, std::string _goods, std::string _Body_type, std::string _name, double _max_speed,
        int _num, int _year, std::string _fuel, std::string _mark, std::string _country):Auto(_fuel,_mark,
        _country,_name,_max_speed,_num,_year), cargo(_cargo), goods(_goods), Body_type(_Body_type){}
    ~Truck(){}
    virtual void SetInfo(std::string _name, double _max_speed, int _num, int _year, std::string _fuel,
        std::string _mark, std::string _country, double _cargo, std::string _goods, std::string _BT);
    virtual std::string GetName() const {return TruckName;}
    virtual int GetNum() const{return TruckNum;}
    virtual int GetYear() const {return year;}
    virtual std::string GetFuel() const {return TruckFuel;}
    double GetCargo() const {return cargo;}
    std::string GetGoods() const {return goods;}
    std::string GetBT() const {return Body_type;}
    friend std::ostream& operator<<(std::ostream&, Truck&);
    friend std::istream& operator>>(std::istream&, Truck&);
};
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cstdlib>
#include <string>
#include <windows.h>
#include "Functions.h"
int main()
{
    setlocale(LC_ALL, "Russian");
    Car*Ob;
    Ob=new Ferrari(150000,0,"","",300, 0, 2006, "", "Феррари", "Забугорье");
    Ferrari T(150000, 0,"","",300, 0, 2006, "", "Феррари", "Забугорье");
    std::cout<<T<<'\n';
    delete Ob;
    std::cout<<"\n";
    Ob=new Lada(1500, 150, "","",160, 0, 1990, "", "Жигули","Россия");
    Lada S(1500, 150, "","",160, 0, 1990, "", "Жигули","Россия");
    std::cout<<S<<'\n';
    std::cout<<"\n";
    delete Ob;
    return 0;
}
Ну вот нечто из ряда полиморфизма)

Функция вылет водителя при аварии, реализована как виртуальная в car, и в двух производных классах Ferrari и Lada
0
Эксперт С++
 Аватар для CyBOSSeR
2348 / 1721 / 149
Регистрация: 06.03.2009
Сообщений: 3,675
27.06.2010, 23:00
Lavroff, по какой причине методы GetName и GetNum не реализованы в базовом классе?
Осмысленно используй переходы на новую строку - в текущем варианте текст сливается.
Используй табличный стиль оформления кода:
C++
1
2
3
4
std::string name;      // Название транс средства
double      max_speed; // Максимальная скорость
int         num;       // Количество пассажиров
int         year;      // Год выпуска
1
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
27.06.2010, 23:03  [ТС]
CyBOSSeR, А зачем их реализовывать? Они делают класс абстрактным. В производных классах эти методы возвращают именованные константы.
0
Эксперт С++
 Аватар для Хохол
476 / 444 / 34
Регистрация: 20.11.2009
Сообщений: 1,293
27.06.2010, 23:04
Что-то у тебя Ob ни разу не используется.
0
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
27.06.2010, 23:06  [ТС]
Цитата Сообщение от Хохол Посмотреть сообщение
Что-то у тебя Ob ни разу не используется.
Не могу врубить как его использовать. Ща подумаю
0
Эксперт С++
 Аватар для Хохол
476 / 444 / 34
Регистрация: 20.11.2009
Сообщений: 1,293
27.06.2010, 23:07
Подсказка: "->"
1
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
27.06.2010, 23:13  [ТС]
Хохол,
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <cstdlib>
#include <string>
#include <windows.h>
#include "Functions.h"
int main()
{
    setlocale(LC_ALL, "Russian");
    Car*Ob;
    Ob=new Ferrari(1500, 150, "","",160, 0, 1990, "", "Жигули","Россия");
    std::cout<<"For ferrari exit is: "<< Ob->ExitPilot() <<'\n';
    delete Ob;
    std::cout<<"\n";
    Ob=new Lada(1500, 150, "","",160, 0, 1990, "", "Жигули","Россия");
    std::cout<<"For lada exit if: "<< Ob->ExitPilot() <<'\n';
    std::cout<<"\n";
    delete Ob;
    return 0;
}
Все решил не переписывать, а конкретно эта функция вот
0
Эксперт С++
 Аватар для CyBOSSeR
2348 / 1721 / 149
Регистрация: 06.03.2009
Сообщений: 3,675
27.06.2010, 23:34
Цитата Сообщение от Lavroff Посмотреть сообщение
CyBOSSeR, А зачем их реализовывать?
Базовый класс должен предоставлять реализацию по умолчанию для большинства методов. Производные классы, при необходимости могут переопределить реализацию по умолчанию.
В твоем случае указанные методы без проблем могут быть реализованы в базовом классе.
Цитата Сообщение от Lavroff Посмотреть сообщение
Они делают класс абстрактным.
Абстрактность класса не должна быть самоцелью.
1
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
28.06.2010, 00:21  [ТС]
CyBOSSeR, Окей. Убрал абстрактные.

Добавлено через 17 минут
Собственно, придется подзабить. Тему можно закрыть. Реализация будет происходить очень медленно, из-за того, что завтра выхожу на работу. Всем спасибо за задание и за помощь!

Добавлено через 16 минут
Конечный итог на сегодняшний день:

C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//Classes.cpp
#include <iostream>
const   std::string CarName("Car");
const   std::string TruckName("Truck");
const   std::string CarFuel("Benzin");
const   std::string TruckFuel("Dizel");
const   std::string ExitFer("Не вылетает");
const   std::string ExitLada("Через лобовое стекло");
const   int         CarNum=4;
const   int         TruckNum=2;
class Transport
{
protected:
std::string name;      // Название транс средства
double      max_speed; // Максимальная скорость
int         num;       // Количество пассажиров
int         year;      // Год выпуска
public:
Transport(std::string _name, double _max_speed, int _num, int _year):name(_name),
max_speed(_max_speed), num(_num), year(_year){}
virtual     ~Transport(){}
virtual     std::string  GetName() const{return name;}
double      GetSpeed() const{return max_speed;}
virtual int GetNum() const{return num;}
int         GetYear() const{return year;}
};
class Auto:public Transport
{
protected:
std::string fuel;//Топливо
std::string mark;//Страна
std::string country;//Производитель
public:
Auto(std::string _fuel, std::string _mark, std::string _country, std::string _name, double _max_speed,
int _num, int _year):Transport(_name,_max_speed,_num,_year),fuel(_fuel),mark(_mark),country(_country){}
virtual ~Auto(){}
virtual std::string GetFuel() const{return fuel;}
std::string GetMark() const{return mark;}
std::string GetCountry() const{return country;};
};
class Car:public Auto
{
protected:
double run;//Пробег
double volume;// Объем багажника
std::string exit;//Выход пилота при аварии
public:
Car (double _run, double _volume, std::string _exit, std::string _name, double _max_speed, int _num, int _year,
std::string _fuel, std::string _mark, std::string _country):Auto(_fuel,_mark,_country,_name,
_max_speed,_num,_year),run(_run),volume(_volume),exit(_exit){}
~Car(){}
virtual void SetInfo(std::string _name, double _max_speed, int _num, int _year, std::string _fuel,
std::string _mark, std::string _country, double _run, double _volume, std::string Exit);
virtual std::string ExitPilot(){return exit;}
virtual std::string GetName() const {return CarName;}
virtual int GetNum() const {return CarNum;}
virtual std::string GetFuel() const {return CarFuel;}
double GetRun() const {return run;}
double GetVolume() const {return volume;}
friend std::ostream& operator<<(std::ostream&, Car&);
friend std::istream& operator>>(std::istream&, Car&);
};
class Ferrari:public Car
{
public:
Ferrari(double _run, double _volume,std::string _exit, std::string _name, double _max_speed, int _num, int _year, 
std::string _fuel, std::string _mark, std::string _country):Car(_run,_volume, _exit, _name,_max_speed,_num,
_year,_fuel,_mark,_country){}
~Ferrari(){}
virtual std::string ExitPilot(){return ExitFer;}
};
class Lada:public Car
{
public:
Lada(double _run, double _volume,std::string _exit, std::string _name, double _max_speed, int _num, int _year, 
std::string _fuel, std::string _mark, std::string _country):Car(_run,_volume, _exit, _name,_max_speed,_num,
_year,_fuel,_mark,_country){}
~Lada(){}
virtual std::string ExitPilot(){return ExitLada;}
};
class Truck:public Auto
{
private:
double cargo;//Грузоподъемность
std::string goods;//Что перевозит
std::string Body_type;//Тип кузова
public:
Truck(double _cargo, std::string _goods, std::string _Body_type, std::string _name, double _max_speed,
int _num, int _year, std::string _fuel, std::string _mark, std::string _country):Auto(_fuel,_mark,
_country,_name,_max_speed,_num,_year), cargo(_cargo), goods(_goods), Body_type(_Body_type){}
~Truck(){}
virtual void SetInfo(std::string _name, double _max_speed, int _num, int _year, std::string _fuel,
std::string _mark, std::string _country, double _cargo, std::string _goods, std::string _BT);
virtual std::string GetName() const {return TruckName;}
virtual int GetNum() const{return TruckNum;}
virtual std::string GetFuel() const {return TruckFuel;}
double GetCargo() const {return cargo;}
std::string GetGoods() const {return goods;}
std::string GetBT() const {return Body_type;}
friend std::ostream& operator<<(std::ostream&, Truck&);
friend std::istream& operator>>(std::istream&, Truck&);
};
C++
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
//Functions.h
#include <iostream>
#include <cstdlib>
#include <string>
#include "classes.cpp"
void Car::SetInfo(std::string _name, double _max_speed, int _num, int _year, 
    std::string _fuel, std::string _mark, std::string _country, double _run, double _volume, std::string _exit)
{
        max_speed=_max_speed; year=_year; mark=_mark; country=_country; run=_run; volume=_volume; exit=_exit;
}
std::ostream& operator<<(std::ostream&str, Car&p)
{
        str<<"Name: "<< p.GetName() <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
        str<<"Num: "<< p.GetNum() <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
        str<<"Fuel: "<< p.GetFuel() <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
        str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Run: "<< p.GetRun() <<'\n';
        str<<"Volume: "<< p.GetVolume() <<'\n'; str<<"Exit from car: "<< p.ExitPilot() <<'\n'; return str;
}
std::istream& operator>>(std::istream&str, Car&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed; std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter run: \n";str>>p.run; std::cout<<"Enter volume: \n";str>>p.volume;
    p.SetInfo(p.name,p.max_speed,p.num,p.year,p.fuel,p.mark,p.country,p.run,p.volume, p.exit);
    return str;
}
 
void Truck::SetInfo(std::string _name, double _max_speed, int _num, int _year, std::string _fuel, 
                    std::string _mark, std::string _country, double _cargo, std::string _goods, std::string _Body_type)
{
    max_speed=_max_speed; year=_year; mark=_mark; country=_country; cargo=_cargo; 
    goods=_goods; Body_type=_Body_type;
}
std::ostream& operator<<(std::ostream&str, Truck&p)
{
    str<<"Name: "<< p.GetName() <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
    str<<"Num: "<< p.GetNum() <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
    str<<"Fuel: "<< p.GetFuel() <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
    str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Cargo: "<< p.GetCargo() <<'\n';
    str<<"Goods: "<< p.GetGoods() <<'\n'; str<<"Body_tipe: "<< p.GetBT() <<'\n'; return str;
}
std::istream& operator>>(std::istream&str, Truck&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed;std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter cargo: \n";str>>p.cargo;std::cout<<"Enter goods: \n";str>>p.goods; 
    std::cout<<"Enter body tipe: \n";str>>p.Body_type;
    p.SetInfo(p.name,p.max_speed,p.num,p.year,p.fuel,p.mark,p.country,p.cargo, p.goods, p.Body_type);
    return str;
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Transport.cpp
#include <iostream>
#include <cstdlib>
#include "Functions.h"
int main()
{
    setlocale(LC_ALL, "Russian");
    Ferrari T(15000,0,"","",360,0,2008,"","Ferrari","England");
    Lada S(15000,150,"","",200,0,2006,"","Lada 2010","Russia");
    std::cout<< T <<'\n';
    std::cout<<"\n";
    std::cout<< S <<'\n';
    std::cout<<"\n";
    std::cout<<"End\n";
    return 0;
}
Добавлено через 7 минут
Тфу ты. Все равно летит формат. Обыдно.
0
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
23.07.2010, 06:48  [ТС]
Итак. Возрождаем-с и продолжаем-с.

C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//classes.h
#ifndef _CLASSES_H_
#define _CLASSES_H_
 
#include <iostream>
 
const std::string CarName("Car");
const std::string TruckName("Truck");
const std::string BusName("Bus");
const std::string TramName("Tram");
const std::string MetroName("Metro");
 
const std::string CarFuel("Benzin");
const std::string TruckFuel("Dizel");
 
const int CarNum=4;
const int TruckNum=2;
const int BusNum=100;
const int TramNum=50;
const int MetroNum=500;
 
const std::string BusWhere("On the earth");
const std::string TramWhere("On rails");
const std::string MetroWhere("Under ground");
 
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
class Transport
{
protected:
    std::string name;      // Название транс средства. Константа
    double max_speed; // Максимальная скорость
    int num;       // Количество пассажиров. Константа
    int year;      // Год выпуска
public:
    Transport(){}
    Transport(std::string name_, double max_speed_, int num_, int year_):
      name(name_), max_speed(max_speed_), num(num_), year(year_){}
    virtual ~Transport(){}
    virtual std::string  GetName() const{return name;}
    double  GetSpeed() const{return max_speed;}
    virtual int GetNum() const{return num;}
    virtual void SetInfo(double max_speed_, int year_);
    int GetYear() const{return year;}
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
class Auto:public Transport
{
protected:
    std::string fuel;//Топливо. Константа
    std::string mark;//Страна
    std::string country;//Производитель
public:
    Auto(){}
    Auto(std::string fuel_, std::string mark_, std::string country_, std::string name_, double max_speed_, int num_, int year_)
        :Transport(name_,max_speed_,num_,year_),fuel(fuel_),mark(mark_),country(country_){}
    virtual ~Auto(){}
    virtual std::string GetFuel() const{return fuel;}
    virtual void SetInfo(std::string mark_, std::string country_);
    std::string GetMark() const{return mark;}
    std::string GetCountry() const{return country;};
};
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
class Car:public Auto
{
protected:
    double run;//Пробег
    double volume;// Объем багажника
public:
    Car(){}
    Car (double run_, double volume_, std::string name_, double max_speed_, int num_, int year_,
        std::string fuel_, std::string mark_, std::string country_):Auto(fuel_,mark_,country_,name_,
        max_speed_,num_,year_),run(run_),volume(volume_){}
    virtual ~Car(){}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_, double run_, double volume_);
    virtual std::string GetName() const {return CarName;}
    virtual int GetNum() const {return CarNum;}
    virtual std::string GetFuel() const {return CarFuel;}
    double  GetRun() const {return run;}
    double  GetVolume() const {return volume;}
    friend std::ostream& operator<< (std::ostream&os, Car&Ob);
    friend std::istream& operator>>(std::istream&is, Car&Ob);
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class Truck:public Auto
{
private:
    double cargo;//Грузоподъемность
    std::string goods;//Что перевозит
    std::string Body_type;//Тип кузова
public:
    Truck(){}
    Truck(double cargo_, std::string goods_, std::string Body_type_, std::string name_, double max_speed_,
        int num_, int year_, std::string fuel_, std::string mark_, std::string country_):Auto(fuel_,mark_,
        country_,name_,max_speed_,num_,year_), cargo(cargo_), goods(goods_), Body_type(Body_type_){}
    virtual ~Truck(){}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_, double cargo_, std::string goods_, std::string BT_);
    virtual std::string GetName() const {return TruckName;}
    virtual int GetNum() const{return TruckNum;}
    virtual int GetYear() const {return year;}
    virtual std::string GetFuel() const {return TruckFuel;}
    double GetCargo() const {return cargo;}
    std::string GetGoods() const {return goods;}
    std::string GetBT() const {return Body_type;}
    friend std::ostream& operator<<(std::ostream&, Truck&);
    friend std::istream& operator>>(std::istream&, Truck&);
};
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
class Town_Transport:public Transport
{
protected:
    std::string Where;//Где ходит транспорт. Константа.
    double Price_of_ticket;//Цена билета
public:
    Town_Transport(){}
    Town_Transport(std::string Where_, double P_o_t_, std::string name_,double m_s_, int num_, int year_)
        :Transport(name_, m_s_, num_, year_), Where(Where_), Price_of_ticket(P_o_t_){}
    virtual ~Town_Transport(){}
    virtual std::string GetWhere() const {return Where;}
    virtual double GetPrice() const {return Price_of_ticket;}
    virtual void SetInfo(double P_o_t_);
};
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
class Bus:public Town_Transport
{
public:
    Bus(){}
    Bus(std::string Where_, double P_o_t_, std::string name_, double m_s_, int num_, int year_)
        :Town_Transport(Where_, P_o_t_, name_, m_s_, num_, year_){}
    virtual ~Bus(){}
    virtual std::string GetName() const {return BusName;}
    virtual int GetNum() const {return BusNum;}
    virtual std::string GetWhere() const {return BusWhere;}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, Bus&);
    friend std::istream& operator >> (std::istream&, Bus&);
};
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
class Tram:public Town_Transport
{
public:
    Tram(){}
    Tram(std::string Where_, double P_o_t_, std::string name_, double m_s_, int num_, int year_)
        :Town_Transport(Where_, P_o_t_, name_, m_s_, num_, year_){}
    virtual ~Tram(){}
    virtual std::string GetName() const {return TramName;}
    virtual int GetNum() const {return TramNum;}
    virtual std::string GetWhere() const {return TramWhere;}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, Tram&);
    friend std::istream& operator >> (std::istream&, Tram&);
};
class Metro:public Town_Transport
{
public:
    Metro(){}
    Metro(std::string Where_, double P_o_t_, std::string name_, double m_s_, int num_, int year_)
        :Town_Transport(Where_, P_o_t_, name_, m_s_, num_, year_){}
    virtual ~Metro(){}
    virtual std::string GetName() const {return MetroName;}
    virtual int GetNum() const {return MetroNum;}
    virtual std::string GetWhere() const {return MetroWhere;}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, Metro&);
    friend std::istream& operator >> (std::istream&, Metro&);
};
#endif
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//classes.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "Classes.h"
 
void Transport::SetInfo(double max_speed_, int year_)
{
    max_speed=max_speed_;
    year=year_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Auto::SetInfo(std::string mark_, std::string country_)
{
    mark=mark_;
    country=country_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Car::SetInfo(double max_speed_, int year_, std::string mark_, std::string country_, double _run, double _volume)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    run=_run; 
    volume=_volume;
}
/////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, Car&p)
{
        str<<"Name: "<< p.GetName() <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
        str<<"Num: "<< p.GetNum() <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
        str<<"Fuel: "<< p.GetFuel() <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
        str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Run: "<< p.GetRun() <<'\n';
        str<<"Volume: "<< p.GetVolume() <<'\n'; return str;
}
///////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Car&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed; std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter run: \n";str>>p.run; std::cout<<"Enter volume: \n";str>>p.volume;
    return str;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
void Truck::SetInfo(double max_speed_, int year_,std::string mark_,std::string country_,double cargo_,std::string goods_,std::string BT_)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    cargo=cargo_; 
    goods=goods_; 
    Body_type=BT_;
}
//////////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, Truck&p)
{
    str<<"Name: "<< p.GetName() <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
    str<<"Num: "<< p.GetNum() <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
    str<<"Fuel: "<< p.GetFuel() <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
    str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Cargo: "<< p.GetCargo() <<'\n';
    str<<"Goods: "<< p.GetGoods() <<'\n'; str<<"Body_tipe: "<< p.GetBT() <<'\n'; return str;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Truck&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed;std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter cargo: \n";str>>p.cargo;std::cout<<"Enter goods: \n";str>>p.goods; 
    std::cout<<"Enter body tipe: \n";str>>p.Body_type;
    return str;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Town_Transport::SetInfo(double P_o_t_)
{
    Price_of_ticket=P_o_t_;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void Bus::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
/////////////////////////////////////////////////////////////////////
std::ostream& operator << (std::ostream&os, Bus&Ob)
{
    os<<"Name: "<< Ob.GetName() <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< Ob.GetNum() <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< Ob.GetWhere() <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Bus&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Tram::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, Tram&Ob)
{
    os<<"Name: "<< Ob.GetName() <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< Ob.GetNum() <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< Ob.GetWhere() <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Tram&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Metro::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, Metro&Ob)
{
    os<<"Name: "<< Ob.GetName() <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< Ob.GetNum() <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< Ob.GetWhere() <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Metro&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//trans.cpp
#include <iostream>
#include <cstdlib>
#include "Classes.h"
int main()
{
    int k=0;
Start:
    std::cout<<"Enter k: 1 for work with Transport, 2 for work with Town transport\n";
    std::cin>>k;
    if(k==1)
    {
        int l=0;
StartTr:
        std::cout<<"Enter l: 1 for work with Car, 2 for work with Truck\n";
        std::cin>>l;
        if(l==1)
        {
            int Num=0;
            Car*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Car[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            int Num1=0;
            Truck*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num1;
            Arr=new Truck[Num1];
            for(int i=0;i<Num1;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num1;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to beginning of Transport\n";
            goto StartTr;
        }
    }
    else if(k==2)
    {
        int l=0;
StartTT:
        std::cout<<"Enter l: 1 for work with Bus, 2 for work with Trum, 3 for work with Metro\n";
        std::cin>>l;
        if(l==1)
        {
            int Num2=0;
            Bus*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num2;
            Arr=new Bus[Num2];
            for(int i=0;i<Num2;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num2;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            int Num3=0; 
            Tram*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num3;
            Arr=new Tram[Num3];
            for(int i=0;i<Num3;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num3;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==3)
        {
            int Num4=0; 
            Metro*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num4;
            Arr=new Metro[Num4];
            for(int i=0;i<Num4;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num4;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to the beginning of Town Transport\n";
            goto StartTT;
        }
    }
    else 
    {
        std::cout<<"There is no such option. Program going to the beginning\n";
        goto Start;
    }
        
    return 0;
}
0
Эксперт С++
 Аватар для CyBOSSeR
2348 / 1721 / 149
Регистрация: 06.03.2009
Сообщений: 3,675
23.07.2010, 09:43
Lavroff, почему методы GetName, GetNum подклассов и т.п. возвращают значения глобальных констант? Не надо переопределять данные методы - реализации в базовом классе достаточно. Просто передавай соответсвующие константы в конструктор класса - он для этого и нужен. А то сейчас получается, что поля базового класса:
C++
1
2
3
4
std::string name;      // Название транс средства. Константа
double max_speed; // Максимальная скорость
int num;       // Количество пассажиров. Константа
int year;      // Год выпуска
хранятся в экземплярах подклассов, но никак не используются.
1
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
23.07.2010, 22:33  [ТС]
CyBOSSeR, Ага. Спасибо. Поправлю!

Закончен раздел Town_Transport. На очереди воздушные средства, что будет вроде интереснее. Затем военная техника пойдет наверное.

C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//Classes.h
#ifndef _CLASSES_H_
#define _CLASSES_H_
 
#include <iostream>
 
const std::string CarName("Car");
const std::string TruckName("Truck");
const std::string BusName("Bus");
const std::string TramName("Tram");
const std::string MetroName("Metro");
const std::string TrolleyName("Trolley bus");
const std::string TrainName("Electric train");
 
const std::string CarFuel("Benzin");
const std::string TruckFuel("Dizel");
 
const int CarNum=4;
const int TruckNum=2;
const int BusNum=100;
const int TramNum=50;
const int MetroNum=500;
const int TrolleyNum=105;
const int TrainNum=700;
 
const std::string BusWhere("On the ground");
const std::string TramWhere("On rails");
const std::string MetroWhere("Under ground");
const std::string TrolleyWhere("On the ground");
const std::string TrainWhere("On the railway");
 
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
class Transport
{
protected:
    std::string name; // Название транс средства. Константа
    double max_speed; // Максимальная скорость
    int num;          // Количество пассажиров. Константа
    int year;         // Год выпуска
public:
    Transport(){}
    Transport(std::string name_, double max_speed_, int num_, int year_):
      name(name_), max_speed(max_speed_), num(num_), year(year_){}
    virtual ~Transport(){}
    std::string  GetName() const{return name;}
    double  GetSpeed() const{return max_speed;}
    int GetNum() const{return num;}
    int GetYear() const{return year;}
    virtual void SetInfo(double max_speed_, int year_);
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
class Auto:public Transport
{
protected:
    std::string fuel;//Топливо. Константа
    std::string mark;//Страна
    std::string country;//Производитель
public:
    Auto(){}
    Auto(std::string fuel_, std::string mark_, std::string country_, std::string name_, double max_speed_, int num_, int year_)
        :Transport(name_,max_speed_,num_,year_),fuel(fuel_),mark(mark_),country(country_){}
    virtual ~Auto(){}
    std::string GetFuel() const{return fuel;}
    std::string GetMark() const{return mark;}
    std::string GetCountry() const{return country;};
    virtual void SetInfo(std::string mark_, std::string country_);
};
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
class Car:public Auto
{
protected:
    double run;//Пробег
    double volume;// Объем багажника
public:
    Car(){}
    Car (double run_, double volume_, double max_speed_, int year_,
        std::string mark_, std::string country_):Auto(CarFuel,mark_,country_,CarName,
        max_speed_,CarNum,year_),run(run_),volume(volume_){}
    virtual ~Car(){}
    double  GetRun() const {return run;}
    double  GetVolume() const {return volume;}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_,
        double run_, double volume_);
    friend std::ostream& operator<< (std::ostream&os, Car&Ob);
    friend std::istream& operator>>(std::istream&is, Car&Ob);
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class Truck:public Auto
{
private:
    double cargo;//Грузоподъемность
    std::string goods;//Что перевозит
    std::string Body_type;//Тип кузова
public:
    Truck(){}
    Truck(double cargo_, std::string goods_, std::string Body_type_, double max_speed_,
        int year_, std::string mark_, std::string country_):Auto(TruckFuel,mark_,
        country_, TruckName,max_speed_,TruckNum,year_), cargo(cargo_), goods(goods_), Body_type(Body_type_){}
    virtual ~Truck(){}
    double GetCargo() const {return cargo;}
    std::string GetGoods() const {return goods;}
    std::string GetBT() const {return Body_type;}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_,
        double cargo_, std::string goods_, std::string BT_);
    friend std::ostream& operator<<(std::ostream&, Truck&);
    friend std::istream& operator>>(std::istream&, Truck&);
};
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
class Town_Transport:public Transport
{
protected:
    std::string Where;//Где ходит транспорт. Константа.
    double Price_of_ticket;//Цена билета
public:
    Town_Transport(){}
    Town_Transport(std::string Where_, double P_o_t_, std::string name_,double m_s_, int num_, int year_)
        :Transport(name_, m_s_, num_, year_), Where(Where_), Price_of_ticket(P_o_t_){}
    virtual ~Town_Transport(){}
    std::string GetWhere() const {return Where;}
    double GetPrice() const {return Price_of_ticket;}
    virtual void SetInfo(double P_o_t_);
};
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
class Bus:public Town_Transport
{
public:
    Bus(){}
    Bus(double P_o_t_, double m_s_, int year_)
        :Town_Transport(BusWhere, P_o_t_, BusName, m_s_, BusNum, year_){}
    virtual ~Bus(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, Bus&);
    friend std::istream& operator >> (std::istream&, Bus&);
};
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
class Tram:public Town_Transport
{
public:
    Tram(){}
    Tram(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TramWhere, P_o_t_, TramName, m_s_, TramNum, year_){}
    virtual ~Tram(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, Tram&);
    friend std::istream& operator >> (std::istream&, Tram&);
};
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
class Metro:public Town_Transport
{
public:
    Metro(){}
    Metro(double P_o_t_, double m_s_, int year_)
        :Town_Transport(MetroWhere, P_o_t_, MetroName, m_s_, MetroNum, year_){}
    virtual ~Metro(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, Metro&);
    friend std::istream& operator >> (std::istream&, Metro&);
};
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
class Trolley_Bus:public Town_Transport
{
public:
    Trolley_Bus(){}
    Trolley_Bus(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TrolleyWhere, P_o_t_, TrolleyName, m_s_, TrolleyNum, year_){}
    virtual ~Trolley_Bus(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator <<(std::ostream&, Trolley_Bus&);
    friend std::istream& operator >>(std::istream&, Trolley_Bus&);
};
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
class Electric_Train:public Town_Transport
{
public:
    Electric_Train(){}
    Electric_Train(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TrainWhere, P_o_t_, TrainName, m_s_, TrainNum, year_){}
    virtual ~Electric_Train(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator <<(std::ostream&, Electric_Train&);
    friend std::istream& operator >>(std::istream&, Electric_Train&);
};
#endif
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//Classes.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "Classes.h"
 
void Transport::SetInfo(double max_speed_, int year_)
{
    max_speed=max_speed_;
    year=year_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Auto::SetInfo(std::string mark_, std::string country_)
{
    mark=mark_;
    country=country_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Car::SetInfo(double max_speed_, int year_, std::string mark_, std::string country_, double _run, double _volume)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    run=_run; 
    volume=_volume;
}
/////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, Car&p)
{
        str<<"Name: "<< CarName <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
        str<<"Num: "<< CarNum <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
        str<<"Fuel: "<< CarFuel <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
        str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Run: "<< p.GetRun() <<'\n';
        str<<"Volume: "<< p.GetVolume() <<'\n'; return str;
}
///////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Car&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed; std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter run: \n";str>>p.run; std::cout<<"Enter volume: \n";str>>p.volume;
    return str;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
void Truck::SetInfo(double max_speed_, int year_,std::string mark_,std::string country_,double cargo_,std::string goods_,std::string BT_)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    cargo=cargo_; 
    goods=goods_; 
    Body_type=BT_;
}
//////////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, Truck&p)
{
    str<<"Name: "<< TruckName <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
    str<<"Num: "<< TruckNum <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
    str<<"Fuel: "<< TruckFuel <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
    str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Cargo: "<< p.GetCargo() <<'\n';
    str<<"Goods: "<< p.GetGoods() <<'\n'; str<<"Body_tipe: "<< p.GetBT() <<'\n'; return str;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Truck&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed;std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter cargo: \n";str>>p.cargo;std::cout<<"Enter goods: \n";str>>p.goods; 
    std::cout<<"Enter body tipe: \n";str>>p.Body_type;
    return str;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Town_Transport::SetInfo(double P_o_t_)
{
    Price_of_ticket=P_o_t_;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void Bus::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
/////////////////////////////////////////////////////////////////////
std::ostream& operator << (std::ostream&os, Bus&Ob)
{
    os<<"Name: "<< BusName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< BusNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< BusWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Bus&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Tram::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, Tram&Ob)
{
    os<<"Name: "<< TramName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TramNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TramWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Tram&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Metro::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, Metro&Ob)
{
    os<<"Name: "<< MetroName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< MetroNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< MetroWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Metro&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Trolley_Bus::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, Trolley_Bus&Ob)
{
    os<<"Name: "<< TrolleyName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TrolleyNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TrolleyWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Trolley_Bus&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Electric_Train::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, Electric_Train&Ob)
{
    os<<"Name: "<< TrainName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TrainNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TrainWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Electric_Train&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//Trans.cpp
#include <iostream>
#include <cstdlib>
#include "Classes.h"
int main()
{
    int Num=0;
    int k=0;
    int l=0;
Start:
    std::cout<<"Enter k: 1 for work with Transport, 2 for work with Town transport\n";
    std::cin>>k;
    if(k==1)
    {
StartTr:
        std::cout<<"Enter l: 1 for work with Car, 2 for work with Truck\n";
        std::cin>>l;
        if(l==1)
        {
            Car*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Car[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Truck*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Truck[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to beginning of Transport\n";
            goto StartTr;
        }
    }
    else if(k==2)
    {
StartTT:
        std::cout<<"Enter l: 1 for work with Bus, 2 for work with Tram, 3 for work with Metro," 
            "4 for work with Trolley bus, 5 for work with Train\n";
        std::cin>>l;
        if(l==1)
        {
            Bus*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Bus[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Tram*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Tram[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==3)
        {
            Metro*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Metro[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==4)
        {
            Trolley_Bus*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Trolley_Bus[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==5)
        {
            Electric_Train*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Electric_Train[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<< Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to the beginning of Town Transport\n";
            goto StartTT;
        }
    }
    else 
    {
        std::cout<<"There is no such option. Program going to the beginning\n";
        goto Start;
    }
        
    return 0;
}
Добавлено через 4 часа 27 минут
Так... Подустал чуток. +Три новых класса. Air_Transport и производные от него AirPlane и Helicopter.

C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//Classes.h
#ifndef _CLASSES_H_
#define _CLASSES_H_
 
#include <iostream>
#include <string>
//Именные константы
const std::string CarName("Car");
const std::string TruckName("Truck");
const std::string BusName("Bus");
const std::string TramName("Tram");
const std::string MetroName("Metro");
const std::string TrolleyName("Trolley bus");
const std::string TrainName("Electric train");
const std::string PlaneName("Airplane");
const std::string HelName("Hellicopter");
//Топливные константы
const std::string CarFuel("Benzin");
const std::string TruckFuel("Dizel");
//Колличество людей. Константы
const int CarNum=4;
const int TruckNum=2;
const int BusNum=100;
const int TramNum=50;
const int MetroNum=500;
const int TrolleyNum=105;
const int TrainNum=700;
const int PlaneNum=200;
const int HelNum=2;
//Место езды. Константы
const std::string BusWhere("On the ground");
const std::string TramWhere("On rails");
const std::string MetroWhere("Under ground");
const std::string TrolleyWhere("On the ground");
const std::string TrainWhere("On the railway");
//С помощью чего летает. Константы
const std::string PlaneFlying("Tho wings");
const std::string HelFlying("With screw");
//Максимальная высота. Константы
const int PlaneHeight=10000;
const int HelHeight=5000;
//Материал. Константы
const std::string PlaneMat("Titan");
const std::string HelMat("Iron");
//Макс. длина полета. Константы
const double PlaneLen=5000.450;
const double HelLen=2000;
 
 
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
class Transport
{
protected:
    std::string name; // Название транс средства. Константа
    double max_speed; // Максимальная скорость
    int num;          // Количество пассажиров. Константа
    int year;         // Год выпуска
public:
    Transport(){}
    Transport(std::string name_, double max_speed_, int num_, int year_):
      name(name_), max_speed(max_speed_), num(num_), year(year_){}
    virtual ~Transport(){}
    std::string  GetName() const{return name;}
    double  GetSpeed() const{return max_speed;}
    int GetNum() const{return num;}
    int GetYear() const{return year;}
    virtual void SetInfo(double max_speed_, int year_);
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
class Auto:public Transport
{
protected:
    std::string fuel;//Топливо. Константа
    std::string mark;//Страна
    std::string country;//Производитель
public:
    Auto(){}
    Auto(std::string fuel_, std::string mark_, std::string country_, std::string name_, double max_speed_, int num_, int year_)
        :Transport(name_,max_speed_,num_,year_),fuel(fuel_),mark(mark_),country(country_){}
    virtual ~Auto(){}
    std::string GetFuel() const{return fuel;}
    std::string GetMark() const{return mark;}
    std::string GetCountry() const{return country;};
    virtual void SetInfo(std::string mark_, std::string country_);
};
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
class Car:public Auto
{
protected:
    double run;//Пробег
    double volume;// Объем багажника
public:
    Car(){}
    Car (double run_, double volume_, double max_speed_, int year_,
        std::string mark_, std::string country_):Auto(CarFuel,mark_,country_,CarName,
        max_speed_,CarNum,year_),run(run_),volume(volume_){}
    virtual ~Car(){}
    double  GetRun() const {return run;}
    double  GetVolume() const {return volume;}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_,
        double run_, double volume_);
    friend std::ostream& operator<< (std::ostream&os, const Car&Ob);
    friend std::istream& operator>>(std::istream&is, Car&Ob);
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class Truck:public Auto
{
private:
    double cargo;//Грузоподъемность
    std::string goods;//Что перевозит
    std::string Body_type;//Тип кузова
public:
    Truck(){}
    Truck(double cargo_, std::string goods_, std::string Body_type_, double max_speed_,
        int year_, std::string mark_, std::string country_):Auto(TruckFuel,mark_,
        country_, TruckName,max_speed_,TruckNum,year_), cargo(cargo_), goods(goods_), Body_type(Body_type_){}
    virtual ~Truck(){}
    double GetCargo() const {return cargo;}
    std::string GetGoods() const {return goods;}
    std::string GetBT() const {return Body_type;}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_,
        double cargo_, std::string goods_, std::string BT_);
    friend std::ostream& operator<<(std::ostream&, const Truck&);
    friend std::istream& operator>>(std::istream&, Truck&);
};
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
class Town_Transport:public Transport
{
protected:
    std::string Where;//Где ходит транспорт. Константа.
    double Price_of_ticket;//Цена билета
public:
    Town_Transport(){}
    Town_Transport(std::string Where_, double P_o_t_, std::string name_,double m_s_, int num_, int year_)
        :Transport(name_, m_s_, num_, year_), Where(Where_), Price_of_ticket(P_o_t_){}
    virtual ~Town_Transport(){}
    std::string GetWhere() const {return Where;}
    double GetPrice() const {return Price_of_ticket;}
    virtual void SetInfo(double P_o_t_);
};
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
class Bus:public Town_Transport
{
public:
    Bus(){}
    Bus(double P_o_t_, double m_s_, int year_)
        :Town_Transport(BusWhere, P_o_t_, BusName, m_s_, BusNum, year_){}
    virtual ~Bus(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, const Bus&);
    friend std::istream& operator >> (std::istream&, Bus&);
};
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
class Tram:public Town_Transport
{
public:
    Tram(){}
    Tram(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TramWhere, P_o_t_, TramName, m_s_, TramNum, year_){}
    virtual ~Tram(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, const Tram&);
    friend std::istream& operator >> (std::istream&, Tram&);
};
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
class Metro:public Town_Transport
{
public:
    Metro(){}
    Metro(double P_o_t_, double m_s_, int year_)
        :Town_Transport(MetroWhere, P_o_t_, MetroName, m_s_, MetroNum, year_){}
    virtual ~Metro(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, const Metro&);
    friend std::istream& operator >> (std::istream&, Metro&);
};
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
class Trolley_Bus:public Town_Transport
{
public:
    Trolley_Bus(){}
    Trolley_Bus(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TrolleyWhere, P_o_t_, TrolleyName, m_s_, TrolleyNum, year_){}
    virtual ~Trolley_Bus(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator <<(std::ostream&, const Trolley_Bus&);
    friend std::istream& operator >>(std::istream&, Trolley_Bus&);
};
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
class Electric_Train:public Town_Transport
{
public:
    Electric_Train(){}
    Electric_Train(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TrainWhere, P_o_t_, TrainName, m_s_, TrainNum, year_){}
    virtual ~Electric_Train(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator <<(std::ostream&, const Electric_Train&);
    friend std::istream& operator >>(std::istream&, Electric_Train&);
};
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
class Air_Transport:public Transport
{
protected:
    std::string Flying;//Каким образом летают. Константа.
    int max_height;//Макс высота в киллометрах. Константа.
    std::string Material;//Из чего сделано средство. Константа.
    double max_lenght;//Макс дальность полета при полном баке. Константа
public:
    Air_Transport(){}
    Air_Transport(std::string Flying_, int m_h_, std::string Material_, double max_lenght,
        std::string name_, double m_s_, int num_, int year_):Transport(name_, m_s_, num_, year_){}
    virtual ~Air_Transport(){}
    std::string GetFlying() const {return Flying;}
    int GetHeight() const {return max_height;}
    std::string GetMat() const {return Material;}
    double GetLenght() const {return max_lenght;}
};
class AirPlane:public Air_Transport
{
private:
    int num_of_eng;//Колличество двигателей(турбин)
    double lenght_of_body;//Длина фюзеляжа
    int num_of_members;//Колличество членов экипажа
public:
    AirPlane(){}
    AirPlane(int n_o_e_, double l_o_b_, int n_o_m_, int year_, double m_s_)
        :Air_Transport(PlaneFlying, PlaneHeight, PlaneMat, PlaneLen, PlaneName, m_s_, PlaneNum, year_),
        num_of_eng(n_o_e_), lenght_of_body(l_o_b_), num_of_members(n_o_m_){}
    virtual ~AirPlane(){}
    int GetEng() const {return num_of_eng;}
    double GetBody() const {return lenght_of_body;}
    int GetMemb() const {return num_of_members;}
    virtual void SetInfo(int n_o_e_, double l_o_b_, int n_o_m_, int year_, double m_s_);
    friend std::ostream& operator <<(std::ostream&, const AirPlane&);
    friend std::istream& operator >>(std::istream&, AirPlane&);
};
class Helicopter:public Air_Transport
{
private:
    double speed;//Скорость вращения винта
public:
    Helicopter(){}
    Helicopter(double speed_, int year_, double m_s_)
        :Air_Transport(HelFlying, HelHeight, HelMat, HelLen, HelName, m_s_, HelNum, year_), speed(speed_){}
    virtual ~Helicopter(){}
    double GetSp() const {return speed;}
    virtual void SetInfo(double speed_, int year_, double m_s_);
    friend std::ostream& operator <<(std::ostream&, const Helicopter&);
    friend std::istream& operator >>(std::istream&, Helicopter&);
};
#endif
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//Classes.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "Classes.h"
 
void Transport::SetInfo(double max_speed_, int year_)
{
    max_speed=max_speed_;
    year=year_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Auto::SetInfo(std::string mark_, std::string country_)
{
    mark=mark_;
    country=country_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Car::SetInfo(double max_speed_, int year_, std::string mark_, std::string country_, double _run, double _volume)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    run=_run; 
    volume=_volume;
}
/////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, const Car&p)
{
        str<<"Name: "<< CarName <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
        str<<"Num: "<< CarNum <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
        str<<"Fuel: "<< CarFuel <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
        str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Run: "<< p.GetRun() <<'\n';
        str<<"Volume: "<< p.GetVolume() <<'\n'; return str;
}
///////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Car&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed; std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter run: \n";str>>p.run; std::cout<<"Enter volume: \n";str>>p.volume;
    return str;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
void Truck::SetInfo(double max_speed_, int year_,std::string mark_,std::string country_,double cargo_,std::string goods_,std::string BT_)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    cargo=cargo_; 
    goods=goods_; 
    Body_type=BT_;
}
//////////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, const Truck&p)
{
    str<<"Name: "<< TruckName <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
    str<<"Num: "<< TruckNum <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
    str<<"Fuel: "<< TruckFuel <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
    str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Cargo: "<< p.GetCargo() <<'\n';
    str<<"Goods: "<< p.GetGoods() <<'\n'; str<<"Body_tipe: "<< p.GetBT() <<'\n'; return str;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Truck&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed;std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter cargo: \n";str>>p.cargo;std::cout<<"Enter goods: \n";str>>p.goods; 
    std::cout<<"Enter body tipe: \n";str>>p.Body_type;
    return str;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Town_Transport::SetInfo(double P_o_t_)
{
    Price_of_ticket=P_o_t_;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void Bus::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
/////////////////////////////////////////////////////////////////////
std::ostream& operator << (std::ostream&os, const Bus&Ob)
{
    os<<"Name: "<< BusName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< BusNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< BusWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Bus&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Tram::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Tram&Ob)
{
    os<<"Name: "<< TramName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TramNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TramWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Tram&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Metro::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Metro&Ob)
{
    os<<"Name: "<< MetroName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< MetroNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< MetroWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Metro&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Trolley_Bus::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Trolley_Bus&Ob)
{
    os<<"Name: "<< TrolleyName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TrolleyNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TrolleyWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Trolley_Bus&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Electric_Train::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Electric_Train&Ob)
{
    os<<"Name: "<< TrainName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TrainNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TrainWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Electric_Train&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void AirPlane::SetInfo(int n_o_e_, double l_o_b_, int n_o_m_, int year_, double m_s_)
{
    Transport::SetInfo(m_s_, year_);
    num_of_eng=n_o_e_;
    lenght_of_body=l_o_b_;
    num_of_members=n_o_m_;
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const AirPlane&Ob)
{
    os<<"Name: "<< PlaneName <<'\n'; os<<"Max speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< PlaneNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Flying: "<< PlaneFlying <<'\n'; os<<"Max height: "<< PlaneHeight <<'\n';
    os<<"Matetial: "<< PlaneMat <<'\n'; os<<"Max lenght: "<< PlaneLen <<'\n';
    os<<"Num of eng: "<< Ob.GetEng() <<'\n'; os<<"Lenght of body: "<< Ob.GetBody() <<'\n';
    os<<"Num of members: "<< Ob.GetMemb() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, AirPlane&Ob)
{
    std::cout<<"Enter max speed: \n";is>>Ob.max_speed; std::cout<<"Enter year: \n";is>>Ob.year;
    std::cout<<"Enter num of eng: \n";is>>Ob.num_of_eng; std::cout<<"Enter lenght of body: \n";is>>Ob.lenght_of_body;
    std::cout<<"Enter num of members: \n";is>>Ob.num_of_members;
    return is;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void Helicopter::SetInfo(double speed_, int year_, double m_s_)
{
    Transport::SetInfo(m_s_, year_);
    speed=speed_;
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Helicopter&Ob)
{
    os<<"Name: "<< HelName <<'\n'; os<<"Max speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< HelNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Flying: "<< HelFlying <<'\n'; os<<"Max height: "<< HelHeight <<'\n';
    os<<"Matetial: "<< HelMat <<'\n'; os<<"Max lenght: "<< HelLen <<'\n';
    os<<"Speed: "<< Ob.GetSp() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Helicopter&Ob)
{
    std::cout<<"Enter max speed: \n";is>>Ob.max_speed; std::cout<<"Enter year: \n";is>>Ob.year;
    std::cout<<"Enter speed: \n";is>>Ob.speed;
    return is;
}
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//Trans.cpp
#include <iostream>
#include <cstdlib>
#include "Classes.h"
int main()
{
    int Num=0;
    int k=0;
    int l=0;
Start:
    std::cout<<"Enter k:\n" 
    "1 for work with Transport\n" 
    "2 for work with Town transport\n" 
    "3 for work with Air transport\n";
    std::cin>>k;
    if(k==1)
    {
StartTr:
        std::cout<<"Enter l:\n" 
        "1 for work with Car\n" 
        "2 for work with Truck\n";
        std::cin>>l;
        if(l==1)
        {
            Car*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Car[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Truck*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Truck[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to beginning of Transport\n";
            goto StartTr;
        }
    }
    else if(k==2)
    {
StartTT:
        std::cout<<"Enter l:\n" 
        "1 for work with Bus\n" 
        "2 for work with Tram\n" 
        "3 for work with Metro\n" 
        "4 for work with Trolley bus\n" 
        "5 for work with Train\n";
        std::cin>>l;
        if(l==1)
        {
            Bus*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Bus[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Tram*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Tram[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==3)
        {
            Metro*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Metro[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==4)
        {
            Trolley_Bus*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Trolley_Bus[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==5)
        {
            Electric_Train*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Electric_Train[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<< Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to the beginning of Town Transport\n";
            goto StartTT;
        }
    }
    if(k==3)
    {
StartAT:
        std::cout<<"Enter l:\n"
        "1 for work with Airplane\n" 
        "2 for work with Helicopter\n";
        std::cin>>l;
        if(l==1)
        {
            AirPlane*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new AirPlane[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Helicopter*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Helicopter[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to beginning of Air Transport\n";
            goto StartAT;
        }
    }
    else 
    {
        std::cout<<"There is no such option. Program going to the beginning\n";
        goto Start;
    }
    system("pause");
    return 0;
}
0
Maniac
Эксперт С++
 Аватар для ISergey
1465 / 966 / 160
Регистрация: 02.01.2009
Сообщений: 2,820
Записей в блоге: 1
24.07.2010, 05:13
Не знаю как кому.. но я бы спрятал все константы в namespace, хотябы..
0
В астрале
Эксперт С++
 Аватар для ForEveR
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
24.07.2010, 14:12  [ТС]
ISergey, Можно конечно... Но для чего?

Добавлено через 8 часов 56 минут
C++
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
//Namespace.h
#ifndef _NAMESPACE_H_
#define _NAMESPACE_H_
////////////////////////////////////////////////////////////////////
namespace Const
{
//Именные константы
const std::string CarName("Car");
const std::string TruckName("Truck");
const std::string BusName("Bus");
const std::string TramName("Tram");
const std::string MetroName("Metro");
const std::string TrolleyName("Trolley bus");
const std::string TrainName("Electric train");
const std::string PlaneName("Airplane");
const std::string HelName("Hellicopter");
//Топливные константы
const std::string CarFuel("Benzin");
const std::string TruckFuel("Dizel");
//Колличество людей. Константы
const int CarNum=4;
const int TruckNum=2;
const int BusNum=100;
const int TramNum=50;
const int MetroNum=500;
const int TrolleyNum=105;
const int TrainNum=700;
const int PlaneNum=200;
const int HelNum=2;
//Место езды. Константы
const std::string BusWhere("On the ground");
const std::string TramWhere("On rails");
const std::string MetroWhere("Under ground");
const std::string TrolleyWhere("On the ground");
const std::string TrainWhere("On the railway");
//С помощью чего летает. Константы
const std::string PlaneFlying("Tho wings");
const std::string HelFlying("With screw");
//Максимальная высота. Константы
const int PlaneHeight=10000;
const int HelHeight=5000;
//Материал. Константы
const std::string PlaneMat("Titan");
const std::string HelMat("Iron");
//Макс. длина полета. Константы
const double PlaneLen=5000.450;
const double HelLen=2000;
}
#endif
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//Classes.h
#ifndef _CLASSES_H_
#define _CLASSES_H_
 
#include <iostream>
#include <string>
#include "Namespace.h"
 
using namespace Const;
 
 
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
class Transport
{
protected:
    std::string name; // Название транс средства. Константа
    double max_speed; // Максимальная скорость
    int num;          // Количество пассажиров. Константа
    int year;         // Год выпуска
public:
    Transport(){}
    Transport(std::string name_, double max_speed_, int num_, int year_):
      name(name_), max_speed(max_speed_), num(num_), year(year_){}
    virtual ~Transport(){}
    std::string  GetName() const{return name;}
    double  GetSpeed() const{return max_speed;}
    int GetNum() const{return num;}
    int GetYear() const{return year;}
    virtual void SetInfo(double max_speed_, int year_);
};
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
class Auto:public Transport
{
protected:
    std::string fuel;//Топливо. Константа
    std::string mark;//Страна
    std::string country;//Производитель
public:
    Auto(){}
    Auto(std::string fuel_, std::string mark_, std::string country_, std::string name_, double max_speed_, int num_, int year_)
        :Transport(name_,max_speed_,num_,year_),fuel(fuel_),mark(mark_),country(country_){}
    virtual ~Auto(){}
    std::string GetFuel() const{return fuel;}
    std::string GetMark() const{return mark;}
    std::string GetCountry() const{return country;};
    virtual void SetInfo(std::string mark_, std::string country_);
};
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
class Car:public Auto
{
protected:
    double run;//Пробег
    double volume;// Объем багажника
public:
    Car(){}
    Car (double run_, double volume_, double max_speed_, int year_,
        std::string mark_, std::string country_):Auto(CarFuel,mark_,country_,CarName,
        max_speed_,CarNum,year_),run(run_),volume(volume_){}
    virtual ~Car(){}
    double  GetRun() const {return run;}
    double  GetVolume() const {return volume;}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_,
        double run_, double volume_);
    friend std::ostream& operator<< (std::ostream&os, const Car&Ob);
    friend std::istream& operator>>(std::istream&is, Car&Ob);
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class Truck:public Auto
{
private:
    double cargo;//Грузоподъемность
    std::string goods;//Что перевозит
    std::string Body_type;//Тип кузова
public:
    Truck(){}
    Truck(double cargo_, std::string goods_, std::string Body_type_, double max_speed_,
        int year_, std::string mark_, std::string country_):Auto(TruckFuel,mark_,
        country_, TruckName,max_speed_,TruckNum,year_), cargo(cargo_), goods(goods_), Body_type(Body_type_){}
    virtual ~Truck(){}
    double GetCargo() const {return cargo;}
    std::string GetGoods() const {return goods;}
    std::string GetBT() const {return Body_type;}
    virtual void SetInfo(double max_speed_, int year_, std::string mark_, std::string country_,
        double cargo_, std::string goods_, std::string BT_);
    friend std::ostream& operator<<(std::ostream&, const Truck&);
    friend std::istream& operator>>(std::istream&, Truck&);
};
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
class Town_Transport:public Transport
{
protected:
    std::string Where;//Где ходит транспорт. Константа.
    double Price_of_ticket;//Цена билета
public:
    Town_Transport(){}
    Town_Transport(std::string Where_, double P_o_t_, std::string name_,double m_s_, int num_, int year_)
        :Transport(name_, m_s_, num_, year_), Where(Where_), Price_of_ticket(P_o_t_){}
    virtual ~Town_Transport(){}
    std::string GetWhere() const {return Where;}
    double GetPrice() const {return Price_of_ticket;}
    virtual void SetInfo(double P_o_t_);
};
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
class Bus:public Town_Transport
{
public:
    Bus(){}
    Bus(double P_o_t_, double m_s_, int year_)
        :Town_Transport(BusWhere, P_o_t_, BusName, m_s_, BusNum, year_){}
    virtual ~Bus(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, const Bus&);
    friend std::istream& operator >> (std::istream&, Bus&);
};
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
class Tram:public Town_Transport
{
public:
    Tram(){}
    Tram(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TramWhere, P_o_t_, TramName, m_s_, TramNum, year_){}
    virtual ~Tram(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, const Tram&);
    friend std::istream& operator >> (std::istream&, Tram&);
};
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
class Metro:public Town_Transport
{
public:
    Metro(){}
    Metro(double P_o_t_, double m_s_, int year_)
        :Town_Transport(MetroWhere, P_o_t_, MetroName, m_s_, MetroNum, year_){}
    virtual ~Metro(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator << (std::ostream&, const Metro&);
    friend std::istream& operator >> (std::istream&, Metro&);
};
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
class Trolley_Bus:public Town_Transport
{
public:
    Trolley_Bus(){}
    Trolley_Bus(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TrolleyWhere, P_o_t_, TrolleyName, m_s_, TrolleyNum, year_){}
    virtual ~Trolley_Bus(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator <<(std::ostream&, const Trolley_Bus&);
    friend std::istream& operator >>(std::istream&, Trolley_Bus&);
};
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
class Electric_Train:public Town_Transport
{
public:
    Electric_Train(){}
    Electric_Train(double P_o_t_, double m_s_, int year_)
        :Town_Transport(TrainWhere, P_o_t_, TrainName, m_s_, TrainNum, year_){}
    virtual ~Electric_Train(){}
    virtual void SetInfo(double P_o_t_, double m_s_, int year_);
    friend std::ostream& operator <<(std::ostream&, const Electric_Train&);
    friend std::istream& operator >>(std::istream&, Electric_Train&);
};
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
class Air_Transport:public Transport
{
protected:
    std::string Flying;//Каким образом летают. Константа.
    int max_height;//Макс высота в киллометрах. Константа.
    std::string Material;//Из чего сделано средство. Константа.
    double max_lenght;//Макс дальность полета при полном баке. Константа
public:
    Air_Transport(){}
    Air_Transport(std::string Flying_, int m_h_, std::string Material_, double max_lenght,
        std::string name_, double m_s_, int num_, int year_):Transport(name_, m_s_, num_, year_){}
    virtual ~Air_Transport(){}
    std::string GetFlying() const {return Flying;}
    int GetHeight() const {return max_height;}
    std::string GetMat() const {return Material;}
    double GetLenght() const {return max_lenght;}
};
class AirPlane:public Air_Transport
{
private:
    int num_of_eng;//Колличество двигателей(турбин)
    double lenght_of_body;//Длина фюзеляжа
    int num_of_members;//Колличество членов экипажа
public:
    AirPlane(){}
    AirPlane(int n_o_e_, double l_o_b_, int n_o_m_, int year_, double m_s_)
        :Air_Transport(PlaneFlying, PlaneHeight, PlaneMat, PlaneLen, PlaneName, m_s_, PlaneNum, year_),
        num_of_eng(n_o_e_), lenght_of_body(l_o_b_), num_of_members(n_o_m_){}
    virtual ~AirPlane(){}
    int GetEng() const {return num_of_eng;}
    double GetBody() const {return lenght_of_body;}
    int GetMemb() const {return num_of_members;}
    virtual void SetInfo(int n_o_e_, double l_o_b_, int n_o_m_, int year_, double m_s_);
    friend std::ostream& operator <<(std::ostream&, const AirPlane&);
    friend std::istream& operator >>(std::istream&, AirPlane&);
};
class Helicopter:public Air_Transport
{
private:
    double speed;//Скорость вращения винта
public:
    Helicopter(){}
    Helicopter(double speed_, int year_, double m_s_)
        :Air_Transport(HelFlying, HelHeight, HelMat, HelLen, HelName, m_s_, HelNum, year_), speed(speed_){}
    virtual ~Helicopter(){}
    double GetSp() const {return speed;}
    virtual void SetInfo(double speed_, int year_, double m_s_);
    friend std::ostream& operator <<(std::ostream&, const Helicopter&);
    friend std::istream& operator >>(std::istream&, Helicopter&);
};
#endif
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//Classes.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "Classes.h"
 
void Transport::SetInfo(double max_speed_, int year_)
{
    max_speed=max_speed_;
    year=year_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Auto::SetInfo(std::string mark_, std::string country_)
{
    mark=mark_;
    country=country_;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void Car::SetInfo(double max_speed_, int year_, std::string mark_, std::string country_, double _run, double _volume)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    run=_run; 
    volume=_volume;
}
/////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, const Car&p)
{
        str<<"Name: "<< CarName <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
        str<<"Num: "<< CarNum <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
        str<<"Fuel: "<< CarFuel <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
        str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Run: "<< p.GetRun() <<'\n';
        str<<"Volume: "<< p.GetVolume() <<'\n'; return str;
}
///////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Car&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed; std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter run: \n";str>>p.run; std::cout<<"Enter volume: \n";str>>p.volume;
    return str;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
void Truck::SetInfo(double max_speed_, int year_,std::string mark_,std::string country_,double cargo_,std::string goods_,std::string BT_)
{
    Transport::SetInfo(max_speed_, year_);
    Auto::SetInfo(mark_, country_);
    cargo=cargo_; 
    goods=goods_; 
    Body_type=BT_;
}
//////////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream&str, const Truck&p)
{
    str<<"Name: "<< TruckName <<'\n'; str<<"Max_speed: "<< p.GetSpeed() <<'\n';
    str<<"Num: "<< TruckNum <<'\n'; str<<"Year: "<< p.GetYear() <<'\n';
    str<<"Fuel: "<< TruckFuel <<'\n'; str<<"Mark: "<< p.GetMark() <<'\n';
    str<<"Country: "<< p.GetCountry() <<'\n'; str<<"Cargo: "<< p.GetCargo() <<'\n';
    str<<"Goods: "<< p.GetGoods() <<'\n'; str<<"Body_tipe: "<< p.GetBT() <<'\n'; return str;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator>>(std::istream&str, Truck&p)
{
    std::cout<<"Enter max speed: \n";str>>p.max_speed;std::cout<<"Enter year: \n";str>>p.year;
    std::cout<<"Enter mark: \n";str>>p.mark; std::cout<<"Enter country: \n";str>>p.country; 
    std::cout<<"Enter cargo: \n";str>>p.cargo;std::cout<<"Enter goods: \n";str>>p.goods; 
    std::cout<<"Enter body tipe: \n";str>>p.Body_type;
    return str;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Town_Transport::SetInfo(double P_o_t_)
{
    Price_of_ticket=P_o_t_;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void Bus::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
/////////////////////////////////////////////////////////////////////
std::ostream& operator << (std::ostream&os, const Bus&Ob)
{
    os<<"Name: "<< BusName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< BusNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< BusWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
//////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Bus&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Tram::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Tram&Ob)
{
    os<<"Name: "<< TramName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TramNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TramWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Tram&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Metro::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Metro&Ob)
{
    os<<"Name: "<< MetroName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< MetroNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< MetroWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Metro&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Trolley_Bus::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Trolley_Bus&Ob)
{
    os<<"Name: "<< TrolleyName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TrolleyNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TrolleyWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Trolley_Bus&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void Electric_Train::SetInfo(double P_o_t_, double m_s_, int year_)
{
    Transport::SetInfo(m_s_, year_);
    Town_Transport::SetInfo(P_o_t_);
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Electric_Train&Ob)
{
    os<<"Name: "<< TrainName <<'\n'; os<<"Max_speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< TrainNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Where: "<< TrainWhere <<'\n'; os<<"Price of ticket: "<< Ob.GetPrice() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Electric_Train&Ob)
{
    std::cout<<"Enter max_speed: \n"; is>>Ob.max_speed; std::cout<<"Enter year: \n"; is>>Ob.year;
    std::cout<<"Enter price of ticket: \n"; is>>Ob.Price_of_ticket;
    return is;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void AirPlane::SetInfo(int n_o_e_, double l_o_b_, int n_o_m_, int year_, double m_s_)
{
    Transport::SetInfo(m_s_, year_);
    num_of_eng=n_o_e_;
    lenght_of_body=l_o_b_;
    num_of_members=n_o_m_;
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const AirPlane&Ob)
{
    os<<"Name: "<< PlaneName <<'\n'; os<<"Max speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< PlaneNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Flying: "<< PlaneFlying <<'\n'; os<<"Max height: "<< PlaneHeight <<'\n';
    os<<"Matetial: "<< PlaneMat <<'\n'; os<<"Max lenght: "<< PlaneLen <<'\n';
    os<<"Num of eng: "<< Ob.GetEng() <<'\n'; os<<"Lenght of body: "<< Ob.GetBody() <<'\n';
    os<<"Num of members: "<< Ob.GetMemb() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, AirPlane&Ob)
{
    std::cout<<"Enter max speed: \n";is>>Ob.max_speed; std::cout<<"Enter year: \n";is>>Ob.year;
    std::cout<<"Enter num of eng: \n";is>>Ob.num_of_eng; std::cout<<"Enter lenght of body: \n";is>>Ob.lenght_of_body;
    std::cout<<"Enter num of members: \n";is>>Ob.num_of_members;
    return is;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void Helicopter::SetInfo(double speed_, int year_, double m_s_)
{
    Transport::SetInfo(m_s_, year_);
    speed=speed_;
}
///////////////////////////////////////////////////////////////////////
std::ostream& operator <<(std::ostream&os, const Helicopter&Ob)
{
    os<<"Name: "<< HelName <<'\n'; os<<"Max speed: "<< Ob.GetSpeed() <<'\n';
    os<<"Num: "<< HelNum <<'\n'; os<<"Year: "<< Ob.GetYear() <<'\n';
    os<<"Flying: "<< HelFlying <<'\n'; os<<"Max height: "<< HelHeight <<'\n';
    os<<"Matetial: "<< HelMat <<'\n'; os<<"Max lenght: "<< HelLen <<'\n';
    os<<"Speed: "<< Ob.GetSp() <<'\n';
    return os;
}
///////////////////////////////////////////////////////////////////////
std::istream& operator >>(std::istream&is, Helicopter&Ob)
{
    std::cout<<"Enter max speed: \n";is>>Ob.max_speed; std::cout<<"Enter year: \n";is>>Ob.year;
    std::cout<<"Enter speed: \n";is>>Ob.speed;
    return is;
}
C++
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//Trans.cpp
#include <iostream>
#include <cstdlib>
#include "Classes.h"
int main()
{
    int Num=0;
    int k=0;
    int l=0;
Start:
    std::cout<<"Enter k:\n" 
    "1 for work with Transport\n" 
    "2 for work with Town transport\n" 
    "3 for work with Air transport\n";
    std::cin>>k;
    if(!std::cin.good())
    {
        std::cout<<"Error\n";
        exit(1);
    }
    if(k==1)
    {
StartTr:
        std::cout<<"Enter l:\n" 
        "1 for work with Car\n" 
        "2 for work with Truck\n";
        std::cin>>l;
        if(std::cin.fail())
        {
            std::cout<<"Error\n";
            exit(1);
        }
        if(l==1)
        {
            Car*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new Car[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Truck*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new Truck[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to beginning of Transport\n";
            goto StartTr;
        }
    }
    else if(k==2)
    {
StartTT:
        std::cout<<"Enter l:\n" 
        "1 for work with Bus\n" 
        "2 for work with Tram\n" 
        "3 for work with Metro\n" 
        "4 for work with Trolley bus\n" 
        "5 for work with Train\n";
        std::cin>>l;
        if(std::cin.fail())
        {   
            std::cout<<"Error\n";
            exit(1);
        }
        if(l==1)
        {
            Bus*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            Arr=new Bus[Num];
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            if(std::cin.fail())
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Tram*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new Tram[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==3)
        {
            Metro*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new Metro[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==4)
        {
            Trolley_Bus*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new Trolley_Bus[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==5)
        {
            Electric_Train*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new Electric_Train[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<< Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to the beginning of Town Transport\n";
            goto StartTT;
        }
    }
    else if(k==3)
    {
StartAT:
        std::cout<<"Enter l:\n"
        "1 for work with Airplane\n" 
        "2 for work with Helicopter\n";
        std::cin>>l;
        if(std::cin.fail())
        {   
            std::cout<<"Error\n";
            exit(1);
        }
        if(l==1)
        {
            AirPlane*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new AirPlane[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else if(l==2)
        {
            Helicopter*Arr;
            std::cout<<"Enter number of elements in array\n";
            std::cin>>Num;
            if(std::cin.fail())
            {   
                std::cout<<"Error\n";
                exit(1);
            }
            Arr=new Helicopter[Num];
            for(int i=0;i<Num;i++)
                std::cin>>Arr[i];
            for(int i=0;i<Num;i++)
                std::cout<<Arr[i];
            delete[] Arr;
        }
        else
        {
            std::cout<<"There is no such option. Program going to beginning of Air Transport\n";
            goto StartAT;
        }
    }
    else 
    {
        std::cout<<"There is no such option. Program going to the beginning\n";
        goto Start;
    }
    system("pause");
    return 0;
}
0
 Аватар для Фоат
165 / 82 / 32
Регистрация: 05.02.2010
Сообщений: 318
29.07.2010, 14:18
Ребята , Вы молодцы, ваша тема очень интересна , пока тока изучаю С++ и Ооп и пытаюсь сделать элементарное .
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
BasicMan
Эксперт
29316 / 5623 / 2384
Регистрация: 17.02.2009
Сообщений: 30,364
Блог
29.07.2010, 14:18
Помогаю со студенческими работами здесь

ООП на С++
Помогите пожалуйста!! Не понимаю как это сделать(( Создать программу с классом Student порождающий обьекты - данные об студентах...

ООП
1) Для класса символьной строки определить отношение лексикографического порядка, перегрузив с помощью дружественной функции операцию...

по ООП .
Помогите пожалуйтса с решением задач ! на С++ 1.Дана неубывающая последовательность действительных чисел. Вставить в неё...

ООП
проблема в классе квадрат- ниже код, я не прошу его переписывать, попробуйте кто то у себя запустите и будьте добры скажите почему там...

ООП
Создать класс Vegetable, содержащий следующие элементы: - поле «вес» float Mass; - поле «зрелость» int Ripeness; - метод получения...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
37
Ответ Создать тему
Новые блоги и статьи
модель ЗдравоСохранения 5. Меньше увольнений- больше дохода!
anaschu 24.03.2026
Теперь система здравосохранения уменьшает количество увольнений. 9TO2GP2bpX4 a42b81fb172ffc12ca589c7898261ccb/ https:/ / rutube. ru/ video/ a42b81fb172ffc12ca589c7898261ccb/ Слева синяя линия -. . .
Midnight Chicago Blues
kumehtar 24.03.2026
Такой Midnight Chicago Blues, знаешь?. . Когда вечерние улицы становятся ночными, а ты не можешь уснуть. Ты идёшь в любимый старый бар, и бармен наливает тебе виски. Ты смотришь на пролетающие. . .
Контроль уникальности заводского номера - вариант №2
Maks 24.03.2026
В отличие от предыдущего варианта добавлено прерывание циклов, также добавлены новые переменные для сохранения контекста ошибки перед прерыванием цикла: Процедура ПередЗаписью(Отказ, РежимЗаписи,. . .
SDL3 для Desktop (MinGW): Вывод текста со шрифтом TTF с помощью библиотеки SDL3_ttf на Си и C++
8Observer8 24.03.2026
Содержание блога Финальные проекты на Си и на C++: finish-text-sdl3-c. zip finish-text-sdl3-cpp. zip
Жизнь в неопределённости
kumehtar 23.03.2026
Жизнь — это постоянное существование в неопределённости. Например, даже если у тебя есть список дел, невозможно дойти до точки, где всё окончательно завершено и больше ничего не осталось. В принципе,. . .
Модель здравоСохранения: работники работают быстрее после её введения.
anaschu 23.03.2026
geJalZw1fLo Корпорация до введения программа здравоохранения имела много невыполненных работниками заданий, после введения программы количество заданий выросло. Но на выплатах по больничным это. . .
Контроль уникальности заводского номера - вариант №1
Maks 23.03.2026
Алгоритм контроля уникальности заводского (или серийного) номера на примере документа выдачи шин для спецтехники с табличной частью в КА2. Данные берутся из регистра сведений, по которому настроено. . .
Хочу заставить корпорации вкладываться в здоровье сотрудников: делаю мат модель здравосохранения
anaschu 22.03.2026
e7EYtONaj8Y Z4Tv2zpXVVo https:/ / github. com/ shumilovas/ med2. git
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru