Starting from:

$25

COMP2017 - Station Machination - Solved

You have been given the task to create a program that will find the next earliest train departure after your arrival at the station. This program will notify the user of the next train departure they should board using information from a timetable containing multiple entries of the starting station, destination station and the time the train is departing the starting station. The timetable will be in the form of a text file which will contain the source, destination and departure times of all trains on the rail network. The timetable information will be read by your program from standard input. The user will provide command line arguments, providing the source, destination and time of arrival at the source station.

Program Structure                                                                                     
 

Timetable Data                                                                                                                       
The train network timetable will be presented in a double colon separated format. The format will specify the source, destination and leaving time from the source station.

 The source and destination component may contain spaces and will be sub-strings of the line entry. Each entry in the timetable is separated by a new line. Following the <time> , a new line character is expected. Each entry will not exceed the maximum number of characters (4096), however, in the event your submission encounters an entry greater than the maximum string length, your program must skip this entry.

The data is formatted in the following form.

 

The following is an example schedule.

 

Your submission must be able to handle erroneous data that is contained within the schedule. This may include entries that contain an inappropriate number of colons or breaks, missing source, destination and time information as well as invalid time formats.

To clarify, You do not need to handle intermediate stations

Standard Input                                                                                                                       
Your program will need to accept the train network schedule via standard input. The data will be pushed into standard input via redirection and you will be able to use any allowed function that can operate directly on standard input such as  fgets , fscanf , fread .

Do note, your program cannot hold all the data from the file in main memory as per the restrictions of this assignment, you will need to process it, line by line. If no data is supplied, your program should output to standard error No timetable to process .

 You should only read through the file once, your program should not attempt to re-read the data after it has been read. Please do not attempt to use rewind or fseek on standard input.

Command Line Arguments                                                                                                
The search criteria is passed to the program via command line arguments, your program will need to accept all three command line arguments or it should otherwise quickly exit and output how to use the program. Refer to to the Not Enough Arguments section.

The command line arguments are given in the format and order:

 

The following is an example of program execution with command line arguments.

./choochoo Sydney Melbourne "11:59:59" < timetable.csv

The next train to Melbourne from Sydney departs at 12:05:40

     The time format must be supplied in 24 hour format and in the following format <hh>:<mm>: <ss> , where hh represents the hour, mm represents the minutes and ss , the number of seconds.

Examples                                                                                                      
 

Each example will contain the timetable contents, specified as timetable.list, program execution

Single Station 1                                                                                                                      
timetable.list

 

 

Single Station 2                                                                                                                      
timetable.list

 

Multiple Stations                                                                                                                   
timetable.list

 

Missing Station                                                                                                                      
timetable.list

 

 

Not enough arguments                                                                                                       

More products