This is the code for graphical calculator. You can copy this code and past in notepad and then run it with your C & C++ compilers.
;#include
#include
#include
#include
#include
#include
void shp();
void main()
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
int x1=0,x2=0,y1=0,y2=0;
float ac,bc,rc;
char ch;
shp();
gotoxy(22,7);
cout<<"= ";
cin>>ac;
//////////////////////////////////////////////////////////////////////////////
do
{
shp();
if(ch==72)
{y1-=20;
y2-=20;}
if(ch==80)
{y1+=20;
y2+=20;}
if(ch==75)
{ x1-=100;
x2-=100;}
if(ch==77)
{x1+=100;
x2+=100;}
if(x1>300 ||y1>20)
{ x1=0;
x2=0;
y1=0;
y2=0;}
if(x1<0||y1<0)
{ x1=300;
x2=300;
y1=20;
y2=20;}
/////////////////////////////////////////////////////////////////////////////
setcolor(BLUE);
rectangle(150+x1,150+y1,250+x2,170+y2);
ch=getche();
}
while(ch!=13);
//////////////////////////////////////////////////////////////////////////////
gotoxy(22,9);
cout<<"= ";
cin>>bc;
clrscr();
shp();
if(x1==0)
{ch=1;}
if(x1==100)
{ch=2;}
if(x1==200)
{ch=3;}
if(x1==300)
{ch=4;}
if(y1==20&&x1==0)
{ch=5;}
if(y1==20&&x1==100)
{ch=6;}
if(y1==20&&x1==200)
{ch=7;}
if(y1==20&&x1==300)
{ch=8;}
//////////////////////////////////////////////////////////////////////////////
switch(ch)
{
case 1:
outtextxy(340,105,"sum");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<<""<
gotoxy(30,9);
cout<
gotoxy(58,9);
cout<
break;
case 2:
outtextxy(340,105,"sub");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<<""<
gotoxy(30,9);
cout<
gotoxy(58,9);
cout<
break;
case 3:
outtextxy(338,109,"mul");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<<""<
gotoxy(30,9);
cout<
gotoxy(58,9);
cout<
break;
case 4:
outtextxy(338,109,"div");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<<""<
gotoxy(30,9);
cout<
gotoxy(58,9);
cout<
break;
case 5:
setcolor(RED);
settextstyle(4,0,3);
outtextxy(340,90,"=");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<
gotoxy(30,9);
cout<
gotoxy(53,9);
cout<
break;
case 6:
setcolor(RED);
settextstyle(4,0,3);
outtextxy(340,90,"=");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<
gotoxy(30,9);
cout<
gotoxy(53,9);
cout<
break;
case 7:
setcolor(RED);
settextstyle(4,0,3);
outtextxy(340,90,"=");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<
gotoxy(30,9);
cout<
gotoxy(53,9);
cout<
break;
case 8:
outtextxy(338,109,"pwr");
gotoxy(30,7);
cout<
gotoxy(53,7);
cout<<""<
gotoxy(30,9);
cout<
gotoxy(58,9);
cout<
break;
}
getche();
}
//////////////////////////////////////////////////////////////////////////////
void shp()
{
setcolor(3);
rectangle(135,10,570,70);
settextstyle(4,0,6);
outtextxy(160,4,"Simple Calculator");
////////////////////////////////////////////////////////////////////////////////////////
setcolor(RED);
rectangle(145,86,555,275);
rectangle(153,88,547,120);
rectangle(150,94,330,145);
rectangle(150,94,330,120);
rectangle(150,94,370,145);
settextstyle(4,0,3);
outtextxy(340,113,"=");
setcolor(WHITE);
rectangle(150,90,550,150);
rectangle(150,90,550,190);
rectangle(150,170,550,190);
rectangle(150,150,250,190);
rectangle(150,150,350,190);
rectangle(150,150,450,190);
//////////////////////////////////////////////////////////////////////////////
settextstyle(4,0,1);
outtextxy(185,147,"+");
outtextxy(276,148,"-");
outtextxy(378,146,"*");
settextstyle(0,0,0);
outtextxy(466,160,"/");
outtextxy(182,175,"cube");
outtextxy(273,175,"sqr");
outtextxy(375,175,"sqrt");
outtextxy(466,175,"power");
/////////////////////////////////////////////////////////////////////////////
setcolor(RED);
outtextxy(340,195,"Help");
setcolor(6);
outtextxy(165,210,"1 Enter 1st value in block 1.");
outtextxy(165,225,"2 Enter 2nd value in block 2.");
outtextxy(165,240,"3 Move curser up and down with arrow keys.");
outtextxy(165,255,"4 Press ""Enter"" key to select operation.");
settextstyle(4,0,16);
outtextxy(30,110,"W j");
outtextxy(30,30,"W");
setcolor(3);
rectangle(10,425 ,620,477);
settextstyle(0,0,1);
outtextxy(16,430,"NAME: Muhammad Waqas");
outtextxy(16,445,"Roll # 9275");
outtextxy(16,460,"Class : BCs-A(2011 - 2014)");
outtextxy(400,430,"S u b m e t t e d T o");
outtextxy(380,460,"S i r . U m e r H a y a t");
setcolor(9);
circle(350,360,40);
outtextxy(325,355,"Welcome");
//////////////////////////////////////////////////////////////////////////////////////
}
Hope you Like this
No comments:
Post a Comment