Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <windows.h>
- using namespace std;
- class Transport {
- protected:
- int capacity;
- public:
- void getCapacity() {
- cout << "Введите грузоподьемность: ";
- cin >> capacity;
- }
- bool find(int a) {
- return (capacity <= a);
- }
- virtual void getData() = 0;
- };
- class Car :public Transport {
- private:
- string model;
- int number, velocity;
- public:
- void getData() {
- cout << "Марка машины: "; cin >> model;
- cout << "Номер машины: "; cin >> number;
- cout << "Средняя скорость: "; cin >> velocity;
- Transport::getCapacity();
- cout << endl;
- }
- void getInfo() {
- cout << "Марка: " << model << endl;
- cout << "Номер машины: " << number << endl;
- cout << "Средняя скорость: " << velocity << endl;
- cout << "Грузоподьемность: " << capacity << endl;
- cout << endl;
- }
- };
- class Motorbike :public Transport {
- private:
- string model;
- int number, velocity, carriage;
- public:
- void getData() {
- cout << "Марка мотоцикла: "; cin >> model;
- cout << "Номер мотоцикла: "; cin >> number;
- cout << "Средняя скорость: "; cin >> velocity;
- cout << "Наличие коляски('1' - есть, '0' - нет): "; cin >> carriage;
- switch (carriage) {
- case 1: {Transport::getCapacity(); cout << endl;
- break; }
- case 0: { cout << "Грузоподьемность: 0" << endl;
- break; }
- default: cout << "Введен неверный символ!";
- }
- }
- };
- class Truck :public Transport {
- private:
- string model;
- int number, velocity, trailer;
- public:
- void getData() {
- cout << "Марка грузовика: "; cin >> model;
- cout << "Номер грузовика: "; cin >> number;
- cout << "Средняя скорость: "; cin >> velocity;
- cout << "Наличие прицепа('1' - есть, '0' - нет): "; cin >> trailer;
- switch (trailer) {
- case 1: {Transport::getCapacity();
- cout << "Грузоподьемность с прицепом: " << capacity * 2 << endl;
- break; }
- case 0: { Transport::getCapacity();
- break; }
- default: cout << "Введен неверный символ!";
- }
- }
- };
- int main() {
- setlocale(LC_ALL, "russian");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- Car * CarBase[20];
- int n = 0;
- char choice;
- cout << "Добавить машину в базу данных(д/н): ";
- cin >> choice;
- do {
- switch (choice) {
- case 'д': CarBase[n] = new Car(); break;
- case 'н': continue;
- default: {cout << "Вы ввели неверный символ!" << endl;
- choice = 'д';
- continue;
- }
- }
- CarBase[n++]->getData();
- cout << " Ввести еще машину (д/н)? ";
- cin >> choice;
- } while (choice == 'д');
- Motorbike mtb;
- mtb.getData();
- Truck trck;
- trck.getData();
- int a;
- cout << "Введите необходимую грузоподьемность машины: ";
- cin >> a;
- for (int j = 0; j < n; j++) {
- if (CarBase[j]->find(a))
- CarBase[j]->getInfo();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement