diff options
| -rw-r--r-- | .vscode/settings.json | 5 | ||||
| -rw-r--r-- | Lab3/CST116-Lab3-Florea.cpp | 108 | ||||
| -rwxr-xr-x | a.out | bin | 44082 -> 53330 bytes | |||
| -rw-r--r-- | large.txt | 48 | ||||
| -rw-r--r-- | small.txt | 11 |
5 files changed, 159 insertions, 13 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2eb4839 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "iomanip": "cpp" + } +}
\ No newline at end of file diff --git a/Lab3/CST116-Lab3-Florea.cpp b/Lab3/CST116-Lab3-Florea.cpp index b8c3fe0..d392d95 100644 --- a/Lab3/CST116-Lab3-Florea.cpp +++ b/Lab3/CST116-Lab3-Florea.cpp @@ -3,32 +3,114 @@ #include <iostream> #include <string.h> +#include <fstream> using namespace std; using std::cout; -using std::cin; +using std::cin; using std::endl; +using std::setprecision; +using std::fixed; -string getFileName(); +void getFileName(string&); +void readData(fstream&, int[], int[], int[], int[], float[], float[], float[], float[], float[]); +void displayData(int[], int[], int[], int[], float[], float[], float[], float[], float[], int); int main() { - cout << "Hello World!\n"; - getFileName(); + int pick_up_loc[50]; + int drop_off_loc[50]; + int pass_count[50]; + int trip[50]; + float distance[50]; + float fare_amount[50]; + float toll_amount[50]; + float total[50]; + float cost_mi[50]; + string file_name; + string data_contents; + getFileName(file_name); + + fstream data_file; + data_file.open(file_name); + + if (data_file.is_open()) + { + readData(data_file, pick_up_loc, drop_off_loc, pass_count, trip, distance, fare_amount, toll_amount, total, cost_mi); + } + else if (!(data_file.is_open())) + { + cout << "Trouble opening " << file_name << "." << endl; + } + } -string getFileName() +void getFileName(string& name) { - string file_name; cout << "Enter the name of the file including extension: " << endl; - cin >> file_name; - - return file_name; + cin >> name; } -void readData() +void readData(fstream& file, int pick[], int drop[], int passenger[], int trip[], float distance[], float fare[], float toll[], float total[], float cost_mi[]) +{ + int counter = 0; + file >> pick[counter] >> drop[counter] >> passenger[counter] >> distance[counter] >> fare[counter] >> toll[counter]; + total[counter] = fare[counter] + toll[counter]; + + trip[counter] = counter + 1; + + if (distance[counter] == 0) + { + cost_mi[counter] = 0; + } + else cost_mi[counter] = fare[counter] / distance[counter]; + + while( !file.eof() ) + { + counter++; + file >> pick[counter] >> drop[counter] >> passenger[counter] >> distance[counter] >> fare[counter] >> toll[counter]; + + trip[counter] = counter + 1; + + total[counter] = fare[counter] + toll[counter]; + if (distance[counter] == 0) + { + cost_mi[counter] = 0; + } + else cost_mi[counter] = fare[counter] / distance[counter]; + + } + + file.close(); + + displayData(trip, pick, drop, passenger, distance, fare, toll, total, cost_mi, counter); +} + +void displayData(int trip[], int pick[], int drop[], int passenger[], float distance[], float fare[], float toll[], float total[], float cost_mi[], int counter) { - int pick_up_loc; - int drop_off_loc; -}
\ No newline at end of file + int total_people = 0; + float total_cost = 0; + + int width = 15; + cout << setw(width) << "Trip #" << setw(width) << "Pick Up" << setw(width) << "Drop off" << setw(width) << "# of ppl"; + cout << setw(width) << "Distance" << setw(width) << "Fare" << setw(width) << "Toll"; + cout << setw(width) << "Total" << setw(width) << "Cost/Mile" << setw(width) << endl; + + for (int idx = 0; idx <= counter; idx++) + { + cout << setw(width) << trip[idx] << setw(width) << pick[idx] << setw(width) << drop[idx]; + cout << setprecision(2) << fixed << setw(width) << passenger[idx] << setw(width) << distance[idx] << setw(width) << fare[idx]; + cout << setw(width) << toll[idx] << setw(width) << total[idx] << setw(width) << cost_mi[idx] << endl; + + total_people = total_people + passenger[idx]; + total_cost = total_cost + fare[idx] + toll[idx]; + + } + + cout << setw(width) << "People transported: " << total_people << endl; + cout << setw(width) << "Total paid: " << total_cost << endl; + cout << setw(width) << "Average cost per person: " << total_cost / total_people << endl; + + +} Binary files differdiff --git a/large.txt b/large.txt new file mode 100644 index 0000000..d9fa1b1 --- /dev/null +++ b/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
\ No newline at end of file diff --git a/small.txt b/small.txt new file mode 100644 index 0000000..f9423ec --- /dev/null +++ b/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 |