// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #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() { 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"; }