0% found this document useful (0 votes)
54 views

New Text DocumA Calculator Program in C Using Graphics

This C program creates a basic graphical calculator using mouse input. It initializes the graphics screen and defines functions for drawing buttons, handling mouse clicks, and performing calculations. The main routine draws the calculator interface with number and operator buttons. It gets mouse positions and calls functions to add numbers, perform operations, and display the result when buttons are clicked. The program continuously listens for mouse input and redraws the interface to allow for repeated calculations.

Uploaded by

ajaykaundal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

New Text DocumA Calculator Program in C Using Graphics

This C program creates a basic graphical calculator using mouse input. It initializes the graphics screen and defines functions for drawing buttons, handling mouse clicks, and performing calculations. The main routine draws the calculator interface with number and operator buttons. It gets mouse positions and calls functions to add numbers, perform operations, and display the result when buttons are clicked. The program continuously listens for mouse input and redraws the interface to allow for repeated calculations.

Uploaded by

ajaykaundal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 68

#include<stdio.

h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
int initmouse();
void showptr();
void openwindow();
void closewindow();
void hideptr();
void getmousepos(int *,int*,int*);
void restrictptr(int,int,int,int);
int button,x,y,x1,y1,x2,y2,s;
long double num=0,get,num1=0,result=0;
long double addnum(int);
char opr;
int a,b,r,s,i1,count,c,sq,newnum=1,d=0;
union REGS i,o;
void main(void)
{
int driver=DETECT,mode;
int q,p[12];
char input;
char *inpu[4][4]={"1","2","3","4",
"5","6","7","8",
"9","0","+","-" ,
"*","/","clr","="};
char inp[4][4]={'1','2','3','4',
'5','6','7','8',
'9','0','+','-' ,
'*','/','l','='};

initgraph(&driver,&mode,"c:\\tc\\bgi");
if(initmouse()==0)
{
printf("not");
getch();
exit(0);
}
openwindow();
getch();
cleardevice();
setfillstyle(CLOSE_DOT_FILL,10);
bar(260,82,450,320);
bar(430,70,450,320);
setfillstyle(1,GREEN);
bar(236,82,432,300);
setcolor(GREEN);
rectangle(238,50,430,80);
rectangle(237,49,431,81);
rectangle(236,48,432,82);
c=240;
d=100;
s=0;
for(a=0;a<4;a++)
{
c=240;
for(b=0;b<4;b++)
{
setfillstyle(1,RED);
bar(c,d,c+40,d+40);
setcolor(YELLOW);

outtextxy(c+10,d+14,inpu[a][b]);
c+=50;
}
d+=50;
}
showptr();
num=0;
gotoxy(36,5);
printf("%18.1Lf",num);
count=0;
while(!kbhit())
{
outtextxy(30,20,"Press any key to exit..");
i1=0;
c=240;
d=100;
rectangle(0,0,638,478);
getmousepos(&button,&x,&y);
for(a=0;a<4;a++)
{
c=240;
for(b=0;b<4;b++)
{
if((x>=c&&x<=c+40)&&(y>=d&&y<=d+40))
{
if((button&1)==1)
{
while((button&1)==1)
{
setcolor(10);
rectangle(c,d,c+40,d+40);

rectangle(c-1,d-1,c+41,d+41);
rectangle(c-2,d-2,c+42,d+42);
break;
}
delay(100);
setcolor(GREEN);
rectangle(c,d,c+40,d+40);
rectangle(c-1,d-1,c+41,d+41);
rectangle(c-2,d-2,c+42,d+42);
input=inp[a][b];
switch(input)
{
case '1':
get=addnum(1);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '2':
get=addnum(2);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '3':
get=addnum(3);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '4':
get=addnum(4);
gotoxy(36,5);

printf("%18.1Lf",get);
break;
case '5':
get=addnum(5);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '6':
get=addnum(6);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '7':
get=addnum(7);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '8':
get=addnum(8);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '9':
get=addnum(9);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '0':
get=addnum(0);
gotoxy(36,5);

printf("%18.1Lf",get);
break;
case '+':
num1=num;
num=0;
opr='+';
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case '-':
num1=num;
num=0;
opr='-';
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case '*':
num1=num;
num=0;
opr='*';
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case '/':
num1=num;
num=0;
opr='/';
gotoxy(36,5);
printf("%18.1Lf",num);
break;

case 'l':
num=0;
num1=0;
result=0;
count=0;
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case '=':
switch(opr)
{
case '+':
if(count<1)
{
result=num+num1;
}
else
{
result=result+num;
}
gotoxy(36,5);
printf("%18.1Lf",result);
count+=1;
break;
case '-':
if(count<1)
{
result=num1-num;
}
else

{
result=result-num;
}
gotoxy(36,5);
printf("%18.1Lf",result);
count+=1;
break;
case '*':
if(count<1)
{
result=num1*num;
}
else
{
result=result*num;
}
gotoxy(36,5);
printf("%18.1Lf",result);
count+=1;
break;
case '/':
if(count<1)
{
result=num1/num;
}
else
{
result=result/num;
}
gotoxy(36,5);

printf("%18.1Lf",result);
count+=1;
break;
}
}
}
}
c+=50;
}
d+=50;
}
setcolor(YELLOW);
delay(150);
}
getch();
closewindow();
getch();
}
long double addnum(int getnum)
{
num=num*10+getnum;
return(num);
}
int initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
void showptr()

{
i.x.ax=1;
int86(0x33,&i,&o);
}
void hideptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
void restrictptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
o.x.cx=x1;
o.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
o.x.cx=y1;
o.x.dx=y2;
int86(0x33,&i,&o);
}
void getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
void openwindow()
{

int aa,bb,cc,dd,maxx,maxy,i=10;
maxx=getmaxx();
maxy=getmaxy();
rectangle(0,0,maxx,maxy);
aa=250;
bb=400;
cc=260;
for(dd=250;dd<350;dd+=20)
{
setfillstyle(1,2);
bar(dd,bb,cc,bb+10);
cc+=20;
}
aa=250;
bb=400;
cc=260;
while(!kbhit())
{
setcolor(i);
outtextxy(20,20,"Hello, Every body i am ashish chaudhary");
outtextxy(20,32,"I have created this basic calculator using graphics");
outtextxy(20,44,"This is a 16 digits calculator, you can use upto 16 digit for c
laculation");
outtextxy(20,56,"Don't use more than 16 digit's");
outtextxy(20,68,"Currently i am doing B.Sc(c.s) ");
outtextxy(20,80,"If you want to contact to me use my e-mail Id--");
outtextxy(20,92,"[email protected]");
outtextxy(20,104,"my phone number is 9997796324");
outtextxy(20,116,"Press any key to continue.......");
if((aa==350)&&(cc==360))
{

aa=250;
cc=260;
continue;
}
else
{
setcolor(10);
rectangle(aa,bb,cc,bb+10);
rectangle(aa-1,bb-1,cc+1,bb+11);
}
delay(300);
setcolor(BLACK);
rectangle(aa,bb,cc,bb+10);
rectangle(aa-1,bb-1,cc+1,bb+11);
aa+=20;
cc+=20;
}

}
void closewindow()
{
int i,j,k;
cleardevice();
rectangle(0,0,638,478);
k=0;
while(!kbhit())
{
setcolor(k);
settextstyle(5,0,8);
outtextxy(100,200,"THANK YOU");

line(90,300,600,300);
delay(200);
k++;
}
}

code 2
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
#include<stdlib.h>
//#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<string.h>
float *mem;
int X=0, Y=0;
int row=17,col=5;
char dummy;
char flag='d',flagp='0';
char bflag='u',bflagp='u';
int mflag=0;
char ch,ch1,ch2;
int sflag=0;
int midx,midy;
# define UNCLICKED 0
# define CLICKED 1
# define PI 3.14159
char str1[]={"Laique Abbas Roll Number 031"};
void typeit (int x,int y,int spacing,char string[])
{
char temp[2];
for (int i=0;i<strlen(string);i++)
{
delay(100);
temp[0]=string[i];
temp[1]='\0';
outtextxy(x+(i+1)*spacing,y,temp);
}//endfor
}
void front()
{
int x,y,h;
for(x=0;x<=100;x++)
{

settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(1);
settextstyle(1,0,4);
setusercharsize(x,6,x,3);
setcolor(14);
moveto(310,135);
outtext("..");
setcolor(6);
moveto(310,130);
outtext("I I");
if(x<50)
delay(30);
else
delay(20);
}
for(y=0;y<=100;y++)
{
setcolor(0);
settextstyle(1,0,4);
setusercharsize(y,6,y,3);
moveto(310,135);
outtext("..");
moveto(310,130);
outtext("I I");
if(y>20)
{
settextstyle(7,0,3);
setusercharsize(y-20,35,y-20,30);
setcolor(9);
outtext("CALCULATER");
setcolor(2);
outtext("___________");
delay(15);
if(y<100)
{
settextstyle(7,0,3);
setusercharsize(y-20,35,y-20,30);
setcolor(0);
outtext("CALCULATER");
}
}
}
//delay(1000);
settextstyle(3,0,2);
delay(50);
outtextxy(midx-200,midy,"Group Members:-");
//x=10,y=10;
setcolor(6);
settextstyle(4,0,4);
typeit(midx-200,midy+50,15,str1);
getch();
//closegraph();
}
char input();
double add(double,double,char);
double angle_conv(double);
void basecng(double,double);
/************************************************************/
/*
*/

/* THIS FUNCTION DRAWS THE BUTTONS OF THE CALCULATER


*/
/*
*/
/************************************************************/
void button_3d(int x1,int y1,int x2,int y2,int check,char* text,int color)
{
int up,low;
setfillstyle(1,7);
bar(x1,y1,x2,y2);
if(check==0)
//Unclicked
up=15,low=8;
else
up=8,low=15;
//Clicked
setcolor(low);
line(x2,y1,x2,y2);
line(x2-1,y1,x2-1,y2);
line(x1,y2,x2,y2);
line(x1+1,y2-1,x2,y2-1);
setcolor(up);
line(x1,y1,x2,y1);
line(x1+1,y1+1,x2-1,y1+1);
line(x1,y1,x1,y2);
line(x1+1,y1+1,x1+1,y2-1);
setcolor(color);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(x1+(x2 - x1)/2,(y1+(y2 - y1)/2)-2, text);
}
/*********************************************************************/
/*
*/
/*
This function makes the opening screen
*/
/*
*/
/*********************************************************************/
void frontpage(void)
{
int mx, my;
mx = (getmaxx() / 2);
my = (getmaxy() / 2);
//SET baqckground color
setfillstyle(9, 1);
bar(0,0,getmaxx(),getmaxy());
//DRAW a bar, and make it look like a 3d bar
setfillstyle(1,7);
bar(50,20,600,400);
//DRAW lines for the top and left side
setcolor(15);
line(50,20,600,20);
line(51,21,599,21);
line(50,20,50,400);
line(51,21,51,399);
//DRAW lines for the bottom and right side
setcolor(8);
line(600,20,600,400);

line(599,21,599,400);
line(50,400,600,400);
line(51,399,600,399);
//DRAW two 3D bars for the left and right side
setfillstyle(9,8);
bar(70,40,100,380);
//getch();
bar(545,40,575,380);
setcolor(8);
rectangle(70,40,100,380);
rectangle(545,40,575,380);
setcolor(15);
line(100,40,100,380);
line(70,380,100,380);
line(575,40,575,380);
line(545,380,575,380);
//DRAW two 3D
setcolor(8);
line(110, 40,
line(535, 40,
setcolor(15);
line(111, 40,
line(536, 40,

divider lines on both sides


110, 380);
535, 380);
111, 380);
536, 380);

//PRINT 3D text CALENDAR 2002


settextstyle(1, 0, 4);
settextjustify(1,1);
setcolor(15);
outtextxy(mx+2, my - 46, "MY CALCULATER");
setcolor(7);
outtextxy(mx + 1, my - 45, "MY CALCULATER");
setcolor(8);
outtextxy(mx + 2, my - 44, "MY CALCULATER");
//PRINT 3D text 2002
setcolor(15);
outtextxy(mx, my + 10, "2010");
setcolor(7);
outtextxy(mx + 1, my + 11, "2010");
setcolor(8);
outtextxy(mx + 2, my + 12, "2010");
//PRINT copyright notice
settextstyle(2, 0, 5);
setcolor(1);
outtextxy(mx + 1, my + 85, "Copyright 2010 by LMRT Creations");
getch(); //PAUSE for a while
}
/*********************************************************************/
/*
*/
/*
This function makes the claculating screen
*/
/*
*/
/*********************************************************************/
void screen(int x1, int y1, int x2, int y2)

{
setlinestyle(0,0,1);
setfillstyle(SOLID_FILL, 8);
bar(x1, y1, x2, y2);
setfillstyle(SOLID_FILL, BLACK);
bar(x1+1, y1+1, x2-1, y2-1);

settextjustify(CENTER_TEXT, CENTER_TEXT);
setcolor(15);
line(x1+1, y1+1, x1+1, y2-1);
line(x1+1, y1+1, x2-1, y1+1);
line(x1+2, y1+2, x1+2, y2-2);
line(x1+2, y1+2, x2-2, y1+2);
setcolor(8);
line(x1+1, y2-1, x2-1, y2-1);
line(x2-1, y1+1, x2-1, y2-1);
line(x1+2, y2-2, x2-2, y2-2);
line(x2-2, y1+2, x2-2, y2-2);
}
/************************************************************************/
/*
*/
/*
Mouse Related Functions
*/
/*
*/
/************************************************************************/
void init_mouse()
{
union REGS iregs, oregs;
iregs.x.ax = 0;
int86 (0x33, &iregs, &oregs);
if (oregs.x.ax == 0)
{
cleardevice();
printf("mouse not installed\n");
getch();
exit(1);
}
iregs.x.ax = 1;
int86 (0x33, &iregs ,&oregs);
}
/*************************************************************/
void mouse()
{
int button,x1,y1;
union REGS iregs, oregs;
iregs.x.ax = 3;
int86 (0x33, &iregs ,&oregs);
button = oregs.x.bx & 3;
x1 = oregs.x.cx;
y1 = oregs.x.dx;

if(oregs.x.bx & 1)
{
X = x1 ; Y = y1;
}
if(button == 3)
exit(0);
}

/*************************************************************/
void hide_mouse()
{
union REGS ioRegs;
ioRegs.x.ax=2;
int86(0x33,&ioRegs,&ioRegs);
}

/*************************************************************/
void show_mouse()
{
union REGS ioRegs;
ioRegs.x.ax=1;
int86(0x33,&ioRegs,&ioRegs);
}
/*************************************************************/
void remove_mouse()
{
union REGS ioRegs;
ioRegs.x.ax=0;
int86(0x33,&ioRegs,&ioRegs);
}
/*************************************************************************/
/*
*/
/*
THIS FUNCTION DRAWS THE CALCULATER ON THE SCREEN
*/
/*
*/
/*************************************************************************/
void
structure()
{
init_mouse();
setbkcolor(0);
cleardevice();
hide_mouse();
//**********************************************************
// Buttons Making
front();
frontpage();
settextstyle(2,0,4);
button_3d(50,20,600,400,UNCLICKED,"",1);
screen(100,50,545,120);
// screen

// main box

setfillstyle(1,8);
bar(52,22,598,42);
button_3d(575,23,595,40,UNCLICKED,"x",0);
setcolor(0);
outtextxy(120,30,"Calculater v1.0");
button_3d(108,140,208,160,UNCLICKED,"DEC",15); // box of decimal
button_3d(218,140,318,160,UNCLICKED,"OCT",0); // box of octal
button_3d(328,140,428,160,UNCLICKED,"HEX",0); // box of hexal
button_3d(438,140,538,160,UNCLICKED,"BIN",0); // box of binary
button_3d(350,205,380,225,UNCLICKED,"7",0); // Box Of 7
button_3d(390,205,420,225,UNCLICKED,"8",0); // Box Of 8
button_3d(430,205,460,225,UNCLICKED,"9",0); // Box Of 9
button_3d(350,230,380,250,UNCLICKED,"4",0);
button_3d(390,230,420,250,UNCLICKED,"5",0);
button_3d(430,230,460,250,UNCLICKED,"6",0);

// Box Of 4
// Box Of 5
// Box Of 6

button_3d(480,230,510,250,UNCLICKED,"*",0); // Box Of *
button_3d(515,230,545,250,UNCLICKED,"/",0); // Box Of \
button_3d(480,205,510,225,UNCLICKED,"AC",4);
//Box Of AllClear (AC)
button_3d(515,205,545,225,UNCLICKED,"CE",4);
//Box Of Clear (C)
button_3d(350,255,380,275,UNCLICKED,"1",0);
button_3d(390,255,420,275,UNCLICKED,"2",0);
button_3d(430,255,460,275,UNCLICKED,"3",0);

// Box Of 1
// Box Of 2
// Box Of 3

button_3d(350,280,380,300,UNCLICKED,"0",0); // Box Of Zero (0)


button_3d(390,280,420,300,UNCLICKED,".",0); // Box Of Period (.)
button_3d(430,280,460,300,UNCLICKED,"pi",0); // Box Of PhiFunction
button_3d(480,255,510,275,UNCLICKED,"-",0); // Box Of button_3d(515,255,545,275,UNCLICKED,"+",0); // Box Of +
button_3d(350,305,460,325,UNCLICKED,"=",0); // Box Of Equality
button_3d(480,305,545,325,UNCLICKED,"shift",BLUE); // Box Of shift
button_3d(480,280,510,300,UNCLICKED,"sqrt",0);
button_3d(515,280,545,300,UNCLICKED,"inv",0);
button_3d(100,205,150,230,UNCLICKED,"Sin",0);
button_3d(160,205,210,230,UNCLICKED,"Cos",0);
button_3d(220,205,270,230,UNCLICKED,"Tan",0);

//Box of x^n
//box of 1/x

button_3d(100,250,150,275,UNCLICKED,"sin^-1",0);
button_3d(160,250,210,275,UNCLICKED,"cos^-1",0);
button_3d(220,250,270,275,UNCLICKED,"tan^-1",0);

// Box OfSin Function


// Box Of CosFunction
// Box Of Tan Function

button_3d(100,300,150,325,UNCLICKED,"ln",0);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(BLUE);
settextstyle(2,0,4);
outtextxy(125,290,"e");
outtextxy(185,290,"10^x");
outtextxy(245,290,"x^3");
button_3d(160,300,210,325,UNCLICKED,"log",0);
button_3d(220,300,270,325,UNCLICKED,"x^2",0);
button_3d(100,350,150,370,UNCLICKED,"deg",15);

// Box Of sin^-1
// Box Of cos^-1
// Box Of tan^-1
// Box Of ln

// Box Of log
// Box Of x^2

button_3d(160,350,210,370,UNCLICKED,"rad",0);
button_3d(220,350,270,370,UNCLICKED,"gra",0);
button_3d(480,350,545,370,UNCLICKED,"Off",4);
button_3d(350,350,380,370,UNCLICKED,"M+",0);
button_3d(390,350,420,370,UNCLICKED,"M-",0);
button_3d(430,350,460,370,UNCLICKED,"MR",0);

}
/*********************************************************/
/*
*/
/*
Main starts
*/
/*
*/
/*********************************************************/
void main()
{
clrscr();
double y=0,z=0,pnt,pnt1=0,x=0,r=0;
int gdriver = DETECT, gmode, errorcode;
int i;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
midx=getmaxx()/2;midy=getmaxy()/2;
structure();
gotoxy(row,col);
printf("\t\t\t\t\t");
gotoxy(row,col);
printf("0");
mem=(float*)malloc(y*sizeof(float));
while( ch!=27&&ch1!=27) //While Escape is not pressed
{
//and if base is not 10
pnt1=0;//no doubleing point entered Yet
ch2='0';
// for(int a=0;ch!=27;a++)//a indicates whether a no. has been entered or not
while(ch2!=27)
//a=0 means that no no. has been entered yet
{

if(bflagp!='u')
{
//gotoxy(row,col);
dummy=input();
if(dummy!='o')
{
gotoxy(row,col);
printf("The trail version does not support this feature");
input();
gotoxy(row,col);
printf("\t\t\t\t\t\t");
// ch='0';
}
y=0;z=0;ch='0';
gotoxy(row,col);
printf("\t\t\t\t\t\t");
gotoxy(row,col);
printf("0");
// bflagp='u';
}
ch=input();
if(ch=='>'||ch=='<'||ch=='?')
{ sflag=0;
if(ch=='>') //M+
*mem+=y;
if(ch=='<') //M*mem-=y;
if(ch=='?')
//MR
{
y=*mem;
gotoxy(row,col);
printf("\t\t\t\t\t\t");
gotoxy(row,col);
printf("%g",y);
}
if(*mem==0)
mflag=0;
if(*mem!=0)
mflag=1;
}
if(mflag==0)
{
gotoxy(row,7);
printf(" ");
}
if(mflag!=0)
{
gotoxy(row,7);
printf("M");
}
gotoxy(row,col);
if(ch=='a')
{
sflag=0;

y=0;
gotoxy(row,col);
printf("\t\t\t\t\t");
gotoxy(row,col);
printf("0");
}
if(ch=='o')
//for clearing the screen of the calculater
{
sflag=0;
y=0;z=0;
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("0");
gotoxy(row,col);
break;
}
if(ch=='q')
{
sflag=0;
y=sqrt(y);
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",y);
}
if(ch=='m')
{
sflag=0;
y=1/y;
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",y);
}
if(ch=='+'||ch=='-'||ch=='/'||ch=='\\'||ch=='='||ch=='*')
{
sflag=0;
break;
}
if(ch=='.') //case for a decimal point
{
sflag=0;
if(pnt1==0) //ie no decimal has been entered yet
{
gotoxy(row,col);
printf("\t\t\t\t
");//
double
gotoxy(row,col);
printf("%g.",y);
pnt1=.1; //ie one decimal point no has been entered
continue; //go back to the begining and get the next number
}
else
//decimal point has alredy been entered and thus no change in th
e screen
{
sflag=0;
continue; //go back to the begining

}
}//out of the '.' condition
if(pnt1!=0) //ie we have a doubleing point
{ sflag=0;
if(ch<='9'&&ch>='0') //input integer
{
// printf("%c",ch);
x=(double)ch;//type cast the character into double to perforn further operati
ons
x-=48;
//since character digit indoubleing -48 gives the corresponding A
SCII
x=x*pnt1; //make it a decimal
y=x+y;
//add it in result
pnt1*=.1; //shift to the second doubleing point
gotoxy(row,col);
printf("%g",y);
gotoxy(row,col);
continue; //back to the top
}
}
//if no decimal point number then proceed
if(ch<='9'&&ch>='0')
{ sflag=0;
x=(double)ch;
//typecast to double
x-=48;
//get corresponding ASCII
y=(y*10)+x;
//add to right of result
gotoxy(row,col); //go back to start of the calc screen
printf("\t\t\t\t
"); //clear the screen
gotoxy(row,col);
printf("%g",y); //print the number
}
if(ch=='u'||ch=='v'||ch=='w'||ch=='x')
{ sflag=0;
if(bflagp==bflag&&bflag=='u')
continue;
else
basecng(y,pnt1);
}
if(ch=='d'||ch=='r'||ch=='g')
{sflag=0;
y=angle_conv(y);
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",y);
// gotoxy(row,col);
// printf("%g",y);
// continue;
}
if(ch=='s'||ch=='c'||ch=='t'||ch=='i'||ch=='j'||ch=='k'||ch=='n'||ch=='l'||ch=
='p'||ch=='h')
//ie the user opted for a function
{
if(ch=='s'||ch=='c'||ch=='t') //sin /cos/tan
{ sflag=0;
if(flag!='r')
{
flagp=flag;

flag='r';
y=angle_conv(y);
flag=flagp;
}
// gotoxy(row,col);
// printf("%g",y);getch();
switch(ch)
{
case 's':
case 'c':
case 't':
}

y=sin(y); break;
y=cos(y); break;
y=tan(y); break;

}
if(ch=='i'||ch=='j'||ch=='k')
{sflag=0;
if(flag!='r')
{
// flagp=flag;
flagp='r';
//y=angle_conv(y);
}
switch(ch)
{
case 'i': y=asin(y); break;
case 'j':
y=acos(y); break;
case 'k':
y=atan(y); break;
}
if(flag!='r')
y=angle_conv(y);
}
else if(ch=='n')
{
if(sflag==1)
{
y=exp(y);
sflag=0;
}
else
y=log(y);
//ln
}
else if(ch=='l')
{
if(sflag==1)
{
y=pow(10,y);
sflag=0;
}
else
y=log10(y);
//log
}
else if(ch=='p')
{
if(sflag==1)
{
y=pow(y,3);
sflag=0;
}
else
y=pow(y,2);
//square

}
else if(ch=='h')
{
sflag=0;
y=PI;
//pi
}
gotoxy(row,col);
printf("\t\t\t\t
gotoxy(row,col);
printf("%g",y);
}//else condition

");//Clear the screen

}//out of second condition ie we now have the first no. or function or operater
for(;ch!=27&&ch1!='='&&ch!='=';)//ie the characters input are not ESCAPE or Equ
al to
{
pnt1=0;z=0;
if(ch=='o'||ch1=='o')
{

// For Clear The Screen

sflag=0;
y=0;z=0;
gotoxy(row,col);
printf("\t\t\t\t
");
//
gotoxy(col,row);
gotoxy(row,col);
printf("0");
gotoxy(row,col);
break;
}
for(;ch1!=27;)
{
gotoxy(row,col);
//
printf("%g",z);
//
z=0;
ch1=input();
if(ch1=='>'||ch1=='<'||ch1=='?')
{
if(ch1=='>') //M+
*mem+=z;
if(ch1=='<') //M*mem-=z;
if(ch1=='?')
//MR
{
z=*mem;
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",z);
}
if(*mem==0)
mflag=0;
if(*mem!=0)
mflag=1;
}
if(mflag==0)

{
gotoxy(row,7);
printf(" ");
}
if(mflag!=0)
{
gotoxy(row,7);
printf("M");
}
gotoxy(row,col);
if(ch1=='a')
{
z=0;
gotoxy(row,col);
printf("\t\t\t\t ");
gotoxy(row,col);
printf("0");
}
if(ch=='o'||ch1=='o')
// For Clear The Screen
{
y=0;z=0;
gotoxy(row,col);
//cout<<"
";
printf("\t\t\t\t
");
gotoxy(row,col);
printf("0");
gotoxy(row,col);
break;
}
if(ch1=='q')
{
z=sqrt(z);
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",z);
}
if(ch1=='m')
{
z=1/z;
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",z);
}
if(ch1=='.')
{
if(pnt1==0)
{
gotoxy(row,col);
printf("\t\t\t\t
gotoxy(row,col);
//cout<<z<<".";
printf("%g.",z);
pnt1=.1;
continue;

");

}
else
{
continue;
}
}
if(pnt1!=0)
{
if(ch1<='9'&&ch1>='0')
{
//
printf("%c",ch1);
x=(double)ch1;
x-=48;
x=x*pnt1;
z=x+z;
pnt1=pnt1*.1;
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",z);
continue;
}
}
if(ch1=='+'||ch1=='-'||ch1=='*'||ch1=='/'||ch1=='=')
break;
if(ch1>='0'&&ch1<='9')
{
x=(double)ch1;
x=x-48;
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
z=(z*10)+x;
printf("%g",z);
}
if(ch=='u')
if(ch=='d'||ch=='r'||ch=='g')
{
z=angle_conv(z);
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",z);
// continue;
}
if(ch1=='s'||ch1=='c'||ch1=='t'||ch1=='i'||ch1=='j'||ch1=='k'||ch1=='n'||ch1=='l
'||ch1=='p'||ch1=='h')
//ie the user opted for a function
{
if(ch1=='s'||ch1=='c'||ch1=='t') //sin
{
if(flag!='r')
{
flagp=flag;
flag='r';
angle_conv(z);
flag=flagp;
}
switch(ch1)

{
case 's':
case 'c':
case 't':
}

z=sin(z); break;
z=cos(z); break;
z=tan(z); break;

}
if(ch1=='i'||ch1=='j'||ch1=='k')
{
if(flag!='r')
{
flagp='r';
}
switch(ch1)
{
case 'i': z=asin(z); break;
case 'j':
z=acos(z); break;
case 'k':
z=atan(z); break;
}
z=angle_conv(z);
}
else if(ch1=='l')
{
z=log10(z);
//log
}
else if(ch1=='p')
{
z=pow(z,2);
//square
}
else if(ch1=='h')
{
z=PI;
//pi
}
gotoxy(row,col);
printf("\t\t\t\t
gotoxy(row,col);
printf("%g",z);
gotoxy(row,col);

");

}
}
if(ch1=='+'||ch1=='-'||ch1=='=')
{
y=add(y,z,ch);
if(ch2!='0')
{
y=add(r,y,ch2);
ch2='0';
}
}
else
{
if(ch=='*'||ch=='/')
y=add(y,z,ch);
else
{
ch2=ch;
r=y;
y=z;
}

}
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",y);
ch=ch1;
ch1='0';
if(ch=='='||ch1=='=')
break;
}
if(ch=='o'||ch1=='o')
{ y=0;z=0;
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("0");
gotoxy(row,col);
continue;
}
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%g",y);
z=0;
}

// For Clear The Screen

//
getch();
closegraph();
remove_mouse();
exit(0);
}

/*************************************************************/
/*
*/
/*
This function gets the user's Input
*/
/*
*/
/*************************************************************/
char input()
{
X=0;Y=0;
char ch;
show_mouse();
if(bflag!='u')
{
button_3d(108,140,208,160,UNCLICKED,"DEC",15);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
bflag='u';
}
do
{
mouse();
if (X>=350 && X<=380 && Y>=205 && Y<=225) // Condition For 7

{
hide_mouse();
button_3d(350,205,380,225,CLICKED,"7",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,205,380,225,UNCLICKED,"7",0);
show_mouse();
ch='7';
return ch;
}
//**********************************************
if (X>=390 && X<=420 && Y>=205 && Y<=225) // Condition For 8
{
hide_mouse();
button_3d(390,205,420,225,CLICKED,"8",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,205,420,225,UNCLICKED,"8",0);
show_mouse();
ch='8';
return ch;
}
//*****************************************
if (X>=430 && X<=460 && Y>=205 && Y<=225) // Condition For 9
{
hide_mouse();
button_3d(430,205,460,225,CLICKED,"9",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,205,460,225,UNCLICKED,"9",0);
show_mouse();
ch='9';
return ch;
}
//***********************************
if (X>=350 && X<=380 && Y>=230 && Y<=250) // Condition For 4
{
hide_mouse();
button_3d(350,230,380,250,CLICKED,"4",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,230,380,250,UNCLICKED,"4",0);
show_mouse();
ch='4';
return ch;
}

//***********************************
if (X>=390 && X<=420 && Y>=230 && Y<=250) // Condition For 5
{
hide_mouse();
button_3d(390,230,420,250,CLICKED,"5",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,230,420,250,UNCLICKED,"5",0);
show_mouse();
ch='5';
return ch;
}
//***********************************
if (X>=430 && X<=460 && Y>=230 && Y<=250) // Condition For 6
{
hide_mouse();
button_3d(430,230,460,250,CLICKED,"6",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,230,460,250,UNCLICKED,"6",0);
show_mouse();
ch='6';
return ch;
}
//***********************************
if (X>=480 && X<=510 && Y>=230 && Y<=250) // Condition For *
{
hide_mouse();
button_3d(480,230,510,250,CLICKED,"*",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,230,510,250,UNCLICKED,"*",0);
show_mouse();
ch='*';
return ch;
}
//***********************************
if (X>=515 && X<=545 && Y>=230 && Y<=250) // Condition For /
{
hide_mouse();
button_3d(515,230,545,250,CLICKED,"/",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,230,545,250,UNCLICKED,"/",0);
show_mouse();
ch='/';

return ch;
}
//***********************************
int a,b;
if (X>=350 && X<=380 && Y>=255 && Y<=275) // Condition For 1
{
hide_mouse();
button_3d(350,255,380,275,CLICKED,"1",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,255,380,275,UNCLICKED,"1",0);
show_mouse();
ch='1';
return ch;
}
// *************************************
if (X>=390 && X<=420 && Y>=255 && Y<=275) // Condition For 2
{
hide_mouse();
button_3d(390,255,420,275,CLICKED,"2",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,255,420,275,UNCLICKED,"2",0);
show_mouse();
ch='2';
return ch;
}
// *************************************
if (X>=430 && X<=460 && Y>=255 && Y<=275) // Condition For 3
{
hide_mouse();
button_3d(430,255,460,275,CLICKED,"3",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,255,460,275,UNCLICKED,"3",0);
show_mouse();
ch='3';
return ch;
}
// *************************************
if (X>=350 && X<=380 && Y>=280 && Y<=300) // Condition For 0
{
hide_mouse();
button_3d(350,280,380,300,CLICKED,"0",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,280,380,300,UNCLICKED,"0",0);
show_mouse();
ch='0';

return ch;
}
// *************************************
if (X>=390 && X<=420 && Y>=280 && Y<=300) // Condition For .
{
hide_mouse();
button_3d(390,280,420,300,CLICKED,".",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,280,420,300,UNCLICKED,".",0);
show_mouse();
ch='.';
return ch;
}
//**********************************************
if (X>=430 && X<=460 && Y>=280 && Y<=300) // Condition For pi
{
hide_mouse();
button_3d(430,280,460,300,CLICKED,"pi",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,280,460,300,UNCLICKED,"pi",0);
show_mouse();
ch='h';
return ch;
}
//***********************************************
if (X>=480 && X<=510 && Y>=255 && Y<=275) // Condition For {
hide_mouse();
button_3d(480,255,510,275,CLICKED,"-",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,255,510,275,UNCLICKED,"-",0);
show_mouse();
ch='-';
return ch;
}
//**************************************************
if (X>=515 && X<=545 && Y>=255 && Y<=275) // Condition For +
{
hide_mouse();
button_3d(515,255,545,275,CLICKED,"+",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,255,545,275,UNCLICKED,"+",0);
show_mouse();
ch='+';

return ch;
}
//*****************************************************
if (X>=350 && X<=460 && Y>=305 && Y<=325) // Condition For =
{
hide_mouse();
button_3d(350,305,460,325,CLICKED,"=",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,305,460,325,UNCLICKED,"=",0);
show_mouse();
ch='=';
return ch;
}
//*****************************************************
if (X>=480 && X<=545 && Y>=305 && Y<=325) // Condition For shift
{
hide_mouse();
button_3d(480,305,545,325,CLICKED,"shift",BLUE);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,305,545,325,UNCLICKED,"shift",BLUE);
show_mouse();
ch='~';
sflag=1;
return ch;
}
//*************************************
if (X>=480 && X<=510 && Y>=205 && Y<=225) // Condition For AC
{
hide_mouse();
button_3d(480,205,510,225,CLICKED,"AC",4);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,205,510,225,UNCLICKED,"AC",4);
show_mouse();
ch='o';
return ch;
}
/********************C*/
if (X>=515 && X<=545 && Y>=205 && Y<=225) // Condition For C
{
hide_mouse();
button_3d(515,205,545,225,CLICKED,"CE",4);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,205,545,225,UNCLICKED,"CE",4);
show_mouse();
ch='a';

return ch;
}
// ****************************************
if (X>=100 && X<=150 && Y>=205 && Y<=230) // Condition For Sin
{
hide_mouse();
button_3d(100,205,150,230,CLICKED,"Sin",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(100,205,150,230,UNCLICKED,"Sin",0);
show_mouse();
ch='s';
return ch;
}
//***********************************
if (X>=160 && X<=210 && Y>=205 && Y<=230) // Condition For Cos
{
hide_mouse();
button_3d(160,205,210,230,CLICKED,"Cos",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(160,205,210,230,UNCLICKED,"Cos",0);
show_mouse();
ch='c';
return ch;
}
//***********************************
if(X>=515&&X<=545&&Y>=280&&Y<=300)
//inverse
{
hide_mouse();
button_3d(515,280,545,300,CLICKED,"inv",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(515,280,545,300,UNCLICKED,"inv",0);
show_mouse();
ch='m';
return ch;
}
if (X>=220 && X<=270 && Y>=205 && Y<=230) // Condition For Tan
{
hide_mouse();
button_3d(220,205,270,230,CLICKED,"Tan",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(220,205,270,230,UNCLICKED,"Tan",0);
show_mouse();
ch='t';
return ch;

}
//*********************************** */
if (X>=100 && X<=150 && Y>=250 && Y<=275) // Condition For sin^-1
{
hide_mouse();
button_3d(100,250,150,275,CLICKED,"sin^-1",0);
show_mouse();
delay(150);
hide_mouse();
button_3d(100,250,150,275,UNCLICKED,"sin^-1",0);
show_mouse();
ch='i';
return ch;
}
//**************************
if (X>=160 && X<=210 && Y>=250 && Y<=275) // Condition For cos^-1
{
hide_mouse();
button_3d(160,250,210,275,CLICKED,"cos^-1",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(160,250,210,275,UNCLICKED,"cos^-1",0);
show_mouse();
ch='j';
return ch;
}
//**************************
if (X>=430 && X<=460 && Y>=350 && Y<=370) // Condition For MR
{
hide_mouse();
button_3d(430,350,460,370,CLICKED,"MR",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(430,350,460,370,UNCLICKED,"MR",0);
show_mouse();
ch='?';
return ch;
}
if (X>=390 && X<=420 && Y>=350 && Y<=370) // Condition For M{
hide_mouse();
button_3d(390,350,420,370,CLICKED,"M-",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(390,350,420,370,UNCLICKED,"M-",0);
show_mouse();
ch='<';
return ch;
}
if (X>=350 && X<=380 && Y>=350 && Y<=370) // Condition For M+
{
hide_mouse();

button_3d(350,350,380,370,CLICKED,"M+",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(350,350,380,370,UNCLICKED,"M+",0);
show_mouse();
ch='>';
return ch;
}
if (X>=220 && X<=270 && Y>=250 && Y<=275) // Condition For tan^-1
{
hide_mouse();
button_3d(220,250,270,275,CLICKED,"tan^-1",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(220,250,270,275,UNCLICKED,"tan^-1",0);
show_mouse();
ch='k';
return ch;
}
//**************************
if (X>=100 && X<=150 && Y>=300 && Y<=325) // Condition For ln
{
hide_mouse();
button_3d(100,300,150,325,CLICKED,"ln",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(100,300,150,325,UNCLICKED,"ln",0);
show_mouse();
ch='n';
return ch;
}
//**************************
if (X>=160 && X<=210 && Y>=300 && Y<=325) // Condition For log
{
hide_mouse();
button_3d(160,300,210,325,CLICKED,"log",0);
show_mouse();
delay(150);
hide_mouse();
button_3d(160,300,210,325,UNCLICKED,"log",0);
show_mouse();
ch='l';
return ch;
}
//**************************
if (X>=220 && X<=270 && Y>=300 && Y<=325) // Condition For X^2
{
hide_mouse();
button_3d(220,300,270,325,CLICKED,"x^2",0);
show_mouse();
delay(250);
hide_mouse();

button_3d(220,300,270,325,UNCLICKED,"x^2",0);
show_mouse();
ch='p';
return ch;
}
if (X>=100 && X<=150 && Y>=350 && Y<=370) // Condition For deg
{
hide_mouse();
button_3d(100,350,150,370,CLICKED,"deg",15);
button_3d(160,350,210,370,UNCLICKED,"rad",0);
button_3d(220,350,270,370,UNCLICKED,"gra",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(100,350,150,370,UNCLICKED,"deg",15);
show_mouse();
ch='d';
flagp=flag;
flag=ch;
return ch;
}
//**************************
if (X>=160 && X<=210 && Y>=350 && Y<=370) // Condition For rad
{
hide_mouse();
button_3d(100,350,150,370,UNCLICKED,"deg",0);
button_3d(160,350,210,370,CLICKED,"rad",15);
button_3d(220,350,270,370,UNCLICKED,"gra",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(160,350,210,370,UNCLICKED,"rad",15);
show_mouse();
ch='r';
flagp=flag;
flag=ch;
return ch;
}
if (X>=220 && X<=270 && Y>=350 && Y<=370) // Condition For gra
{
hide_mouse();
button_3d(100,350,150,370,UNCLICKED,"deg",0);
button_3d(160,350,210,370,UNCLICKED,"rad",0);
button_3d(220,350,270,370,CLICKED,"gra",15);
show_mouse();
delay(250);
hide_mouse();
button_3d(220,350,270,370,UNCLICKED,"gra",15);
show_mouse();
ch='g';
flagp=flag;
flag=ch;
return ch;
}
if ((X>=480 && X<=545 &&Y>=350 &&Y <=370)||(X>=575&&X<=595&&Y>=23&&Y<=40))
//OFF
{
free(mem);
exit(0);

}
if (X>=108 && X<=208 && Y>=140 && Y<=160) // Condition For dec
{
hide_mouse();
button_3d(108,140,208,160,CLICKED,"DEC",15);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",15);
show_mouse();
ch='u';
bflagp=bflag;
bflag=ch;
return ch;
}
if (X>=218 && X<=318 && Y>=140 && Y<=160) // Condition For oct
{
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",0);
button_3d(218,140,318,160,CLICKED,"OCT",15);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(218,140,318,160,UNCLICKED,"OCT",15);
show_mouse();
ch='v';
bflagp=bflag;
bflag=ch;
return ch;
}
if (X>=328 && X<=428 && Y>=140 && Y<=160) // Condition For hex
{
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",0);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,CLICKED,"HEX",15);
button_3d(438,140,538,160,UNCLICKED,"BIN",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(328,140,428,160,UNCLICKED,"HEX",15);
show_mouse();
ch='w';
bflagp=bflag;
bflag=ch;
return ch;
}
if (X>=438 && X<=538 && Y>=140 && Y<=160) // Condition For dec
{
hide_mouse();
button_3d(108,140,208,160,UNCLICKED,"DEC",0);
button_3d(218,140,318,160,UNCLICKED,"OCT",0);
button_3d(328,140,428,160,UNCLICKED,"HEX",0);
button_3d(438,140,538,160,CLICKED,"BIN",15);
show_mouse();

delay(250);
hide_mouse();
button_3d(438,140,538,160,UNCLICKED,"BIN",15);
show_mouse();
ch='x';
bflagp=bflag;
bflag=ch;
return ch;
}
if(X>=480&&X<=510&&Y>=280&&Y<=300)
{
hide_mouse();
button_3d(480,280,510,300,CLICKED,"sqrt",0);
show_mouse();
delay(250);
hide_mouse();
button_3d(480,280,510,300,UNCLICKED,"sqrt",0);
show_mouse();
ch='q';
return ch;
}
}while(kbhit() == 0);
ch=getch();
return ch;
}
/*************************************************************************/
/*
*/
/*
This function performs the Calculations
*/
/*
*/
/*************************************************************************/
double add(double x,double y,char ch)
{
switch(ch)
{
case '+':
y=x+y;
break;
case '-':
y=x-y;
break;
case '*':
y=x*y;
break;
case '/':
y=x/y;
}
return y;
}
double angle_conv(double no)
{
if(flagp=='d')
{
if(flag=='r')
{
no=no*PI/180;
}
if(flag=='g')

{
no=no*1.1111111;
}
}
else if(flagp=='r')
{
if(flag=='d')
{
no=no*180/PI;
}
if(flag=='g')
{
no=no*180/PI*1.1111111;
}
}
else if(flagp=='g')
{
if(flag=='r')
{
no=no/(180*1.1111111)*PI;
}
if(flag=='d')
{
no=no/1.1111111;
}
}
return(no);
}
void basecng(double y,double pnt1)
{
char str[17];
if(pnt1!=0)
{
gotoxy(row,col);
printf("The trial version does not support this feature");
getch();
bflag='u';
bflagp='0';
main();
}
if(bflagp!='u')
{
gotoxy(row,col);
printf("The trial version does not support this feature ");
getch();
bflagp='0';
bflag='u';
main();
}
switch(bflag)
{
case 'v':
itoa(y,str,8);
gotoxy(row,col);
printf("\t\t\t\t
");
gotoxy(row,col);
printf("%s",str);
bflagp='0';

break;
case 'w':
itoa(y,str,16);
gotoxy(row,col);
printf("\t\t\t\t
gotoxy(row,col);
printf("%s",str);
bflagp='0';
// getch();
break;
case 'x':
itoa(y,str,2);
gotoxy(row,col);
printf("\t\t\t\t
gotoxy(row,col);
printf("%s",str);
// getch();
bflagp='0';
break;
}
bflag='u';
}

");

");

code 2
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
int initmouse();
void showptr();
void openwindow();
void closewindow();
void hideptr();
void getmousepos(int *,int*,int*);
void restrictptr(int,int,int,int);
int button,x,y,x1,y1,x2,y2,s;
long double num=0,get,num1=0,result=0;
long double addnum(int);
char opr;
int a,b,r,s,i1,count,c,sq,newnum=1,d=0;

union REGS i,o;


void main(void)
{
int driver=DETECT,mode;
int q,p[12];
char input;
char *inpu[4][4]={"1","2","3","4",
"5","6","7","8",
"9","0","+","-" ,
"*","/","clr","="};
char inp[4][4]={'1','2','3','4',
'5','6','7','8',
'9','0','+','-' ,
'*','/','l','='};
initgraph(&driver,&mode,"c:\\tc\\bgi");
if(initmouse()==0)
{
printf("not");
getch();
exit(0);
}
openwindow();
getch();
cleardevice();
setfillstyle(CLOSE_DOT_FILL,10);
bar(260,82,450,320);
bar(430,70,450,320);
setfillstyle(1,GREEN);
bar(236,82,432,300);
setcolor(GREEN);

rectangle(238,50,430,80);
rectangle(237,49,431,81);
rectangle(236,48,432,82);
c=240;
d=100;
s=0;
for(a=0;a<4;a++)
{
c=240;
for(b=0;b<4;b++)
{
setfillstyle(1,RED);
bar(c,d,c+40,d+40);
setcolor(YELLOW);
outtextxy(c+10,d+14,inpu[a][b]);
c+=50;
}
d+=50;
}
showptr();
num=0;
gotoxy(36,5);
printf("%18.1Lf",num);
count=0;
while(!kbhit())
{
outtextxy(30,20,"Press any key to exit..");
i1=0;
c=240;
d=100;

rectangle(0,0,638,478);
getmousepos(&button,&x,&y);
for(a=0;a<4;a++)
{
c=240;
for(b=0;b<4;b++)
{
if((x>=c&&x<=c+40)&&(y>=d&&y<=d+40))
{
if((button&1)==1)
{
while((button&1)==1)
{
setcolor(10);
rectangle(c,d,c+40,d+40);
rectangle(c-1,d-1,c+41,d+41);
rectangle(c-2,d-2,c+42,d+42);
break;
}
delay(100);
setcolor(GREEN);
rectangle(c,d,c+40,d+40);
rectangle(c-1,d-1,c+41,d+41);
rectangle(c-2,d-2,c+42,d+42);
input=inp[a][b];
switch(input)
{
case '1':
get=addnum(1);
gotoxy(36,5);

printf("%18.1Lf",get);
break;
case '2':
get=addnum(2);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '3':
get=addnum(3);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '4':
get=addnum(4);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '5':
get=addnum(5);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '6':
get=addnum(6);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '7':
get=addnum(7);
gotoxy(36,5);

printf("%18.1Lf",get);
break;
case '8':
get=addnum(8);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '9':
get=addnum(9);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '0':
get=addnum(0);
gotoxy(36,5);
printf("%18.1Lf",get);
break;
case '+':
num1=num;
num=0;
opr='+';
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case '-':
num1=num;
num=0;
opr='-';
gotoxy(36,5);
printf("%18.1Lf",num);

break;
case '*':
num1=num;
num=0;
opr='*';
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case '/':
num1=num;
num=0;
opr='/';
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case 'l':
num=0;
num1=0;
result=0;
count=0;
gotoxy(36,5);
printf("%18.1Lf",num);
break;
case '=':
switch(opr)
{
case '+':
if(count<1)
{
result=num+num1;

}
else
{
result=result+num;
}
gotoxy(36,5);
printf("%18.1Lf",result);
count+=1;
break;
case '-':
if(count<1)
{
result=num1-num;
}
else
{
result=result-num;
}
gotoxy(36,5);
printf("%18.1Lf",result);
count+=1;
break;
case '*':
if(count<1)
{
result=num1*num;
}
else
{
result=result*num;

}
gotoxy(36,5);
printf("%18.1Lf",result);
count+=1;
break;
case '/':
if(count<1)
{
result=num1/num;
}
else
{
result=result/num;
}
gotoxy(36,5);
printf("%18.1Lf",result);
count+=1;
break;
}
}
}
}
c+=50;
}
d+=50;
}
setcolor(YELLOW);
delay(150);
}
getch();

closewindow();
getch();
}
long double addnum(int getnum)
{
num=num*10+getnum;
return(num);
}
int initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
void showptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void hideptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
void restrictptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
o.x.cx=x1;
o.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;

o.x.cx=y1;
o.x.dx=y2;
int86(0x33,&i,&o);
}
void getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
void openwindow()
{
int aa,bb,cc,dd,maxx,maxy,i=10;
maxx=getmaxx();
maxy=getmaxy();
rectangle(0,0,maxx,maxy);
aa=250;
bb=400;
cc=260;
for(dd=250;dd<350;dd+=20)
{
setfillstyle(1,2);
bar(dd,bb,cc,bb+10);
cc+=20;
}
aa=250;
bb=400;
cc=260;

while(!kbhit())
{
setcolor(i);
outtextxy(20,20,"Hello, Every body i am ashish chaudhary");
outtextxy(20,32,"I have created this basic calculator using graphics");
outtextxy(20,44,"This is a 16 digits calculator, you can use upto 16 digit for c
laculation");
outtextxy(20,56,"Don't use more than 16 digit's");
outtextxy(20,68,"Currently i am doing B.Sc(c.s) ");
outtextxy(20,80,"If you want to contact to me use my e-mail Id--");
outtextxy(20,92,"[email protected]");
outtextxy(20,104,"my phone number is 9997796324");
outtextxy(20,116,"Press any key to continue.......");
if((aa==350)&&(cc==360))
{
aa=250;
cc=260;
continue;
}
else
{
setcolor(10);
rectangle(aa,bb,cc,bb+10);
rectangle(aa-1,bb-1,cc+1,bb+11);
}
delay(300);
setcolor(BLACK);
rectangle(aa,bb,cc,bb+10);
rectangle(aa-1,bb-1,cc+1,bb+11);
aa+=20;

cc+=20;
}

}
void closewindow()
{
int i,j,k;
cleardevice();
rectangle(0,0,638,478);
k=0;
while(!kbhit())
{
setcolor(k);
settextstyle(5,0,8);
outtextxy(100,200,"THANK YOU");
line(90,300,600,300);
delay(200);
k++;
}
}
code 3
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
float a,b,c;
char o,w;
void ari();
void trig();
void main(void)
{
do
{
clrscr();
printf("\t\t*** CALCULATOR ***\n\n\t");
printf("1 -> Arithmetic Calculation\n\n\t");
printf("2 -> Trigonometric & Logical calculations\n");

scanf("\n%c",&o);
switch(o)
{
case '1':
ari();
break;
case '2':
trig();
break;
default:
printf("Invalid entry.");
}
printf("\n\nDo you want to continue:\t");
scanf("\n\n%c",&o);
}while(o== 'y');
getch();
}
void ari()
{
printf("\n\t***Arithmetic Calculation***\n\n");
printf("Enter the expression:");
scanf("\n%f",&a);
scanf("\n%c",&o);
switch(o)
{
case '+':
scanf("\n%f",&b);
c = a + b;
printf("\t= %.2f",c);
break;
case '-':
scanf("\n%f",&b);
c = a - b;
printf("\t= %.2f",c);
break;
case '*':
scanf("\n%f",&b);
c = a * b;
printf("\t= %.2f",c);
break;
case '/':
scanf("\n%f",&b);
c = a / b;
printf("\t= %.2f",c);
break;
default:
printf("Check the operator");
}
}
void trig()
{
printf("\n\t***Trigonometric & Logical calculations***");
printf("\n\n\ts -> Sin");
printf("\n\n\tc -> Cos");
printf("\n\n\tt -> Tan");
printf("\n\n\tl -> Log");
printf("\n\n\tp -> Power");

printf("\n\n\tr -> Square Root\n\n");


scanf("\n%c",&o);
switch(o)
{
case 's':
printf("Enter the value of sin:");
scanf("\n%f",&a);
b=sin(a);
printf("\tsin %.0f = %.2f",a,b);
break;
case 'c':
printf("Enter the value of cos:");
scanf("\n%f",&a);
b=cos(a);
printf("\tcos %.0f = %.2f",a,b);
break;
case 't':
printf("Enter the value of tan:");
scanf("\n%f",&a);
b=tan(a);
printf("\ttan %.0f = %.2f",a,b);
break;
case 'l':
printf("Enter the value of log:");
scanf("\n%f",&a);
b=log10(a);
printf("\tlog %.0f = %.4f",a,b);
break;
case 'p':
printf("Enter the base and power eg(2,3):");
scanf("\n%f",&a);
scanf("\n%f",&b);
c=pow(a,b);
printf("\t%.0f to the Power %.0f = %.2f",a,b,c);
break;
case 'r':
scanf("\n%f",&a);
b=sqrt(a);
printf("\troot %.0f = %.2f",b);
break;
default:
printf("Check the values");
}
}
//OUTPUT

//***CALULATOR***
//1 -> Arithmetic Calculation
//2 -> Trigonometric & Logical calculations
//1
/****Arithmetic Calculation***

2+3
= 5.00
Do you want to continue: y
***CALCULATOR***
1 -> Arithmetic Calculation
2 -> Trigonometric & Logical calculations
2
***Trigonometric & Logical calculations***
s -> Sin
c -> Cos
t -> Tan
l -> Log
p -> Power
r -> Square Root
s 0
sin 0 = 0.00
Do you want to continue: n
*/
code4
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define PI 3.142
static float mem;
void print(void);
void BasicOperation(void);
void Trignometric(void);
void Sqrt(void);
void Pow(void);
void Log(void);
void DegRed(void);
void Memory(void);
void main(void)
{
int choice;
clrscr();
x:
printf("Enter a choice\n 1.To perform an operation between two numbers\n 2.T
o print value of a trignometric function \n 3.To find square root of a number.\n
4.To find power of a number.\n 5.To find log of a number \n 6.TO convert degree
to radian or vice versa \n 7.Store a number(M+) \n 8.Print the stored value in
memory \n 9.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:

BasicOperation();
break;
case 2:
Trignometric();
break;
case 3:
Sqrt();
break;
case 4:
Pow();
break;
case 5:
Log();
break;
case 6:
DegRed();
break;
case 7:
Memory();
break;
case 8:
print();
break;
case 9:
exit(0);
default:
printf("You did not entered a valid choice.Try again\n");
goto x;
}
}
void BasicOperation(void)
{
float num1,num2;
char op;
clrscr();
start:
printf("Enter expression in the format(num1 operator num2):\n");
scanf("%f%c%f",&num1,&op,&num2);
switch(op)
{
case '+':
printf("The result is %f\n",num1+num2);
break;
case '-':
printf("The result is %f\n",num1-num2);
break;
case '*':
printf("The result is %f\n",num1*num2);
break;
case '/':
printf("The result is %f\n",num1/num2);
break;
default:
printf("You did not entered a valid choice try again.\n");
goto start;
}
getch();
}

void Trignometric(void)
{
int choice;
float angle;
clrscr();
printf("Enter angle in radians");
scanf("%f",&angle);
printf("Enter funtion number to find its value\n 1.Sin\n 2.Cos \n 3.Tan \n")
;
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("sin%f=%f\n",angle,(float)sin(angle));
break;
case 2:
printf("cos%f=%f\n",angle,(float)cos(angle));
break;
case 3:
printf("tan%f=%f\n",angle,(float)tan(angle));
break;
default:
printf("Wrong Selection program terminating\n");
}
getch();
}
void Sqrt(void)
{
float num;
printf("Enter the number whose square root is to be calculated:\n");
scanf("%f",&num);
printf("The square root of %f is %f\n",num,(float)sqrt(num));
getch();
}
void Pow(void)
{
float x,n;
printf("Enter a number folowed by the power(x,n):\n");
scanf("%f,%f",&x,&n);
printf("The result is %f\n",pow(x,n));
getch();
}
void Log(void)
{
float num;
printf("Enter the number whose log is to be calculated:\n");
scanf("%f",&num);
printf("log of %f is %f \n",num,log(num));
getch();
}
void DegRed(void)
{
int choice;
float degree,radian;
printf("Enter a choice:\n 1.Degree to radian\n 2.Radian to degree");
scanf("%d",&choice);
if(choice==1)
{
printf("Enter degrees\n");
scanf("%f",&degree);

radian=(180*degree)/PI;
printf("%fdegrees=%fradians",degree,radian);
}
else
{
printf("Enter radians:\n");
scanf("%f",&radian);
degree=(PI*radian)/180;
printf("%fradians=%f degrees",radian,degree);
}
getch();
}
void Memory(void)
{
printf("Enter a value to be stored:\n");
scanf("%f",&mem);
printf("Value successfully stored.Press any key to go to main menu\n");
getch();
main();
}
void print(void)
{
clrscr();
printf("The value stored in the memory is %f",mem);
getch();
}
code 5
#include"graphics.h"
#include"dos.h"
#include"stdio.h"
#include"math.h"
union REGS i,o;
char *text[]={ "7","8","9","*",
"4","5","6","/",
"1","2","3","+",
"0","00",".","-",
"M","M+","M-","+/-",
"MR","MC","x^2","sr",
"OFF","AC","CE","="};
int k=0,pass,op,prop,newnum=1,bt,memo=1,d=0,sq;
long double num=0,accum,m;
void normalbutton(int ,int ,int ,int,char**);
void main(void)
{
int gd=DETECT,gm,x1,x2,y1,y2,i,j,maxx,maxy,x,y,button;
char *text1[]={""","T","o"," ","K","n","o","w"," ","a","b","o",
"u","t"," ","m","e"," ","l","o","g","o","n"," ",":"};
char *text2[]={"w","w","w",".","g","e","o","c","i","t","i","e","s",
".","c","o","m","/","t","a","l","k","d","e","e","p",
"e","s","h"};

initgraph(&gd,&gm,"");
if(initmouse()==0)
{
closegraph();
restorecrtmode();
printf("
Mouse driver not loded");
exit(1);
}
showmouseptr();
// x=y=50;
movemouseptr(&x,&y);
setbkcolor(11);
setcolor(1);
rectangle(198,140,417,163);
rectangle(199,141,418,164);
rectangle(197,139,416,162);
rectangle(185,130,430,450);
rectangle(184,129,431,451);
rectangle(182,127,433,454);
rectangle(181,126,434,453);
//setfillstyle(SOLID_FILL,3);
//bar(200,142,415,161);
outtextxy(200,50,"A Calculator in C");
outtextxy(200,100,"Press OFF button to exit....");
y1=140;
y2=160;
for(j=0;j<7;j++)
{
x1=200;
x2=235;
y1+=40;
y2+=40;
for(i=0;i<4;i++)
{
normalbutton(x1,x2,y1,y2,text);
x1+=60;
x2+=60;
}
}
while(1)
{
getmousepos(&button,&x,&y);
y1=140;
y2=160;
/*

if( (x>400&&x<450) && (y>400&&y<420) )


{ if((button & 1)==1)
{ sound(500);
delay(5);
exit();
}
}
*/
for(j=0;j<7;j++)
{
x1=200;
x2=235;
y1+=40;
y2+=40;
for(i=0;i<4;i++)
{
if((x<x2&&x>x1)&&(y<y2&&y>y1))
{
if((button & 1)==1)
{ gotoxy(28,10);
// printf("%d",ch=*text[j*4+i]);
// printf("char is %c",ch);
bt=j*4+i;
// printf("char is %d",j*4+i);
setcolor(11);
outtextxy(x1+12,y1+7,text[j*4+i]);
if(num>pow(10.0,18))
exit();
sound(500);delay(10);nosound();
delay(250);
sound(400);delay(10);
nosound();
switch (bt)
{
case 8 :
addnum(1);
break;
case 9 :
addnum(2);
break;
case 10 :
addnum(3);
break;
case 4 :
addnum(4);
break;
case 5 :
addnum(5);
break;
case 6 :
addnum(6);
break;
case 0 :
addnum(7);
break;
case 1 :
addnum(8);

break;
case 2 :
addnum(9);
break;
case 12 :
addnum(0);
break;
case 11 :
// plus
operation(1);
break;
case 15 :
// minus
operation(2);
break;
case 3 :
// multiplication
operation(3);
break;
case 7 :
// division
operation(4);
break;
case 13:
doublezero();
break;
case 14 :
decimal();
break;
case 16:
mem();
break;
case 20:
recallmem();
break;
case 19:
plusminus();
break;
case 17:
plusm();
break;
case 18:
minusm();
break;
case 21:
clearm();
break;
case 22 :
square();
break;
case 23:
sqroot();
break;
case 24:
// OFF
hidemouseptr();
setcolor(1);

for(j=0;j<20;j++)
{
for(i=75;i<481;i+=20)
line(0,0+i+j,640,j+0+i);
delay(100);
}
setcolor(14);
outtextxy(225,200,"Thanks for using it !");
delay(2000);
setcolor(13);
for(j=0;j<20;j++)
{
for(i=0;i<640;i+=20)
line(0+i+j,0,j+0+i,640);
delay(100);
}
setcolor(1);
for(i=0;i<25;i++)
{
outtextxy(75+10*i,200,text1[i]);
sound(3000);
delay(50);
nosound();
}
for(i=0;i<29;i++)
{
outtextxy(125+10*i,225,text2[i]);
sound(3000);
delay(50);
nosound();
}
delay(2500);
sound(5000);
delay(10);
exit();
break;
case 25:
allclear();
break;
case 26:
clear();
break;
case 27:
// equalto
operation(5);
break;

}
setcolor(1);

outtextxy(x1+12,y1+7,text[j*4+i]);
}
}
x1+=60;
x2+=60;
}
}
}

}
void normalbutton(int x1,int x2,int y1,int y2,char **text)
{
setcolor(15);
rectangle(x1-2,y1-2,x2+1,y2+1);
rectangle(x1-1,y1-1,x2+2,y2+2);
setcolor(7);
rectangle(x1,y1,x2+2,y2+2);
rectangle(x1,y1,x2+1,y2+1);
setfillstyle(SOLID_FILL,14);
bar(x1,y1,x2,y2);
setcolor(1);
outtextxy(x1+12,y1+7,text[k]);
k++;
}
/* initmouse */
initmouse()
{
i.x.ax=0;
int86 (0x33,&i,&o);
return(o.x.ax);
}
hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}
/* displays mouse pointer */
showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
return 0;
}
/*gets mouse coordinates and button status*/
getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;

*x=o.x.cx;
*y=o.x.dx;
return 0;
}
/* Move mouse ptr to x,y */
movemouseptr(int *x,int *y)
{
i.x.ax=4;
int86(0x33,&i,&o);
o.x.cx=*x;
o.x.dx=*y;
return 0;
}
addnum(int pass)
{ if(sq)
newnum=1;
if(newnum)
{
if(d)
{
num=pass/(pow(10.0,d));
d++;
newnum=0;
}
else
{ num=pass;
newnum=0;
}
}
else
{
/* if(num==0)
{
if(d)
{
num=num+pass/(pow(10.0,d));
d++;
}
else
num=pass;
}
*/
// else
{
if(d)
{
if(num<0)
num=num-pass/(pow(10.0,d));
else
num=num+pass/(pow(10.0,d));
d++;
}
else
{
num=num*10+pass;
}
}
}
printf("%25.5Lf",num);
}

operation(int opr)
{ long double pnum;
pnum=num;
if(newnum && (prop != 5) && memo)
{
}
else
{ newnum=1;
d=0;
sq=0;
switch(prop)
{
case 1:
accum=accum+pnum;
break;
case 2:
accum=accum-pnum;
break;
case 3:
accum=accum*pnum;
break;
case 4:
accum=accum/pnum;
break;
default:
accum=pnum;
}
}
prop=opr;
num=accum;
printf("%25.5Lf",num);
}
allclear()
{
sq=0;
accum=0;
num=0;
d=0;
newnum=1;
printf("%25.5Lf",num);
}
mem()
{
m=num;
}
recallmem()
{
memo=0;
printf("%25.5Lf",m);
num=m;
}
plusminus()
{ if(num!=0)
{ num*=-1;
printf("%25.5Lf",num);
}
}

plusm()
{
m+=num;
}
minusm()
{
m-=num;
}
clearm()
{
m=0;
}
decimal()
{
if(!d)
{d=1;
if(newnum==1)
{
num=0;
}
printf("%25.5Lf",num);
}
}
square()
{ sq=1;
num*=num;
printf("%25.5Lf",num);
// newnum=1;
}
sqroot()
{ sq=1;
num=pow(num,0.5);
printf("%25.5Lf",num);
// newnum=1;
}
doublezero()
{
if(d)
{
// num=num+pass/(pow(100.0,d));
d++;
d++;
}
else
num*=100;
printf("%25.5Lf",num);
}
clear()
{
num=0;
printf("%25.5Lf",num);
}

You might also like