From aaea2967bc68003cb052c564e2009379d5481bcc Mon Sep 17 00:00:00 2001 From: Musa Ahmed Date: Wed, 30 Nov 2022 17:48:53 -0800 Subject: renamed the files --- BlankConsoleLab/BlankConsoleLab.vcxproj | 2 +- BlankConsoleLab/BlankConsoleLab.vcxproj.filters | 2 +- BlankConsoleLab/CST116-Lab3-Output.txt | 91 ------------- BlankConsoleLab/CST116-Lab3-Pseudocode.txt | 73 ---------- BlankConsoleLab/Lab3-Ahmed.cpp | 170 ------------------------ BlankConsoleLab/large.txt | 48 ------- BlankConsoleLab/out.txt | 59 -------- BlankConsoleLab/read.txt | 19 --- BlankConsoleLab/small.txt | 11 -- BlankConsoleLab/temp.txt | 6 - CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.cpp | 170 ++++++++++++++++++++++++ CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.filters | 30 +++++ CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.vcxproj | 151 +++++++++++++++++++++ CST116-Lab3-Ahmed/CST116-Lab3-Output.txt | 91 +++++++++++++ CST116-Lab3-Ahmed/CST116-Lab3-Pseudocode.txt | 73 ++++++++++ CST116-Lab3-Ahmed/large.txt | 48 +++++++ CST116-Lab3-Ahmed/out.txt | 59 ++++++++ CST116-Lab3-Ahmed/small.txt | 11 ++ 18 files changed, 635 insertions(+), 479 deletions(-) delete mode 100644 BlankConsoleLab/CST116-Lab3-Output.txt delete mode 100644 BlankConsoleLab/CST116-Lab3-Pseudocode.txt delete mode 100644 BlankConsoleLab/Lab3-Ahmed.cpp delete mode 100644 BlankConsoleLab/large.txt delete mode 100644 BlankConsoleLab/out.txt delete mode 100644 BlankConsoleLab/read.txt delete mode 100644 BlankConsoleLab/small.txt delete mode 100644 BlankConsoleLab/temp.txt create mode 100644 CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.cpp create mode 100644 CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.filters create mode 100644 CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.vcxproj create mode 100644 CST116-Lab3-Ahmed/CST116-Lab3-Output.txt create mode 100644 CST116-Lab3-Ahmed/CST116-Lab3-Pseudocode.txt create mode 100644 CST116-Lab3-Ahmed/large.txt create mode 100644 CST116-Lab3-Ahmed/out.txt create mode 100644 CST116-Lab3-Ahmed/small.txt diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index 4d48773..55930eb 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -139,7 +139,7 @@ - + diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters index 2dfd9f0..7d7d39a 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters @@ -15,7 +15,7 @@ - + Source Files diff --git a/BlankConsoleLab/CST116-Lab3-Output.txt b/BlankConsoleLab/CST116-Lab3-Output.txt deleted file mode 100644 index 9ae6094..0000000 --- a/BlankConsoleLab/CST116-Lab3-Output.txt +++ /dev/null @@ -1,91 +0,0 @@ -OUTPUT FOR LARGE TEXT - -Please enter the input file name including extension: -large.txt -Trip Pick Drop # ppl Distance Fare Toll Total Cost per Mile -0 129 7 3 1.3 7.5 0 7.5 5.77 -1 36 69 1 11.4 32 5.76 37.8 3.31 -2 7 41 1 4.6 15 5.76 20.8 4.51 -3 150 61 2 6.75 23 0 23 3.41 -4 112 17 1 3.84 15 0 15 3.91 -5 80 112 6 1.64 9.5 0 9.5 5.79 -6 256 183 1 16.1 44.5 0 44.5 2.77 -7 138 166 2 7.4 24.5 6.12 30.6 4.14 -8 142 50 5 1.7 8 0 8 4.71 -9 107 163 0 3.6 17 0 17 4.72 -10 132 3 2 19.1 52 6.12 58.1 3.04 -11 48 41 1 4.07 18 4.36 22.4 5.49 -12 132 226 1 14.3 39 0 39 2.73 -13 229 151 1 3.96 14.5 4.58 19.1 4.82 -14 238 166 1 0.76 4.5 0 4.5 5.92 -15 151 238 2 0.64 5 2.2 7.2 11.2 -16 138 82 4 3 12 0 12 4 -17 264 231 3 10.7 32.5 0 32.5 3.03 -18 170 114 5 2.01 9 0 9 4.48 -19 186 87 2 3.45 12 0 12 3.48 -20 209 256 1 3.79 17 0 17 4.49 -21 132 107 1 17.2 52 6.12 58.1 3.38 -22 232 112 1 3.1 11 0 11 3.55 -23 164 141 3 2.85 10.5 0 10.5 3.68 -24 129 7 3 1.3 7.5 0 7.5 5.77 -25 36 69 1 11.4 32 5.76 37.8 3.31 -26 7 41 1 4.6 15 5.76 20.8 4.51 -27 150 61 2 6.75 23 0 23 3.41 -28 112 17 1 3.84 15 0 15 3.91 -29 80 112 6 1.64 9.5 0 9.5 5.79 -30 256 183 1 16.1 44.5 0 44.5 2.77 -31 138 166 2 7.4 24.5 6.12 30.6 4.14 -32 142 50 5 1.7 8 0 8 4.71 -33 107 163 0 3.6 17 0 17 4.72 -34 132 3 2 19.1 52 6.12 58.1 3.04 -35 48 41 1 4.07 18 4.36 22.4 5.49 -36 132 226 1 14.3 39 0 39 2.73 -37 229 151 1 3.96 14.5 4.58 19.1 4.82 -38 238 166 1 0.76 4.5 0 4.5 5.92 -39 151 238 2 0.64 5 2.2 7.2 11.2 -40 138 82 4 3 12 0 12 4 -41 264 231 3 10.7 32.5 0 32.5 3.03 -42 170 114 5 2.01 9 0 9 4.48 -43 186 87 2 3.45 12 0 12 3.48 -44 209 256 1 3.79 17 0 17 4.49 -45 132 107 1 17.2 52 6.12 58.1 3.38 -46 232 112 1 3.1 11 0 11 3.55 -47 164 141 3 2.85 10.5 0 10.5 3.68 - - - ** Avg Cost Per Person: 10.5 ** - - - ** People Transported: 100 ** - - - ** Total Cost: 1052 ** - The End - - -OUTPUT FOR SMALL TEXT - - -Please enter the input file name including extension: -small.txt -Trip Pick Drop # ppl Distance Fare Toll Total Cost per Mile -0 129 7 3 1.3 7.5 0 7.5 5.77 -1 36 69 1 11.4 32 5.76 37.8 3.31 -2 7 41 1 4.6 15 5.76 20.8 4.51 -3 150 61 2 6.75 23 0 23 3.41 -4 112 17 1 3.84 15 0 15 3.91 -5 80 112 6 1.64 9.5 0 9.5 5.79 - - - ** Avg Cost Per Person: 8.11 ** - - - ** People Transported: 14 ** - - - ** Total Cost: 113.52 ** - The End - -C:\Users\macho\source\repos\cst116-lab3-M005A\x64\Debug\BlankConsoleLab.exe (process 9692) exited with code 0. -To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. -Press any key to close this window . . . \ No newline at end of file diff --git a/BlankConsoleLab/CST116-Lab3-Pseudocode.txt b/BlankConsoleLab/CST116-Lab3-Pseudocode.txt deleted file mode 100644 index 059fda7..0000000 --- a/BlankConsoleLab/CST116-Lab3-Pseudocode.txt +++ /dev/null @@ -1,73 +0,0 @@ -Initialize a constant int MAX for the maximum amount of records, set to 50 - -START MAIN - -initialize function ReadData, with input file, arrays, and counters -initialize function WriteOutputFile with output file, counters, and arrays -initialize PrintTotalsAndSummary with output file, counters, and arrays - -Initialize an array for each needed value, with the length being equal to max -initialize record counter -initialize people counter -initialize payment counter - -initialize filename -initialize input file -initialize output file - -prompt the user to input a filename wiht extension - set the input equal to filename - -open the file - -if the file is open - call the function ReadData and have its return value be set into record_counter - - close the input file - - if the output file is open - call the functions writeoutputfile and printotalsummary - close the output file - - else - print an error message -else - print an error message - -return 0 - -END MAIN - -ReadData - - prints out headers corresponding to each array - read in the first line of data from the input file and have it set to the first of each array - - while it is not the end of the file - the totalfare at the current index is equal to the far + toll - print out the arrays at the current index, formatting into a table - - if the distance at the current index is 0, the cost per mile is 0 - otherwise the cost per mile is equal to the total cost over the distance - - increment the index - read data again - - return counter - - -WriteOutputFile - - enter a for loop which goes until the end of the total records in the file - print out all the modified data to the output file at the current index - -PrintTotalsAndSummary - - enter a for loop which goes until the end of the total records in the file - set the total amount of people to the array of passCount at the index added together - set a double temp equal to the far + toll at the current index - paid += temp - the totalFare at the current index is equal to temp - - print out the avg cost per person, # people transported, and the total cost to both - the screen and the output file. diff --git a/BlankConsoleLab/Lab3-Ahmed.cpp b/BlankConsoleLab/Lab3-Ahmed.cpp deleted file mode 100644 index 72076d7..0000000 --- a/BlankConsoleLab/Lab3-Ahmed.cpp +++ /dev/null @@ -1,170 +0,0 @@ - -#include -#include // For the files!!!! -#include // For manipulators & formatting options -#include -#include - -using std::cin; -using std::cout; -using std::endl; -using std::setw; -using std::ios; -using std::string; -using std::ifstream; -using std::ofstream; -using std::setprecision; - - - -// The max amount of records in one file -const int MAX = 50; - -// initialize all functions -int ReadData(ifstream& inFile, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[], int counter, double totalFare[]); -void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[]); -void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], double distance[], double fare[], double toll[], double totalFare[], double costPMile[], double paid); - - -int main() -{ - // initialize all arrays and counters - int pick[MAX]; - int drop[MAX]; - int passCount[MAX]; - double distance[MAX]; - double fare[MAX]; - double toll[MAX]; - double totalFare[MAX] = { 0 }; - double costPMile[MAX] = { 0 }; - int record_counter(0); - int people(0); - int counter = 0; - double paid = 0; - - // initialize files - string filename; - ifstream inFile; - ofstream outFile("out.txt"); - - - cout << "Please enter the input file name including extension: " << endl; - cin >> filename; - - // open the requested file - inFile.open(filename); - - if (inFile.is_open()) - { - // read the data from the file, and output the total number of records (store into arrays) - record_counter = ReadData(inFile, pick, drop, passCount, distance, fare, toll, costPMile, counter, totalFare); - - // close the read file - inFile.close(); - - if (outFile.is_open()) - { - // write the new data to the output file - WriteOutputFile(outFile, record_counter, people, pick, drop, passCount, distance, fare, toll, costPMile); - // output the summary both to screen and to file - PrintTotalsAndSummary(outFile, record_counter, people, passCount, distance, fare, toll, totalFare, costPMile, paid); - 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, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[], int counter, double totalFare[]) -{ - - // print headers - cout << setiosflags(ios::left) << setw(10) << "Trip" << setw(15) - << "Pick" << setw(10) << "Drop" << setw(10) - << "# ppl" - << setw(10) << "Distance" << setw(10) - << "Fare" - << setw(10) << "Toll" - << setw(10) << "Total" - << setw(10) << "Cost per Mile" << endl; - - inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; // Priming Read - // read all of the data into arrays - while (!inFile.eof()) - { - totalFare[counter] = fare[counter] + toll[counter]; - cout << setiosflags(ios::left) << setw(10) << counter << setw(15) - << pick[counter] - << setw(10) << drop[counter] << setw(10) - << passCount[counter] - << setw(10) << distance[counter] << setw(10) - << fare[counter] - << setw(10) << toll[counter] << setw(15) - << totalFare[counter] << setw(10); - // if distance is 0 then there is no cost per mile - if (distance[counter] == 0) { - costPMile[counter] = 0; - } - // cost per mile = (toll + fare) / distance - else { - costPMile[counter] = (toll[counter] + fare[counter]) / distance[counter]; - } - cout << setprecision(3) << costPMile[counter]; - counter++; - inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; - cout << endl; - - } - - return counter; -} -void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[]) -{ - - // write the same data to the output files - outFile << " Here is the Output File" << endl; - for (int r = 0; r < totalRecords; r++) - { - - outFile << setiosflags(ios::left) << setw(15) - << pick[r] - << setw(15) << drop[r] << setw(15) - << passCount[r] - << setw(15) << distance[r] << setw(15) - << fare[r] - << setw(15) << toll[r] - << setw(15) << costPMile[r] << endl; - } - -} -void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], double distance[], double fare[], double toll[], double totalFare[], double costPMile[], double paid) -{ - // do the calculations for all of the totals. - for (int i = 0; i < totalRecords; i++) { - people += passCount[i]; - double temp = fare[i] + toll[i]; - paid += temp; - totalFare[i] = temp; - - } - // print ot screen - cout << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n" - << "\n\n\t** People Transported: " << people << " **\n" - << "\n\n\t** Total Cost: " << setprecision(5) << paid << " **\n" - - << "\t\t The End \n"; - // print to output file - outFile << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n" - << "\n\n\t** People Transported: " << people << " **\n" - << "\n\n\t** Total Cost: " << paid << " **\n" - << "\t\t The End \n"; -} - diff --git a/BlankConsoleLab/large.txt b/BlankConsoleLab/large.txt deleted file mode 100644 index 1c3dbbb..0000000 --- a/BlankConsoleLab/large.txt +++ /dev/null @@ -1,48 +0,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 -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 diff --git a/BlankConsoleLab/out.txt b/BlankConsoleLab/out.txt deleted file mode 100644 index addee3c..0000000 --- a/BlankConsoleLab/out.txt +++ /dev/null @@ -1,59 +0,0 @@ - Here is the Output File -129 7 3 1.3 7.5 0 5.76923 -36 69 1 11.41 32 5.76 3.30938 -7 41 1 4.6 15 5.76 4.51304 -150 61 2 6.75 23 0 3.40741 -112 17 1 3.84 15 0 3.90625 -80 112 6 1.64 9.5 0 5.79268 -256 183 1 16.08 44.5 0 2.76741 -138 166 2 7.4 24.5 6.12 4.13784 -142 50 5 1.7 8 0 4.70588 -107 163 0 3.6 17 0 4.72222 -132 3 2 19.1 52 6.12 3.04293 -48 41 1 4.07 18 4.36 5.49386 -132 226 1 14.3 39 0 2.72727 -229 151 1 3.96 14.5 4.58 4.81818 -238 166 1 0.76 4.5 0 5.92105 -151 238 2 0.64 5 2.2 11.25 -138 82 4 3 12 0 4 -264 231 3 10.74 32.5 0 3.02607 -170 114 5 2.01 9 0 4.47761 -186 87 2 3.45 12 0 3.47826 -209 256 1 3.79 17 0 4.48549 -132 107 1 17.2 52 6.12 3.37907 -232 112 1 3.1 11 0 3.54839 -164 141 3 2.85 10.5 0 3.68421 -129 7 3 1.3 7.5 0 5.76923 -36 69 1 11.41 32 5.76 3.30938 -7 41 1 4.6 15 5.76 4.51304 -150 61 2 6.75 23 0 3.40741 -112 17 1 3.84 15 0 3.90625 -80 112 6 1.64 9.5 0 5.79268 -256 183 1 16.08 44.5 0 2.76741 -138 166 2 7.4 24.5 6.12 4.13784 -142 50 5 1.7 8 0 4.70588 -107 163 0 3.6 17 0 4.72222 -132 3 2 19.1 52 6.12 3.04293 -48 41 1 4.07 18 4.36 5.49386 -132 226 1 14.3 39 0 2.72727 -229 151 1 3.96 14.5 4.58 4.81818 -238 166 1 0.76 4.5 0 5.92105 -151 238 2 0.64 5 2.2 11.25 -138 82 4 3 12 0 4 -264 231 3 10.74 32.5 0 3.02607 -170 114 5 2.01 9 0 4.47761 -186 87 2 3.45 12 0 3.47826 -209 256 1 3.79 17 0 4.48549 -132 107 1 17.2 52 6.12 3.37907 -232 112 1 3.1 11 0 3.54839 -164 141 3 2.85 10.5 0 3.68421 - - - ** Avg Cost Per Person: 10.5204 ** - - - ** People Transported: 100 ** - - - ** Total Cost: 1052.04 ** - The End diff --git a/BlankConsoleLab/read.txt b/BlankConsoleLab/read.txt deleted file mode 100644 index d5ff001..0000000 --- a/BlankConsoleLab/read.txt +++ /dev/null @@ -1,19 +0,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 - - -John 19 -Molly 23 -Tim 48 -Keil 42 -Trinh 21 -Musa 18 -Anthony 25 -Kevin 27 -Cheryl 32 -Kim 16 -Dave 25 -Will 34 \ No newline at end of file diff --git a/BlankConsoleLab/small.txt b/BlankConsoleLab/small.txt deleted file mode 100644 index 1fba087..0000000 --- a/BlankConsoleLab/small.txt +++ /dev/null @@ -1,11 +0,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 \ No newline at end of file diff --git a/BlankConsoleLab/temp.txt b/BlankConsoleLab/temp.txt deleted file mode 100644 index 94e4c00..0000000 --- a/BlankConsoleLab/temp.txt +++ /dev/null @@ -1,6 +0,0 @@ -129 7 3 1.3 7.5 0 5.76923 -36 69 1 11.41 32 5.76 3.30938 -7 41 1 4.6 15 5.76 4.51304 -150 61 2 6.75 23 0 3.40741 -112 17 1 3.84 15 0 3.90625 -80 112 6 1.64 9.5 0 5.79268 diff --git a/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.cpp b/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.cpp new file mode 100644 index 0000000..72076d7 --- /dev/null +++ b/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.cpp @@ -0,0 +1,170 @@ + +#include +#include // For the files!!!! +#include // For manipulators & formatting options +#include +#include + +using std::cin; +using std::cout; +using std::endl; +using std::setw; +using std::ios; +using std::string; +using std::ifstream; +using std::ofstream; +using std::setprecision; + + + +// The max amount of records in one file +const int MAX = 50; + +// initialize all functions +int ReadData(ifstream& inFile, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[], int counter, double totalFare[]); +void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[]); +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], double distance[], double fare[], double toll[], double totalFare[], double costPMile[], double paid); + + +int main() +{ + // initialize all arrays and counters + int pick[MAX]; + int drop[MAX]; + int passCount[MAX]; + double distance[MAX]; + double fare[MAX]; + double toll[MAX]; + double totalFare[MAX] = { 0 }; + double costPMile[MAX] = { 0 }; + int record_counter(0); + int people(0); + int counter = 0; + double paid = 0; + + // initialize files + string filename; + ifstream inFile; + ofstream outFile("out.txt"); + + + cout << "Please enter the input file name including extension: " << endl; + cin >> filename; + + // open the requested file + inFile.open(filename); + + if (inFile.is_open()) + { + // read the data from the file, and output the total number of records (store into arrays) + record_counter = ReadData(inFile, pick, drop, passCount, distance, fare, toll, costPMile, counter, totalFare); + + // close the read file + inFile.close(); + + if (outFile.is_open()) + { + // write the new data to the output file + WriteOutputFile(outFile, record_counter, people, pick, drop, passCount, distance, fare, toll, costPMile); + // output the summary both to screen and to file + PrintTotalsAndSummary(outFile, record_counter, people, passCount, distance, fare, toll, totalFare, costPMile, paid); + 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, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[], int counter, double totalFare[]) +{ + + // print headers + cout << setiosflags(ios::left) << setw(10) << "Trip" << setw(15) + << "Pick" << setw(10) << "Drop" << setw(10) + << "# ppl" + << setw(10) << "Distance" << setw(10) + << "Fare" + << setw(10) << "Toll" + << setw(10) << "Total" + << setw(10) << "Cost per Mile" << endl; + + inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; // Priming Read + // read all of the data into arrays + while (!inFile.eof()) + { + totalFare[counter] = fare[counter] + toll[counter]; + cout << setiosflags(ios::left) << setw(10) << counter << setw(15) + << pick[counter] + << setw(10) << drop[counter] << setw(10) + << passCount[counter] + << setw(10) << distance[counter] << setw(10) + << fare[counter] + << setw(10) << toll[counter] << setw(15) + << totalFare[counter] << setw(10); + // if distance is 0 then there is no cost per mile + if (distance[counter] == 0) { + costPMile[counter] = 0; + } + // cost per mile = (toll + fare) / distance + else { + costPMile[counter] = (toll[counter] + fare[counter]) / distance[counter]; + } + cout << setprecision(3) << costPMile[counter]; + counter++; + inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; + cout << endl; + + } + + return counter; +} +void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[]) +{ + + // write the same data to the output files + outFile << " Here is the Output File" << endl; + for (int r = 0; r < totalRecords; r++) + { + + outFile << setiosflags(ios::left) << setw(15) + << pick[r] + << setw(15) << drop[r] << setw(15) + << passCount[r] + << setw(15) << distance[r] << setw(15) + << fare[r] + << setw(15) << toll[r] + << setw(15) << costPMile[r] << endl; + } + +} +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], double distance[], double fare[], double toll[], double totalFare[], double costPMile[], double paid) +{ + // do the calculations for all of the totals. + for (int i = 0; i < totalRecords; i++) { + people += passCount[i]; + double temp = fare[i] + toll[i]; + paid += temp; + totalFare[i] = temp; + + } + // print ot screen + cout << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n" + << "\n\n\t** People Transported: " << people << " **\n" + << "\n\n\t** Total Cost: " << setprecision(5) << paid << " **\n" + + << "\t\t The End \n"; + // print to output file + outFile << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n" + << "\n\n\t** People Transported: " << people << " **\n" + << "\n\n\t** Total Cost: " << paid << " **\n" + << "\t\t The End \n"; +} + diff --git a/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.filters b/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.filters new file mode 100644 index 0000000..2dfd9f0 --- /dev/null +++ b/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.vcxproj b/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.vcxproj new file mode 100644 index 0000000..4d48773 --- /dev/null +++ b/CST116-Lab3-Ahmed/CST116-Lab3-Ahmed.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {3cecade6-3e15-4852-bd24-65bfe5d3a3aa} + BlankConsoleLab + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/CST116-Lab3-Ahmed/CST116-Lab3-Output.txt b/CST116-Lab3-Ahmed/CST116-Lab3-Output.txt new file mode 100644 index 0000000..9ae6094 --- /dev/null +++ b/CST116-Lab3-Ahmed/CST116-Lab3-Output.txt @@ -0,0 +1,91 @@ +OUTPUT FOR LARGE TEXT + +Please enter the input file name including extension: +large.txt +Trip Pick Drop # ppl Distance Fare Toll Total Cost per Mile +0 129 7 3 1.3 7.5 0 7.5 5.77 +1 36 69 1 11.4 32 5.76 37.8 3.31 +2 7 41 1 4.6 15 5.76 20.8 4.51 +3 150 61 2 6.75 23 0 23 3.41 +4 112 17 1 3.84 15 0 15 3.91 +5 80 112 6 1.64 9.5 0 9.5 5.79 +6 256 183 1 16.1 44.5 0 44.5 2.77 +7 138 166 2 7.4 24.5 6.12 30.6 4.14 +8 142 50 5 1.7 8 0 8 4.71 +9 107 163 0 3.6 17 0 17 4.72 +10 132 3 2 19.1 52 6.12 58.1 3.04 +11 48 41 1 4.07 18 4.36 22.4 5.49 +12 132 226 1 14.3 39 0 39 2.73 +13 229 151 1 3.96 14.5 4.58 19.1 4.82 +14 238 166 1 0.76 4.5 0 4.5 5.92 +15 151 238 2 0.64 5 2.2 7.2 11.2 +16 138 82 4 3 12 0 12 4 +17 264 231 3 10.7 32.5 0 32.5 3.03 +18 170 114 5 2.01 9 0 9 4.48 +19 186 87 2 3.45 12 0 12 3.48 +20 209 256 1 3.79 17 0 17 4.49 +21 132 107 1 17.2 52 6.12 58.1 3.38 +22 232 112 1 3.1 11 0 11 3.55 +23 164 141 3 2.85 10.5 0 10.5 3.68 +24 129 7 3 1.3 7.5 0 7.5 5.77 +25 36 69 1 11.4 32 5.76 37.8 3.31 +26 7 41 1 4.6 15 5.76 20.8 4.51 +27 150 61 2 6.75 23 0 23 3.41 +28 112 17 1 3.84 15 0 15 3.91 +29 80 112 6 1.64 9.5 0 9.5 5.79 +30 256 183 1 16.1 44.5 0 44.5 2.77 +31 138 166 2 7.4 24.5 6.12 30.6 4.14 +32 142 50 5 1.7 8 0 8 4.71 +33 107 163 0 3.6 17 0 17 4.72 +34 132 3 2 19.1 52 6.12 58.1 3.04 +35 48 41 1 4.07 18 4.36 22.4 5.49 +36 132 226 1 14.3 39 0 39 2.73 +37 229 151 1 3.96 14.5 4.58 19.1 4.82 +38 238 166 1 0.76 4.5 0 4.5 5.92 +39 151 238 2 0.64 5 2.2 7.2 11.2 +40 138 82 4 3 12 0 12 4 +41 264 231 3 10.7 32.5 0 32.5 3.03 +42 170 114 5 2.01 9 0 9 4.48 +43 186 87 2 3.45 12 0 12 3.48 +44 209 256 1 3.79 17 0 17 4.49 +45 132 107 1 17.2 52 6.12 58.1 3.38 +46 232 112 1 3.1 11 0 11 3.55 +47 164 141 3 2.85 10.5 0 10.5 3.68 + + + ** Avg Cost Per Person: 10.5 ** + + + ** People Transported: 100 ** + + + ** Total Cost: 1052 ** + The End + + +OUTPUT FOR SMALL TEXT + + +Please enter the input file name including extension: +small.txt +Trip Pick Drop # ppl Distance Fare Toll Total Cost per Mile +0 129 7 3 1.3 7.5 0 7.5 5.77 +1 36 69 1 11.4 32 5.76 37.8 3.31 +2 7 41 1 4.6 15 5.76 20.8 4.51 +3 150 61 2 6.75 23 0 23 3.41 +4 112 17 1 3.84 15 0 15 3.91 +5 80 112 6 1.64 9.5 0 9.5 5.79 + + + ** Avg Cost Per Person: 8.11 ** + + + ** People Transported: 14 ** + + + ** Total Cost: 113.52 ** + The End + +C:\Users\macho\source\repos\cst116-lab3-M005A\x64\Debug\BlankConsoleLab.exe (process 9692) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . \ No newline at end of file diff --git a/CST116-Lab3-Ahmed/CST116-Lab3-Pseudocode.txt b/CST116-Lab3-Ahmed/CST116-Lab3-Pseudocode.txt new file mode 100644 index 0000000..059fda7 --- /dev/null +++ b/CST116-Lab3-Ahmed/CST116-Lab3-Pseudocode.txt @@ -0,0 +1,73 @@ +Initialize a constant int MAX for the maximum amount of records, set to 50 + +START MAIN + +initialize function ReadData, with input file, arrays, and counters +initialize function WriteOutputFile with output file, counters, and arrays +initialize PrintTotalsAndSummary with output file, counters, and arrays + +Initialize an array for each needed value, with the length being equal to max +initialize record counter +initialize people counter +initialize payment counter + +initialize filename +initialize input file +initialize output file + +prompt the user to input a filename wiht extension + set the input equal to filename + +open the file + +if the file is open + call the function ReadData and have its return value be set into record_counter + + close the input file + + if the output file is open + call the functions writeoutputfile and printotalsummary + close the output file + + else + print an error message +else + print an error message + +return 0 + +END MAIN + +ReadData + + prints out headers corresponding to each array + read in the first line of data from the input file and have it set to the first of each array + + while it is not the end of the file + the totalfare at the current index is equal to the far + toll + print out the arrays at the current index, formatting into a table + + if the distance at the current index is 0, the cost per mile is 0 + otherwise the cost per mile is equal to the total cost over the distance + + increment the index + read data again + + return counter + + +WriteOutputFile + + enter a for loop which goes until the end of the total records in the file + print out all the modified data to the output file at the current index + +PrintTotalsAndSummary + + enter a for loop which goes until the end of the total records in the file + set the total amount of people to the array of passCount at the index added together + set a double temp equal to the far + toll at the current index + paid += temp + the totalFare at the current index is equal to temp + + print out the avg cost per person, # people transported, and the total cost to both + the screen and the output file. diff --git a/CST116-Lab3-Ahmed/large.txt b/CST116-Lab3-Ahmed/large.txt new file mode 100644 index 0000000..1c3dbbb --- /dev/null +++ b/CST116-Lab3-Ahmed/large.txt @@ -0,0 +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 +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 diff --git a/CST116-Lab3-Ahmed/out.txt b/CST116-Lab3-Ahmed/out.txt new file mode 100644 index 0000000..addee3c --- /dev/null +++ b/CST116-Lab3-Ahmed/out.txt @@ -0,0 +1,59 @@ + Here is the Output File +129 7 3 1.3 7.5 0 5.76923 +36 69 1 11.41 32 5.76 3.30938 +7 41 1 4.6 15 5.76 4.51304 +150 61 2 6.75 23 0 3.40741 +112 17 1 3.84 15 0 3.90625 +80 112 6 1.64 9.5 0 5.79268 +256 183 1 16.08 44.5 0 2.76741 +138 166 2 7.4 24.5 6.12 4.13784 +142 50 5 1.7 8 0 4.70588 +107 163 0 3.6 17 0 4.72222 +132 3 2 19.1 52 6.12 3.04293 +48 41 1 4.07 18 4.36 5.49386 +132 226 1 14.3 39 0 2.72727 +229 151 1 3.96 14.5 4.58 4.81818 +238 166 1 0.76 4.5 0 5.92105 +151 238 2 0.64 5 2.2 11.25 +138 82 4 3 12 0 4 +264 231 3 10.74 32.5 0 3.02607 +170 114 5 2.01 9 0 4.47761 +186 87 2 3.45 12 0 3.47826 +209 256 1 3.79 17 0 4.48549 +132 107 1 17.2 52 6.12 3.37907 +232 112 1 3.1 11 0 3.54839 +164 141 3 2.85 10.5 0 3.68421 +129 7 3 1.3 7.5 0 5.76923 +36 69 1 11.41 32 5.76 3.30938 +7 41 1 4.6 15 5.76 4.51304 +150 61 2 6.75 23 0 3.40741 +112 17 1 3.84 15 0 3.90625 +80 112 6 1.64 9.5 0 5.79268 +256 183 1 16.08 44.5 0 2.76741 +138 166 2 7.4 24.5 6.12 4.13784 +142 50 5 1.7 8 0 4.70588 +107 163 0 3.6 17 0 4.72222 +132 3 2 19.1 52 6.12 3.04293 +48 41 1 4.07 18 4.36 5.49386 +132 226 1 14.3 39 0 2.72727 +229 151 1 3.96 14.5 4.58 4.81818 +238 166 1 0.76 4.5 0 5.92105 +151 238 2 0.64 5 2.2 11.25 +138 82 4 3 12 0 4 +264 231 3 10.74 32.5 0 3.02607 +170 114 5 2.01 9 0 4.47761 +186 87 2 3.45 12 0 3.47826 +209 256 1 3.79 17 0 4.48549 +132 107 1 17.2 52 6.12 3.37907 +232 112 1 3.1 11 0 3.54839 +164 141 3 2.85 10.5 0 3.68421 + + + ** Avg Cost Per Person: 10.5204 ** + + + ** People Transported: 100 ** + + + ** Total Cost: 1052.04 ** + The End diff --git a/CST116-Lab3-Ahmed/small.txt b/CST116-Lab3-Ahmed/small.txt new file mode 100644 index 0000000..1fba087 --- /dev/null +++ b/CST116-Lab3-Ahmed/small.txt @@ -0,0 +1,11 @@ +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 -- cgit v1.2.3