summaryrefslogtreecommitdiff
path: root/CST116-Lab3-PseudoCode-Florea.txt
blob: d8c47e20b755a8a42b85a4d298cbdd572f72174c (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
protype func getFileName(pass string by reference)
protype func readData(pass fstream by reference, int array, int array, int array, int array, float array, float array, float array, float array, float array)
protype func displayData(pass int array, int array, int array, int array, float array, float array, float array, float array, float array, int)

def func main()
    init var pick_up_loc as int array with 50 slots
    init var drop_off_loc as int array with 50 slots
    init var pass_count as int array with 50 slots
    init var trip as int arary with 50 slots
    init var distance as float array with 50 slots
    init var fare_amount as float array with 50 slots
    init var toll_amount as float array with 50 slots
    init var total as float array with 50 slots
    init var cost_mi as float array with 50 slots

    init var file_name as string

    call func getFileName(pass file_name)

    create fstream object data_file
    use data_file object to open file_name

    if data_file is opened successfully
        call func 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 not opened successfully
        print "Trouble opening " + file_name


def func getFileName(parameter name as string pass by reference)
    print "Enter the name of the file including extension"
    take input and store it in name

def func readData(fstream& file, int pick[], int drop[], int passenger[], int trip[], float distance[], float fare[], float toll[], float total[], float cost_mi[])
    init var counter set it to 0
    take first line of data from file and store it in the correct array corresponding to its position

    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 not at end of file
        add 1 to counter
        take current line of data from file and store it in the correct array corresponding to its position
        trip[counter] = counter + 1
        total[counter] = fare[counter] + toll[counter]

        if current distance = 0
            cost_mi[counter] = 0
        else cost_mi[counter] = fare[counter] / distance[counter]
    
    close data_file
    
    call func displayData(trip, pick, drop, passenger, distance, fare, toll, total, cost_mi, counter)


def func displayData(int trip[], int pick[], int drop[], int passenger[], float distance[], float fare[], float toll[], float total[], float cost_mi[], int counter)
    init var total_people as int, set it to 0
    init var total_cost as float, set it to 0

    init var width as int, set it to 50

    display with width "Trip #, Pick Up, Drop off, # of ppl, distance, fare, toll, total, cost/mile"

    for int idx = 0, idx <= counter, idx++
        display with width and fixed precision set to 2, trip + pick, drop, passenger, distance, fare, toll, total, cost_mi

        total_people = total_people + passenger[idx]
        total_cost = total_cost + fare[idx] + toll[idx]
    
    display "People transported" + total_people
    display "Total paid" + total_cost
    display "Average cost per person" total_cost / total_people