From b0f2aab4f1e2936074dd6794841222ec780552a4 Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 30 Nov 2022 21:54:47 -0800 Subject: names --- BlankConsoleLab/BlankConsoleLab.cpp | 134 ------------------------ BlankConsoleLab/BlankConsoleLab.vcxproj | 3 +- BlankConsoleLab/BlankConsoleLab.vcxproj.filters | 2 +- BlankConsoleLab/cst116-Lab3-EvanMihm.cpp | 130 +++++++++++++++++++++++ BlankConsoleLab/infile.txt | 59 +++++++++-- 5 files changed, 181 insertions(+), 147 deletions(-) delete mode 100644 BlankConsoleLab/BlankConsoleLab.cpp create mode 100644 BlankConsoleLab/cst116-Lab3-EvanMihm.cpp diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp deleted file mode 100644 index e80c091..0000000 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ /dev/null @@ -1,134 +0,0 @@ -//lab3 -#include -#include -#include -#include -#include - -using std::cin; -using std::cout; -using std::endl; -using std::setw; -using std::ios; -using std::accumulate; - -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[], int totalfare, int cpm); -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 text is 6 cols by x rows - -int main() -{ - int pick[MAX]; - int drop[MAX]; - int psgr[MAX]; - float dist[MAX]; - float fare[MAX]; - float toll[MAX]; - int record_counter(0); - - int cpm{}; - int totalfare{}; - - ifstream inFile; - - ofstream outFile("LabResults.txt"); - - inFile.open("infile.txt"); - - if (inFile.is_open()) - { - record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll, totalfare, cpm); - 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! ** "; - } - - - totalfare = fare[MAX] + toll[MAX]; - return 0; -// totalfare = fare + toll; -// cpm = fare / dist; - -} -int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], int totalfare, int cpm) -{ - int counter = 0; - - - inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; // Priming Read - - cout << "Pick" << setw(12) << "Drop" << setw(15) << "Passengers" << setw(12) - << "Distance" << setw(13) << "Fare" << setw(13) << "Toll" << endl; - - 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]; - } - - cout << "Total Fare = " << totalfare << endl; - cout << "Cost Per Mile = " << cpm << endl; - - 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 - 0; 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"; -} diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index d2e3ee2..ef3b17f 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -24,6 +24,7 @@ {3cecade6-3e15-4852-bd24-65bfe5d3a3aa} BlankConsoleLab 10.0 + cst116-Lab3-EvanMihm @@ -139,7 +140,7 @@ - + diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters index aca1dd9..accf1da 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters @@ -15,7 +15,7 @@ - + Source Files diff --git a/BlankConsoleLab/cst116-Lab3-EvanMihm.cpp b/BlankConsoleLab/cst116-Lab3-EvanMihm.cpp new file mode 100644 index 0000000..ab62c04 --- /dev/null +++ b/BlankConsoleLab/cst116-Lab3-EvanMihm.cpp @@ -0,0 +1,130 @@ +//lab3 +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +using std::endl; +using std::setw; +using std::ios; +using std::accumulate; + +using std::ifstream; +using std::ofstream; + +const int MAX = 100; + +//readfile, what it reads in for the number position +int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], int totalfare, int cpm); +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); + + int cpm{}; + int totalfare{}; + + ifstream inFile; + + ofstream outFile("LabResults.txt"); + + inFile.open("infile.txt"); + + if (inFile.is_open()) + { + record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll, totalfare, cpm); + 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! ** "; + } + + totalfare = fare[MAX] + toll[MAX]; + return 0; +// totalfare = fare + toll; +// cpm = fare / dist; +} +int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], int totalfare, int cpm) +{ + int counter = 0; + + + inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; // Priming Read + + cout << "Pick" << setw(12) << "Drop" << setw(15) << "Passengers" << setw(12) + << "Distance" << setw(13) << "Fare" << setw(13) << "Toll" << endl; + + 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]; + } + + cout << "Total Fare = " << totalfare << endl; + cout << "Cost Per Mile = " << cpm << endl; + + 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 - 0; 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"; +} diff --git a/BlankConsoleLab/infile.txt b/BlankConsoleLab/infile.txt index f9423ec..1c3dbbb 100644 --- a/BlankConsoleLab/infile.txt +++ b/BlankConsoleLab/infile.txt @@ -1,11 +1,48 @@ -129 7 3 1.3 7.5 0 - -36 69 1 11.41 32 5.76 - -7 41 1 4.6 15 5.76 - -150 61 2 6.75 23 0 - -112 17 1 3.84 15 0 - -80 112 6 1.64 9.5 0 \ No newline at end of file +129 7 3 1.3 7.5 0 +36 69 1 11.41 32 5.76 +7 41 1 4.6 15 5.76 +150 61 2 6.75 23 0 +112 17 1 3.84 15 0 +80 112 6 1.64 9.5 0 +256 183 1 16.08 44.5 0 +138 166 2 7.4 24.5 6.12 +142 50 5 1.7 8 0 +107 163 0 3.6 17 0 +132 3 2 19.1 52 6.12 +48 41 1 4.07 18 4.36 +132 226 1 14.3 39 0 +229 151 1 3.96 14.5 4.58 +238 166 1 0.76 4.5 0 +151 238 2 0.64 5 2.2 +138 82 4 3 12 0 +264 231 3 10.74 32.5 0 +170 114 5 2.01 9 0 +186 87 2 3.45 12 0 +209 256 1 3.79 17 0 +132 107 1 17.2 52 6.12 +232 112 1 3.1 11 0 +164 141 3 2.85 10.5 0 +129 7 3 1.3 7.5 0 +36 69 1 11.41 32 5.76 +7 41 1 4.6 15 5.76 +150 61 2 6.75 23 0 +112 17 1 3.84 15 0 +80 112 6 1.64 9.5 0 +256 183 1 16.08 44.5 0 +138 166 2 7.4 24.5 6.12 +142 50 5 1.7 8 0 +107 163 0 3.6 17 0 +132 3 2 19.1 52 6.12 +48 41 1 4.07 18 4.36 +132 226 1 14.3 39 0 +229 151 1 3.96 14.5 4.58 +238 166 1 0.76 4.5 0 +151 238 2 0.64 5 2.2 +138 82 4 3 12 0 +264 231 3 10.74 32.5 0 +170 114 5 2.01 9 0 +186 87 2 3.45 12 0 +209 256 1 3.79 17 0 +132 107 1 17.2 52 6.12 +232 112 1 3.1 11 0 +164 141 3 2.85 10.5 0 -- cgit v1.2.3