Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct list_node {
- train* data;
- list_node* next;
- }
- struct train {
- string destination;
- int number;
- unsigned int arrivalTime;
- }
- class TrainList {
- list_node *head;
- public:
- TrainList() {head = NULL;}
- ~TrainList();
- bool checkTrainIdValid(int id);
- void add();
- void remove();
- void show();
- void save();
- void load();
- }
- TrainList::~TrainList() {
- while (head != NULL) {
- list_node *tmp = head->next;
- delete head;
- head = tmp;
- }
- }
- bool TrainList::checkTrainNumberValid(int number) {
- list_node *iter = head;
- while (iter != NULL) {
- if (iter->number == number) {
- cerr << "Train with such number already exists!!!" << endl;
- return false;
- }
- }
- return true;
- }
- int main() {
- TrainList trains;
- while(true) {
- cout << "Commands:" << endl;
- cout << "Enter 1 to add new train;" << endl;
- cout << "Enter 2 to modify one of the trains" << endl;
- cout << "Enter 3 to show existing trains" << endl;
- cout << "Enter 4 to modify one of the trains" << endl;
- cout << "Enter 5 to delete one of the trains" << endl;
- cout << "Enter 6 to save trains to file" << endl;
- cout << "Enter 7 to load trains from file" << endl;
- cout << "Enter 8 to exit" << endl;
- string command;
- cin >> command;
- if(command.size() > 1) {
- cerr << "Wrond command, try again!" << endl;
- continue;
- }
- switch(command[0]) {
- case '1':
- trains.add();
- break;
- case '2':
- trains.modify();
- break;
- case '3':
- trains.show();
- break;
- case '4':
- break;
- case '5':
- break;
- case '6':
- break;
- case '7':
- break;
- case '8':
- break;
- case '9':
- break;
- default:
- cerr << "Wrond command, try again!" << endl;
- continue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement