PASCAL PROGRAMS

ASSIGNMENTS

 

1

8h Feb

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);

    

END.

 

Modify this program so that it asks for your street name and number

Then outputs

Name is…………….

Initial is……………..

Age is………………

Street number is…….

Street name is ……...

2

22nd Feb

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 10.

3

8th Mar

VAR

    count           : INTEGER;

    total             : INTEGER;

    alphabet     : CHAR;

 

BEGIN

  total := 0;

    FOR count := 1 TO 10 DO

      BEGIN

          total := total + 10;

          WRITE('count =',count:,'  total =',total:5);

          WRITELN;

      END;

 

 

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

22nd Mar

VAR count : INTEGER;

 

BEGIN

  count := 4;

  REPEAT

    WRITE('This is the REPEAT loop');

    WRITE('the count is ',count:);

    WRITELN;

    count := count + 1;

  UNTIL count = 20;

  WRITELN(' We have completed the loop ');

END.

 

Change this program so that it outputs the numbers 5,10,15,20 only.

5

5th Apr

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);

    WRITELN;

    counter := counter + 1;

  END;

END.

 

Change this program so that it outputs the numbers 2,4,6,8,10 only.

6

3rd May

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 this equation

Y=X2+2X+1

 

7

17th May

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 number word for a number

 

Eg 2 gives Two

8

31st May

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

for I:=1 to 5 do DrawBox(I*4,I*2,10*I,4*I);

 

By changing the numbers in the parentheses ie 4,2,10,4.

 

Try to get the computer to draw different coloured boxes by using

TextColor(I)

9

14th Jun

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

3 4 5

on the screen

10

28th Jun

VAR

   guess,N,number,count:integer;

 

BEGIN

    count:=0;

    number:=random(N)+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.

 

There are some lines missing from this program. Put them in and …

 

Write a 'congratulations' when the user guesses the correct number and tell the user how many guesses they had.

 

Is there a relationship between N and count?

Hosted by www.Geocities.ws

1