Custom Search

Tuesday, March 19, 2013

Graphics program in C


Graphics program in C


#include //stdio.h
#include //conio.h
#include //math.h
#include //graphics.h
#include //dos.h
#include"e:\package\SEMI~1\calc\files\buttons.h"

void cleartext(int x1,int y1,int *t);
void operation(double *v1,double *v2,double *temp,double *dec,int *dec_inc,char *op1, char *op2,char t_op,int *flag);
void clear_all(double *v1,double *v2,double *temp,double *dec,int *dec_inc,char *op1, char *op2,int *flag);


char temp1[10];
void main()
{
union REGS i,o;

int x1,y1;
int b_s;
int t=0;
int dec_inc=0,ndigits=0;
int opchkf,new_f,dec_f,n2_f;
double v1,v2,dec,temp;
char op1='a',op2='a',t_op;
int gd = DETECT,gm;
initgraph(&gd,&gm,"e:\\tcpp\\bgi");
settextstyle(3,0,3);
clrscr();
opchkf=new_f=dec_f=0;
v1=v2=dec=temp=0;
buttons();
x1=getmaxx();
y1=getmaxy();
i.x.ax=0;
int86(51,&i,&o);
i.x.ax=1;
int86(51,&i,&o);

while(!kbhit())
{

flushall();
i.x.ax=1;
int86(51,&i,&o);

i.x.ax=3;
int86(51,&i,&o);
b_s=o.x.bx&7;
if(ndigits<9 span="">
{
/*1*/
if((o.x.cx>x1/7+20)&&(o.x.cx<2 amp="" o.x.dx="" x1="">y1/7+30)&&(o.x.dx<2 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+1;
else
{
dec=dec*10+1;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("1");
}

/*4*/
if((o.x.cx>x1/7+20)&&(o.x.cx<2 amp="" o.x.dx="" x1="">2*y1/7+30)&&(o.x.dx<3 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;
opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+4;
else
{
dec=dec*10+4;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("4");
}

/*7*/
if((o.x.cx>x1/7+20)&&(o.x.cx<2 amp="" o.x.dx="" x1="">3*y1/7+30)&&(o.x.dx<4 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+7;
else
{
dec=dec*10+7;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("7");
}

/*2*/
if((o.x.cx>2*x1/7+20)&&(o.x.cx<3 amp="" o.x.dx="" x1="">y1/7+30)&&(o.x.dx<2 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+2;
else
{
dec=dec*10+2;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("2");
}

/*5*/
if((o.x.cx>2*x1/7+20)&&(o.x.cx<3 amp="" o.x.dx="" x1="">2*y1/7+30)&&(o.x.dx<3 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+5;
else
{
dec=dec*10+5;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("5");
}

/*8*/
if((o.x.cx>2*x1/7+20)&&(o.x.cx<3 amp="" o.x.dx="" x1="">3*y1/7+30)&&(o.x.dx<4 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+8;
else
{
dec=dec*10+8;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("8");
}

/*3*/
if((o.x.cx>3*x1/7+20)&&(o.x.cx<4 amp="" o.x.dx="" x1="">y1/7+30)&&(o.x.dx<2 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+3;
else
{
dec=dec*10+3;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("3");
}

/*6*/
if((o.x.cx>3*x1/7+20)&&(o.x.cx<4 amp="" o.x.dx="" x1="">2*y1/7+30)&&(o.x.dx<3 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+6;
else
{
dec=dec*10+6;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("6");
}

/*9*/
if((o.x.cx>3*x1/7+20)&&(o.x.cx<4 amp="" o.x.dx="" x1="">3*y1/7+30)&&(o.x.dx<4 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+9;
else
{
dec=dec*10+9;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("9");
}

/*0*/
if((o.x.cx>2*x1/7+20)&&(o.x.cx<3 amp="" o.x.dx="" x1="">4*y1/7+30)&&(o.x.dx<5 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(new_f==1)
{
new_f=0;

opchkf=0;
cleartext(x1,y1,&t); 
}
if(dec_f==0)
temp=temp*10+0;
else
{
dec=dec*10+0;
dec_inc++;
}
ndigits++;
moveto(x1/5+t,y1/11);
t+=12;
outtext("0");
}
}
/*.*/
if((o.x.cx>1*x1/7+20)&&(o.x.cx<2 amp="" o.x.dx="" x1="">4*y1/7+30)&&(o.x.dx<5 amp="" b_s="=1))</span" y1="">
{
if(n2_f)
{
n2_f=0;
cleartext(x1,y1,&t);
}
if(dec_f==0)
{
dec_f=1;
moveto(x1/5+t,y1/11);
t+=12;
outtext(".");
}
}

/* + */
if((o.x.cx>4*x1/7+20)&&(o.x.cx<5 amp="" o.x.dx="" x1="">y1/7+30)&&(o.x.dx<2 amp="" b_s="=1))</span" y1="">
{
t_op='+';
dec_f=0;
ndigits=0;
n2_f=1;
operation(&v1,&v2,&temp,&dec,&dec_inc,&op1,&op2,t_op,&opchkf);
setfillstyle(1,WHITE);
bar(7*x1/10+14,2*y1/14+4,8*x1/10-10,4*y1/14-30);
moveto(7*x1/10+24,2*y1/14+10);
t+=12;
outtext("+");
}

/* - */
if((o.x.cx>4*x1/7+20)&&(o.x.cx<5 amp="" o.x.dx="" x1="">2*y1/7+30)&&(o.x.dx<3 amp="" b_s="=1))</span" y1="">
{
t_op='-';
dec_f=0;
ndigits=0;
n2_f=1;
operation(&v1,&v2,&temp,&dec,&dec_inc,&op1,&op2,t_op,&opchkf);
setfillstyle(1,WHITE);
bar(7*x1/10+14,2*y1/14+4,8*x1/10-10,4*y1/14-30);
moveto(7*x1/10+24,2*y1/14+10);
t+=12;
outtext("-");

}

/* * */
if((o.x.cx>4*x1/7+20)&&(o.x.cx<5 amp="" o.x.dx="" x1="">3*y1/7+30)&&(o.x.dx<4 amp="" b_s="=1))</span" y1="">
{
t_op='*';
dec_f=0;
ndigits=0;
n2_f=1;
operation(&v1,&v2,&temp,&dec,&dec_inc,&op1,&op2,t_op,&opchkf);
bar(7*x1/10+24,2*y1/14,8*x1/10-10,4*y1/14-30);
moveto(7*x1/10+24,2*y1/14+10);
t+=12;
outtext("*");
delay(100);
}

/* / */
if((o.x.cx>4*x1/7+20)&&(o.x.cx<5 amp="" o.x.dx="" x1="">4*y1/7+30)&&(o.x.dx<5 amp="" b_s="=1))</span" y1="">
{
t_op='/';
dec_f=0;
ndigits=0;
n2_f=1;
operation(&v1,&v2,&temp,&dec,&dec_inc,&op1,&op2,t_op,&opchkf);
bar(7*x1/10+14,2*y1/14,8*x1/10-10,4*y1/14-30);
moveto(7*x1/10+24,2*y1/14+10);
t+=12;
outtext("/");
}

/* = */
if((o.x.cx>3*x1/7+20)&&(o.x.cx<4 amp="" o.x.dx="" x1="">4*y1/7+30)&&(o.x.dx<5 amp="" b_s="=1))</span" y1="">
{
new_f=1;
t_op='=';
ndigits=0;
dec_f=0;
cleartext(x1,y1,&t);
operation(&v1,&v2,&temp,&dec,&dec_inc,&op1,&op2,t_op,&opchkf);
bar(7*x1/10+14,2*y1/14,8*x1/10-10,4*y1/14-30);
moveto(7*x1/10+24,2*y1/14+10);
t+=12;
outtext("=");
moveto(200,400);
outtext("Hit any key to clear....");
getch();
setfillstyle(1,BLACK);
bar(200,400,600,430);
bar(7*x1/10+14,2*y1/14,8*x1/10+120,4*y1/14+60);
clear_all(&v1,&v2,&temp,&dec,&dec_inc,&op1,&op2,&opchkf);
setfillstyle(1,WHITE);
cleartext(x1,y1,&t);
op1=op2='a';
}

b_s=0;
delay(100);
}
getch();
closegraph();
}

void operation(double *v1,double *v2,double *temp,double *dec,int *dec_inc,char *op1, char *op2,char t_op,int *flag)
{
int infy;
*op2 = t_op;
if( *op1 == '=')
{
*op1 = *op2;
}
else
{
*v2 = *temp + *dec*pow(10,-*dec_inc);
*dec=*dec_inc=*temp=0;
if(*flag == 0)
{
*flag = 1;
*op1 = *op2;
*v1 = *v2;
*v2 = 0;
}
else
{
switch(*op1)
{
case '+':
*v1 = *v1 + *v2;
break;
case '-':
*v1 = *v1 - *v2;
break;
case '*':
*v1 = *v1 * *v2;
break;
case '/':
if(*v2!=0)
*v1 = *v1 / *v2;
else
{
outtext("ìììììì");
infy=0;
}
break;
}
if(infy)
{
sprintf(temp1,"%f",*v1);
outtext(temp1);
*op1 = *op2;
*v2 = 0;
}
}

}
}

void cleartext(int x1,int y1,int *t)
{
moveto(x1/5,y1/11);
*t=0;
bar(2*x1/10,y1/10,7*x1/10,2*y1/14);
}

void clear_all(double *v1,double *v2,double *temp,double *dec,int *dec_inc,char *op1, char *op2,int *flag)
{
*v1=*v2=*temp=*dec=*dec_inc=*op1=*op2=*flag=0;
}
 

No comments:

Post a Comment