1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using std::setw;
void Output_Extra_Stats(int total_people, double fares[50]);
int main()
{
// initialize the taxi trips lists
double taxi_trips[50][8];
cout << "Enter the file you'd like to read with the extension";
string filename;
cin >> filename;
cout << endl;
//These ints and doubles will be used for file reading
int start_point;
int end_point;
int passengers;
double distance;
double fare_amount;
double toll_amount;
//Open the file then read it.
std::ifstream input;
input.open(filename);
int total_trips = 0;
if (input.is_open()) {
//Reads each line of the file, then saves it to the taxi_trips
while (input >> start_point >> end_point >> passengers >> distance >> fare_amount >> toll_amount) {
//Set start point
taxi_trips[total_trips][0] = start_point;
taxi_trips[total_trips][1] = end_point;
taxi_trips[total_trips][2] = passengers;
taxi_trips[total_trips][3] = distance;
taxi_trips[total_trips][4] = fare_amount;
taxi_trips[total_trips][5] = toll_amount;
taxi_trips[total_trips][6] = 0.0;
taxi_trips[total_trips][7] = 0.0;
total_trips++;
}
//Adds the total fare and the cost per mile to each taxi trip
for (int i = 0; i < total_trips; i++) {
taxi_trips[i][6] = taxi_trips[i][4] + taxi_trips[i][5];
if (taxi_trips[i][3] != 0) {
taxi_trips[i][7] = taxi_trips[i][6] / taxi_trips[i][3];
taxi_trips[i][7] = ceil(taxi_trips[i][7] * 100.0) / 100.0;
}
}
int total_people = 0;
// Initializes everything in the fares list to 0. This way it dosen't break later.
double fares[50];
for (int i = 0; i < 50; i++) {
fares[i] = 0;
}
//Sets the total amount of people, and saves the fares.
for (int i = 0; i < total_trips; i++) {
total_people += taxi_trips[i][2];
fares[i] = taxi_trips[i][6];
}
//Prints the lables for output
cout << setw(10) << "Trip#" << setw(10) << "# ppl" << setw(10) << "Dist." << setw(10) << "Fare" << setw(10) << "Toll" << setw(10) << "Total" << setw(10) << "Cost/MI" << endl;
//Prints the output for each taxi trip
for (int i = 0; i < total_trips; i++) {
cout << setw(4) << setfill(' ') << " " << setw(3) << setfill('0') << taxi_trips[i][0] << setw(3) << setfill('0') << taxi_trips[i][1] << setw(10)
<< setfill(' ') << taxi_trips[i][2] << setw(10) << taxi_trips[i][3] << setw(10) << taxi_trips[i][4] << setw(10) << taxi_trips[i][5] << setw(10)
<< taxi_trips[i][6] << setw(10) << taxi_trips[i][7] << endl;
}
//Finish the output
Output_Extra_Stats(total_people, fares);
}
input.close();
return 0;
}
void Output_Extra_Stats(int total_people, double fares[50]) {
// Sets the total fares, and the average cost per person
double total_fares = 0.0;
for (int i = 0; i < 50; i++) {
total_fares += fares[i];
}
double average_cost_per_person = total_fares / total_people;
average_cost_per_person = ceil(average_cost_per_person * 100.0) / 100.0;
//Prints the People transported, total paid, and average cost per person.
cout << endl;
cout << "People Transported: " << total_people << endl;
cout << "Total Paid: " << total_fares << endl;
cout << "Average Cost Per Person: " << average_cost_per_person << endl;
}
/*
Pseudocode
main(){
taxi_trips[50][8]
read the file
assign each list to an item in taxi_trips. Leaving the last two entries at 0.0
total_trips = amount of trips counted in file.
for each trip in the file
set the second to last item to the fare + toll
check if the distance of the trip != 0
set the last item to the fare / distance
int total_people = 0
double fares[50]
for each trip in the file (using i)
total_people += [i][2]
fares[i] = taxi_trips[i][6]
print the following from each trip in order
# ppl -> Dist. -> Fare -> Toll -> Total -> Cost/MI
Output_Extra_Stats(total_people, fares)
}
Output_Extra_Stats(int total_people, double fares[50]){
double total_fares = 0;
for the amount of fares
total_fares += fares[i]
double average_cost_per_person = total_fares / total_people
print total people, total paid, then average cost per person
}
*/
|