diff options
| author | Anibal LopezBonilla <[email protected]> | 2022-11-24 11:11:24 -0800 |
|---|---|---|
| committer | Anibal LopezBonilla <[email protected]> | 2022-11-24 11:11:24 -0800 |
| commit | b959c63972f80c1f7db8bc40d12f44d9f32ae3ce (patch) | |
| tree | 94e9f4f432613ecd1201501441f0b3f21b750873 /BlankConsoleLab/BlankConsoleLab.cpp | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | cst116-lab3-lopez-bonilla-b959c63972f80c1f7db8bc40d12f44d9f32ae3ce.tar.xz cst116-lab3-lopez-bonilla-b959c63972f80c1f7db8bc40d12f44d9f32ae3ce.zip | |
Push 1
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 97 |
1 files changed, 92 insertions, 5 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..bb8a6ba 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,15 +2,102 @@ // #include <iostream> - -using namespace std; - -using std::cout; +#include <fstream> // For the files!!!! +#include <iomanip> // For manipulators & formatting options using std::cin; +using std::cout; using std::endl; +using std::setw; +using std::ios; + +using std::ifstream; +using std::ofstream; + + +const int MAX = 100; + +int ReadData(ifstream& inFile, ofstream& outFile,int pickUP[],int DropO[],int Traveller[],float Dis[],float TollA[]); +void WriteOutputFile(ofstream& outFile, int pickUP[], int DropO[], int Traveller[], float Dis[], float TollA[], + int counter); +void PrintTotalsAndSummary(ofstream& out, int totalRecords); int main() { - cout << "Hello World!\n"; + + int pickUP[MAX]; + int dropO[MAX]; + int Traveller[MAX]; + float Dis[MAX]; + float FareA[MAX]; + float TollA[MAX]; + + ifstream inFile; + //"C:\Users\speed\TEMP" + // Notice how this automatically opens the file + ofstream outFile("C:\\Users\\speed\\TEMP\\Apollo17Output.txt"); + //C:\\TEMP\\Chap_11_data.txt + inFile.open("C:\\Users\\speed\\TEMP\\Apollo_17.txt"); + + if (inFile.is_open()) + { + record_counter = ReadData(inFile, outFile, name, age); + inFile.close(); + + if (outFile.is_open()) + { + WriteOutputFile(outFile, name, age, 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, ofstream& outFile, char name[][MAX], int age[]) +{ + int counter = 0; + inFile >> name[counter] >> age[counter]; // Priming Read + + while (!inFile.eof()) + { + cout << setiosflags(ios::left) << setw(25) + << name[counter] << resetiosflags(ios::left) + << setw(4) << age[counter] << endl; + counter++; + inFile >> name[counter] >> age[counter]; + } + + return counter; +} +void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter) +{ + outFile << " Here is the Output File" << endl; + for (int r = 0; r <= counter; r++) + { + outFile << setiosflags(ios::left) << setw(25) + << name[r] << setw(4) + << resetiosflags(ios::left) << age[r] + << endl; + } } +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) +{ + // To screen + cout << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; + + // To file + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; +} + |