Pascal/Turbo Pascal - PROGRAMA PASCAL DIBUJAR

 
Vista:

PROGRAMA PASCAL DIBUJAR

Publicado por carlos (12 intervenciones) el 16/04/2012 20:58:07
Hola, tengo que diseñar un programa en el que, se introduzca por el teclado un número entero impar y dibuje primero un triángulo isósceles con el símbolo #(cuya base tenga tantos caracteres como el número introducido). Después, deberá dibujar un rombo con el símbolo * cuya diagonal horizontal sea también ese mismo número. Por ejemplo, si el usuario introduce el número 7, el programa dará el siguiente resultado: 1

Para realizar esto, tengo que escribir y llamar a tres funciones:

DibujaLinea (dibujará una línea de uno de los polígonos).

DibujaTriángulo (dibujará el triángulo).

DibujaRombo (dibujará el rombo).

Lo he intentado pero no hay manera. Podeis echarme un cable? Gracias.
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

PROGRAMA PASCAL DIBUJAR

Publicado por ramon (2158 intervenciones) el 17/04/2012 19:20:35
{Espero esto te sirva }

program dibujo;
uses
crt;
const
triangulo = '#';
rombo = '*';
var
i, num : integer;

function numero : integer;
begin
write('Entre numero : ');
readln(num);
numero := num;
end;

procedure ajusta(var x, y, x2, y2 : integer);
begin
if x < 1 then
x := 1;
if x > 79 then
x := 79;
if x2 > 79 then
x2 := 79;
if x2 < 1 then
x2 := 1;
if y < 1 then
y := 1;
if y > 24 then
y := 24;
if y2 > 24 then
y2 := 24;
if y2 < 1 then
y2 := 1;
end;

procedure dibujalinea(x, y, x2, y2 : integer; car : char);
var
d, dx, dy, ai, bi, xi, yi : integer;
begin
ajusta(x,y,x2,y2);
if (x < x2) then
begin
xi := 1;
dx := x2 - x;
end
else
begin
xi := - 1;
dx := x - x2;
end;
if (y < y2) then
begin
yi := 1;
dy := y2 - y;
end
else
begin
yi := - 1;
dy := y - y2;
end;
gotoxy(x,y);write(car);
if dx > dy then
begin
ai := (dy - dx) * 2;
bi := dy * 2;
d := bi - dx;
repeat
if (d >= 0) then
begin
y := y + yi;
d := d + ai;
end
else
d := d + bi;
x := x + xi;
gotoxy(x,y);write(car);
until (x = x2);
end
else
begin
ai := (dx - dy) * 2;
bi := dx * 2;
d := bi - dy;
repeat
if (d >= 0) then
begin
x := x + xi;
d := d + ai;
end
else
d := d + bi;
y := y + yi;
gotoxy(x,y);write(car);
until (y = y2);
end;
end;

procedure dibujaunalinea(n : integer;car : char);
begin
clrscr;
dibujalinea(n,5,n + n,5,car);
gotoxy(6,24);write(' Pulse Una Tecla');
readkey;
end;

procedure dibujatriangulo(n : integer; car : char);
begin
clrscr;
dibujalinea(n,n + 1,n + (n * 4),n + 1,car);
dibujalinea(n,n + 1,n + (n * 2),(n + 1) - n,car);
dibujalinea(n + (n * 4),n + 1,n + (n * 2),(n + 1) - n,car);
gotoxy(6,24);write(' Pulse Una Tecla');
readkey;
end;

procedure dibujarombo(n : integer; car : char);
begin
clrscr;
dibujalinea(2 + n,2 + n,2 + n + n,2 + n - n,car);
dibujalinea( 2 + n, 2 + n,2 + n + n,2 + n + n,car);
dibujalinea(2 + n * 3,2 + n,2 + n + n,2 + n - n,car);
dibujalinea(2 + n * 3,2 + n,2 + n + n,2 + n + n,car);
gotoxy(6,24);write(' Pulse Una Tecla');
readkey;
end;

procedure menu;
var
opci : char;
fin : boolean;
begin
fin := false;
repeat
clrscr;
gotoxy(2,2);write('<<<<< MENU DIBUJO >>>>>>');
gotoxy(4,4);write(' 1 = Linea recta');
gotoxy(4,5);write(' 2 = Triangilo');
gotoxy(4,6);write(' 3 = Rombo');
gotoxy(4,7);write(' 4 = Salir');
gotoxy(4,9);write('*** Elija Opcion ***');
opci := readkey;
clrscr;
case opci of
#49 : dibujaunalinea(numero,'Ä');
#50 : dibujatriangulo(numero,'*');
#51 : dibujarombo(numero,'#');
#52 : fin := true;
end;
until fin = true;
end;

begin
menu;
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

PROGRAMA PASCAL DIBUJAR

Publicado por carlos (12 intervenciones) el 18/04/2012 16:42:25
muchas gracias ramon, es muy parecido a lo que me pedian exactamente. Lo que se me olvido decir es que todavia no he dado eso del gotoxy, ni lo de function, solo procedure, y el programa tiene que quedar asi: http://es.scribd.com/doc/89988541/5-Diseno-Descendente-Procedimientos-y-Funciones (ejercicio 1)


El numero que introduce el usuario por teclado es el numero de # que hay en la base, a partir de ahi el porgrama automaticamente dibujara el triangulo y el rombo(sin espacios entre los # ni lineas en blanco), usando:

DibujaLinea (dibujará una línea de uno de los polígonos).

DibujaTriángulo (dibujará el triángulo).

DibujaRombo (dibujará el rombo).
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

PROGRAMA PASCAL DIBUJAR

Publicado por ramon (2158 intervenciones) el 19/04/2012 19:26:31
{Esta otra forma como veras para el dibujo de caracteres en modo texto
no se puede hacer mucho mas la separación lo da el testo o sea el formato del
carácter }

program geometrias;
uses
crt;
const
triangulo = '#';
rombo = '*';
var
i, num : integer;
p, k : integer;
dibu : string;

function numero : integer;
begin
write('Entre numero : ');
readln(num);
numero := num;
fillchar(dibu,num + 1,' ');
dibu[0] := chr(num);
end;

procedure dibujalinea; {r/R = *******, i/I = * , k/K = * }
var {q/Q = * * * }
n : integer; {* * * }
espa : string[80]; {*}
cua : char;
begin
write('Entre Que Linea [r, i, k, q] Del Poligono : ');
readln(cua);
clrscr;
case cua of
'r','R' : begin
for n := 1 to i do
begin
dibu[n] := rombo;
dibu[0] := chr(n);
end;
write(' ',dibu);
end;
'i','I' : begin
for n := 1 to i do
begin
writeln(' ',rombo);
end;
end;
'k','K' : begin
fillchar(espa,i + 1,' ');
espa[0] := chr(i);
espa := '';
writeln;
for n := 1 to i do
begin
writeln(' ',espa,'*');
espa := espa + ' ';
end;
end;
'q','Q' : begin
fillchar(espa,i + 1,' ');
espa[0] := chr(i);
writeln;
for n := i downto 1 do
begin
espa[n] := '*';
writeln(' ',espa);
espa[n] := ' ';
end;
end;
end;
end;

procedure dibujatriangulo;
var
p, c, t : integer;
di : string[80];
begin
c := length(dibu) div 2 + 1;
p := c;
fillchar(di,i + 1,' ');
di[0] := chr(i);
for t := 1 to i div 2 + 1 do
begin
di[c] := triangulo;
di[p] := triangulo;
writeln(' ',di);
c := c - 1;
p := p + 1;
end;
end;

procedure dibujarombo;
var
t, p, c : integer;
rom : string[80];
begin
fillchar(rom,i + 1,' ');
rom[0] := chr(i);
c := length(rom) div 2 + 1;
p := c;
for t := 1 to i div 2 do
begin
rom[c] := '*';
rom[p] := '*';
rom[c + 1] := ' ';
rom[p - 1] := ' ';
writeln(' ',rom);
c := c - 1;
p := p + 1;
end;
fillchar(rom,80 - i,' ');
rom[0] := chr(i);
c := 1;
p := i;
for t := 1 to i div 2 + 1 do
begin
rom[c] := rombo ;
rom[p] := rombo ;
rom[c - 1] := ' ';
rom[p + 1] := ' ';
writeln(' ',rom);
c := c + 1;
p := p - 1;
end;
end;


begin
clrscr;
i := numero;
writeln;
dibujalinea;
writeln;
dibujatriangulo;
writeln;
dibujarombo;
readln;
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