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
|
Initialize a constant int MAX for the maximum amount of records, set to 50
START MAIN
initialize function ReadData, with input file, arrays, and counters
initialize function WriteOutputFile with output file, counters, and arrays
initialize PrintTotalsAndSummary with output file, counters, and arrays
Initialize an array for each needed value, with the length being equal to max
initialize record counter
initialize people counter
initialize payment counter
initialize filename
initialize input file
initialize output file
prompt the user to input a filename wiht extension
set the input equal to filename
open the file
if the file is open
call the function ReadData and have its return value be set into record_counter
close the input file
if the output file is open
call the functions writeoutputfile and printotalsummary
close the output file
else
print an error message
else
print an error message
return 0
END MAIN
ReadData
prints out headers corresponding to each array
read in the first line of data from the input file and have it set to the first of each array
while it is not the end of the file
the totalfare at the current index is equal to the far + toll
print out the arrays at the current index, formatting into a table
if the distance at the current index is 0, the cost per mile is 0
otherwise the cost per mile is equal to the total cost over the distance
increment the index
read data again
return counter
WriteOutputFile
enter a for loop which goes until the end of the total records in the file
print out all the modified data to the output file at the current index
PrintTotalsAndSummary
enter a for loop which goes until the end of the total records in the file
set the total amount of people to the array of passCount at the index added together
set a double temp equal to the far + toll at the current index
paid += temp
the totalFare at the current index is equal to temp
print out the avg cost per person, # people transported, and the total cost to both
the screen and the output file.
|