blob: 0988d3437b8c7b693d6d2d3f995f8df593738ec4 (
plain) (
blame)
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
|
int ReadData(ifstream& file)
{
int t = -1;
while (!file.eof())
{
t++;
file >> Pick_up[t] >> Drop_off[t] >> Passenger_count[t] >> Distance_travelled[t] >> Fare_amount[t] >> Toll_amount[t];
Total_fare[t] = Fare_amount[t] + Toll_amount[t];
if (Distance_travelled[t] != 0)
{
CPM[t] = Fare_amount[t] / Distance_travelled[t];
}
else CPM[t] = 0;
}
t++;
return t;
}
Reads the data file and also does the math of the functions.
void GenerateTotals(int numEntries)
{
int Total_Passengers = 0;
double Total_Paid = 0;
for (int i = 0; i <= numEntries; i++)
{
Total_Passengers += Passenger_count[i];
Total_Paid += Total_fare[i];
}
cout << "Total Passengers: " << Total_Passengers << endl;
cout << "Total Paid: $" << Total_Paid << endl;
cout << "AVG Cost per Person: $" << Total_Paid / Total_Passengers << endl;
cout << "Total Trips: " << numEntries << endl;
}
Displays mathematical information as a totalled amount.
int main()
{
ifstream inFile;
string fileName;
cout << fixed << setprecision(2);
char choice = 'Y';
while (choice == 'Y')
{
while (!inFile.is_open())
{
cout << "Please enter data file name with the .txt extention" << endl;
cin >> fileName;
inFile.open(fileName);
if (inFile.is_open()) {
cout << "\nAccess Granted: " << fileName << endl;
}
else
{
cout << "\nError 404 Acess Denied....ahh ahh ahh you didn't say the magic word! ahh ahh ahh!" << fileName << endl;
}
cout << endl;
}
int numEntries = ReadData(inFile);
GenerateTotals(numEntries);
choice = 'A';
while (choice != 'Y' && choice != 'N')
{
cout << "\nWould you like a diplay table of the data? Y/N" << endl;
cin >> choice;
}
if (choice == 'Y')
{
cout << left << setw(10) << "\nEntry" << setw(10) << "Pickup"
<< setw(10) << "Dropoff" << setw(10) << "#PASS"
<< setw(10) << "DIST" << setw(10) << "Fares"
<< setw(10) << "Tolls" << setw(10) << "Total$"
<< setw(10) << "$/Mile" << endl;
for (int i = 0; i < numEntries; i++)
{
cout << left << setw(10) << i + 1 << Pick_up[i]
<< setw(10) << Drop_off[i] << setw(10) << Passenger_count[i]
<< setw(10) << Distance_travelled[i] << setw(10) << Fare_amount[i]
<< setw(10) << Toll_amount[i] << setw(10) << Total_fare[i]
<< setw(10) << CPM[i] << endl;
}
}
choice = 'A';
while (choice != 'Y' && choice != 'N')
{
cout << "\nWould you like to open another file? Y/N" << endl;
cin >> choice;
}
inFile.close();
cout << endl;
}
}
For some reason while I'm sure my code is correct the output somehow mixes my data by making my Pickup and Dropoff #'s into 1 number.
It is currently 11:02 PM Pacific time. I appologize for shoddy work.
|