diff options
| author | [email protected] <[email protected]> | 2022-11-30 23:04:32 -0800 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2022-11-30 23:04:32 -0800 |
| commit | 2673ae2c97ddc3be561740b44bf17e4ba0198918 (patch) | |
| tree | 0569c2a4d089126cec483112c338af35fa6f32f0 | |
| parent | All ze code is done and working! (diff) | |
| download | cst116-lab3-smith-benjamin-2673ae2c97ddc3be561740b44bf17e4ba0198918.tar.xz cst116-lab3-smith-benjamin-2673ae2c97ddc3be561740b44bf17e4ba0198918.zip | |
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 12 | ||||
| -rw-r--r-- | CST116-Lab3-Smith-Pseudo-Code.txt | 27 |
2 files changed, 38 insertions, 1 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index c0c3e2e..3a9a791 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -24,9 +24,11 @@ float Fare_Calc(double moneys[], int counting); int main() { + //Setup stream to the already existing file with the data ifstream infile; infile.open("C:\\Users\\cowpi\\source\\repos\\cst116-lab3-Smith-Benjamin\\large.txt"); + //If the file opened correctly, it will read all its data to the already initialized arrays if (infile.is_open()) { while (!infile.eof()) { infile >> pickup[counter] >> dropoff[counter] >> passengers[counter] >> distance_trav[counter] >> fare[counter] >> toll[counter]; @@ -34,19 +36,22 @@ int main() } infile.close(); } + //If the file didn't open correctly. it will give an error and end the program else { cout << "There was an error loading the in file. You may need to reset its address to one on your local device." << endl; system("pause"); return 0; } - + //The user may enter the name of the file for which data is to be exported cout << "Please enter the name of the file you wish to export the results into" << endl << "You must include the \".txt\" at the end of your file name: "; cin >> filename; + //Setup stream to create or overwrite a file for data to be transferred to ofstream outfile; outfile.open(filename); + //If the file opened correctly, it will do the math to output the correct fare and cost-per-mile values to the file if (outfile.is_open()) { for (int counting = 0; counting < counter; counting++) { total_fare[counting] = fare[counting] + toll[counting]; @@ -61,18 +66,21 @@ int main() cout << "The file was correctly creating and/or written to" << endl; outfile.close(); } + //If the file didn't open correctly. it will give an error and end the program else { cout << "There was an error creating or writing to the file" << endl; system("pause"); return 0; } + //All other calculations and screen-displayings will be done via this function call Other_Calculations(total_fare, counter); return 0; } void Other_Calculations(double money[], int count_var) { + //Output the values of the total travellers, total fares, and cost per person cout << endl << endl << endl; cout << "The total number of travellers is: " << count_var << "." << endl; cout << "The total amount of the fares is: " << Fare_Calc(total_fare, count_var) << "." << endl; @@ -80,8 +88,10 @@ void Other_Calculations(double money[], int count_var) { } float Fare_Calc(double moneys[], int counting) { + //Initialize the sum variable to 0 int sum = 0; + //Add up the totals of all the fares for (int count_variable = 0; count_variable < counting; count_variable++) { sum += total_fare[count_variable]; } diff --git a/CST116-Lab3-Smith-Pseudo-Code.txt b/CST116-Lab3-Smith-Pseudo-Code.txt new file mode 100644 index 0000000..8a3843e --- /dev/null +++ b/CST116-Lab3-Smith-Pseudo-Code.txt @@ -0,0 +1,27 @@ +main(): +1) Setup stream to the already existing file with the data +2) If the file opened correctly, start a while loop until the end of the file is reached, counting how many times it loops + 2.1) Read all its data to the already initialized arrays for each type of value storage + 2.2) Close the file +3) If the file didn't open correctly, give an error and end the program +4) Collect the user's input for the name of the output file +5) Setup stream to create or overwrite a file for data to be transferred to using the user's previously input name +6) If the file opened correctly, start a for loop for as many times the counting variable didn't see the end of the in file + 6.1) Do the math to output the correct fare and cost-per-mile values to the file + 6.2) Close the file +7) If the file didn't open correctly, give an error and end the program +8) Call the Other_Calculations function using the array 'total_fare' and the counting variable from earlier +9) return 0; + + +Other_Calculations: +1) cout << endl a few times to create a visually pleasing spacing +2) Output the total number of travellers (the counting variable form earlier's value) +3) Output the total amount of the fares combined, calling the Fare_Calc function using the 'total_fare' array and the counting variable from earlier +4) Output the average cost per person (Far_Calc / counting variable from earlier) + + +Fare_Cals: +1) Initialize the 'sum' variable to 0 +2) Add the totals of all the fares in the 'total_fare' to the 'sum' variable +3) return sum;
\ No newline at end of file |