SHARE
TWEET

Untitled

a guest Nov 12th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct list_node {
  2.     train* data;
  3.     list_node* next;
  4. }
  5.  
  6. struct train {
  7.     string destination;
  8.     int number;
  9.     unsigned int arrivalTime;
  10. }
  11.  
  12. class TrainList {
  13.     list_node *head;
  14.  
  15. public:
  16.     TrainList() {head = NULL;}
  17.     ~TrainList();
  18.  
  19.     bool checkTrainIdValid(int id);
  20.     void add();
  21.     void remove();
  22.     void show();
  23.  
  24.     void save();
  25.     void load();
  26. }
  27.  
  28. TrainList::~TrainList() {
  29.     while (head != NULL) {
  30.         list_node *tmp = head->next;
  31.         delete head;
  32.         head = tmp;
  33.     }
  34. }
  35.  
  36. bool TrainList::checkTrainNumberValid(int number) {
  37.     list_node *iter = head;
  38.     while (iter != NULL) {
  39.         if (iter->number == number) {
  40.             cerr << "Train with such number already exists!!!" << endl;
  41.             return false;
  42.         }
  43.     }
  44.  
  45.     return true;
  46. }
  47.  
  48. int main() {
  49.     TrainList trains;
  50.     while(true) {
  51.         cout << "Commands:" << endl;
  52.         cout << "Enter 1 to add new train;" << endl;
  53.         cout << "Enter 2 to modify one of the trains" << endl;
  54.         cout << "Enter 3 to show existing trains" << endl;
  55.         cout << "Enter 4 to modify one of the trains" << endl;
  56.         cout << "Enter 5 to delete one of the trains" << endl;
  57.         cout << "Enter 6 to save trains to file" << endl;
  58.         cout << "Enter 7 to load trains from file" << endl;
  59.         cout << "Enter 8 to exit" << endl;
  60.  
  61.         string command;
  62.         cin >> command;
  63.  
  64.         if(command.size() > 1) {
  65.             cerr << "Wrond command, try again!" << endl;
  66.             continue;
  67.         }
  68.  
  69.         switch(command[0]) {
  70.             case '1':
  71.                 trains.add();
  72.                 break;
  73.             case '2':
  74.                 trains.modify();
  75.                 break;
  76.             case '3':
  77.                 trains.show();
  78.                 break;
  79.             case '4':
  80.                
  81.                 break;
  82.             case '5':
  83.                
  84.                 break;
  85.             case '6':
  86.                
  87.                 break;
  88.             case '7':
  89.                
  90.                 break;
  91.             case '8':
  92.                
  93.                 break;
  94.             case '9':
  95.                
  96.                 break;
  97.             default:
  98.                 cerr << "Wrond command, try again!" << endl;
  99.                 continue;
  100.         }
  101.     }
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top