#include <iostream>
#include <string>
#include <list>
#include <stdlib.h>
#include <windows.h>
#include <fstream>
using namespace std;
class Bus {
public:
int id;
string driverName;
bool inPark;
int routeId;
Bus(int id1, string driverName1, int routeId1) {
id = id1;
driverName = driverName1;
routeId = routeId1;
inPark = false;
}
void info() {
cout << "Автобус #" << id << ", ФИО Водителя: " << driverName;
if (inPark) {
cout << ", Находится в парке";
} else {
cout << ", Номер маршрута: #" << routeId;
}
cout << endl;
}
};
list<Bus*> trvl;
list<Bus*> park;
void mainMenu();
void addMenu();
void uehalMenu();
void priehalMenu();
void showData();
void addMenu() {
int id;
string driverName;
int routeId;
cout << "========" << endl;
cout << "Добавить новый автобус:" << endl;
cout << "Введите номер автобуса" << endl;
cin >> id;
cin.ignore();
cout << "Введите ФИО водителя" << endl;
cin >> driverName;
cin.ignore();
cout << "Введите номер маршрута" << endl;
cin >> routeId;
cin.ignore();
Bus *bus = new Bus(id, driverName, routeId);
trvl.push_back(*(&bus));
cout << "Автобус добавлен" << endl;
cout << "========" << endl;
mainMenu();
}
void uehalMenu() {
int id;
int routeId;
cout << "========" << endl;
cout << "Введите номер автобуса" << endl;
cin >> id;
cin.ignore();
cout << "Введите номер маршрута" << endl;
cin >> routeId;
cin.ignore();
for (auto it = park.begin(); it != park.end(); ++it) {
if ((*it)->id == id) {
(*it)->routeId = routeId;
trvl.push_back(*it);
park.remove(*it);
}
}
cout << "Автобус удалён из парка" << endl;
cout << "========" << endl;
mainMenu();
}
void priehalMenu() {
int id;
cout << "========" << endl;
cout << "Введите номер автобуса" << endl;
cin >> id;
cin.ignore();
for (auto it = trvl.begin(); it != trvl.end(); ++it) {
if ((*it)->id == id) {
(*it)->inPark = true;
park.push_back(*it);
trvl.remove(*it);
}
}
cout << "========" << endl;
mainMenu();
}
void showData() {
cout << "========" << endl;
cout << "Автобусы в маршруте:" << endl;
for (auto it = trvl.begin(); it != trvl.end(); ++it) {
(*it)->info();
}
cout << "========" << endl;
cout << "Автобусы в парке:" << endl;
for (auto it = park.begin(); it != park.end(); ++it) {
(*it)->info();
}
if (trvl.size() < 1 && park.size() < 1) {
cout << "Нет данных в автобусах" << endl;
}
cout << "========" << endl;
mainMenu();
}
void LoadBD(){
int number;
string full_name;
int route;
ifstream f("bd.txt");
ifstream f1("bd2.txt");
if (!f.is_open() || !f1.is_open()){
cout << "\t\tОТСУТСТВУЕТ БАЗА ДАННЫХ АВТОБУСНОГО ПАРКА! РАБОТА НЕВОЗМОЖНА!" << endl;
return;
}
while (!f.eof()){
f>>number;
f>>route;
f>>full_name;
Bus *bus = new Bus(number, full_name, route);
trvl.push_back(*(&bus));
}
while (!f1.eof()){
f1>>number;
f1>>route;
f1>>full_name;
Bus *bus = new Bus(number, full_name, route);
park.push_back(*(&bus));
}
cout << "\t\tУСПЕШНАЯ ЗАГРУЗКА БАЗЫ ДАННЫХ" << endl;
}
void mainMenu() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
LoadBD();
string choice;
cout << "Главное меню:" << endl;
cout << "1. Добавить новый автобус" << endl;
cout << "2. Выезд автобуса из парк" << endl;
cout << "3. Въезд автобуса в парк" << endl;
cout << "4. Сведения об автобусах" << endl;
cout << "0. Выход" << endl;
cin >> choice;
cin.ignore();
switch (atoi(choice.c_str())) {
default:
cout << "Выбран неверный пункт меню" << endl;
break;
case 1:
addMenu();
break;
case 2:
uehalMenu();
break;
case 3:
priehalMenu();
break;
case 4:
showData();
break;
case 0:
exit(0);
break;
}
}
int main() {
mainMenu();
}