|
program CalottaCircolare; // 02/10/09 22.25
uses crt,graph;
type tstr=string[90];
calotta=object
private
r,al:double;
public
constructor inizio(b:double);
destructor fine;
procedure SetAl(v:double);
function funzione:double;
function MaxArea:double;
end; //fine classe calotta
grafico=object
private
xmax,ymax,c:word;
kx,ky:double;
coor:calotta;
public
constructor iniziog;
destructor finegr;
procedure assi;
procedure ciclo;
procedure punto(x,y:double);
end; //fine classe grafico;
var punti:grafico;
function numint(n:longint):tstr; forward;
function numdec(n:double; fine:shortint):tstr; forward;
function realDomanda(f:string; l1,l2:double):double;
var t:double;
ch:boolean;
num:string;
errore:integer;
begin
repeat
write(f+' ');
readln(num);
val(num, t, errore);
if errore=0 then
begin
ch:=((t>=l1) and (t<=l2));
if not ch then writeln('I limiti ammessi sono tra ',l1:9:2,' e ',l2:9:2);
end
else
begin
ch:=false;
writeln('Sono ammessi solo numeri !');
end;
until ch;
realDomanda:=t;
end;
constructor calotta.inizio(b:double);
begin
r:=b;
end;
procedure calotta.SetAl(v:double);
begin
al:=v;
end;
destructor calotta.fine;
begin
// distruttore
end;
function calotta.funzione:double;
var be,a:double;
begin
be:=al*0.5;
a:=r*r*(be-sin(be)*cos(be));
funzione:=a;
end;
function calotta.MaxArea:double;
begin
al:=2.0*pi;
MaxArea:=funzione;
end;
constructor grafico.iniziog;
begin
coor.inizio(realdomanda('Raggio', 0.001, 500.0));
xmax:=getmaxx;
ymax:=getmaxy;
ky:=ymax/(1.07*coor.MaxArea);
kx:=xmax/(2.0*pi);
c:=3;
assi;
ciclo;
coor.SetAl(2*pi);
outtextxy(10,30,'Area: '+numdec(coor.funzione,4));
end;
procedure grafico.ciclo;
var fine:word;
al,da,y,almax:double;
begin
fine:=5374;
almax:=2.0*pi;
da:=almax/fine;
al:=0;
while (al<=almax) do
begin
coor.SetAl(al);
y:=coor.funzione;
punto(al,y);
al+=da;
end; // fine while
end;
procedure grafico.punto(x,y:double);
var px,py:word;
begin
x*=kx;
y*=ky;
if ((x>=0) and (x<=xmax)) then
begin
px:=round(x);
if ((y>=0) and (y<=ymax)) then
begin
py:=round(ymax-y);
putpixel(px,py,c);
end;
end;
end;
procedure grafico.assi;
begin
setcolor(7);
line(0,0,0,ymax);
line(0,ymax,xmax,ymax);
end;
destructor grafico.finegr;
begin
//distruttore
coor.fine;
end;
function inizio_graf:boolean;
var sg,ng,ec:smallint;
begin
sg:=detect;
initgraph(sg,ng,'');
ec:=graphresult;
if ec=grok then inizio_graf:=true
else
begin
inizio_graf:=false;
writeln('Errore grafico: ',grapherrormsg(ec));
while not keypressed do;
end;
end;
function numint(n:longint):tstr;
var s:tstr;
begin
str(n,s);
numint:=s;
end;
function numdec(n:double; fine:shortint):tstr;
var s:tstr;
i:shortint;
nu:longint;
begin
nu:=trunc(n);
s:=numint(nu);
n:=abs(frac(n));
if fine>8 then fine:=8;
for i:=1 to fine do n*=10;
if n>0 then
begin
nu:=round(n);
s:=s+','+numint(nu);
end;
numdec:=s;
end;
procedure titolo;
begin
writeln('Programma che disegna l''area di una calotta circolare');
writeln('in funzione dell''angolo.');
writeln;
end;
begin
clrscr;
titolo;
readln;
if inizio_graf then
begin
punti.iniziog;
while not keypressed do;
closegraph;
end;
end.
|
|