Question

C++ TrainStation Program Create a function called searchForSchedules that will: - prompt a user to enter...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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:"<<"\t"<<"Group Time"<<"\t"<<"Departure Time"<<endl;
          if(temp3!=NULL)
          {
          while(temp3!=NULL)
          {
             cout<<"\t"<<temp3->Train_id<<"\t"<<temp3->dept_time<<"\t"<<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:\n");
//obj.display();
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ TrainStation Program Create a function called searchForSchedules that will: - prompt a user to enter...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Division by Zero Problem: Create a program titled Division. Have the program prompt the user "Enter...

    Division by Zero Problem: Create a program titled Division. Have the program prompt the user "Enter numerator and denominator" and store the two values entered. (If you wish the user to "Enter numerator/denominator" be sure to adjust your data gathering variables to include a holder variable for the slash character.) Include a function titled Quotient that takes 2 integers as input and provides the quotient of the 2 integers as integer output. (The remainder is truncated. Thus, 5/3 will be...

  • C++ Program Help Prompt your user to enter a length of a word to search from...

    C++ Program Help Prompt your user to enter a length of a word to search from a string. Use forking to spawn a child process to perform the counting task. Allow the child process to finish and output the number of words found (if any), before prompting the user for the next length. Count all words in the string with this length and output the number of words that correspond to this length. Program keeps asking user for length till...

  • Prompt the user to enter two character strings. The program will then create a new string...

    Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-') to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are...

  • Write a "PYTHON" program to prompt the user to enter a fist name, last name, student...

    Write a "PYTHON" program to prompt the user to enter a fist name, last name, student ID and GPA. Create a dictionary with the data. Print out the data. Then remove the GPA and print again.

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Can you help me to create this program, please? Prompt the user for the user for...

    Can you help me to create this program, please? Prompt the user for the user for a number of degrees in Fahrenheit as an int. That number should be passed to a function named ffocREFO. This function will do the necessary calculation to convert the passed temperature to degrees Celsius as a double. The function MUST have a void return type and have the following prototype: void ffccREF(double& celsius, int Faren); In your main, display both the entered temperature and...

  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • Create a C# program that will first prompt the instructors to enter the number of students...

    Create a C# program that will first prompt the instructors to enter the number of students they currently have in their classes. Use this value for the size of the row dimension of your multidimensional array. Next, prompt the instructors to type in the number of scores they would like to enter. This variable will be used to designate the column size dimension of your multidimensional array. Then, use a loop to prompt the user to enter the number of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT