diff options
| author | Evan <[email protected]> | 2022-11-21 02:11:54 -0800 |
|---|---|---|
| committer | Evan <[email protected]> | 2022-11-21 02:11:54 -0800 |
| commit | a682e832c85b904417ef0fb50d8541c9dd558d55 (patch) | |
| tree | eb686286d54e40f4195ea6fc81576f7a2c97aded /BlankConsoleLab/BlankConsoleLab.cpp | |
| parent | hjk (diff) | |
| download | cst116-lab3-evanmihm-a682e832c85b904417ef0fb50d8541c9dd558d55.tar.xz cst116-lab3-evanmihm-a682e832c85b904417ef0fb50d8541c9dd558d55.zip | |
asdfghj
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 105 |
1 files changed, 97 insertions, 8 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 9944142..d404bb7 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -3,8 +3,6 @@ #include <fstream> #include <iomanip> -using namespace std; - using std::cin; using std::cout; using std::endl; @@ -14,12 +12,103 @@ using std::ios; using std::ifstream; using std::ofstream; + +const int MAX = 100; + +int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[]); +void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], + int counter); +void PrintTotalsAndSummary(ofstream& out, int totalRecords); + + +//the first 'array' is the descripption of what needs to be done in total 6 equations/things to do +//next tsxt is 6 cols by x rows + int main() -{//the first 'array' is the descripption of what needs to be done in total 6 equations/things to do - //next tsxt is 6 cols by x rows - ifstream inFile; +{ + int pick[MAX]; + int drop[MAX]; + int psgr[MAX]; + float dist[MAX]; + float fare[MAX]; + float toll[MAX]; + int record_counter(0); + + ifstream inFile; + + // Notice how this automatically opens the file + ofstream outFile("LabResults.txt"); + + inFile.open("infile.txt"); + + if (inFile.is_open()) + { + record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll); + inFile.close(); + + if (outFile.is_open()) + { + WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, record_counter); + PrintTotalsAndSummary(outFile, record_counter); + outFile.close(); + } + else + { + cout << "Trouble Opening File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + } + else + { + cout << "Trouble Opening File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + return 0; +} +int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[]) +{ + int counter = 0; + inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; // Priming Read + + while (!inFile.eof()) + { + cout << setiosflags(ios::left) << setw(5) + << pick[counter] << resetiosflags(ios::left) + << setw(10) << drop[counter] << resetiosflags(ios::left) + << setw(12) << psgr[counter] << resetiosflags(ios::left) + << setw(14) << dist[counter] << resetiosflags(ios::left) + << setw(14) << fare[counter] << resetiosflags(ios::left) + << setw(14) << toll[counter] + << endl; + counter++; + inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; + } + return counter; +} - ofstream outFile("infile.txt"); +void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], + int counter) +{ + outFile << " Here is the Output File" << endl; + for (int r = 0; r <= counter - 1; r++) + { + outFile << setiosflags(ios::left) << setw(5) + << pick[r] << resetiosflags(ios::left) + << setw(10) << drop[r] << resetiosflags(ios::left) + << setw(12) << psgr[r] << resetiosflags(ios::left) + << setw(14) << dist[r] << resetiosflags(ios::left) + << setw(14) << fare[r] << resetiosflags(ios::left) + << setw(14) << toll[r] + << endl; + } +} +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) +{ + // To screen + cout << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; - inFile.open("LabResults.txt"); -}
\ No newline at end of file + // To file + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; +} |