Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Calotta - Calotta.PAS

Calotta.PAS

Caricato da: Poggi Marco
Scarica il programma completo

  1. program CalottaCircolare; // 02/10/09 22.25
  2. uses crt,graph;
  3. type tstr=string[90];
  4.      calotta=object
  5.      private
  6.       r,al:double;
  7.      public
  8.       constructor inizio(b:double);
  9.       destructor fine;
  10.       procedure SetAl(v:double);
  11.       function funzione:double;
  12.       function MaxArea:double;
  13. end; //fine classe calotta
  14.  
  15.     grafico=object
  16.      private
  17.       xmax,ymax,c:word;
  18.       kx,ky:double;
  19.       coor:calotta;
  20.      public
  21.       constructor iniziog;
  22.       destructor finegr;
  23.       procedure assi;
  24.       procedure ciclo;
  25.       procedure punto(x,y:double);
  26. end; //fine classe grafico;
  27.  
  28. var punti:grafico;
  29.  
  30. function numint(n:longint):tstr; forward;
  31. function numdec(n:double; fine:shortint):tstr; forward;
  32.  
  33. function realDomanda(f:string; l1,l2:double):double;
  34. var t:double;
  35.     ch:boolean;
  36.     num:string;
  37.     errore:integer;
  38. begin
  39.  repeat
  40.   write(f+' ');
  41.   readln(num);
  42.   val(num, t, errore);
  43.   if errore=0 then
  44.   begin
  45.    ch:=((t>=l1) and (t<=l2));
  46.    if not ch then writeln('I limiti ammessi sono tra ',l1:9:2,' e ',l2:9:2);
  47.   end
  48.   else
  49.   begin
  50.    ch:=false;
  51.    writeln('Sono ammessi solo numeri !');
  52.   end;  
  53.  until ch;
  54.  realDomanda:=t;
  55. end;
  56.  
  57. constructor calotta.inizio(b:double);
  58. begin
  59.  r:=b;
  60. end;
  61.  
  62. procedure calotta.SetAl(v:double);
  63. begin
  64.  al:=v;
  65. end;
  66.  
  67. destructor calotta.fine;
  68. begin
  69.  // distruttore
  70. end;
  71.  
  72. function calotta.funzione:double;
  73. var be,a:double;
  74. begin
  75.  be:=al*0.5;
  76.  a:=r*r*(be-sin(be)*cos(be));
  77.  funzione:=a;
  78. end;
  79.  
  80. function calotta.MaxArea:double;
  81. begin
  82.   al:=2.0*pi;
  83.   MaxArea:=funzione;
  84. end;
  85.  
  86. constructor grafico.iniziog;
  87. begin
  88.   coor.inizio(realdomanda('Raggio', 0.001, 500.0));
  89.   xmax:=getmaxx;
  90.   ymax:=getmaxy;
  91.   ky:=ymax/(1.07*coor.MaxArea);
  92.   kx:=xmax/(2.0*pi);
  93.   c:=3;
  94.   assi;
  95.   ciclo;
  96.   coor.SetAl(2*pi);
  97.   outtextxy(10,30,'Area: '+numdec(coor.funzione,4));
  98. end;
  99.  
  100. procedure grafico.ciclo;
  101. var fine:word;
  102.     al,da,y,almax:double;
  103. begin
  104.  fine:=5374;
  105.  almax:=2.0*pi;
  106.  da:=almax/fine;
  107.  al:=0;
  108.  while (al<=almax) do
  109.  begin
  110.   coor.SetAl(al);
  111.   y:=coor.funzione;
  112.   punto(al,y);
  113.   al+=da;
  114.  end; // fine while
  115. end;
  116.  
  117. procedure grafico.punto(x,y:double);
  118. var px,py:word;
  119. begin
  120.  x*=kx;
  121.  y*=ky;
  122.  if ((x>=0) and (x<=xmax)) then
  123.  begin
  124.   px:=round(x);
  125.   if ((y>=0) and (y<=ymax)) then
  126.   begin
  127.     py:=round(ymax-y);
  128.     putpixel(px,py,c);
  129.   end;
  130.  end;
  131. end;
  132.  
  133. procedure grafico.assi;
  134. begin
  135.  setcolor(7);
  136.  line(0,0,0,ymax);
  137.  line(0,ymax,xmax,ymax);
  138. end;
  139.  
  140. destructor grafico.finegr;
  141. begin
  142.  //distruttore
  143.  coor.fine;
  144. end;
  145.  
  146. function inizio_graf:boolean;
  147. var sg,ng,ec:smallint;
  148. begin
  149.  sg:=detect;
  150.  initgraph(sg,ng,'');
  151.  ec:=graphresult;
  152.  if ec=grok then inizio_graf:=true
  153.  else
  154.  begin
  155.   inizio_graf:=false;
  156.   writeln('Errore grafico: ',grapherrormsg(ec));
  157.   while not keypressed do;
  158.  end;
  159. end;
  160.  
  161. function numint(n:longint):tstr;
  162. var s:tstr;
  163. begin
  164.   str(n,s);
  165.   numint:=s;
  166. end;
  167.  
  168. function numdec(n:double; fine:shortint):tstr;
  169. var s:tstr;
  170.     i:shortint;
  171.     nu:longint;
  172. begin
  173.   nu:=trunc(n);
  174.   s:=numint(nu);
  175.   n:=abs(frac(n));
  176.   if fine>8 then fine:=8;
  177.   for i:=1 to fine do n*=10;
  178.   if n>0 then
  179.   begin
  180.    nu:=round(n);
  181.    s:=s+','+numint(nu);
  182.   end;
  183.   numdec:=s;
  184. end;
  185.  
  186. procedure titolo;
  187. begin
  188.  writeln('Programma che disegna l''area di una calotta circolare');
  189.  writeln('in funzione dell''angolo.');
  190.  writeln;
  191. end;
  192.  
  193. begin
  194.  clrscr;
  195.  titolo;
  196.  readln;
  197.  if inizio_graf then
  198.  begin
  199.   punti.iniziog;
  200.   while not keypressed do;
  201.   closegraph;
  202.  end;
  203. end.