Pascal/Turbo Pascal - elaborar un programa en pascal

 
Vista:

elaborar un programa en pascal

Publicado por lilibeth (1 intervención) el 28/03/2012 02:35:18
hola, soy nueva en esto y quiero saber como hacer un programa en pascal, simulando un semaforo que me de las siguientes instrucciones si es verde que de un mensaje ''puedes pasar'', en caso que sea rojo o amarillo que diga ''espera quieto''. mandarme los comandos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

elaborar un programa en pascal

Publicado por ramon (2158 intervenciones) el 28/03/2012 22:36:30
{Espero esto sirva}

program semafo;
uses
crt;
var
rojo, verde, anvar : integer;
tiempo : word;

procedure peaton(x, y : integer;paso : boolean; c : integer);
begin
if paso then
begin
if c = 0 then
TextBackground(4)
else
TextBackground(10);
gotoxy(x,y);write(' ');
TextBackground(0);
end
else
begin
TextBackground(0);
gotoxy(x,y);write(' ');
end;
end;
procedure semaforo;
var
cont : integer;
begin
gotoxy(18,3);write('Peaton');
gotoxy(9,4);write('---');
gotoxy(9,5);write('|');
gotoxy(11,5);write('|');
gotoxy(9,6);write('---');
gotoxy(9,7);write('|');
gotoxy(11,7);write('|');
gotoxy(9,8);write('---');
gotoxy(9,9);write('|');
gotoxy(11,9);write('|');
gotoxy(9,10);write('---');
gotoxy(9,11);write('| |');
gotoxy(9,12);write('| |');
gotoxy(9,13);write('| |');
gotoxy(7,14);write('-------');
gotoxy(7,16);write('Termina pulsando una tecla');
rojo := 4;
verde := 10;
anvar := 14;
cont := 1;
tiempo := 6000 div 3;
repeat
case cont of
1 : begin
TextBackground(verde);
gotoxy(10,5);write(' ');
peaton(19,7,true,0);
TextBackground(0);
gotoxy(23,7);write('Espera');
delay(tiempo);
gotoxy(10,5);write(' ');
gotoxy(23,7);write(' ');
peaton(19,7,false,0);
end;
2 : begin
TextBackground(anvar);
gotoxy(10,7);write(' ');
peaton(19,7,true,0);
TextBackground(0);
gotoxy(23,7);write('Espera');
delay(tiempo);
gotoxy(10,7);write(' ');
gotoxy(23,7);write(' ');
peaton(19,7,false,0);
end;
3 : begin
TextBackground(rojo);
gotoxy(10,9);write(' ');
peaton(19,7,true,1);
TextBackground(0);
gotoxy(23,7);write('Pasar');
delay(tiempo);
gotoxy(10,9);write(' ');
gotoxy(23,9);write(' ');
peaton(19,7,false,1);
end;
end;
TextBackground(0);
cont := cont + 1;
if cont > 3 then
cont := 1;
until keypressed;
end;

begin
clrscr;
semaforo;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

elaborar un programa en pascal

Publicado por ricardo (1 intervención) el 07/01/2013 00:12:50
amigo nos podrias explicar como funciona tu semaforo mediante el codigo?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

elaborar un programa en pascal

Publicado por ramon (2158 intervenciones) el 07/01/2013 21:18:26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{Algo a sin}
 
program semafo;
uses
   crt;
  var
     rojo, verde, anvar : integer;
     tiempo : word;
  {marcamos paso peaton o coches}
 procedure peaton(x, y : integer;paso : boolean; c : integer);
 begin
    if paso then         {compruevo si es true o false}
    begin
      if c = 0 then       {si true entonces pongo color que se marco con c}
      TextBackground(4);
      if c = 1 then
      TextBackground(14);
      if c = 2 then
        TextBackground(10);
 
        gotoxy(x,y);write(' '); {pinto el color}
        TextBackground(0);     {restauro a negro fijaros que es color de
                                fondo}
      end
  else         {si false entonces  borro}
     begin
       TextBackground(0);     {con esto borro color o apago semaforo}
       gotoxy(x,y);write(' ');
     end;
  end;
 
procedure semaforo;   {dibujamos semaforo peaton y activamos secuencias}
var
cont : integer;
begin
gotoxy(18,3);write('Peaton');
gotoxy(9,4);write('---');
gotoxy(9,5);write('|');
gotoxy(11,5);write('|');
gotoxy(9,6);write('---');
gotoxy(9,7);write('|');
gotoxy(11,7);write('|');
gotoxy(9,8);write('---');       {dibujamos}
gotoxy(9,9);write('|');
gotoxy(11,9);write('|');
gotoxy(9,10);write('---');
gotoxy(9,11);write('| |');
gotoxy(9,12);write('| |');
gotoxy(9,13);write('| |');
gotoxy(7,14);write('-------');
gotoxy(7,16);write('Termina pulsando una tecla');
rojo := 4;
verde := 10;
anvar := 14;         {asignamos valores}
cont := 1;
tiempo := 6000 div 3;
repeat           {repetimos asta que se pulse una tecla}
case cont of { activamos segun valor de cont}
1 : begin
TextBackground(verde);
gotoxy(10,5);write(' ');  {posicion del cursor y pintado}
peaton(19,7,true,0);      {presento color}
TextBackground(0);
gotoxy(23,7);write('Espera');
delay(tiempo);                    { 1 peaton espera}
gotoxy(10,5);write(' ');
gotoxy(23,7);write(' ');
peaton(19,7,false,0);     {borro color}
end;
2 : begin
TextBackground(anvar);
gotoxy(10,7);write(' ');
peaton(19,7,true,1);      {presento color}
TextBackground(0);
gotoxy(23,7);write('Espera');      { 2 peaton espera}
delay(tiempo);
gotoxy(10,7);write(' ');
gotoxy(23,7);write(' ');
peaton(19,7,false,2);     {borro color}
end;
3 : begin
TextBackground(rojo);
gotoxy(10,9);write(' ');
peaton(19,7,true,2);     {presento color}
TextBackground(0);
gotoxy(23,7);write('Pasar');    { 3 peaton Pasa}
delay(tiempo);
gotoxy(10,9);write(' ');
gotoxy(23,9);write(' ');
peaton(19,7,false,1);       {borro color}
end;
end;
TextBackground(0);
cont := cont + 1;
if cont > 3 then    {si contador mayor de tres entonces cont lo pongo a 1}
cont := 1;
until keypressed;  {espero pulsacion tecla sino sigo}
end;
 
begin
clrscr;
semaforo;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar