Sie sind auf Seite 1von 10

#include<dos.

h>
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include<graphics.h>
#include<time.h>
#include<math.h>
#define t 100
union REGS i,o;
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
return(0);
}
hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
return(0);
}
restrictmouseptr(int x1,int y1, int x2, int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
return(0);
}
getmousepos(int *button, int *x, int *y)
// ham lay toa do cua chuot
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
return(0);
}
//***************************************************************
void ClearWin(int wx1,int wy1,int wx2,int wy2,int color) //tao 1 khung noi dun
g
{

setfillstyle(1,color);
bar(wx1,wy1,wx2,wy2);
}
//***************************************************************
void menu_hien()
{
int a , b;
a = 45; b = 65;
setcolor(12);
rectangle(20,a,120,b); bar(21,a+1,119,b-1);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+b)/2,"Ham Bac 2/1");
delay(t);
setcolor(12);
rectangle(20,a+20,120,b+20); bar(21,a+21,119,b+19);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+20+b+20)/2,"Ham Cosin");
delay(t);
setcolor(12);
rectangle(20,a+40,120,b+40); bar(21,a+41,119,b+39);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+40+b+40)/2,"Ham Bac 4");
delay(t);
setcolor(12);
rectangle(20,a+60,120,b+60); bar(21,a+61,119,b+59);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+60+b+60)/2,"EXIT");
}
//********************//
void menu_an()
{
int a , b ;
a = 45; b = 65;
setcolor(2);
rectangle(20,a,120,b);
setcolor(2);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(2);
outtextxy((20+120)/2,(a+b)/2,"Ham Bac 2/1");
delay(t);
setcolor(2);
rectangle(20,a+20,120,b+20);
setcolor(2);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(2);
outtextxy((20+120)/2,(a+20+b+20)/2,"Ham Cosin");
delay(t);
setcolor(2);
rectangle(20,a+40,120,b+40);
setcolor(2);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(2);
outtextxy((20+120)/2,(a+40+b+40)/2,"Ham Bac 4");
delay(t);

setcolor(2);
rectangle(20,a+60,120,b+60);
setcolor(4);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(2);
outtextxy((20+120)/2,(a+60+b+60)/2,"EXIT");
}
//*************************************************************
void tille()
{
int maxx,maxy;
maxx = getmaxx();
maxy = getmaxy();
rectangle(0,0,maxx,maxy);
setviewport(1,0,maxx-1,maxy-1,0);
setbkcolor(2);
setcolor(5);
rectangle(0,0,maxx-2,18);
setfillstyle(1,9);
bar(1,1,maxx-3,17);
setcolor(15);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((maxx)/2,18/2,"*** Chuong Trinh Ve Do Thi ***");
}
//**************************************************************
void menu()
{
setcolor(14);
rectangle(20,20,100,40);
setfillstyle(1,9);
bar(21,21,99,39);
setcolor(15);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+100)/2,(20+40)/2,"VE DO THI");
}
//*******************//
void menu_click()
{
setcolor(1);
rectangle(20,20,100,40);
setcolor(14);
line(21,40,99,40);
setfillstyle(1,9);
bar(21,21,99,39);
setcolor(5);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+100)/2,(20+40)/2,"VE DO THI");
}
//**************************************************************
void menu_bac1()
{
int a , b;
a = 45; b = 65;
setcolor(15);
rectangle(20,a,120,b);
setcolor(11);

settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+b)/2,"Ham Bac 2/1");
}
//**//
void menu_bac10()
{
int a , b;
a = 45; b = 65;
setcolor(12);
rectangle(20,a,120,b);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+b)/2,"Ham Bac 2/1");
}
//*****************//
void menu_cos()
{
int a , b;
a = 45; b = 65;
setcolor(15);
rectangle(20,a+20,120,b+20);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+20+b+20)/2,"Ham Cosin");
}
//**//
void menu_cos0()
{
int a , b;
a = 45; b = 65;
setcolor(12);
rectangle(20,a+20,120,b+20);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+20+b+20)/2,"Ham Cosin");
}
//******************//
void menu_bac4()
{
int a , b;
a = 45; b = 65;
setcolor(15);
rectangle(20,a+40,120,b+40);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+40+b+40)/2,"Ham Bac 4");
}
//**//
void menu_bac40()
{
int a , b;
a = 45; b = 65;
setcolor(1);

rectangle(20,a+40,120,b+40);
setcolor(1);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(5);
outtextxy((20+120)/2,(a+40+b+40)/2,"Ham Bac 4");
}
//*******************//
void menu_exit()
{
int a , b;
a = 45; b = 65;
setcolor(15);
rectangle(20,a+60,120,b+60);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+60+b+60)/2,"EXIT");
}
//**//
void menu_exit0()
{
int a , b;
a = 45; b = 65;
setcolor(12);
rectangle(20,a+60,120,b+60);
setcolor(11);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(4);
outtextxy((20+120)/2,(a+60+b+60)/2,"EXIT");
}
//***//
void x_exit()
{
int maxx;
maxx = getmaxx();
setcolor(15);
rectangle(maxx-19,1,maxx-3,17);
setfillstyle(1,4);
bar(maxx-18,2,maxx-4,16);
setcolor(15);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(15);
outtextxy((maxx-18+maxx-3)/2,(18)/2,"X");
}
//**************************************************************
void ve_bac1()
{
int i,maxx;
float x1,x2,a,b,c,d,e;
float y1,y2;
int a1,b1,c1,a2,b2;
maxx = getmaxx();
// maxy = getmaxy();
setcolor(15);
rectangle(140,50,maxx-19,470);
/*Ve truc toa do*/
line(140,260,maxx-20,260); //ve truc hoanh
for (i = 180 ; i <= maxx-10 ; i = i + 50)
putpixel(i,260,4);
//Chia truc do

line((maxx-140)/2+131,50,(maxx-140)/2+131,470); //Ve truc tung


for (i = 60 ; i <= 470 ; i = i + 50)
putpixel((maxx-140)/2+131,i,4);
// Nhap gia tri o cho nay
printf("\n\n\n\n\n\n\n\n\nY=a*X^2+b*X+c/\n
e*X+d\n\n\nNhap a ="); scanf("
%f",&a);
printf("Nhap b ="); scanf("%f",&b);
printf("Nhap c ="); scanf("%f",&c);
printf("Nhap d ="); scanf("%f",&d);
printf("Nhap e ="); scanf("%f",&e);
x1=0.02;
// ve nua ben trai
do
{
x1 = x1 - 0.02;
x2 = x1 - 0.02;
y1 = ((a*x1*x1 + b*x1 + c)/(d*x1 + e))*50;
a1 = -(int)y1;
y2 = ((a*x2*x2 + b*x2 + c)/(d*x2 + e))*50;
a2 = -(int)y2;
setcolor(14); delay(5);
line(x1*50+380,a1+260,x2*50+380,a2+260);
} while ( x1 > -5);
x1=-0.02;

// ve nua ben phai

do
{
x1 = x1 + 0.02;
x2 = x1 + 0.02;
y1 = ((a*x1*x1 + b*x1 + c)/(d*x1 + e))*50;
a1 = -(int)y1;
y2 = ((a*x2*x2 + b*x2 + c)/(d*x2 + e))*50;
a2 = -(int)y2;
setcolor(14);
delay(50);
if(a2+260 < 470 && a2+260 > 50)
line(x1*50+380,a1+260,x2*50+380,a2+260);
}
while( x1 < 5);
}
//************************************************************
//////////////Ve do thi ham Cosin/////////////////
void ham_cos(int b)
// ham Y = Cos aX
{
int i,maxx,x,y,x1,y1,a; // a = 2;
maxx = getmaxx();
setcolor(BLUE);
setcolor(15);
rectangle(140,50,maxx-19,470);
/*Ve truc toa do*/
line(140,260,maxx-20,260); //ve truc hoanh
for (i = 240%b+140 ; i <= maxx-10 ; i = i + b)
putpixel(i,260,4);
//Chia truc do
line((maxx-140)/2+131,50,(maxx-140)/2+131,470); //Ve truc tung
for (i = 180%b+80 ; i <= 470 ; i = i + b)
putpixel((maxx-140)/2+131,i,4);
printf("\n\n\n\n\n\n\n\n\n\n\nY = Cos(a*X)\n Nhap a =\n"); scanf("%d",&a);

for(i = 380; i < 619; i ++)


{
x = i - 380;
x1 = i+1-380;
y = (b * cos(a*x*M_PI/(b))+260); y1 = (b * cos(a*x1*M_PI/(b))+260);
if (y < 260) y = 2*260 - y;
else
y = 2*260 - y;
if (y1 < 260) y1 = 2*260 - y1;
else
y1 = 2*260 - y1;
setcolor(YELLOW); delay(5);
line(i,y,i+1,y1);
}
for (i = 380; i > 140; i --)
{
x = i - 380;
x1 = i+1-380;
y = (b * cos(a*x*M_PI/b)+260); y1 = (b * cos(a*x1*M_PI/b)+260);
if (y < 260) y = 2*260 - y;
else
y = 2*260 - y;
if (y1 < 260) y1 = 2*260 - y1;
else
y1 = 2*260 - y1;
setcolor(YELLOW); delay(5);
line(i,y,i+1,y1);
}
}
//************************************************************
//Ve do thi ham bac 4//
void ham4()
{
int i,maxx,y,a1,a2,ad1,ad2;
float x1,x2,a,b,c,d,e,xd1,xd2;
float y1,y2,yd1,yd2;
maxx = getmaxx();
setcolor(BLUE);
setcolor(15);
rectangle(140,50,maxx-19,470);
/*Ve truc toa do*/
line(140,260,maxx-20,260); //ve truc hoanh
for (i = 130 ; i <= maxx-10 ; i = i + 50)
putpixel(i,260,4);
//Chia truc do
line((maxx-140)/2+131,50,(maxx-140)/2+131,470); //Ve truc tung
for (i = 60 ; i <= 470 ; i = i + 50)
putpixel((maxx-140)/2+131,i,4);
printf("\n\n\n\n\n\n\n\n\n\nY=4*X^4-3*X^3\n+3*X^2-2\nNhap a ="); scanf("%f",
&a);
printf("Nhap b ="); scanf("%f",&b);
printf("Nhap c ="); scanf("%f",&c);
printf("Nhap d ="); scanf("%f",&d);
printf("Nhap e ="); scanf("%f",&e);
// bat dau ve//
x1=-0.02; // ve nua ben phai
do
{
x1 = x1 + 0.02;
x2 = x1 + 0.02;
y1 = (a*x1*x1*x1*x1 + b*x1*x1*x1 + c*x1*x1 + d*x1 + e)*50;

a1 = -(int)y1;
y2 = (a*x2*x2*x2*x2 + b*x2*x2*x2 + c*x2*x2 + d*x2 + e)*50;
a2 = -(int)y2;
setcolor(14); delay(2);
if (x1*50+380>140 && a1+260 > 50 && x1*50+380 < maxx-19 && a1+260 < 470)
line(x1*50+380,a1+260,x2*50+380,a2+260);
} while(a2+260 > 50 && a2+260 < 470);
x1=0.02;
// ve nua ben trai
do
{
x1
x2
y1
a1

= x1 - 0.02;
= x1 - 0.02;
= (a*x1*x1*x1*x1 + b*x1*x1*x1 + c*x1*x1 + d*x1 + e)*50;
= -(int)y1;
// if (a1+260 > 50)
y2 = (a*x2*x2*x2*x2 + b*x2*x2*x2 + c*x2*x2 + d*x2 + e)*50;
a2 = -(int)y2;
setcolor(14); delay(2);
//
if(x1*50+380 > 140) xd1 = x1*50+380;
line(x1*50+380,a1+260,x2*50+380,a2+260);
} while(a2+260 > 50 && a2+260 < 470);
}
//***********************************************************
main()
{
int gd=DETECT,gm,maxx,maxy,x,y,button,prevx,prevy;
initgraph(&gd,&gm,"D:\\tc\\bgi");
maxx=getmaxx();
maxy=getmaxy();
rectangle(0,0,maxx,maxy);
setviewport(1,0,maxx-1,maxy-1,0);
tille();
x_exit();
menu();
setbkcolor(2);
if(initmouse()==0)
{
closegraph();
restorecrtmode();
printf("Mouse Driver Not Loaded");
exit(1);
}
restrictmouseptr(1,1,maxx-1,maxy-1);
showmouseptr();
while(kbhit()) getch();
while(!kbhit())
{
getmousepos(&button,&x,&y);
if((button&1)==1)
{
hidemouseptr();
prevx=x;
prevy=y;
while((button&1)==1)
{
setcolor(4);
line(prevx,prevy,x,y);
prevx=x;

prevy=y;
getmousepos(&button,&x,&y);
}
showmouseptr();
}
// ** lam them cho nay cho menu//
while(!kbhit())
{
getmousepos(&button,&x,&y);
if ((button&1)==1)
{
if ((x > 20 && x < 100) && (y > 20 && y < 40))
{
menu_click();
menu_hien();
lable_1:
while(!kbhit()) // tiep o menu thu 2//**********
{
getmousepos(&button,&x,&y);
if ((button&1)==1)
{
// chon ham bac 2/1
if ((x > 20 && x < 120) && (y > 45 && y < 65))
{
clrscr();
ClearWin(2,3,maxx,maxy,2);
rectangle(0,0,maxx,maxy);
setviewport(1,0,maxx-1,maxy-1,0);
tille();
x_exit();
menu();
setbkcolor(2);
ClearWin(120,42,maxx,maxy,2);
menu_cos0();
menu_bac40();
menu_exit0();
menu_bac1();
ve_bac1();
}
// Chon ham bac Cosin
if ((x > 20 && x < 120) && (y > 65 && y < 85))
{
clrscr();
ClearWin(2,3,maxx,maxy,2);
rectangle(0,0,maxx,maxy);
setviewport(1,0,maxx-1,maxy-1,0);
tille();
x_exit();
menu();
setbkcolor(2);
ClearWin(120,42,maxx,maxy,2);
menu_bac10();
menu_bac40();
menu_exit0();
menu_cos();
ham_cos(40);
}
// Chon ham bac 4

if ((x > 20 && x < 120) && (y > 85 && y < 105))
{
clrscr();
ClearWin(2,3,maxx,maxy,2);
rectangle(0,0,maxx,maxy);
setviewport(1,0,maxx-1,maxy-1,0);
tille();
x_exit();
menu();
setbkcolor(2);
ClearWin(120,42,maxx,maxy,2);
menu_bac10();
menu_cos0();
menu_exit0();
menu_bac4();
ham4();
}
// Chon nut thoat
if ((x > 20 && x < 120) && (y > 105 && y < 125))
{
ClearWin(140,200,maxx-20,maxy-20,8);
menu_bac10();
menu_cos0();
menu_bac40();
menu_exit();
exit(1);
}
// Chon ra ngoai
if ((x < 20 || x > 120) || (y < 45 || y > 125))
{
ClearWin(0,42,maxx,maxy,2);
menu();
break;
}
}
}
}
if (((x > 20) || (x < 100)) || ((y > 20) || (y < 40)))// Khi chua
kick vao trong menu nao
menu_an();
if ((x > (maxx-19) && x < (maxx-3))&&(y > 1 && y <17)) // Khi clic
k vao dau X tren ngoai thi Exit
{
exit(1);
}
}
}
//ket thuc viec lam them
}
getch();
return(0);
}

Das könnte Ihnen auch gefallen