summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/CST116-Lab3-Havaldar.cpp
blob: dc4acf290b27d886991600912f5ec017506a4640 (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
/*
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(10) << "Trip"
        << setw(10) << "Pickup" 
        << setw(10) << "Dropoff" 
        << setw(10) << "#ppl" 
        << setw(10) << "Distance" 
        << setw(10) << "Fare" 
        << setw(10) << "Toll" 
        << setw(10) << "Total" 
        << setw(10) << "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;
        //output the elements in the file and the calculated vartiables
        cout << setw(10) << count
            << setw(10) << pick 
            << setw(10) << drop 
            << setw(10) << ppl 
            << setw(10) << dis 
            << setw(10) << fare 
            << setw(10) << toll 
            << setw(10) << total 
            << setw(10) << setprecision(3) << cpm << endl;

        //add to totals
        count++;
        totalPpl += ppl;
        totalCost += total;
    }

    //calculate average
    avg = totalCost / totalPpl;

    //output important stats
    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;
}