PASCAL PROGRAMS
ASSIGNMENTS
|
1 |
27th Jul |
VAR name :STRING[10]; initial :CHAR; age :integer; days :real; BEGIN Writeln('what is your surname?'); readln(name); Writeln('what is your initial?'); readln(initial); writeln('what is your age?'); readln(age); days:=365.4*age; writeln('you have been alive at least
',days:5:2,' days in ',age,' years'); writeln('congratulations ',initial,'
',name); END. |
Modify this program so that it asks for your street name and number. |
|
2 |
10th Aug |
VAR guess,number:integer; BEGIN writeln('think of a number between 1
and 3'); write('what is it?'); readln(guess); number:=random(3)+1; IF guess=number THEN writeln ('you got
it!') ELSE writeln('wrong the number was
',number); END. |
Modify this program so that it asks for a number between 1 and 5. |
|
3 |
24th Aug |
VAR count
: INTEGER; total
: INTEGER; alphabet : CHAR; BEGIN total := 0; FOR count := 1 TO 10 DO BEGIN total := total + 12; WRITE('count =',count:,' total =',total:5); WRITELN; END; WRITE('The alphabet is '); FOR alphabet := 'A' TO 'Z' DO WRITE(alphabet); END. |
Write a program that asks the user 'How many numbers do you want to add together?' And then asks the user to enter each number as it goes through the loop. Your program should show the total on the screen |
|
4 |
7th Sep |
VAR count :
INTEGER; BEGIN count := 4; REPEAT WRITE('This is the REPEAT loop'); WRITE('the count is ',count:4); WRITELN; count := count + 2; UNTIL count = 20; WRITELN(' We have completed the loop '); END. |
Change this program so that it counts in 3's and finishes when Count = 21 |
|
5 |
21st Sept |
VAR counter
: INTEGER; BEGIN counter := 4; WHILE counter < 20 DO BEGIN WRITE('We are in the WHILE loop, waiting
'); WRITE('for the counter to reach 20. It
is',counter:4); WRITELN; counter := counter + 2; END; END. |
Change this program so that it counts in 3's and finishes when Count = 21 |
|
6 |
19th Oct |
VAR base,height,area : REAL; BEGIN WRITE('Triangle Enter base '); READLN(base); WRITE('Enter height '); READ(height); area := 0.5 * base * height; WRITELN(' The area is ',area:12:3); END. |
Write a program that will work out the area of a circle if you input the radius. Area=pr2 What will you use for p? |
|
7 |
2nd Nov |
VAR count :
INTEGER; BEGIN WRITE('Enter a number 1 to 5'); READLN(count); CASE count OF 1 : WRITE(' Brown'); 2 : WRITE(' Red'); 3 : WRITE(' Orange'); 4 : WRITE(' Yellow '); 5 : WRITE(' Green'); ELSE WRITE(' You did not type a number 1
to 5'); END; END. |
Write a program that will give the month for an input of number Eg 5 gives May |
|
8 |
16th Nov |
var I:Integer; procedure
DrawBox (X1,Y1,X2,Y2:Integer); var I:Integer; begin GotoXY(X1,Y1); for I:=X1 to X2 do write('-'); for I:=Y1+1 to Y2 do begin GotoXY(X1,I); Write('!'); GotoXY(X2,I); Write('!'); end; GotoXY(X1,Y2); for I:=X1 to X2 do Write('-'); end; begin ClrScr; for I:=1 to 5 do DrawBox(I*4,I*2,10*I,4*I); DrawBox(1,1,80,23); end. |
This program draws boxes on the screen. Change the line DrawBox(1,1,80,23); By changing the numbers. Try to get the computer to draw
different coloured boxes by using TextColor(I) |
|
9 |
30th Nov |
BEGIN ClrScr; GotoXY(15,15); Write('XXXXX'); GotoXY(15,16); Write('X X'); GotoXY(15,16); Write('X X'); GotoXY(15,17); Write('X X'); GotoXY(15,18); Write('XXXXX'); END. |
This program draws a picture of a zero on the screen. Modify this program so that it displays 0 1 2 on the screen |
|
10 |
7th Dec |
VAR guess,number,count:integer; BEGIN count:=0; number:=random(50)+1; REPEAT BEGIN writeln('think of a number between 1
and 50'); write('what is it?'); readln(guess); IF guess>number THEN writeln ('Too
High'); IF guess<number THEN writeln('Too
Low'); count:=count+1; END; UNTIL guess=number END. |
Write a 'congratulations' when the user guesses the correct number and tell the user how many guesses they had. What is the lowest number of guesses you score? |