[C++-sig] (no subject)
Petya Vasileva
luvangel1002 at gmail.com
Fri Nov 18 07:06:48 CET 2005
hey, i am trying to run this program, but it's not letting me. Would you
help me, please!
Thank you!!!
//This program reads in a customer's name and time *
//they were in a parking garage. It then calculates*
//and prints out the average payment of all the *
//people, the payment each person owes, and the *
//change each person gets back. It also calculates*
//and prints out anyone that is under the average *
//payment. *
//**************************************************
# include <iostream>
# include <fstream>
# include <iomanip>
using namespace std;
//****************************************************
// Stubs or prototypes of functions
double AveragePayment();
void Initialize(int & iNumCustomers, int & iNumUnderAverage);
void Titles(ofstream & OutputFile);
void ReadName(ifstream& InputFile, char strNm[]);
int ReadMinutes(ifstream & InputFile);
int Payment(int iMinutes);
void ChangeDue (int iPayment, int & iNumQuarters, int & iNumDimes, int &
iNumNickels, int & iNumPennies);
void PrintIt (ofstream & OutputFile, char strNm[], int iNumMin, intiPayment,
int iNumQuarters, int iNumDimes, int iNumNickels, int iNumPennies);
void UnderAverage(int iPayment, double dAveragePayment, int &iNumCustomers,
int & iNumUnderAverage, ofstream &ofPaymentFile);
void PrintAverage(double dAveragePayment, int iNumCustomers,
intiNumUnderAverage, ofstream &OutputFile);
void FreezeScreen();
//****************************************************
void main()
{
char strNm[20];//Customer name
int iNumMin; //Number of minutes the customer was in the garage
int iNumQuarters;
int iNumDimes;
int iNumNickels;
int iNumPennies;
int iNumCustomers;
int iNumUnderAverage;
//int iNumUnderAverage;
double dAveragePayment; //Average amount paid for parking
int iPayment; //Payment due
double iChangeDue; //Change due to the customer
double dPercentCust; //Percent of customers under the average
ifstream InputFile;
//Input file name
ofstream OutputFile;
//Output file name
AveragePayment();
InputFile.open("ASS9.txt");
Initialize (iNumCustomers, iNumUnderAverage);
if (! InputFile)
{
cout << "Error in opening file" << endl;
cout << endl;
FreezeScreen();
return;
}
OutputFile.open("Output.txt");
Titles(OutputFile);
while(! InputFile.eof())
{
ReadName(InputFile, strNm);
ReadMinutes(InputFile);
Payment(iNumMin);
ChangeDue (iPayment, iNumQuarters, iNumDimes, iNumNickels, iNumPennies);
PrintIt (OutputFile, strNm, iNumMin, iPayment, iNumQuarters, iNumDimes,
iNumNickels, iNumPennies);
UnderAverage(iPayment, dAveragePayment, iNumCustomers, iNumUnderAverage,
OutputFile);
PrintAverage(dAveragePayment, iNumCustomers, iNumUnderAverage, OutputFile);
}
InputFile.close();
OutputFile.close();
FreezeScreen();
}
//****************************************************
//This function freezes the screen and stops the program.
void FreezeScreen()
{
fflush(stdin);
cout << "Hit enter to continue";
getchar();
}
//****************************************************
//This function returns the average amount paid by customers
//to park in the garage.
double AveragePayment()
{
ifstream InputFile;
char strNm[20];
int iNumCustomers;
int iNumMin;
int iPayment;
double dAveragePayment;
InputFile.open("ASS9.txt");
if (InputFile.fail())
{
cout << "Error Opening Input File" << endl;
FreezeScreen();
return -1;
}
else
{
while (! InputFile.eof())
{
InputFile.getline(strNm, 20);
Payment(iNumMin);
iNumCustomers++;
}
}
InputFile.close();
dAveragePayment = iPayment / iNumCustomers;
return dAveragePayment;
}
//****************************************************
//This function initializes all the variables
void Initialize(int & iNumCustomers, int & iNumUnderAverage)
{
int iCntr = 0;
int iNumMin = 0; //Number of minutes the customer was in the garage
int iNumQuarters = 0;
int iNumDimes = 0;
int iNumNickels = 0;
int iNumPennies = 0;
double dAveragePayment = 0; //Average amount paid for parking
double dPayment = 0; //Payment due
int iChangeDue = 0; //Change due to the customer
double dPercentCust = 0;
//int iNumCustomers = 0;
//int iNumUnderAverage = 0;
//return iNumCustomers, iNumUnderAverage;
}
//****************************************************
//This function prints a title for the table in the output file.
void Titles(ofstream & OutputFile)
{
OutputFile << setw(30) << "Parking Garage Payment" << endl;
}
//****************************************************
//This function reads in the name of the customer from the input file
void ReadName(ifstream & InputFile, char strNm[20])
{
InputFile.getline(strNm, 20);
}
//****************************************************
//This function reads in the number of minutes the customer was in the
//garage.
int ReadMinutes(ifstream & InputFile)
{
int iNumMin;
InputFile >> iNumMin;
return iNumMin;
}
//****************************************************
int Payment(int iNumMin)
{
int iPayment;
if(iNumMin <= 60)
{
iPayment = 50;
}
else
{
iPayment = (iNumMin - 60)* 1;
}
if(iPayment >= 1000)
{
iPayment = 1000;
}
return iPayment;
}
//****************************************************
void ChangeDue (int iPayment, int & iNumQuarters, int & iNumDimes, int &
iNumNickels, int & iNumPennies)
{
int iChangeDue;
iChangeDue = 1000 - iPayment;
iNumQuarters = iChangeDue % 25;
iNumDimes = iNumQuarters % 10;
iNumNickels = iNumDimes % 5;
iNumPennies = iNumNickels % 1;
//return iChangeDue, iNumQuarters, iNumDimes, iNumNickels, iNumPennies;
}
//****************************************************
void PrintIt (ofstream & OutputFile, char strNm[], int iNumMin, intiPayment,
int iNumQuarters, int iNumDimes, int iNumNickels, int iNumPennies)
{
OutputFile << setw(7) << strNm
<< setw(15)<< iNumMin
<< setw(21)<< iPayment
<< setw(20)<< iNumQuarters
<< setw(20)<< iNumDimes
<< setw(21)<< iNumNickels
<< setw(20)<< iNumPennies
<< endl;
}
//****************************************************
void UnderAverage(int iPayment, double dAveragePayment, int &iNumCustomers,
int & iNumUnderAverage, ofstream &OutputFile)
{
double dPercentCust;
while (iPayment < dAveragePayment)
{
OutputFile << "Under Average";
iNumUnderAverage ++;
}
dPercentCust = iNumUnderAverage/iNumCustomers;
//return iNumUnderAverage, iNumCustomers, dPercentCust;
}
//***************************************************
void PrintAverage(double dAveragePayment, int iNumCustomers,
intiNumUnderAverage, ofstream &OutputFile)
{
double dAveAmtPaid;
double dPercentCust;
OutputFile << "The average payment was: "
<< dAveAmtPaid
<< "."
<< endl;
OutputFile << "The percent of customers that are under the average is: "
<< dPercentCust
<< "."
<< endl;
}
//***************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20051118/47767863/attachment.htm>
More information about the Cplusplus-sig
mailing list