[SOLVED] COMP2017 Assignment 4-Scheduling-Trains

30.00 $

Category: Tags: , ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Scheduling-Trains-main-shywlx.zip (192.8 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

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.

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.

<source>::<destination>::<time>
Paterson::Werris Creek::23:22:23
Paterson::Werris Creek::00:01:23
Paterson::Werris Creek::00:55:23
Paterson::Lochinvar::01:06:11
Paterson::Lochinvar::02:01:11
Paterson::Lochinvar::02:56:11
Condobolin::Wangaratta::11:56:26
Condobolin::Wangaratta::12:01:26
Condobolin::Wangaratta::12:58:26
Condobolin::Maitland::09:30:22
Condobolin::Maitland::10:01:22
Wangaratta::Maitland::10:58:22

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

seconds.

Examples

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 <source> <destination> <time>
./choochoo Sydney Melbourne "11:59:59" < timetable.csv
The next train to Melbourne from Sydney departs at 12:05:40

<hh>:<mm>:

<ss>

Wirragulla::Cardiff::09:38:23
Wirragulla::Cardiff::10:01:23
Wirragulla::Cardiff::10:30:23
Wirragulla::Cardiff::10:59:23
Wirragulla::Cardiff::11:01:23

Single Station 2

timetable.list

Coffs Harbour::Morisset::19:09:14
Coffs Harbour::Morisset::19:54:14
Coffs Harbour::Morisset::20:01:14
Coffs Harbour::Morisset::20:46:14
Coffs Harbour::Koolewong::19:43:40
Coffs Harbour::Koolewong::20:01:40
./timetable "Coffs Harbour" Koolewong "19:45:15" < timetable.list
The next train to Koolewong from Coffs Harbour 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 Sydney Melbourne "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

  • Scheduling-Trains-main-shywlx.zip