Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ TrainStation Program Create a function called searchForSchedules that will:

ID: 3856567 • Letter: C

Question

C++ TrainStation Program

Create a function called searchForSchedules that will:

- prompt a user to enter a scheduleId

- search for arrival and departure times of trains based on a trains ID number

Create a function called editSchedules that will:

- allow the user to edit the fields for a given schedule that is in the linked list.

- the program must prompt the user to enter the scheduleId as the key to find the schedule to edit. Print a message if the schedule is not found in the linked list.

- for simplicity, the program may re-prompt the user to re-enter all of the fields associated with the given schedule; however, it must reuse the scheduleId value

Explanation / Answer

#include<iostream>
#include<string.h>
#include<iomanip>
#include<fstream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
class TrainStation
{
   struct Railway
   {
       char Train_id[12];
       char dept_time[12];
       char Arrival_time[12];
       struct Railway *next;
   };
   struct Railway *temp1;
   //struct Railway Record[10];
   struct Railway *swapping;
   public:
   void write_to_Notice()
   {
               char tempstr[100];
               char ch;
               do
               {
               memset(tempstr,0,sizeof(tempstr));
temp1 = (struct Railway*)malloc(sizeof(struct Railway));
cout<<"Enter Train Id Number "<<endl;
cin>>tempstr;
strcpy(temp1->Train_id,tempstr);
memset(tempstr,0,sizeof(tempstr));
cout<<"Enter Departure Time Of Train: "<<endl;
cin>>tempstr;
strcpy(temp1->dept_time,tempstr);
memset(tempstr,0,sizeof(tempstr));
cout<<" Enter Arrival Time of Train "<<endl;
cin>>tempstr;
strcpy(temp1->Arrival_time,tempstr);
               temp1->next=swapping;
swapping=temp1;
               cout<<"Do you want to Record one more.Press y to continue:"<<endl;
               cin>>ch;
           }while(ch=='y'||ch=='Y');
           cout<<"Stopped to give input data:"<<endl;
   }
   public:
       int searchForSchedules(char str[])
       {
           struct Railway *temp;
           temp=temp1;
           while(temp!=NULL)
           {
               if(strcmp(temp->Train_id,str)==0)
               {
                   cout<<"The Details are found:"<<endl;
                   cout<<"The Train Departure Time is:"<<temp->dept_time<<endl;
                   cout<<"The Train Arrival Time "<<temp->Arrival_time<<endl;
                   return 0;
               }
               temp=temp->next;
           }
           return -1;
       }
       public:
           void display()
           {
          struct Railway *temp3;
          temp3=temp1;
          cout<<"Train id:"<<" "<<"Group Time"<<" "<<"Departure Time"<<endl;
          if(temp3!=NULL)
          {
          while(temp3!=NULL)
          {
             cout<<" "<<temp3->Train_id<<" "<<temp3->dept_time<<" "<<temp3->Arrival_time<<endl;
             temp3=temp3->next;
           }  
           }
           }
};
int main()
{          
   TrainStation obj;
   char key[12];
   cout<<"Read The Trains Information Details:"<<endl;
   obj.write_to_Notice();
   cout<<"Please Enter The Train id Number"<<endl;
cin>>key;
int result=obj.searchForSchedules(key);
if(result==-1)
printf("The Given Schedule Id Not Found in Notice: ");
//obj.display();
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote