This assessment is CONFIDENTIAL. ý University of Machination
This assignment contributes 10% to your final grade and is due on Sunday 21st of March at 11:59 PM AEDT.
Problem Description
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.
Copyright By PowCoder代写 加微信 powcoder
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
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 fscanf , .
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 or 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.
The time format must be supplied in 24 hour format and in the following format
, where hh represents the hour, mm represents the minutes and ss , the number of
Each example will contain the timetable contents, specified as timetable.list, program execution
Single Station 1
timetable.list
fgets , fread
rewind fseek
./timetable < timetable.csv
./timetable
Single Station 2
timetable.list
::Morisset::19:09:14
::Morisset::19:54:14
::Morisset::20:01:14
::Morisset::20:46:14
::Koolewong::19:43:40
::Koolewong::20:01:40
./timetable ” ” Koolewong “19:45:15” < timetable.list
The next train to Koolewong from departs at 20:01:40
Multiple Stations
timetable.list
Sydney::Melbourne::08:05:00
Sydney::Melbourne::09:32:45
Sydney::Melbourne::11:45:32
Sydney::Melbourne::13:12:19
Sydney::Melbourne::19:59:15
Sydney::Melbourne::22:32:21
Melbourne::Sydney::14:13:12
Melbourne::Sydney::16:55:12
Melbourne::Sydney::18:33:12
Melbourne::Sydney::20:25:12
Melbourne::Sydney::22:22:12
./timetable "19:40:59" < timetable.list
The next train to Melbourne from Sydney departs at 19:59:15
Missing Station
timetable.list
Sydney::Melbourne::08:05:00
Sydney::Melbourne::09:32:45
Sydney::Melbourne::11:45:32
Sydney::Melbourne::13:12:19
Sydney::Melbourne::19:59:15
Sydney::Melbourne::22:32:21
Melbourne::Sydney::14:13:12
Melbourne::Sydney::16:55:12
Melbourne::Sydney::18:33:12
Melbourne::Sydney::20:25:12
Melbourne::Sydney::22:22:12
./timetable Wirragulla Cardiff "10:20:05" < timetable.csv
The next train to Cardiff from Wirragulla departs at 10:30:23
Not enough arguments
Restrictions
Below are a list of restrictions on your submission. An aim of this assignment is to efficiently use memory and construction an application within these fixed boundaries.
You are not allowed to use any dynamic memory of any kind, this includes any alloc family functions, brk, sbrk and mmap. You are not allowed to use any temporary files or or variable length arrays. Static and global variables need to be rationalised when using them.
You are not allowed to use any function that belongs in string.h directly.
You are allowed to reimplement any function that you want to use in string.h such as finding the length of a string, tokenising a string or copying a string from one location to another. You can safely assume the largest line is 4096 characters.
You cannot use static or global memory, utilise the preprocessor #define mechanism for your constants.
Your submission must successfully compile with the submission system's compilation command.
Your program will be compiled using the provided Makefile. You can make modifications to the file, but cannot remove flags from CFLAGS , or change the compiler being used.
If your submission violates any of these restrictions, your submission will receive 0 marks.
Error Handling and Test Cases
The public test cases will only include valid data and you will need to ensure that your program can handle invalid test data. You are tasked with developing your own set of test cases that will need to test both valid input and invalid input. You must document your test cases in a file named
, this file must contain a brief description of each test case you have created. Please keep in the root of your assessment repository. The make test command must successfully execute your test cases and provide human readable output to the user.
Consider the following scenarios when testing your code.
Error cases and return codes
Timetable file that can exceed stack memory limit
Cross-day times (when the closest time is the next day, candidate train may be available on the next day)
Time format
Lines longer than the maximum limit
Unsorted data
./timetable < timetable.list
Please provide