Vẽ đồ thị hàm số trên Pascal

Vẽ đồ thị hàm số dạng đa thức từ bậc 0 tới bậc ba

Program VeDoThi;
uses crt,graph;
var p,j:integer;
    x:real;
    a:array[0..50] of real;
    chon,mh,dpg,c,h,c0,h0,b1,b2:integer;
    kt:char;

Procedure Nhap_dt;
      Begin
          clrscr;
          writeln;
          writeln;
          writeln ('  NHAP DA THUC (BAC <= 3). Vi du: y = x^3 + 6x^2');
          write   ('    Nhap bac cua da thuc: ');readln(p);
          writeln ('    Nhap cac he so cua da thuc:');
                For j:=p downto 0 do
                      Begin
                             write('    a[',j,'] = ');readln(a[j]);
                      End;
     End;

{Ham muc tieu cho ve do thi}
Function func(x:real):real;
 var k:integer;
     dt:real;
 Begin

      dt:=0;
      for k:=0 to p do dt := (dt*x/10)+a[p-k];

      { Su dung luoc do Hooc-ne }

      {dt:= 2*sin(x/10);}
      dt:=dt*10;
      func:=dt;
 End;

 Procedure Do_thi;
    Begin
      c0:=320;h0:=250;b1:=-100;b2:=100;
      c:=70;h:=30;
      mh:=detect;
      initgraph(mh,dpg,'');

      {Viet chu tren man hinh do hoa}

      setcolor(15);
      outtextxy(323,251,'o ');
      outtextxy(545,251,'x ');
      outtextxy(328,15,'y ');
      setcolor(lightgreen);
      settextstyle(3,1,4);
      outtextxy(590,110,'NGUYEN TO SON');

      {Ve he truc toa do}
      setcolor(15);
      {Ve truc 0x}
      line(70,250,550,250); line(540,245,550,250);line(550,250,540,255);
      {Ve truc 0y}
      line(320,450,320,20); line(315,30,320,20);   line(320,20,325,30);

      {Ve chia khoang tren 0y}
      While h            begin
                 h:=h+10;
                 line(318,h,322,h);
            end;

      {Ve chia khoang tren 0x}
      While cb2 ;
      settextstyle(2,0,7);
      outtextxy(5,5,'An enter de tiep tuc...');
      readln ;
      closegraph;
End;

{Chuong trinh chinh}

BEGIN
    clrscr;
    kt:='N';
    while kt<>'Y' do
        begin
             clrscr;
             gotoxy(20,4); writeln('ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿');
             gotoxy(20,5); writeln('³ VE DO THI HAM SO (HAM SO DANG DA THUC)  ³');
             gotoxy(20,6); writeln('³ **************************************  ³');
             gotoxy(20,7); writeln('³      1- Nhap da thuc can ve do thi      ³');
             gotoxy(20,8); writeln('³      2- Xem do thi cua ham vua nhap     ³');
             gotoxy(20,9); writeln('³      3- ** Ket thuc chuong trinh **     ³');
             gotoxy(20,10);writeln('ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ');
             gotoxy(20,11);write('CHON TU 1 DEN 3: ');readln(chon);
             case chon of
             1:Nhap_dt;
             2:do_thi;
             3:exit;
             end;
        end;

    END.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: