Interstate Motorway Pty Limited requires you to design a program that will produce, among others, 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 $3.30 $3.80

These statements will be calculated from the checkpoint log file of the format

3435344 A 2010/02/22 08:22:41
4749038 A 2010/02/25 14:16:35
5186936 C 2010/02/28 08:34:53
3873242 D 2010/03/02 02:40:59
4749038 A 2010/03/05 14:16:35
4092191 A 2010/03/08 23:49:08
3435344 C 2010/03/11 08:22:41
4092191 C 2010/03/14 23:42:08
4749038 D 2010/03/17 14:16:35
3435344 A 2010/03/20 08:22:41
...

where the first column contains the string customer ids , the second column contains the toll stations, the third column contains the date, 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 2010. For simplicity, we will assume that the user will "enter" those records one by one manually, as if they are entered field by field (for this Part I) via
3435344
A
2010/02/22
08:22:41
4749038
A
2010/02/25
14:16:35
...

whereas in reality the so-called "piping" can be utilised very easily.
For the basic part of this program, that is, for the fulfilment of the basic functionalities of this program, students are asked to follow exactly the following steps to achieve it. For the later advanced features, however, students will have more freedom in their program design. For simplicity, we always assume that the program will be run under Microsoft Windows.

Function callings are indispensible in just about every C++ program that is supposed to be able to achieve something non-trivial. To refresh ourselves, explain the difference between passing by value and passing by reference in function calling. Use your own concrete C++ code to exemplify your explanations.
Looping is equally indispensible in any decent C++ programs. Explain the similarity and differences between a while loop and a for loop in C++.
When one reads in a station character, one may wish to check first if that is a valid station. There are different ways to do this. However you are asked to write the C++ function isValidStation prototyped by
bool isValidStation(char station);

so that when the passed station variable contains 'A', 'B', 'C', or 'D', the function returns the value true otherwise it will return the value false.
Write the C++ function readTollRecord prototyped by

bool readTollRecord(string &clientId, char &station, string &date, string &time);

such that it will prompt and read in the 4 fields clientId, station, date and time sequentially from the standard input. The function will return true if the reading has been successful. Otherwise it will return the value false.
Unless your main program illustrates the use of this function well, you need to write a separate driver program test4.cpp to demonstrate its proper use.

Write the C++ function readAllTollRecords prototyped by

int readAllTollRecords(string clientIds[], string dates[],
  string times[], char stations[]);

such that its execution will read all checkpoint log records into the parallel arrays clientsIds, dates, times and stations, through the use of the previously written function readTollRecord. The function readAllTollRecords will return the total number of successfully read records.
Alternatively, you may prototype readAllTollRecords via

void readAllTollRecords(string clientIds[], string dates[],
  string times[], char stations[], int &recTotal);

in which recTotal will be passed (on calling the function) with the number of valid records already contained in the passed parallel arrays, and will contain (on returning from the function) the updated total number of valid records stored in the parallel arrays after reading the new records. We note that for most students, this alternative prototype is in general easier and more straightforward to implement for this assignment.
Unless your main program illustrates the use of this function well, you need to write a separate driver program test5.cpp to demonstrate its proper use.

Write a driver function test6.cpp, along with the functions explicitly mentioned in the above points. We assume that our (checkpoint log) records will not exceed MAXNUM=500 in total. Declare in your driver program the arrays of size MAXNUM for the parallel arrays clientIds, stations, dates and times, and initialise these arrays to precisely the following records:
clientIds contains 1234567, 7654321, and 1234567 as the first 3 elements;
stations contains 'A', 'A', and 'B' as the first 3 elements;
dates contains "2010/01/01", "2010/12/31", and "2010/06/30" as the first 3 elements;
times contains "00:00:00", "23:59:59", "12:00:00" as the first 3 elements.
You should then call the function readAllTollRecords developed earlier.
Write the C++ function clientInvoice prototyped by

double clientInvoice(string clientId, string clientIds[], 
  char stations[], string dates[], string times[],  
  double fees[], int recTotal);

such that it will go through the parellel arrays clientIds, stations, dates, and times, to find the records corresponding to the client ID clientId. For each record with client ID clientId, this function will display the record and add up the toll fee for that record to the total of the invoice. The value recTotal indicates that each of the four parallel arrays contains exactly recTotal valid elements. The fees array carries the toll prices for all the stations in that fees[0] contains the toll fee for station A, fees[1] contains the toll fee for station B, and so on.
Write a driver program test7.cpp as the extension of the previous test6.cpp. Declare inside the driver program also the following fees array

const int MAXSTATION=4;
double fees[MAXSTATION]={ 2.2, 2.8, 3.3, 3.8 };

and then call the function clientInvoice to generate the invoice for a particular client ID clientId="1234567".
Write a function stationTolls prototyped by

int stationTolls(char station, string clientIds[], 
  char stations[],string dates[], string times[],  
  double fees[], int recTotal);

such that it will go through the parellel arrays clientIds, stations, dates, and times, to find the records corresponding to the toll station station. For each record with the toll station station, the function will display the record and add up the total number of such record. The value recTotal indicates that each of the four parallel arrays contains exactly recTotal valid elements. The fees array carries the toll prices for all the stations in that fees[0] contains the toll fee for station A, fees[1] contains the toll fee for station B, and so on. The function stationTolls will return the total number of records for the given toll station station.
Unless your main program illustrates the use of this function well, you need to write a separate driver program test8.cpp to demonstrate its proper use.

Combine all the individual functions (written earlier) together to form the final program tolls.cpp. All the functions you wrote earlier on in the previous points need to be utilised. The initialisation of the parallel arrays for the 3 records in point 6 must be retained. Your program will first read all the records from the user via readAllTollRecords, then use clientInvoice to display the invoice for client ID "1234567", and finally use function stationTolls to display all the toll records, and the total number of them, for the toll station A.
Draw the structure diagram that reflects your complete program tolls.cpp you did in the previous point.
Overall quality on achieving the above requirements.
We note that the above program requirements each account for 1 mark. While the specific user functions mentioned above must be written, their driver programs may be absent if the functionalities of the pertinent driver program are well manifested in the complete program tolls.cpp.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Comments
Nice try, but we aren't rent-a-coders.
#include<iostream>
#include<string>
using namespace std;
bool isValidStation(char station)
{
	switch(station)
	{
		case 'A': case 'a': case 'B': case 'b': case 'C': case 'c': case 'D': case 'd':
			return true;
			break;
		default:
			return false;
			break;
	}
	return 0;
}

bool readTollRecord(string &clientID, char &station, string &date, string &time)
{
	cout <<

cout << "I'm going to ask you to enter four things. So go ahead." << endl; //need to format to make better sense
	cout << "Enter an id: ";
	cin >> clientID;
	if(!cin)
		return false;
	cout << "Enter a station: ";
	cin >> station; //Make sure to fix this later on. couts true if more then char is entered, and overflows to next var
	if(!cin)
		return false;
	if(!isValidStation(station))
		return false;
	cout << "Enter a date: ";
	cin >> date;
	if(!cin)
		return false;
	cout << "Enter a time: ";
	cin >> time;
	if(!cin)
		return false;
	return true;
}

int readAllTollRecords(string clientIds[], char stations[], string dates[], string times[])
{
    int amount;
	cout << "How many records will need to be read?\n";
    cin >> amount;
	for(int i=3; i<amount+3; i++)
	{
		if(readTollRecord(clientIds[i], stations[i], dates[i], times[i]))
			cout << "True:" << endl << clientIds[i] << endl << stations[i] << endl << dates[i] << endl << times[i] << endl;
		else
			cout << "Teh fail" << endl; // Edit words used
			i--;
	}
    return amount;
}

int main()
{
	const int MAXNUM = 500;
	string clientIds[MAXNUM] = { "1234567", "7654321", "1234567" };
	char stations[MAXNUM] = { 'A', 'A', 'B'};
	string dates[MAXNUM] = { "2010/01/01", "2010/12/31", "2010/06/30"};
	string times[MAXNUM] = { "00:00:00", "23:59:59", "12:00:00" };
	readAllTollRecords(clientIds, stations, dates, times);
	system("pause");
	return 0;
}

Edited 6 Years Ago by Nick Evan: Added CODE-tags, merged 2 posts

<edit> Ah.. someone supplied you with a code-freebie. It's your "lucky" day. :icon_wink:

@dude281: We don't give away full solutions to homework problems here. We try to help the student understand how to create the code themselves and do this by explaining and giving small snippets of code. What do you think the OP learned from your code?

Edited 6 Years Ago by Nick Evan: n/a

Comments
words!
This article has been dead for over six months. Start a new discussion instead.