GNVQ
Advance IT
Unit 6 - Pascal Programming 2 Tasks
1-5
Tutor
Tasks - Type in the following programs, compile and
run them.
When you have tested the programs and made sure they
are working, print the code and save your programs to floppy disc.
1
PROGRAM welcome;
Uses WinCRT;
{begin declarations}
VAR
name: ARRAY[0..10] of CHAR;
{begin sequence}
BEGIN
write('Enter your full name
-');
readln(name);
writeln('Hallo ',name, ', Welcome
to Pascal');
END.{Welcome}
{end sequence
2
PROGRAM wages;
Uses WinCRT;
{begin declarations}
VAR
HoursWorked:REAL;{number of hours worked
per week}
RateOfPay:REAL; {hourly rate of pay}
GrossWage:REAL;{weekly wage before deductions}
{end declarations}
{begin sequence}
BEGIN
Write('Input number of hours
worked = ');
ReadLn(HoursWorked);
Write('Input hourly rate of
pay = ');
ReadLn(RateOfPay);
GrossWage:=HoursWorked*RateOfPay;
WriteLn('Gross weekly pay =
', GrossWage:6:2);
END.{Wages}
{end sequence}
3
PROGRAM averages;
Uses winCRT;
VAR
num, total, average: REAL;
count: INTEGER;
BEGIN
FOR count:= 1 TO 10 DO
BEGIN
readln(num);
total:=total+num;
END;
average:= total/10;
writeln('Total = ',total:6:2);
writeln('Average = ',average:6:2);
END.
4
PROGRAM averages2;
Uses winCRT;
VAR
num, total, average: REAL;
count: INTEGER;
BEGIN
WHILE num<100 DO
BEGIN
readln(num);
total:=total+num;
END;
total:=total-num;
average:= total/5;
writeln('Total = ',total:6:2);
writeln('Average = ',average:6:2);
END.
5
Now find the deliberate error in program 4 and correct
it.