From b959c63972f80c1f7db8bc40d12f44d9f32ae3ce Mon Sep 17 00:00:00 2001 From: Anibal LopezBonilla Date: Thu, 24 Nov 2022 11:11:24 -0800 Subject: Push 1 --- BlankConsoleLab/BlankConsoleLab.cpp | 97 +++++++++++++++++++++++++++++++-- BlankConsoleLab/BlankConsoleLab.vcxproj | 8 +-- 2 files changed, 96 insertions(+), 9 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 - -using namespace std; - -using std::cout; +#include // For the files!!!! +#include // 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"; +} + diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index db2e734..d2e3ee2 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode -- cgit v1.2.3