From ece631306a70f3e08cc8358b484528456648426e Mon Sep 17 00:00:00 2001 From: jacobdw22 Date: Mon, 28 Nov 2022 14:31:11 -0800 Subject: Added small.txt and made some changes to the code. Also added a way to choose which file is opened --- BlankConsoleLab/BlankConsoleLab.cpp | 119 -------------------- BlankConsoleLab/BlankConsoleLab.vcxproj | 3 +- BlankConsoleLab/BlankConsoleLab.vcxproj.filters | 3 +- BlankConsoleLab/cst116-lab3-wilson.cpp | 141 ++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 121 deletions(-) delete mode 100644 BlankConsoleLab/BlankConsoleLab.cpp create mode 100644 BlankConsoleLab/cst116-lab3-wilson.cpp diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp deleted file mode 100644 index 113ca96..0000000 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*This is Lab 3 assist program. It does not do Lab 3 specs BUT it will -help ALOT!!! -Not many comments shown in order to require students to think -Use an input file with 6 columns of numbers as required in Lab 3 Write up. -Place file in correct path. -Name it lab3_data.txt -*/ -#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, 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); -int main() -{ - 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("lab3_Report.txt"); - inFile.open("large.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 Input File"; - cout << "\n\n\t\t ** About to EXIT NOW! ** "; - } - } - else - { - cout << "Trouble Opening Output 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; -} -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"; - // To file - outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" - << "\t\t The End \n"; -} \ No newline at end of file diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index 1c2a947..c0a5b52 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -139,10 +139,11 @@ - + + diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters index 60f7705..cebb774 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters @@ -15,12 +15,13 @@ - + Source Files + \ No newline at end of file diff --git a/BlankConsoleLab/cst116-lab3-wilson.cpp b/BlankConsoleLab/cst116-lab3-wilson.cpp new file mode 100644 index 0000000..f58bd45 --- /dev/null +++ b/BlankConsoleLab/cst116-lab3-wilson.cpp @@ -0,0 +1,141 @@ +/*This is Lab 3 assist program. It does not do Lab 3 specs BUT it will +help ALOT!!! +Not many comments shown in order to require students to think +Use an input file with 6 columns of numbers as required in Lab 3 Write up. +Place file in correct path. +Name it lab3_data.txt +*/ +#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 = 60; + +int ReadData(ifstream& inFile, ofstream& outFile, 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); + +int main() +{ + 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("lab3_Report.txt"); + + char file = 'a'; + cout << "Please choose a file to open. Press 's' for small.txt, or press 'l' for large.txt: "; + cin >> file; + cout << endl; + while (file != 's' && file != 'l'){ + switch (file) { + case 's': + inFile.open("small.txt"); + break; + case 'l': + inFile.open("large.txt"); + break; + default: + break; + } + } + + if (inFile.is_open()) + { + record_counter = ReadData(inFile, outFile, 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 Input File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + } + else + { + cout << "Trouble Opening Output File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + return 0; +} +int ReadData(ifstream& inFile, ofstream& outFile, 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; +} +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"; + // To file + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; +} \ No newline at end of file -- cgit v1.2.3