This is the assignment question below, ive made the basis of the program but need to know what do next to make the program do what its supposed to.
Interstate Motorway Pty Limited requires you to design a program that will produce customer statements for passing through E-way checkpoints of four toll stations (denoted by A, B, C and D respectively) distributed on the nationwide motorway. The charge of each pass is specified as follows
Station A B C D
Charge $2.20 $2.80 $2.30 $3.80
These statements will be calculated from the checkpoint log file of the format
3435344 A 2005/02/22/08:22:41
4749038 A 2005/02/25/14:16:35
5186936 C 2005/02/28/08:34:53
3873242 D 2005/03/02/02:40:59
4749038 A 2005/03/05/14:16:35
4092191 A 2005/03/08/23:49:08
3435344 C 2005/03/11/08:22:41
4092191 C 2005/03/14/23:42:08
4749038 D 2005/03/17/14:16:35
3435344 A 2005/03/20/08:22:41
...
where the first column contains customer ids, the second column contains the toll stations and the last column contains the timestamps. Hence the first record in the above, for instance, indicates that the vehicle with tag number (i.e. customer id) 3435344 passed through toll station A at time 08:22:41 on 22nd February 2005.
In order that each statement carries also the customer's name and address, the address file will be provided in the form of
3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 2134
3873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 3205
4092191 @ T Peachey,32 Evan Street,Penrith NSW 2750
4749038 @ D Merritt,70 Albert Street,Werrington NSW 2747
4967987 @ R Bailey,102-47 Pardalote Avenue,Glenmore Park NSW 2745
5186936 @ S Galloway,8-121 Coreen Road,Scoresby VIC 3179
...
For the convenience of processing the log file for the statements, the address file and the log file will be first merged and then sorted line by line alphabetically to generate the toll data file, which will thus look like
3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 2134
3435344 A 2005/02/22/08:22:41
3435344 A 2005/03/20/08:22:41
3435344 B 2005/03/23/18:22:41
3435344 B 2005/04/10/28:22:41
3435344 C 2005/03/11/08:22:41
3435344 C 2005/05/10/14:22:41
3435344 C 2005/05/19/06:22:43
3435344 D 2005/05/01/01:26:41
3873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 3205
3873242 B 2005/03/29/02:40:59
3873242 B 2005/05/16/02:40:59
3873242 C 2005/04/07/22:40:59
3873242 D 2005/03/02/02:40:59
...
For instance, if an address file address.txt is mergered with a log file logfile.txt into a combined file combined.txt, then sorting the combined file will generate the needed toll data file tolldata.txt. Hence in this assignment, we will always assume that the input data are in the form of toll data file and simply forget about the existence of the log file and the address file.
In this assignment, you are required to design an algorithm in pseudocode for the solution of the problem and get it implemented in C++. Your implemented C++ program toll.cpp will read data in the format of the toll data file, i.e.
o customer id as a word
o toll station or '@' as a character
o customer address or timestamp as the rest of the line
calculate the total toll charged for each customer, and produce an invoice statement for each customer who has a non-zero balance. A statement for each customer should include the following information
4. Heading
5. Customer's id, name and address
6. Column heading: Date, Time, Station, Amount
7. All records charged to the customer
8. Total amount the customer owned in the statement
We note that if your program toll.cpp is compiled into toll.exe and the toll data file is tolldata.txt, then using piping
toll.exe < tolldata.txt > statements.txt
should generate precisely the list of toll statements satisfying the above requirements. This means if you are using prompts for interative data input, you need to make sure that the prompts are sent to standard error device using cerr (instead of cout). This way, the prompts will not be piped into the output file statement.txt.
For the top marks, there should be considerations on the unexpected circumstances such as corrupted individual records etc, and the program should be able to report and handle such anomalies accordingly. Such endeavours should be properly documented as well.
this is what ive done so far..
Code:
#include<iostream>
using namespace std;
int main()
{
long id;
char station;
string rest;
while(true)
{
cerr<<"Please input ID: ";
cin>>id;
if(cin.fail()) break;
cerr<<"Input Station: ";
cin>>station;
if(cin.fail()) break;
cerr<<"Input Rest: ";
cin>>ws;
getline(cin, rest);
if(cin.fail()) break;
cout<<id<<' '<<"@ "<<station<<" "<<rest<<endl;
}
system ("pause");
return 0;
}