// 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 } }