diff options
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 575743b..1351c8f 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -1,6 +1,4 @@ -//Lab 3 - - +//CST116_Lab3_joetraver.ccp #include <iostream> #include <fstream> @@ -19,6 +17,7 @@ using std::ofstream; const int MAX = 100; +// Functions used int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[]); void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[], int counter); @@ -29,7 +28,7 @@ void AverageCostPerPerson(ofstream& outFile, float paid, int pplt, float ACM); int main() { - + // All variables int pick[MAX]; int drop[MAX]; int psgr[MAX]; @@ -46,17 +45,24 @@ int main() ifstream inFile; + // Report file location ofstream outFile("C:\\TEMP\\lab3_report.txt"); + // Read file location inFile.open("C:\\TEMP\\lab3_data.txt"); + // Check to ensure read file has been opened if (inFile.is_open()) { + // Establishes the amount of records present and defines the loop counters + // Places the values in each feild in arrays record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll, tfare, CPM); inFile.close(); + // Check to ensure report file is accessable if (outFile.is_open()) { + // Writes values to report with calculations WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, tfare, CPM, record_counter); PassengerCount(outFile, psgr, record_counter, pplt); TotalPaid(outFile, tfare, record_counter, paid); @@ -64,6 +70,7 @@ int main() PrintTotalsAndSummary(outFile, record_counter); outFile.close(); } + // Failsafe Error message else { cout << "Trouble Opening File"; @@ -71,6 +78,7 @@ int main() } } + // Failsafe Error message else { cout << "Trouble Opening File"; @@ -80,6 +88,7 @@ int main() } +// Read and store data from file int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[]) { int counter = 0; @@ -122,8 +131,10 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], } return counter; -} +} +// Writes the report from the given file +// Formats data for external file void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[], int counter) { @@ -154,6 +165,9 @@ void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], floa } } + +// Sums passengers transported +// Places value in report and command prompt void PassengerCount(ofstream& outFile, int psgr[], int counter, int &pplt) { @@ -168,6 +182,8 @@ void PassengerCount(ofstream& outFile, int psgr[], int counter, int &pplt) outFile << fixed << setprecision(2) << endl << "\t\t\t\t\t\tTotal number of passengers transported: " << pplt << endl; } +// Sums the total fairs paid +// Places value in report and command prompt void TotalPaid(ofstream& outFile, float tfare[], int counter, float &paid) { @@ -175,13 +191,14 @@ void TotalPaid(ofstream& outFile, float tfare[], int counter, float &paid) { paid = paid + tfare[i]; - } cout << fixed << setprecision(2) << "\t\t\t\t\t\tTotal fairs paid: $" << paid << endl; outFile << fixed << setprecision(2) << "\t\t\t\t\t\tTotal fairs paid: $" << paid << endl; } +// Average fair per person transported +// Places value in report and command prompt void AverageCostPerPerson(ofstream& outFile, float paid, int pplt, float ACM) { @@ -193,6 +210,7 @@ void AverageCostPerPerson(ofstream& outFile, float paid, int pplt, float ACM) } +// Prints file foot note with entry count void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) { |