blob: a43f3524cf76ce5f9783e27bf966a33522c0bc1f (
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
|
/*
Abdullah Havaldar
CST116 - Lab3
Purpose: The purpose of this program is to take in a file which has the logs of a taxi service and output it in a formatted table along with the average per person, total people moved, and total cost
*/
//precompiler directives
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
int main()
{
//initializing filename to ask user
string fileName;
//ask user for the filename and store file name
cout << "Please enter the input file name including extension: ";
cin >> fileName;
//opening the file
ifstream theFile(fileName);
//variables within the opened file
int count = 1;
int pick;
int drop;
int ppl;
double dis;
double fare;
double toll;
//variables which are to calculate
double avg = 0;
int totalPpl = 0;
double totalCost = 0;
//write the column headers
cout << left;
cout << setw(20) << "Trip"
<< setw(20) << "Pickup"
<< setw(20) << "Dropoff"
<< setw(20) << "#ppl"
<< setw(20) << "Distance"
<< setw(20) << "Fare"
<< setw(20) << "Toll"
<< setw(20) << "Total"
<< setw(20) << "Cost/Mi"
<< endl;
//within the opened file readin the columns as the followiung variables
while (theFile >> pick >> drop >> ppl >> dis >> fare >> toll) {
//take total for each row
double total = fare + toll;
//take price per mile for each row
double cpm = total / dis;
cout << setw(20) << count
<< setw(20) << pick
<< setw(20) << drop
<< setw(20) << ppl
<< setw(20) << dis
<< setw(20) << fare
<< setw(20) << toll
<< setw(20) << total
<< setw(20) << setprecision(3) << cpm << endl;
count++;
totalPpl += ppl;
totalCost += total;
}
avg = totalCost / totalPpl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << "** Avg Cost Per Person: " << avg << " **" << endl;
cout << "** People Transported: " << totalPpl << " **" << endl;
cout << "** Total Paid: " << setprecision(7) << totalCost << " **" << endl;
}
|