| | |
Please Check The Errors'..Dont know what else to do
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2004
Posts: 4
Reputation:
Solved Threads: 0
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
//for logfile
struct log
{
long number;
char date[9];
char time[9];
char gate[2];
};
//for customers
struct customer
{
long number;
char initial[2];
char lname[20];
char snumber[7];
char sname[17];
char stype[17];
char suburb[17];
char state[4];
char postcode[5];
};
//constants for array sizes
const int MAXLOGS=50;
const int MAXCUST=20;
// function protoytpes
int searchProcessed(long[],long,int);//searches already processed records
int find (customer[],long,int); //searches customer array
void showHeadings(); //show headings
void drawline(); //draws line
int main ()
{
//declare array to hold logs
log logArray[MAXLOGS];
//declare infile stream and link to log.txt
ifstream in;
in.open("log.txt");
int numOfLogs = 0; // number of logs
//load-up array with logs
while(!in.eof())
{
in >> logArray[numOfLogs].number;
in >> logArray[numOfLogs].date;
in >> logArray[numOfLogs].time;
in >>logArray[numOfLogs].gate;
in >> ws;
numOfLogs++;
}
in.close();
//declare array of type customer
customer customerArray[MAXCUST];
//open the file
in.open("customer.txt");
int numberOfCustomers = 0; //number of customers
//load-up array with customers
while(!in.eof())
{
in >> customerArray[numberOfCustomers].number;
in >> customerArray[numberOfCustomers].initial;
in >> customerArray[numberOfCustomers].lname;
in >> customerArray[numberOfCustomers].snumber;
in >> customerArray[numberOfCustomers].sname;
in >> customerArray[numberOfCustomers].stype;
in >> customerArray[numberOfCustomers].suburb;
in >> customerArray[numberOfCustomers].state;
in >> customerArray[numberOfCustomers].postcode;
in >> ws;
numberOfCustomers++;
}
in.close();
//declare array of type long, to hold custNumbers of
//previously processed records
long processed[MAXLOGS];
//initialize to zero
for (int i=0;i<MAXLOGS;i++)
{
processed[i]=0;
}
int processedSize=0;//nothing in array yet
// required heading
cout << "\t\tThis is the HEADING of the statement\n" << endl;
//main loop to process records
//processing the log array from first to number of logs
for ( int z = 0; z < numOfLogs; z++ )
{
//if current customer number has not been previously processed
if (searchProcessed(processed,logArray[z].number,numOfLogs) < 0)
{
//add customer number into array of previously processed records
processed[processedSize++] = logArray[z].number;
// find the position of the customer in customer array
// by searching with current customer number from log array
int position = find(customerArray,logArray[z].number,numberOfCustomers);
//if customer is found
if (position >=0)
{
drawline(); //draw a line
cout << "\nEWAY BILL E-way Motorway\n"
<< " " << customerArray[position].number;
cout << "\n \n"<<customerArray[position].lname <<customerArray[position].initial;
cout << " \n"<< customerArray[position].snumber <<customerArray[position].sname <<customerArray[position].stype;
cout << " \n"<<customerArray[position].suburb <<customerArray[position].state <<customerArray[position].postcode;
cout << "E-way motor bill for: "<<customerArray[position].number << endl << endl;
} // end printcustomerstatement
double total = 0.0;//accumulator for totals
showHeadings(); //show headings
drawline(); //draw a line
//from current position of log array to number of logs
//trying to process every entry of customer in the log file
for (int l = z ;l<numOfLogs;l++)
{
//if found an entry matching current customer number
//(first entry is always processed).
//processSize is -1 because it has been incremented above
if(processed[processedSize-1] == logArray[l].number)
{
//display detail line
cout <<setw(8) << logArray[l].date
<<setw(9)<< logArray[l].time
<<setw(8)<< logArray[l].gate;
//checking for toll-gate code
//adding to total for correct amount
//"case of" not used because 'gate' is of type char[]
//not int.
if(! strcmp(logArray[l].gate,"A") )
{
cout <<setw(7)<< "$2.20";
total = total + 2.20;
}
else if(! strcmp(logArray[l].gate,"B") )
{
cout <<setw(7)<< "$2.80";
total = total + 2.80;
}
else if(! strcmp(logArray[l].gate,"C") )
{
cout <<setw(7)<< "$3.30";
total = total + 3.30;
}
else
{
cout <<setw(7)<< "$3.80";
total = total + 3.80;
}
cout << endl;
}
}
cout << endl << setw(8)<<"DATE" <<setw(9) <<"TIME"
<< setw(8) << "STATION"
<< setw(7) << "AMOUNT"
<<endl;
// Function tollCharge
cout << endl << endl;
cout << "Total charge usage of E-way for:" << customerArray[position].number <<" "
<< " $" << setiosflags(ios::fixed)<<setprecision(2)<< total <<endl<<endl;
cout<<"\nEnd OF E-Way Statement";
return 0;
}
// searches the array for number and returns position if found
// else returns -1
int searchProcessed(long processed[], long num,int size)
{
for (int i = 0; i < size;i++)
{
if (num == processed[i])
return i;
}
return -1;
}
//searches customer array for number and returns position if found
//else returns -1
int find (customer customerArray[],long num ,int size)
{
for (int i=0;i<size;i++)
{
if ( num == customerArray[i].number)
return i;
}
return -1;
}
;
}
}
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
//for logfile
struct log
{
long number;
char date[9];
char time[9];
char gate[2];
};
//for customers
struct customer
{
long number;
char initial[2];
char lname[20];
char snumber[7];
char sname[17];
char stype[17];
char suburb[17];
char state[4];
char postcode[5];
};
//constants for array sizes
const int MAXLOGS=50;
const int MAXCUST=20;
// function protoytpes
int searchProcessed(long[],long,int);//searches already processed records
int find (customer[],long,int); //searches customer array
void showHeadings(); //show headings
void drawline(); //draws line
int main ()
{
//declare array to hold logs
log logArray[MAXLOGS];
//declare infile stream and link to log.txt
ifstream in;
in.open("log.txt");
int numOfLogs = 0; // number of logs
//load-up array with logs
while(!in.eof())
{
in >> logArray[numOfLogs].number;
in >> logArray[numOfLogs].date;
in >> logArray[numOfLogs].time;
in >>logArray[numOfLogs].gate;
in >> ws;
numOfLogs++;
}
in.close();
//declare array of type customer
customer customerArray[MAXCUST];
//open the file
in.open("customer.txt");
int numberOfCustomers = 0; //number of customers
//load-up array with customers
while(!in.eof())
{
in >> customerArray[numberOfCustomers].number;
in >> customerArray[numberOfCustomers].initial;
in >> customerArray[numberOfCustomers].lname;
in >> customerArray[numberOfCustomers].snumber;
in >> customerArray[numberOfCustomers].sname;
in >> customerArray[numberOfCustomers].stype;
in >> customerArray[numberOfCustomers].suburb;
in >> customerArray[numberOfCustomers].state;
in >> customerArray[numberOfCustomers].postcode;
in >> ws;
numberOfCustomers++;
}
in.close();
//declare array of type long, to hold custNumbers of
//previously processed records
long processed[MAXLOGS];
//initialize to zero
for (int i=0;i<MAXLOGS;i++)
{
processed[i]=0;
}
int processedSize=0;//nothing in array yet
// required heading
cout << "\t\tThis is the HEADING of the statement\n" << endl;
//main loop to process records
//processing the log array from first to number of logs
for ( int z = 0; z < numOfLogs; z++ )
{
//if current customer number has not been previously processed
if (searchProcessed(processed,logArray[z].number,numOfLogs) < 0)
{
//add customer number into array of previously processed records
processed[processedSize++] = logArray[z].number;
// find the position of the customer in customer array
// by searching with current customer number from log array
int position = find(customerArray,logArray[z].number,numberOfCustomers);
//if customer is found
if (position >=0)
{
drawline(); //draw a line
cout << "\nEWAY BILL E-way Motorway\n"
<< " " << customerArray[position].number;
cout << "\n \n"<<customerArray[position].lname <<customerArray[position].initial;
cout << " \n"<< customerArray[position].snumber <<customerArray[position].sname <<customerArray[position].stype;
cout << " \n"<<customerArray[position].suburb <<customerArray[position].state <<customerArray[position].postcode;
cout << "E-way motor bill for: "<<customerArray[position].number << endl << endl;
} // end printcustomerstatement
double total = 0.0;//accumulator for totals
showHeadings(); //show headings
drawline(); //draw a line
//from current position of log array to number of logs
//trying to process every entry of customer in the log file
for (int l = z ;l<numOfLogs;l++)
{
//if found an entry matching current customer number
//(first entry is always processed).
//processSize is -1 because it has been incremented above
if(processed[processedSize-1] == logArray[l].number)
{
//display detail line
cout <<setw(8) << logArray[l].date
<<setw(9)<< logArray[l].time
<<setw(8)<< logArray[l].gate;
//checking for toll-gate code
//adding to total for correct amount
//"case of" not used because 'gate' is of type char[]
//not int.
if(! strcmp(logArray[l].gate,"A") )
{
cout <<setw(7)<< "$2.20";
total = total + 2.20;
}
else if(! strcmp(logArray[l].gate,"B") )
{
cout <<setw(7)<< "$2.80";
total = total + 2.80;
}
else if(! strcmp(logArray[l].gate,"C") )
{
cout <<setw(7)<< "$3.30";
total = total + 3.30;
}
else
{
cout <<setw(7)<< "$3.80";
total = total + 3.80;
}
cout << endl;
}
}
cout << endl << setw(8)<<"DATE" <<setw(9) <<"TIME"
<< setw(8) << "STATION"
<< setw(7) << "AMOUNT"
<<endl;
// Function tollCharge
cout << endl << endl;
cout << "Total charge usage of E-way for:" << customerArray[position].number <<" "
<< " $" << setiosflags(ios::fixed)<<setprecision(2)<< total <<endl<<endl;
cout<<"\nEnd OF E-Way Statement";
return 0;
}
// searches the array for number and returns position if found
// else returns -1
int searchProcessed(long processed[], long num,int size)
{
for (int i = 0; i < size;i++)
{
if (num == processed[i])
return i;
}
return -1;
}
//searches customer array for number and returns position if found
//else returns -1
int find (customer customerArray[],long num ,int size)
{
for (int i=0;i<size;i++)
{
if ( num == customerArray[i].number)
return i;
}
return -1;
}
;
}
}
•
•
Join Date: Apr 2004
Posts: 9
Reputation:
Solved Threads: 0
Three Great Virtues Of A Programmer
What's the error you see? It's much easier to check if you provide the compiler/linker messages. Also please put your program into [ code] tag, so that the formatting is preserved.
What's the error you see? It's much easier to check if you provide the compiler/linker messages. Also please put your program into [ code] tag, so that the formatting is preserved.
![]() |
Similar Threads
- How to check errors while developing website online. (ASP.NET)
- Please check for errors (PHP)
- Error 993 Partition contains open files. Use the operating system check utility (Windows NT / 2000 / XP)
- Errors help (C++)
Other Threads in the C++ Forum
- Previous Thread: How do I create a program using an Array ?
- Next Thread: How to incorporate Database into C++ ?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





