blob: b0035e1b229e916d5a8d9e8eedf70c2a7c937285 (
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// OUTPUT (Both big.txt and small.txt are tested in one run) //
Please enter your data file name with the .txt extension:
oops
Failed to open oops
Please enter your data file name with the .txt extension:
small
Failed to open small
Please enter your data file name with the .txt extension:
small.txt
Opened small.txt
TOTAL PASSENGERS: 14
TOTAL PAID: $113.52
AVG COST PER PERSON: $8.11
TOTAL TRIPS: 6
Would you like to display a table? Y/N
Y
ENTRY PICKUP DROPOFF #PASS DIST FARE$ TOLL$ TOTAL$ $/MILE
1 129 7 3 1.30 7.50 0.00 7.50 5.77
2 36 69 1 11.41 32.00 5.76 37.76 2.80
3 7 41 1 4.60 15.00 5.76 20.76 3.26
4 150 61 2 6.75 23.00 0.00 23.00 3.41
5 112 17 1 3.84 15.00 0.00 15.00 3.91
6 80 112 6 1.64 9.50 0.00 9.50 5.79
Would you like to open another file? Y/N
Y
Please enter your data file name with the .txt extension:
big.txt
Opened big.txt
TOTAL PASSENGERS: 100
TOTAL PAID: $1052.04
AVG COST PER PERSON: $10.52
TOTAL TRIPS: 48
Would you like to display a table? Y/N
A
Would you like to display a table? Y/N
N
Would you like to open another file? Y/N
A
Would you like to open another file? Y/N
N
// PSEUDO-CODE //
DEFINE a FUNCTION that RETURNS an INTEGER ReadFile(INFILE REFERENCE file){
SET INTEGER counter TO -1;
WHILE (file IS NOT AT THE END){
SET each appropriate ARRAY value at [counter] TO VALUE FROM file;
SET totalFare[counter] TO fareAmount[counter] + tollAmount[counter];
IF (distanceTravelled[counter] IS NOT 0){
SET costPerMile[counter] TO (totalFare[counter] / distanceTravelled[counter]);
}ELSE SET costPerMile[counter] TO 0;
}
}
DEFINE a NULL RETURN FUNCTION GenerateTotals(INTEGER numEntries){
DEFINE INTEGER totalPassengers;
DEFINE DOUBLE totalPaid;
SET totalPassengers TO SUM OF EACH passengerTotal;
SET totalPAID TO SUM OF EACH totalFare;
PRINT ([Total passengers, Total paid, Avg. cost per person (totalPaid / totalPassengers), Number of entries (total trips)]);
}
MAIN(){
DEFINE INFILE inFile;
INITIALIZE CHAR choice AT 'Y';
WHILE (choice IS 'Y'){
WHILE (inFile IS NOT OPEN){
TAKE INPUT for fileName;
TRY to OPEN fileName;
}
INITIALIZE INTEGER numEntries AT RETURN VALUE FROM ReadData USING inFile;
GenerateTotals USING numEntries;
SET choice TO 'A';
WHILE (choice IS NOT 'Y' AND choice IS NOT 'N'){
PRINT( "Do you want to print a table? Y/N" );
SET choice TO INPUT;
}
IF (choice IS 'Y'){
PRINT([Table of values from file]);
}
SET choice TO 'A';
WHILE (choice IS NOT 'Y' AND choice IS NOT 'N'){
PRINT( "Do you want to enter another file? Y/N" );
SET choice TO INPUT;
}
CLOSE file;
// Should loop if user entered Y
}
}
|