Hope people dont mind (Lerner and iamthwee), but I would like to start a new post for this assignment of mine. since I think the length of the other one is putting people off and the code is now a lot different.
Can someone help me finalise this (has been going on for DAYS). There are only a few errors I believe.
I need to read (via piping) a txt file which has format:
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
etc....
use, the cost of stations as A is $2.80, B is $ 2.30 etccc.
to print an invoice with totals per ID. (So one pages has total for ID 3435344, then totals for 3873242....)
This is the code I have prepared to date:
#include <iostream>
#include <string.h>
using namespace std;
void printGenericHeading(int&, int&);
void printCustomerHeading(int&, int&);
void readId (int& , int& , int& ,int&, int& );
void readNameAddress (int& , int& , string& , string& , string & , string& ,int& , int& );
void readDateTime (int& , int& , string& , string& , string& ,int& , int& );
void calculateTotalStation (string& , int , double& , double& , double& , double& , double& , double& , int& );
void resetControlTotals(double&);
void printTotalInvoice (int& , char& , double& , double& , double& , double& , double& );
const int MAX_DETAIL_LINES =100;
const int MAX_LINE = 100;
const int MAX_SIZE = 20;
double TotalInvoice = 0;
int pageCount = 0;
int lineCount = 0;
bool more= true;
void printGenericHeading(int& pageCount, int& lineCount)
{
pageCount = pageCount +1;
cout<<"INVOICE FOR TOLL EXPENSES"<<endl;
cout<<"_________________________"<<endl;
cout<<"TAG\tCUSTOMER\tSTATION"
<<"\t\t\t\t\n";
cout<<"ID\tNAME\t\tID\n";
lineCount = 4;
}
void printCustomerHeading(int& pageCount, int& lineCount)
{
pageCount = pageCount +1;
cout<<"\t\t\t\t\n";
cout<<"t\t\t\t\tDATE\t\tTIME\tAMOUNT\n\n";
lineCount = 3;
}
void readId (int& i,int& id, int MAX_SIZE, int& count)
{
id [MAX_SIZE];
count = 0;
do {
cin>>id[i];
}
while (count<MAX_SIZE);
void readNameAddress (int& MAX_LINE, int& MAX_SIZE, string& name, string& address, string & line, string& inputString,int& count, int& position);
{
name [MAX_SIZE];
address [MAX_SIZE];
line;
count =0;
do {
getline(cin, line);
int position = line.find (',');
name[count] = line.substr (0, position);
address[count] = line.substr (position+1, MAX_LINE);
count++;
}
while (count<MAX_SIZE);
for (int i=0; i<count; i++)
cout <<name[i]<<"\t"<<address[i]<<endl;
}
void readDateTime (int& MAX_LINE, int& MAX_SIZE, string& date, string& time, string& inputString,int& count, int& position);
{
date [MAX_SIZE];
time [MAX_SIZE];
inputString;
count =0;
do {
cerr<<"processing..."<<endl;
getline(cin, inputString);
if(cin.fail()) break;
int position = inputString.find ('/');
date [count] = inputString.substr(0, 10);
time [count]= inputString.substr(11,16-11);
count++;
}
while (count<MAX_SIZE);
for (int i=0; i<count; i++)
cout <<"t\t\t\t\t"<<date[i]<<"\t\t"<<time[i]<<endl;
}
void calculateTotalStation (string& station, int count, double& totalA, double& totalB, double& totalC, double& totalD, double& totalInvoice, double& controlTotal, int& lineCount)
{
totalA = 0;
totalB = 0;
totalC = 0;
totalD = 0;
int i = 0;
do
{
if (station [i] = 'A')
{
totalA= totalA + 2.20;
cout<<totalA;
}
else if(station[i] = 'B')
{
totalB= totalB + 2.80;
cout<<totalB;
}
else if(station[i] == 'C')
{
totalC= totalC + 2.30;
cout<<totalC;
}
else if(station[i] == 'D')
{
totalD= totalD + 3.80;
cout<<totalD;
}
totalInvoice = totalA + totalB + totalC + totalD;
cout<<"TOTAL:\t\t\t\t\t\t\$"<<setprecision(2)<<totalInvoice<<endl;
cout<<"\t\t\t\t\t\t_______"<<endl;
cout<<"\t\t\t\t\t\t_______"<<endl;
cout<<"We thankyou for your prompt payment."<<endl;
lineCount = lineCount + 4;
resetControlTotals(controlTotal);
}while(i < count);
resetControlTotals(controlTotal);
}
void resetControlTotals(double& controlTotal)
{
controlTotal = 0;
}
int main ()
{
int id;
int prevId;
string name;
string prevName;
double invoiceTotal;
double controlTotal;
int pageCount;
int lineCount;
int i;
readId (i, id, MAX_SIZE, count);
prevId =id;
prevName=name;
while(more)
{
if (id!=prevId)
{
calculateTotalStation (station, count, totalA, totalB, totalC, totalD);
prevId= id;
prevName = name;
}
if (lineCount >MAX_DETAIL_LINES)
printGenericHeading(pageCount, lineCount);
printCustomerHeading(pageCount, lineCount);
calculateTotalStation (MAX_SIZE, station, count, totalA, totalB, totalC, totalD);
readId (id, MAX_SIZE, count);
readDateTime (MAX_LINE, MAX_SIZE, date, time, inputString, count, position);
readNameAddress (MAX_LINE, MAX_SIZE, name, address, line, string& inputString,int& count, int& position)
}
printTotalInvoice (MAX_SIZE, station, totalA, totalB, totalC, totalD, totalInvoice);
system("pause");
return 0;
}
Can someone help me finalise this? (DUEin the next couple of hours.)
Thanks!