Prev Up Next
Go backward to 4.2 Text editing
Go up to 4 Labs
Go forward to 4.4 Run a COBOL program

4.3 Enter a PASCAL program

Using the pico text editor create a file called TRIP.PAS containing the following PASCAL program. Use the tab key to indent. Do not worry about minor typing errors. Leave a minor error in your file so that you can see an error message when compiling the program in Lab 4.5: "Pascal program -- compile and run". Use the file name TRIP.PAS for this program.
PROGRAM TRIP(INPUT,OUTPUT);
VAR
        DISTANCE,SPEED,TIME,GALCOST,
        MPG,GALUSED,TOTALCOST:REAL; 
BEGIN
        WRITELN('* COMPUTE TRIP TIME AND COST *'); 
        WRITELN('DISTANCE?');
        READ(DISTANCE);
        WRITELN('AVERAGE SPEED?'); 
        READ(SPEED);
        WRITELN('MILES PER GALLON');
        READ(MPG);
        WRITELN('COST PER GALLON'); 
        READ(GALCOST);
        WRITELN;
        WRITELN('DISTANCE = ',DISTANCE:8:2,' MILES'); 
        WRITELN('AVERAGE SPEED = ',SPEED:8:2,' MILES'); 
        TIME:=DISTANCE/SPEED;
        WRITELN(' TIME OF TRIP = ',TIME:8:2,' HOURS'); 
        WRITELN;
        WRITELN('MILEAGE RATE = ',MPG:8:2,' MILES/GAL'); 
        WRITELN('$ PER GALLON = ',GALCOST:8:2,' DOLLARS'); 
        GALUSED:=DISTANCE/MPG;
        TOTALCOST:=GALUSED*GALCOST;
        WRITELN(' ESTIMATED TRIP EXPENSE = ',TOTALCOST:8:2, 
                ' DOLLARS'); 
END. 

Print a copy of the file on the system printer. Label it with
Your-Name
Lab 4.3: Pascal Source
TABER CSC135
Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".
Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site

Prev Up Next