Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include "graphics.h"
- #include "conio.h"
- #include "process.h"
- #include "stdlib.h"
- #include "math.h"
- #include "dos.h"
- #include "iostream"
- using namespace std;
- int P,W=30,H=200,D=50,N=6,X=400,Y=50;
- void menu();
- struct Diem
- { int x,y;
- };
- void hcos()
- {
- int mh=0,mode=2;
- initgraph(&mh,&mode,"");
- setbkcolor(BLUE);
- settextstyle(5,0,10);
- outtextxy(220,30," Do thi ham so y = cos(x)");
- setviewport(getmaxx()/8,getmaxy()/8,7*getmaxx()/8,7*getmaxy()/8,1);
- rectangle(0,0,3*getmaxx()/4,3*getmaxy()/4);
- setfillstyle(1,YELLOW);//chon kieu duong
- floodfill(getmaxx()/2,getmaxy()/2,YELLOW);
- setviewport(getmaxx()/2,getmaxy()/2,7*getmaxx()/8,7*getmaxy()/8,0);
- setcolor(BLUE);
- line(-3*(getmaxx()/8),0,3*getmaxx()/8,0);
- line(0,-3*(getmaxy()/8),0,3*getmaxy()/8);
- outtextxy(0,0,"(0,0)");
- outtextxy(3*(getmaxx()/8)-7,0,"x");
- outtextxy(0,-3*(getmaxy()/8)-7,"y");
- int x,y;
- for(int i=-400;i<=400;++i)
- {
- //x=2*M_PI*i*20/200;
- x=2*M_PI*i*20/200;
- y=-2000*cos(2*M_PI*i/200)/60;
- putpixel(x,y,RED);
- delay(10);
- }
- setcolor(WHITE);
- outtextxy(220,200," Thoat ESC");
- char c;
- c=getch();
- if(c==27)
- {
- closegraph();
- menu();
- }
- }
- void hsin()
- {
- int mh=0,mode=2;
- initgraph(&mh,&mode,"");
- setbkcolor(GREEN);
- settextstyle(5,0,10);
- outtextxy(220,30," Do thi ham so y = sin(x)");
- setviewport(getmaxx()/8,getmaxy()/8,7*getmaxx()/8,7*getmaxy()/8,1);
- rectangle(0,0,3*getmaxx()/4,3*getmaxy()/4);
- setfillstyle(1,BLUE);
- floodfill(getmaxx()/2,getmaxy()/2,YELLOW);
- setviewport(getmaxx()/2,getmaxy()/2,7*getmaxx()/8,7*getmaxy()/8,0);
- setcolor(BLACK);
- line(-3*(getmaxx()/8),0,3*getmaxx()/8,0);
- line(0,-3*(getmaxy()/8),0,3*getmaxy()/8);
- outtextxy(0,0,"(0,0)");
- outtextxy(3*(getmaxx()/8)-7,0,"x");
- outtextxy(0,-3*(getmaxy()/8)-7,"y");
- int x,y;
- for(int i=-400;i<=400;++i)
- {
- x=2*M_PI*i*20/200;
- y=-2000*sin(2*M_PI*i/200)/60;
- putpixel(x,y,RED);
- delay(10);
- }
- setcolor(WHITE);
- outtextxy(220,200," Thoat ESC");
- char c;
- c=getch();
- if(c==27)
- {
- closegraph();
- menu();
- }
- }
- int a0,a1,r,r1,r2,r3,r4,r5,r6;
- int y1,xc,yc,x1,x2,y2,x3,y3,x4,y4,x5,y5;
- unsigned int visualpage,centre,stangle,endangle;
- void init()
- {
- int mh=0,mode=2;
- initgraph(&mh,&mode,"");
- setbkcolor(WHITE);
- setcolor(RED);
- outtextxy(10,10,"Bam phim Esc de thoat");
- setcolor(YELLOW);
- setfillstyle(1,5);
- centre=getmaxx()/2;
- r=getmaxy()/8;
- r1=1+r/2;
- r2=1+r/4;
- r1=r/10;
- xc=centre-r1;
- yc=180-r;
- x1=xc-(r+r1)/2+5;
- y1=yc-(r+r1)*sqrt(3/4)+5;
- x2=xc-(r+r2);y2=yc-10;
- x3=xc+(r+r2)/2;
- y3=yc-(r+r2)*sqrt(3/4)+10;
- x4=x1-(r1/2)*sqrt(3/4)+1;
- y4=y1+(r1/2)-7;
- x5=x1+(r1/2)*sqrt(3/4)-1;
- y5=y1-(r1/2)+7;
- stangle=270;
- endangle=340;
- }
- void bacnhat()
- {
- int mh=0,mode=2,a,b;
- initgraph(&mh,&mode,"");
- setbkcolor(BLUE);
- outtextxy(220,10," Do thi ham so y = ax+b");
- cout<<"\n";
- cout <<" Nhap a= ";
- cin >>a;
- cout <<"\n";
- cout <<" Nhap b= ";
- cin>>b;
- settextstyle(5,0,10);
- setviewport(getmaxx()/2,getmaxy()/2,getmaxx(),get maxy(),0);
- setcolor(WHITE);
- line(-(getmaxx()/2),0,getmaxx()/2,0);
- line(0,-(getmaxy()/2),0,getmaxy()/2);
- outtextxy(0,0,"(0,0)");
- outtextxy((getmaxx()/2)-10,0,"x");
- outtextxy(0,(getmaxy()/2)-10,"y");
- setcolor(YELLOW);
- line(-(getmaxx()/2)*10,(a*(-1)*(getmaxy()/2)+b)*10,(getmaxx()/2)*10,(a*(getm axy()/2)+b)*10);
- delay(40);
- outtextxy(200,(getmaxy()/2)-30,"Thoat: ESC ");
- char c;
- c=getch();
- if(c==27)
- {
- closegraph();
- menu();
- }
- }
- void parabol()
- {
- int mh=0,mode=2,a,b,e,w,t;
- initgraph(&mh,&mode,"");
- setbkcolor(BLUE);
- settextstyle(5,0,10);
- outtextxy(220,30," Do thi ham so y = a*x*x+bx+c");
- cout<<"\n";
- cout<<" Nhap a=";
- cin>>a;
- cout<<" Nhap b=";
- cin>>b;
- cout<<" Nhap c=";
- cin>>e;
- w=(b*b-4*a*e)/2*a;
- t= -b/(2*a);
- setviewport(getmaxx()/2,getmaxy()/2,getmaxx(),get maxy(),0);
- line(-(getmaxx()/2),-w,getmaxx()/2,-w);
- line(-t,-(getmaxy()/2),-t,getmaxy()/2);
- outtextxy(0,0,"(0,0)");
- outtextxy((getmaxx()/2)-10,0,"x");
- outtextxy(0,(getmaxy()/2)-10,"y");
- float x,y,j;
- for(int i=-200;i<=200;++i)
- {
- x=i;
- y=-a*pow(x,2)-b*x-e; j=y;
- putpixel(x,j,YELLOW);
- // delay(0);
- } outtextxy(200,(getmaxy()/2)-30,"Thoat: ESC ");
- char c;
- c=getch();
- if(c==27)
- {
- closegraph();
- menu();
- }
- }
- void hambac3()
- {
- int mh=0,mode=0,a,b,d,e;
- initgraph(&mh,&mode,"");
- setbkcolor(BLUE);
- settextstyle(5,0,10);
- outtextxy(220,30," Do thi ham so y = a*x*x*x");
- cout<<"Nhap a="; cin>>a;
- setviewport(getmaxx()/2,getmaxy()/2,getmaxx(),getmaxy(),0);
- line(-(getmaxx()/2),0,getmaxx()/2,0);
- line(0,-(getmaxy()/2),0,getmaxy()/2);
- outtextxy(0,0,"(0,0)");
- outtextxy((getmaxx()/2)-10,0,"x");
- outtextxy(0,(getmaxy()/2)-10,"y");
- float x,y,j;
- for(int i=-200;i<=200;++i)
- {
- x=i;
- y=a*pow(x,3); j=y/4000;
- putpixel(x,j,YELLOW);
- delay(10);
- }
- outtextxy(200,(getmaxy()/2)-30,"Thoat: ESC ");
- char c;
- c=getch();
- if(c==27)
- {
- closegraph();
- menu();
- }
- }
- void goi(int h)
- {
- if(h==1) hsin();
- if(h==2) hcos();
- if(h==3) bacnhat();
- if(h==4) parabol();
- if(h==5) hambac3();
- }
- void Ve(int P)
- {
- int i;
- for(i=0;i<N;++i)
- {
- setbkcolor(1);setcolor(3);
- line(X-H,Y+i*D,X-H,Y+i*D+W);
- line(X-H,Y+i*D,X,Y+i*D);
- line(X,Y+i*D,X,Y+i*D+W);
- line(X-H,Y+i*D+W,X,Y+i*D+W);
- setcolor(4);
- if (i==0) outtextxy(220,60,"Do thi ham so sin(x)");
- if (i==1) outtextxy(220,110,"Do thi ham so cos(x)");
- if (i==2) outtextxy(220,160,"Do thi ham bac nhat");
- if (i==3) outtextxy(220,210,"Do thi ham bac hai");
- if (i==4) outtextxy(220,260," Ham bac ba");
- if (i==5) outtextxy(220,310," Thoat chuong trinh");
- outtextxy(100,360," SVTH: Phi Thi Hai Yen");
- }
- setcolor(15);
- line(X-H,Y+(P-1)*D,X-H,Y+(P-1)*D+W);
- line(X-H,Y+(P-1)*D,X,Y+(P-1)*D);
- setcolor(8);
- line(X,Y+(P-1)*D,X,Y+(P-1)*D+W);
- line(X-H,Y+(P-1)*D+W,X,Y+(P-1)*D+W);
- }
- void main()
- {
- P=1;
- menu();
- getch();
- }
- void menu()
- {
- int mh=0,mode=2;
- char c;
- initgraph(&mh,&mode,"D:\TC\bin");
- outtextxy(200,20,"DO THI MOT SO HAM SO SO CAP");
- Ve(P);
- do
- {
- c=getch();
- if (c==13) {
- closegraph();
- if (P==6) exit(0);
- else
- goi(P);
- }
- if (c==72)
- if (P>1)
- {
- P-=1;
- Ve(P);
- }
- else {
- P=N;
- Ve(P);
- }
- if (c==80) if (P<N)
- {
- P+=1;
- Ve(P);
- } else
- {
- P=1;
- Ve(P);
- }
- }
- while (1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement