задание Создать программу с классом Bus, порождающим объекты – данные о конкретных автобусных рейсах. Класс включает в себя следующие поля: - номер рейса; - тип автобуса; - пункт назначения; - цена билета; - время отправления; - время прибытия на конечный пункт. В состав класса входят следующие методы: - конструктор; - деструктор; - функция просмотра текущего состояния объектов print(); - функция установки текущего состояния объектов для остальных элементов; - функция друг, выводящая информацию о рейсах, которыми можно воспользоваться для прибытия в пункт назначения раньше заданного времени - виртуальная функция просмотра текущего объекта print(). Производный класс Express содержит следующие данные об автобусах –экспрессах: - процентная надбавка на цену билета; - выйгрыш во времени; - переопределённую функцию просмотра состояния объектов. С экспрессом вопрос: нужно создавать новый массив, туда закидывать автобусы и делать к ним надбавку и выигрыш по времени, и выводить новый массив или как? Просто сейчас у меня в выводе инфы просто берется основной массив, добавляется надбавка и тд и выводит все автобусы как экспрессы, но я думаю меня препод нахуй пошлет с таким приколом Насчет разделения на 2 файла препод сказал так сделать, так шо не ругайтеся плизки мой код срр файл #include <iostream> #include <iomanip> #include <string> #include "Bus.h" using namespace std; void fast(Bus* mas, int n, string city, int time) { cout << endl; cout << "* номер автобуса: * * время отправления: * * время прибытия: *" << endl; cout << "*****************************************************************" << endl; for (int i = 0; i < n; i++) { if (mas[i].punct_nazn == city && mas[i].time_prib < time) { cout << "* " << mas[i].number << " * * " << setprecision(4) << mas[i].time_ot << " * * " << setprecision(4) << mas[i].time_prib << " * " << endl; cout << "*****************************************************************" << endl; } } } int main() { setlocale(LC_ALL, "ru"); int n; cout << "Количество автобусов: "; cin >> n; cout << "\n"; Bus* mas_bus = new Bus[n]; for (int i = 0; i < n; i++) { int number, nb; float time_ot , time_prib; string type, punct_nazn; double price; cout << "Номер автобуса: "; cin >> number; cout << "\n"; cout << "Время отправления: "; cin >> time_ot; cout << "\n"; while (time_ot > 23.59001 || time_ot < 0 || (0.6 <= time_ot && time_ot < 1) || (1.6 <= time_ot && time_ot < 2) || (2.6 <= time_ot && time_ot < 3) || (3.6 <= time_ot && time_ot < 4) || (4.6 <= time_ot && time_ot < 5) || (5.6 <= time_ot && time_ot < 6) || (6.6 <= time_ot && time_ot < 7) || (7.6 <= time_ot && time_ot < 8) || (8.6 <= time_ot && time_ot < 9) || (9.6 <= time_ot && time_ot < 10) || (10.6 <= time_ot && time_ot < 11) || (11.6 <= time_ot && time_ot < 12) || (12.6 <= time_ot && time_ot < 13) || (13.6 <= time_ot && time_ot < 14) || (14.6 <= time_ot && time_ot < 15) || (15.6 <= time_ot && time_ot < 16) || (16.6 <= time_ot && time_ot < 17) || (17.6 <= time_ot && time_ot < 18) || (18.6 <= time_ot && time_ot < 19) || (19.6 <= time_ot && time_ot < 20) || (20.6 <= time_ot && time_ot < 21) || (21.6 <= time_ot && time_ot < 22) || (22.6 <= time_ot && time_ot < 23)) { cout << "Введите корректное время отправления: "; cin >> time_ot; }; cout << "Время прибытия: "; cin >> time_prib; cout << "\n"; while (time_prib > 23.59001 || time_prib < 0 || (0.6 <= time_prib && time_prib < 1) || (1.6 <= time_prib && time_prib < 2) || (2.6 <= time_prib && time_prib < 3) || (3.6 <= time_prib && time_prib < 4) || (4.6 <= time_prib && time_prib < 5) || (5.6 <= time_prib && time_prib < 6) || (6.6 <= time_prib && time_prib < 7) || (7.6 <= time_prib && time_prib < 8) || (8.6 <= time_prib && time_prib < 9) || (9.6 <= time_prib && time_prib < 10) || (10.6 <= time_prib && time_prib < 11) || (11.6 <= time_prib && time_prib < 12) || (12.6 <= time_prib && time_prib < 13) || (13.6 <= time_prib && time_prib < 14) || (14.6 <= time_prib && time_prib < 15) || (15.6 <= time_prib && time_prib < 16) || (16.6 <= time_prib && time_prib < 17) || (17.6 <= time_prib && time_prib < 18) || (18.6 <= time_prib && time_prib < 19) || (19.6 <= time_prib && time_prib < 20) || (20.6 <= time_prib && time_prib < 21) || (21.6 <= time_prib && time_prib < 22) || (22.6 <= time_prib && time_prib < 23)) { cout << "Введите корректное время прибытия: "; cin >> time_prib; }; cout << "Тип автобуса: "; cin >> type; cout << "\n"; cout << "Пункт назначения: "; cin >> punct_nazn; cout << "\n"; cout << "Стоимость билета "; cin >> price; cout << "\n"; mas_bus[i] = Bus(number, price, time_ot, time_prib, type, punct_nazn); } int gg = 0; while (true) { cout << "Введите: \n 0 - Выход \n 1 - Общая информация об автобусах \n 2 - Для показа автобусов, на которых можно доехать в пункт назначения раньше заданного времени\n 3 - Сделать из обычного автобуса экспресс \n " << endl; cin >> gg; switch (gg) { case 1: { Bus avtiki; avtiki.print(mas_bus, n); break; } case 2: { string city; float time; cout << "Пункт назначения: "; cin >> city; cout << "Время прибытия: "; cin >> time; while (time > 23.59001 || time < 0 || (0.6 <= time && time < 1) || (1.6 <= time && time < 2) || (2.6 <= time && time < 3) || (3.6 <= time && time < 4) || (4.6 <= time && time < 5) || (5.6 <= time && time < 6) || (6.6 <= time && time < 7) || (7.6 <= time && time < 8) || (8.6 <= time && time < 9) || (9.6 <= time && time < 10) || (10.6 <= time && time < 11) || (11.6 <= time && time < 12) || (12.6 <= time && time < 13) || (13.6 <= time && time < 14) || (14.6 <= time && time < 15) || (15.6 <= time && time < 16) || (16.6 <= time && time < 17) || (17.6 <= time && time < 18) || (18.6 <= time && time < 19) || (19.6 <= time && time < 20) || (20.6 <= time && time < 21) || (21.6 <= time && time < 22) || (22.6 <= time && time < 23)) { cout << "Введите корректное время прибытия: "; cin >> time; }; fast(mas_bus, n, city, time); break; } case 3: { Express expr; expr.print(mas_bus, n); break; } default: { return 0; } } } }; C #include <iostream> #include <iomanip> #include <string> #include "Bus.h" using namespace std; void fast(Bus* mas, int n, string city, int time) { cout << endl; cout << "* номер автобуса: * * время отправления: * * время прибытия: *" << endl; cout << "*****************************************************************" << endl; for (int i = 0; i < n; i++) { if (mas[i].punct_nazn == city && mas[i].time_prib < time) { cout << "* " << mas[i].number << " * * " << setprecision(4) << mas[i].time_ot << " * * " << setprecision(4) << mas[i].time_prib << " * " << endl; cout << "*****************************************************************" << endl; } } } int main() { setlocale(LC_ALL, "ru"); int n; cout << "Количество автобусов: "; cin >> n; cout << "\n"; Bus* mas_bus = new Bus[n]; for (int i = 0; i < n; i++) { int number, nb; float time_ot , time_prib; string type, punct_nazn; double price; cout << "Номер автобуса: "; cin >> number; cout << "\n"; cout << "Время отправления: "; cin >> time_ot; cout << "\n"; while (time_ot > 23.59001 || time_ot < 0 || (0.6 <= time_ot && time_ot < 1) || (1.6 <= time_ot && time_ot < 2) || (2.6 <= time_ot && time_ot < 3) || (3.6 <= time_ot && time_ot < 4) || (4.6 <= time_ot && time_ot < 5) || (5.6 <= time_ot && time_ot < 6) || (6.6 <= time_ot && time_ot < 7) || (7.6 <= time_ot && time_ot < 8) || (8.6 <= time_ot && time_ot < 9) || (9.6 <= time_ot && time_ot < 10) || (10.6 <= time_ot && time_ot < 11) || (11.6 <= time_ot && time_ot < 12) || (12.6 <= time_ot && time_ot < 13) || (13.6 <= time_ot && time_ot < 14) || (14.6 <= time_ot && time_ot < 15) || (15.6 <= time_ot && time_ot < 16) || (16.6 <= time_ot && time_ot < 17) || (17.6 <= time_ot && time_ot < 18) || (18.6 <= time_ot && time_ot < 19) || (19.6 <= time_ot && time_ot < 20) || (20.6 <= time_ot && time_ot < 21) || (21.6 <= time_ot && time_ot < 22) || (22.6 <= time_ot && time_ot < 23)) { cout << "Введите корректное время отправления: "; cin >> time_ot; }; cout << "Время прибытия: "; cin >> time_prib; cout << "\n"; while (time_prib > 23.59001 || time_prib < 0 || (0.6 <= time_prib && time_prib < 1) || (1.6 <= time_prib && time_prib < 2) || (2.6 <= time_prib && time_prib < 3) || (3.6 <= time_prib && time_prib < 4) || (4.6 <= time_prib && time_prib < 5) || (5.6 <= time_prib && time_prib < 6) || (6.6 <= time_prib && time_prib < 7) || (7.6 <= time_prib && time_prib < 8) || (8.6 <= time_prib && time_prib < 9) || (9.6 <= time_prib && time_prib < 10) || (10.6 <= time_prib && time_prib < 11) || (11.6 <= time_prib && time_prib < 12) || (12.6 <= time_prib && time_prib < 13) || (13.6 <= time_prib && time_prib < 14) || (14.6 <= time_prib && time_prib < 15) || (15.6 <= time_prib && time_prib < 16) || (16.6 <= time_prib && time_prib < 17) || (17.6 <= time_prib && time_prib < 18) || (18.6 <= time_prib && time_prib < 19) || (19.6 <= time_prib && time_prib < 20) || (20.6 <= time_prib && time_prib < 21) || (21.6 <= time_prib && time_prib < 22) || (22.6 <= time_prib && time_prib < 23)) { cout << "Введите корректное время прибытия: "; cin >> time_prib; }; cout << "Тип автобуса: "; cin >> type; cout << "\n"; cout << "Пункт назначения: "; cin >> punct_nazn; cout << "\n"; cout << "Стоимость билета "; cin >> price; cout << "\n"; mas_bus[i] = Bus(number, price, time_ot, time_prib, type, punct_nazn); } int gg = 0; while (true) { cout << "Введите: \n 0 - Выход \n 1 - Общая информация об автобусах \n 2 - Для показа автобусов, на которых можно доехать в пункт назначения раньше заданного времени\n 3 - Сделать из обычного автобуса экспресс \n " << endl; cin >> gg; switch (gg) { case 1: { Bus avtiki; avtiki.print(mas_bus, n); break; } case 2: { string city; float time; cout << "Пункт назначения: "; cin >> city; cout << "Время прибытия: "; cin >> time; while (time > 23.59001 || time < 0 || (0.6 <= time && time < 1) || (1.6 <= time && time < 2) || (2.6 <= time && time < 3) || (3.6 <= time && time < 4) || (4.6 <= time && time < 5) || (5.6 <= time && time < 6) || (6.6 <= time && time < 7) || (7.6 <= time && time < 8) || (8.6 <= time && time < 9) || (9.6 <= time && time < 10) || (10.6 <= time && time < 11) || (11.6 <= time && time < 12) || (12.6 <= time && time < 13) || (13.6 <= time && time < 14) || (14.6 <= time && time < 15) || (15.6 <= time && time < 16) || (16.6 <= time && time < 17) || (17.6 <= time && time < 18) || (18.6 <= time && time < 19) || (19.6 <= time && time < 20) || (20.6 <= time && time < 21) || (21.6 <= time && time < 22) || (22.6 <= time && time < 23)) { cout << "Введите корректное время прибытия: "; cin >> time; }; fast(mas_bus, n, city, time); break; } case 3: { Express expr; expr.print(mas_bus, n); break; } default: { return 0; } } } }; классы /* Bus.h */ #include <iostream> #include <string> using namespace std; class Bus { friend void fast(Bus* mas, int n, string city, int time); int main(); public: int number; float time_ot, time_prib, exptime; string type, punct_nazn; double price; Bus() { number = price = 0; time_ot = time_prib = 0; type = punct_nazn = '0'; } Bus(int number, double price, float time_ot, float time_prib, string type, string punct_nazn) { this->number = number; this->time_ot = time_ot; this->time_prib = time_prib; this->type = type; this->punct_nazn = punct_nazn; this->price = price; }; ~Bus() { cout << "деструктор.\n"; }; virtual void print(Bus* mas, int n) { for (int i = 0; i < n; i++) { cout << " Номер автобуса - " << mas[i].number << " \n Время отправления - " << setprecision(4) << mas[i].time_ot << " \n Время прибытия - " << setprecision(4) << mas[i].time_prib << " \n Тип автобуса - " << mas[i].type << " \n Пункт назначения - " << mas[i].punct_nazn << " \n Стоимость - " << setprecision(4) << mas[i].price << endl << endl; }; }; }; class Express :public Bus { public: float nadb = 0, time_win = 0; void print(Bus* mas, int n) override { cout << "Надбавка (в процентах)" << endl; cin >> nadb; cout << "Выигрыш по времени" << endl; cin >> time_win; for (int i = 0; i < n; i++) { mas[i].time_prib = (mas[i].time_prib - time_win); mas[i].price = (mas[i].price * ( 1 + ( nadb / 100 ))); }; for (int i = 0; i < n; i++) { cout << "Экспресс автобусы" << endl; cout << " Номер автобуса - " << mas[i].number << " \n Время отправления - " << setprecision(4) << mas[i].time_ot << " \n Время прибытия - " << setprecision(4) << mas[i].time_prib << " \n Тип автобуса - " << mas[i].type << " \n Пункт назначения - " << mas[i].punct_nazn << " \n Стоимость - " << setprecision(4) << (mas[i].price) << endl << endl; }; for (int i = 0; i < n; i++) { mas[i].time_prib = (mas[i].time_prib + time_win); mas[i].price = (mas[i].price / ( 1 + ( nadb / 100 ))); }; }; }; #pragma once #pragma once C /* Bus.h */ #include <iostream> #include <string> using namespace std; class Bus { friend void fast(Bus* mas, int n, string city, int time); int main(); public: int number; float time_ot, time_prib, exptime; string type, punct_nazn; double price; Bus() { number = price = 0; time_ot = time_prib = 0; type = punct_nazn = '0'; } Bus(int number, double price, float time_ot, float time_prib, string type, string punct_nazn) { this->number = number; this->time_ot = time_ot; this->time_prib = time_prib; this->type = type; this->punct_nazn = punct_nazn; this->price = price; }; ~Bus() { cout << "деструктор.\n"; }; virtual void print(Bus* mas, int n) { for (int i = 0; i < n; i++) { cout << " Номер автобуса - " << mas[i].number << " \n Время отправления - " << setprecision(4) << mas[i].time_ot << " \n Время прибытия - " << setprecision(4) << mas[i].time_prib << " \n Тип автобуса - " << mas[i].type << " \n Пункт назначения - " << mas[i].punct_nazn << " \n Стоимость - " << setprecision(4) << mas[i].price << endl << endl; }; }; }; class Express :public Bus { public: float nadb = 0, time_win = 0; void print(Bus* mas, int n) override { cout << "Надбавка (в процентах)" << endl; cin >> nadb; cout << "Выигрыш по времени" << endl; cin >> time_win; for (int i = 0; i < n; i++) { mas[i].time_prib = (mas[i].time_prib - time_win); mas[i].price = (mas[i].price * ( 1 + ( nadb / 100 ))); }; for (int i = 0; i < n; i++) { cout << "Экспресс автобусы" << endl; cout << " Номер автобуса - " << mas[i].number << " \n Время отправления - " << setprecision(4) << mas[i].time_ot << " \n Время прибытия - " << setprecision(4) << mas[i].time_prib << " \n Тип автобуса - " << mas[i].type << " \n Пункт назначения - " << mas[i].punct_nazn << " \n Стоимость - " << setprecision(4) << (mas[i].price) << endl << endl; }; for (int i = 0; i < n; i++) { mas[i].time_prib = (mas[i].time_prib + time_win); mas[i].price = (mas[i].price / ( 1 + ( nadb / 100 ))); }; }; }; #pragma once #pragma once
а в чем собственно вопрос? задание у тебя дано, как видишь - так и кодь. или это "посмотрите я код написал"
енотик, /* Bus.h */ #include <iostream> #include <string> using namespace std; class Bus { friend void fast(Bus* mas, int n, string city, int time); int main(); public: int number; float time_ot, time_prib, exptime; string type, punct_nazn; double price; Bus(int number, double price, float time_ot, float time_prib, string type, string punct_nazn) { this->number = number; this->time_ot = time_ot; this->time_prib = time_prib; this->type = type; this->punct_nazn = punct_nazn; this->price = price; }; ~Bus() { cout << "деструктор.\n"; }; virtual void print() { cout << " Номер автобуса: " << this->number << endl << " Время отправления: " << this->time_ot << endl << " Время прибытия: " << this->time_prib << endl << " Тип автобуса: " << this->type << endl << " Пункт назначения: " << this->punct_nazn << endl << " Стоимость: " << this->price << endl << endl; }; }; class Express : public Bus { public: float nadb = 0, time_win = 0; Express(Bus* nonExpressBus, float nadb, float time_win) : Bus( nonExpressBus->number, nonExpressBus->price * (1 + nadb / 100), nonExpressBus->time_ot, nonExpressBus->time_prib - time_win, nonExpressBus->type, nonExpressBus->punct_nazn){ this->nadb = nadb; this->time_win = time_win; }; void print() override { cout << " Надбавка: " << this->nadb << "%" << endl << " Выигрыш по времени: " << this->time_win << endl; Bus::print(); }; }; int main() { Bus** buses = new Bus*[2]; buses[0] = new Bus(1, 50, 1300, 1700, "Ikarus", "Boo"); buses[1] = new Bus(2, 50, 1300, 1700, "Ikarus", "Foo"); for(int i = 0; i < 2; i++) buses[i]->print(); Bus* oldBus = buses[1]; buses[1] = new Express(buses[1], 20, 100); delete oldBus; for(int i = 0; i < 2; i++) buses[i]->print(); for(int i = 0; i < 2; i++) delete buses[i]; delete buses; return 0; } C /* Bus.h */ #include <iostream> #include <string> using namespace std; class Bus { friend void fast(Bus* mas, int n, string city, int time); int main(); public: int number; float time_ot, time_prib, exptime; string type, punct_nazn; double price; Bus(int number, double price, float time_ot, float time_prib, string type, string punct_nazn) { this->number = number; this->time_ot = time_ot; this->time_prib = time_prib; this->type = type; this->punct_nazn = punct_nazn; this->price = price; }; ~Bus() { cout << "деструктор.\n"; }; virtual void print() { cout << " Номер автобуса: " << this->number << endl << " Время отправления: " << this->time_ot << endl << " Время прибытия: " << this->time_prib << endl << " Тип автобуса: " << this->type << endl << " Пункт назначения: " << this->punct_nazn << endl << " Стоимость: " << this->price << endl << endl; }; }; class Express : public Bus { public: float nadb = 0, time_win = 0; Express(Bus* nonExpressBus, float nadb, float time_win) : Bus( nonExpressBus->number, nonExpressBus->price * (1 + nadb / 100), nonExpressBus->time_ot, nonExpressBus->time_prib - time_win, nonExpressBus->type, nonExpressBus->punct_nazn){ this->nadb = nadb; this->time_win = time_win; }; void print() override { cout << " Надбавка: " << this->nadb << "%" << endl << " Выигрыш по времени: " << this->time_win << endl; Bus::print(); }; }; int main() { Bus** buses = new Bus*[2]; buses[0] = new Bus(1, 50, 1300, 1700, "Ikarus", "Boo"); buses[1] = new Bus(2, 50, 1300, 1700, "Ikarus", "Foo"); for(int i = 0; i < 2; i++) buses[i]->print(); Bus* oldBus = buses[1]; buses[1] = new Express(buses[1], 20, 100); delete oldBus; for(int i = 0; i < 2; i++) buses[i]->print(); for(int i = 0; i < 2; i++) delete buses[i]; delete buses; return 0; }