Aula 10

Revisões

 

 

 

 

 

 

 

Completa o algoritmo à direita

 

Algoritmo ordenar números

 

 

Sabendo que:

 

a>b and b > c  (ordem a – b - c)

a>b and c >b   (ordem a – c - b)

 

b>a and a > c  (ordem b – a - c)

b>c and c >a   (ordem b – c - a)

 

c>a and a >b  (ordem c – a - b)

c>b and b >a   (ordem c – b - a)

 

VAR  A, B,C, temp:INTEGER;

 Begin

 

    WRITE('Numero 1: ');       READLN(A);

    WRITE('Numero 2: ');       READLN(B);

    WRITE('Numero 3: ');       READLN(C);

 

   IF (A> B) and (B>C) THEN

         begin

             temp:=A;

             A:=C;

             C:=temp;

             writeln ('O maior é A');

             WRITELN('Numeros Ordenados ');

             WRITE('Numero 1: '); WRITELN(A);

             WRITE('Numero 2: '); WRITELN(B);

             WRITE('Numero 3: '); WRITELN(C);

         end

 

           else if (B>A)and (A>C) then

                   begin

                        temp:=A;

                        A:=C;

                        C:=B;

                        B:=temp;

                        writeln ('O maior é B');

                        WRITELN('Numeros Ordenados ');

                        WRITE('Numero 1: '); WRITELN(A);

                        WRITE('Numero 2: '); WRITELN(B);

                        WRITE('Numero 3: '); WRITELN(C);

                    end

                  else if  (C>A)and (A>B) then

                        begin

                        writeln ('O maior é C');

                        WRITELN('Numeros Ordenados ');

                        end

                           ELSE

                               writeln('iguais');

   readln;

  End.                    

 

 

a)      Escreve um programa que determine se um número digitado pelo utilizador é maior ou menor que 100

 

 

Nota: Para estes programas não é possível utilizar o cabeçalho do lazaruz.

 

B) Compila os programas à direita.

 

B1) Escreve o enunciado de cada um deles

 

B2) Existem alguma Palavras novas. Identifica-as e explica cada uma delas.

Program Program1a_Lesson10;

Uses Crt;

Label Return;  {used respectively with the

                goto statement; beware of it}

Var SEL : Integer;

    YN : Char;

          

Begin

 Return: Clrscr;

 Writeln('[1].PLAY GAME');

 WRITELN('[2].LOAD GAME');

 WRITELN('[3].MULTIPLAYER');

 WRITELN('[4].EXIT GAME');

 Writeln('note: Do note press anything except');

 Writeln('numbers; otherwise an error occurs!');

 Readln(SEL);

 If SEL = 1 then

  Begin

   Writeln('Are you able to create a game');

   Writeln('of yourself using pascal??');

   Delay(2000);

   Goto Return;

  End;

 If SEL = 2 then

  Begin

   Writeln('Ahhh... no saved games');

   Delay(2000);

   Goto Return;

  End;

 If SEL = 3 then

  Begin

   Writeln('networking or 2 players?');

   Delay(2000);

   Goto Return;

  End;

 If SEL = 4 then

  Begin

   Writeln('Exit?');

   YN := Readkey;

   If YN = 'y' then

    Begin

     Writeln('Nooooooooooooo...');

     Delay(1000);

     Halt; {EXIT PROGRAM}

    End;

   If YN = 'n' then

    Goto Return;

  End;

End.

Program Program1b_Lesson10;

Uses Crt;

Label Return;  {use of the goto statement

                is not recommended..avoid it}

Var SEL : Integer;

    YN  : Char;

 

Begin

 Return:Clrscr;

 Writeln('[1].PLAY GAME');

 WRITELN('[2].LOAD GAME');

 WRITELN('[3].MULTIPLAYER');

 WRITELN('[4].EXIT GAME');

 Writeln('note: Do note press anything except');

 Writeln('numbers; otherwise an error occurs!');

 Readln(SEL);

 Case SEL of

  1 : Begin

       Writeln('Are you able to create');

       Writeln('a game of yourself using pascal??');

       Delay(2000);

       Goto Return;

      End;

  2 : Begin

       Writeln('Ahhh... no saved games');

       Delay(2000);

       Goto Return;

      End;

  3 : Begin

       Writeln('networking or 2 players?');

       Delay(2000);

       Goto Return;

      End;

  4 : Begin

       Writeln('Exit?');

       YN := Readkey;

       Case YN of {a sort of a nested case statement}

        'y' : Begin

               Writeln('Nooooooooooooo...');

               Delay(1000);

               Halt;

              End;

        'n' : Goto Return;

       End;{End Case2}

      End;{Close Conditional Expression 4}

 End;  {End Case1}

End.  

Program Program2_Lesson10;

Uses Crt;

Label Return; { avoid it }

Var YN : Char;

          

Begin

 Return:ClrScr;

 Writeln('Exiting?');

 YN := Readkey;

 Case YN of

  'y' : Halt;

  'n' : Begin

         Writeln('What are you going to do here, anyway?');

         Delay(2000);

         Halt;

        End;

  Else

  Begin

   Writeln('Either press ''y'' for yes');

   Writeln('or ''n'' for no.. please try again..');

   Delay(3500);

   ClrScr;

   Goto Return;

  End;

 End; {CASE}

End. {PROGRAM}

 

 

 

 

 

program aula10_ex;

uses

  crt;

 

var

  Idade:integer;

 

begin

  clrscr;

  write('How old are you? ');

  readln(Idade);

  writeln;

  case Idade of

     -1: begin

            writeln('Hello Little Baby...');

            writeln('Enjoy your nine months of peaceful life!');

         end;

     0:     writeln('Hello Baby');

     1..5:  writeln('Hello Little Boy / Girl');

     6..10: writeln('Hello Boy / Girl');

     11..15:  writeln('Hello Little Man / Woman');

     16..25:  writeln('Hi');

     26..45:  writeln('Hello');

     46..60:  writeln('Hello Mister / Madam');

     61..120: writeln('Hello Old Man / Old Woman');

     else     begin

                writeln('Hello World...');

                writeln('Can you hear me?');

              end;

  end;

  readln;

end.