Monday, November 2, 2009

PROGRAMS


Basic Programs




Programs of Patterns  



 Programs of Recursion


Programs of Function 


Programs of String & Pointer



Programs of Array 
  


Programs of LinkList


Intermediate Programs








Programs of OOPS



Programs of basics of graphics 



 Programs of Advanced graphics

  

If u have ur own code, u can post it here so that others can take benefit from it


If ur program is very big, u can also post it on this email: er.upinder.dhami@gmail.com

Projects and games


Two sentences are given and we were required to print the common word in the two sentences. Words were delimited by space, full stop, ? , ! and , . The trick in the question was that common word should be printed only once so if ur first sentence contains two word "how" and second contains "how" then in output how should be printed only once for this u can replace each matched word in second sentence by spaces .

Wednesday, September 23, 2009

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{    clrscr();
    char str1[500],str2[500];
    char substr1[50][50],substr2[50][50];
    for(int l=0;l<50;l++)
    {    strcpy(substr1[l],"");
        strcpy(substr2[l],"");
    }

    cout<<"enter the first string: ";
    gets(str1);
    cout<<"enter the second string: ";
    gets(str2);
    int i=0,index=0,s1index=0;

    while(str1[i]!='\0')
    {    if(str1[i]==' '||str1[i]=='?'||str1[i]=='.'||str1[i]=='!'||str1[i]=='_')
        {    for(int j=index, k=0;j<i;j++,k++)
            {    substr1[s1index][k]=str1[j];
            }

            substr1[s1index][k]='\0';
            s1index++;
            index=i+1;
        }
        i++;
    }
    index=0;
    s1index=0;
    i=0;
    while(str2[i]!='\0')
    {    if(str2[i]==' '||str2[i]=='?'||str2[i]=='.'||str2[i]=='!'||str2[i]=='_')
        {    for(int j=index, k=0;j<i;j++,k++)
            {    substr2[s1index][k]=str2[j];
            }

            substr2[s1index][k]='\0';
            s1index++;
            index=i+1;
           }
           i++;
    }
    cout<<"repeated words are: ";
    i=0;
     //    for(int g=0;g<5;g++)
     //    {cout<<substr1[g]<<endl;}
     //    for(int d=0;d<5;d++)
     //    {cout<<substr2[d]<<endl;}
    while(strcmp(substr1[i],"")!=0)
    {        int j=0;
         while(strcmp(substr2[j],"")!=0)
        {      if(strcmp(substr1[i],substr2[j])==0)
            cout<<substr1[i];
            j++;
        }
        i++;

    }
    getch();



}

A string of charater is given.Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE. OUTPUT: E or I,J(if equal occurance)

//to find the charater which is repeated most time in string
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    char ch;
    struct node
    {    char info;
        node *link;
    };
    node *start,*q,*p,*r;
    start=NULL;
    cout<<"enter the string: ";
    while((ch=getch())!='\r')
    {       cout<<ch;
        node *p=new node;
        p->info=ch;
        if(start==NULL)
        {    start=p;
            p->link=NULL;
        }
        else
        {       q=start;
            while(q->link!=NULL)
            {    q=q->link;
            }
            q->link=p;
            p->link=NULL;
        }
    }
    char record[50];
    int count[50],idx=0;
    for(int i=0;i<50;i++)
    {    record[i]=NULL;
        count[i]=0;
    }

    while(start!=NULL)
    {       p=start;
        ch=start->info;
        while(p!=NULL)
        {       q=p->link;
            if(q->info==ch)
            {       p->link=q->link;
                delete q;
                count[idx]++;
                continue;

            }
            p=p->link;
        }
        if(count[idx]==count[0])
        {    record[idx]=ch;

            idx++;
        }
        if(count[idx]>count[0])
        {       count[0]=count[idx];
            for(int i=1;i<50;i++)
            {    count[i]=0;
                record[i]=NULL;
            }

            idx=0;
            record[idx]=ch;
            idx++;
        }
        start=start->link;

    }
    cout<<"\nmaximum occurance numbers are: ";
    i=0;
    while(record[i]!=NULL)
    {    cout<<record[i]<<", ";
        i++;
    }

    getch();
}

program to convert binary number into decimal number in c++

//binary to decimal conversion
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{       clrscr();
    int num[50];
    char ch,st[2];
    for(int i=0;i<50;i++)
    num[i]=-1;

    i=0;
    cout<<"enter the binary number: ";
    while((ch=getch())!='\r')
    {
        cout<<ch;
        st[0]=ch;
        st[1]='\0';
        num[i]=atoi(st);
        i++;
    }
    int max=0,sum=0,m=0;
    while(num[max]!=-1)
    max++;

    max--;
    cout<<endl<<endl;
    while(max>=0)
    {    sum=sum+(num[max]*pow(2,m));
        max--;m++;
    }
    cout<<endl<<sum;
    getch();

}

there is a matrix N x N .Its elements consist of either value =1 or value=0. If there is a any zero in the row, then the output matrix should have all zeroes in that row. If there is a single zero in any column then that column should have all zeroes n the output matrix.

#include<iostream.h>
#include<conio.h>
void main()
{    clrscr();
    int mat[50][50],r,c,stack[500],id=0;
    for(int i=0;i<500;i++)
    stack[i]=-1;

    cout<<"enter the number of rows and columns resp: ";
    cin>>r>>c;
    cout<<"enter the elements: ";
    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       cin>>mat[i][j];
        }
    }
    cout<<"ur entered matrix is: "<<endl;
    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       cout<<mat[i][j]<<" ";
        }
        cout<<endl;
    }

    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       if(mat[i][j]==0)
            {    stack[id]=i;
                id++;
                stack[id]=j;
                id++;
            }
        }
    }
    int k=0;

    while(stack[k]!=-1)
    {    for(i=0;i<r;i++)
        {    for(int j=0;j<c;j++)
            {    mat[(stack[k])][j]=0;
            }
            mat[i][(stack[k+1])]=0;
        }
        k+=2;
    }
    cout<<"after ur operation ur matrix become:\n";
    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       cout<<mat[i][j]<<" ";
        }
        cout<<endl;
    }

    getch();
}

Solved Placement papers of different IT companies

Monday, September 21, 2009

Solved C& C++ technical paper of Nagarro

Program to find the factorial of a large number

Thursday, September 10, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,i,k,a[200],temp,index,n,x,test;
cout<<"enter the no. of test cases";
cin>>test;
while(test>0)
{
cout<<endl<<"enter the number ";
cin>>num;
k=num;
for(i=0;k>=1;i++)
{
  a[i]=k%10;
  k=k/10;
    }


   for(n=1;n<num;n++)
   {
   temp=0;

      for(index=0;index<i;index++)
      {
            x=a[index]*n+temp;
            a[index]=x%10;
            temp=x/10;
            }

            while(temp!=0)
            {
               a[index]=temp%10;
               temp=temp/10;
               index++;
               i++;
                 }
}
for(i=index-1;i>=0;i--)
cout<<a[i];
test--;}
clrscr();
cout<<"made by anil";

        getch();



        }

project of shooting game

Tuesday, September 1, 2009

#include<iostream.h>
#include<alloc.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>;
#include<graphics.h>
void front_page();
void second_page();
void final_page();
    long o=0,g=0,a=20;
    float v;
    char w;
void main()
{    int gde=DETECT,gme;
    initgraph(&gde,&gme,"c:\\tc");
    mit:           //label
    front_page();
    w=getch();
    switch(w)
    {    case '1':v=1.2; break;
        case '2':v=2.0; break;
        case '3':v=5; break;
        default: goto mit;
    }
    cleardevice();
    int c=0;
    char *h;
    second_page();
    int maxx,maxy,area,x=580,ch,xdirn=1,ydirn=1;
    float y=25;
    void *buff;
    setcolor(WHITE);
    setfillstyle(SOLID_FILL,RED );
    circle(605,50,25);
    floodfill(605,50,WHITE);
    area=imagesize(580,25,630,75);
    buff=malloc(area);
    getimage(580,25,630,75,buff);
    maxx=getmaxx();
    maxy=getmaxy();
    while(1)
    {    putimage(x,y,buff,XOR_PUT);
        //delay(0);
        y=y+(ydirn*v);
        putimage(x,y,buff,XOR_PUT);
        if(y>maxy-50||y<20)
        {    c=0;
            sound(130);
            delay(5);
            nosound();
            ydirn*=-1;
        }
        int marea,m=98,n=235,ch,mdirn=1,ndirn=1,mn;
        int maxm,maxn,narea,buffn;
        void *buffe;
        setcolor(DARKGRAY);
        setfillstyle(SOLID_FILL,DARKGRAY );
        rectangle(98,235,105,239);
        floodfill(101,237,DARKGRAY);
        marea=imagesize(98,235,105,239);
        buffe=malloc(marea);
        getimage(98,235,105,239,buffe);
        maxm=getmaxx();
        maxn=getmaxy();
        gotoxy(2,10);
        int in;
        cout<<"BULLETS REMAINING = ";
        for(in=0;in<=a-1;in++)
        {    cout<<"!";
        }
        if(kbhit())
        {    mn=getch();
            char *bul;
            if(a==0)
            break;
            if((mn==115||mn==83) &&c==0)
            {    a=a-1;
                cout<<0;
                sound(9999);
                delay(10);
                c++;
                nosound();
                while(m<=maxm)
                {    putimage(m,n,buffe,XOR_PUT);
                    m=m+(mdirn*2);
                    delay(0);
                    putimage(m,n,buffe,XOR_PUT);
                    gotoxy(11,3);
                    cout<<g;
                    if(m==maxm-51 && (y<=235 && y+25>=205))
                    {    g=g+10;
                        o=g;
                        sound(2200);
                        delay(900);
                        putimage(700,25,buff,XOR_PUT);
                        nosound();
                    }
                }
            }
            else
            {    if(mn==27)
                break;
            }
        }
    }
    cleardevice();
    final_page();
    getch();
    closegraph();
}
void front_page()
{    setbkcolor(GREEN);
    setcolor(WHITE);
    setfillstyle(SOLID_FILL,RED );
    circle(505,190,50);
    floodfill(505,190,WHITE);
    setcolor(BROWN);
    line(0,235,35,235);
    line(0,235,0,258);
    line(35,240,35,235);
    line(0,258,35,240);
    setfillstyle(1,BROWN);
    floodfill(2,240,BROWN);
    setcolor(DARKGRAY);
    line(35,235,102,235);
    line(35,240,35,235);
    line(35,240,102,240);
    line(102,235,102,240);
    setfillstyle(1,DARKGRAY);
    floodfill(99,236,DARKGRAY);
    arc(35,220,250,310,25);
    line(35,242,38,243);
    settextstyle(1,0,1);
    setcolor(BLUE);
    outtextxy(200,300,"MADE BY :- MOHIT VASHISHT");
    outtextxy(200,317,"E_MAIL   :- mohitvashisht88@yahoo.com");
    settextstyle(4,0,5);
    outtextxy(200,50,"SHOOTING");
    outtextxy(250,120,"GAME");
    gotoxy(20,12);
    cout<<" 1 : EASY";
    gotoxy(20,13);
    cout<<" 2 : MEDIUM";
    gotoxy(20,14);
    cout<<" 3 : TOUGH";
    gotoxy(10,16);
    cout<<"ENTER THE LEVEL = ";
}
void second_page()
{    setcolor(BROWN);
    setbkcolor(YELLOW);
    line(0,235,35,235);
    line(0,235,0,258);
    line(35,240,35,235);
    line(0,258,35,240);
    setfillstyle(1,BROWN);
    floodfill(2,240,BROWN);
    setcolor(DARKGRAY);
    line(35,235,102,235);
    line(35,240,35,235);
    line(35,240,102,240);
    line(102,235,102,240);
    setfillstyle(1,DARKGRAY);
    floodfill(99,236,DARKGRAY);
    arc(35,220,250,310,25);
    line(35,242,38,243);
    outtextxy(10,35,"SCORE");
    outtextxy(10,50,"FIRE");
    outtextxy(50,50,"S");
    outtextxy(10,65,"EXIT");
    outtextxy(50,65,"esc");
}
void final_page()
{    setcolor(BROWN);
    setbkcolor(RED);
          for(int x=1;x<=4;x++)
    {
        clrscr();
        setbkcolor(RED);
        delay(100);
        gotoxy(31,12);
        cout<<"YOUR SCORE = "<<o;
        sound(2200);
        delay(750);
        nosound();
    }
    gotoxy(28,16);
    cout<<"PRESS ANY KEY TO EXIT";
}

graphical project of students database

#include<iostream.h>
 #include<conio.h>
 #include<stdio.h>
 #include<string.h>
 #include<process.h>
 #include<fstream.h>
 #include<dos.h>
 #include<graphics.h>
 #include "c:/tc/file1.cpp"
 #include "c:/tc/file2.cpp"
 char fname[]="c:/temp1.bin";

 class student
 {
     char name[20],fees[20],rollno[20],e_mail[20];
     public:
     int input();
     void output(int,int);
     int compare(char r[]);
 };

 struct node
 {
     student info;
     node *link;
 };

  class linklist
  {
     node * start;
     public:
     linklist()
     {
      start=NULL;
     }
     void file2list();
     void list2file();
     void insert(student);
     void show();
     void search();
     void delete1();
     void modify();
  };


  void linklist::file2list()
  {
      ifstream f;
      f.open(fname,ios::binary);
      student n;
      if(f.fail())
      {
       cout<<"\n FILE COULD NOT BE OPENED:";
       return;
      }
      while(1)
      {
        f.read((char*)&n,sizeof(n));
        if(f.eof())
        break;
        insert(n);
      }
      f.close();
  }


  void linklist::list2file()
  {
     ofstream f;
     f.open(fname,ios::binary);
     student n;
     node*p=start;
     while(p!=NULL)
     {
         n=p->info;
         f.write((char*)&n,sizeof(n));
         p=p->link;
     }
     f.close();
  }


  int student::input()
  {
     char s[4][50];
     int a;
     a=showform(s,4);
     if(a==0)
     return 0;
     else
     {
          strcpy(rollno,s[0]);
          strcpy(name,s[1]);
          strcpy(fees,s[2]);
          strcpy(e_mail,s[3]);
          return 1;
     }
  }

  void student::output(int x,int y)
  {
     outtextxy(x,y,rollno);
     outtextxy(x+100,y,name);
     outtextxy(x+200,y,fees);
     outtextxy(x+300,y,e_mail);

  }


  int student::compare(char r[10])
  {
     if(strcmp(rollno,r)==0)
     {
         return 1;
     }
     else
     {
          return 0;
     }
   }

void linklist::delete1()
 {     char temp[20];
       cout<<"Enter the roll no. whose record u want to delete:-> ";
       gets(temp);
       student n;
       node *p,*q;
       int i=0;
       p=start;
       q=p->link;
       if(start==NULL)
       {    cout<<"Linked list is empty";
        getch();
        return;
       }
       while(q!=NULL)
       {     n=q->info;
        if(n.compare(temp)==1)
        {    i++;
         p->link=q->link;
         q->link=NULL;
         delete q;
         cout<<"\n\n     Record is successfully deleted";
         break;

        }
        p=p->link;
        q=q->link;
       }

      if(i==0)
      cout<<"\n\n\n     NO RECORD FOUND";


 }
  void linklist::search()
  {
      student n;
      char k[10];
      cout<<"\n ENTER THE ROLL NO THAT U WANT TO SEARCH:";
      cin>>k;
      int z=0;
      node *p=start;
      while(p!=NULL)
      {
           n=p->info;
           if(n.compare(k)==1)
           {
            cout<<"\n RECORD IS FOUND:";
            n.output(100,80);
            z++;
           }
           p=p->link;
       }
       if(z==0)
       {
           cout<<"\n RECORD IS NOT FOUND:";
       }
   }


  void linklist::insert(student n)
  {
       node*q=new node;
       q->info=n;
       q->link=NULL;
       if(start==NULL)
       {
        start=q;
       }
       else
       {
        node* p=start;
        while(p->link!=NULL)
        {
              p=p->link;
        }
        p->link=q;
        }
  }

  void linklist::show()
  {
        cleardevice();
        student n;
        node *p=start;
        int a=10,b=30;
        while(p!=NULL)
        {
         n=p->info;
         n.output(a,b);
         b+=30;
         p=p->link;
        }
  }

  void linklist::modify()
  {
       char temp[20];
       cout<<"enter the roll no. whose record u want to modify:->  ";
       gets(temp);
       student n;
       node *p,*q;
       int i=0;
       p=start;
       q=p->link;
       if(start==NULL)
       {    cout<<"\n\n\n   Linked list is empty";
        getch();
        return;
       }
       while(q!=NULL)
       {     n=q->info;
        if(n.compare(temp)==1)
        {    i++;
         cout<<"Privious record is:->  "<<endl;
         n.output(100,80);
         getch();
         cleardevice();
         cout<<"\n\n    Now enter new record:->  ";
         n.input();
         q->info=n;
         cout<<"\n\n\n\n\n\n\n\n\n\n        Record is successfully modify";
         break;
         }
        p=p->link;
        q=q->link;
       }

      if(i==0)
      cout<<"\n\n    NO RECORD FOUND";

  }

  void main()
  {
      int d,m;
      d=DETECT;
      initgraph(&d,&m,"c:/tc");

      student n;
      char choice;
      linklist l;
      l.file2list();
      while(1)
      {
         cleardevice();
         choice=mmenu();
         cleardevice();
         setbkcolor(0);
         settextstyle(0,0,0);
         switch (choice)
         {
          case 1:
          if(n.input()==1)
          {
               l.insert(n);
               l.list2file();
          }
          break;

          case 2:
          l.show();
          break;
          case 3:
          l.search();
          break;
          case 4:
          l.delete1();
          l.list2file();
          break;
          case 5:
          l.modify();
          l.list2file();
          break;
          case 6:
          exit(0);
         }
         getch();
       }
  }







?///////////////////////////////////////////////////////////////////////////////////
//////////////////////////file1////////////////////////////////////////////////////


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<process.h>
int color;
void arrow(int xx,int yy,int color)
{   setcolor(color);
    int a[]={xx-50,yy+7,xx-40,yy+7,xx-20,yy+20,xx-40,yy+33,xx-50,yy+33,xx-50,yy+26,xx-40,yy+26,xx-27,yy+20,xx-40,yy+14,xx-50,yy+14,xx-50,yy+7};
    drawpoly(11,a);
    setfillstyle(1,color);
    floodfill(xx-40,yy+10,color);
}

void msetfocus(int l,int r,int t,int b,char s[])
{    arrow(l,t,8);
     setcolor(15);
     rectangle(l,t,r,b);
     setfillstyle(1,15);
     floodfill(l+2,t+2,15);
     setcolor(6);
     outtextxy(l+5,t,s);
}

void mlostfocus(int l,int r,int t,int b,char s[])
{    arrow(l,t,7);
     setcolor(7);
     rectangle(l,t,r,b);
     setfillstyle(1,7);
     floodfill(l+2,t+2,7);
     setcolor(6);
     outtextxy(l+5,t,s);
}

void men(char x[][50],int msize,int hl)
{
     int lf,tp,rh,bt;
     lf=175;
     rh=lf+225;
     tp=150;
     bt=tp+40;
     setcolor(5);
     settextstyle(1,HORIZ_DIR,4);
     outtextxy(140,60,x[0]);

     settextstyle(1,HORIZ_DIR,2);
     for(int i=1;i<=msize;i++)
     {   if(i==hl)
     msetfocus(lf,rh,tp,bt,x[i]);
     else
     mlostfocus(lf,rh,tp,bt,x[i]);
     tp+=40;
     bt+=40;
     }
}

void getkey(int &j,int &k,int &l)
{    REGS n,m;
     m.h.ah=0X00;
     int86(22,&m,&n);
     j=n.h.ah;
     k=n.h.al;
     m.h.ah=0X02;
     int86(22,&m,&n);
     l=n.h.al;
}

int mmenu()
{
settextstyle(1,HORIZ_DIR,2);
setbkcolor(7);
int ac,sc,st,z=1;
char mstr[][50]={"STUDEMT'S DATABASE","INSERT NEW RECORD ","SHOW ALL RECORD","SEARCH A RECORD","DELETE A RECORD ","MODIFY A RECORD","EXIT"};
while(1)
{
    men(mstr,6,z);
    getkey(sc,ac,st);
       /*sound(7);
    delay(100);
    nosound();   */
    if(sc==72 && z>=1)
    {
          if(z==1)
          {    z=6;
           continue;
          }
          z--;
    }
    else if(sc==80&& z<=6)
    {
          z++;
          if(z==7)
          z=1;
    }
    else if(sc==1)
    return 0;

    else if(sc==28)
    { return z;
    }
}
getch();
}





//////////////////////////////////////////////////////////////////////////
/////////////////////////file2///////////////////////////////////////////


void setfocus(int,int,int,int,char*);
void lostfocus(int,int,int,int,char*);
void lostfocus1(int,int,int,int,char*);

int showform(char str[][50],int n)
{
cleardevice();
int z;
int cur=0,max=0;
int lf=200,rh=320,tp=20,bt=40;
char s1[2],s2[50];
int s,a,p;

   strcpy(s2,"");
   outtextxy(50,28,"ROLL NO.->");
   outtextxy(50,78,"NAME ->");
   outtextxy(50,128,"FEE ->");
   outtextxy(50,178,"E_MAIL ->");
   setfocus(lf,tp,rh,bt,s2);

   for(int i=0;i<n;i++)
   strcpy(str[i],"");

   while(1)
   {
   getkey(s,a,p);
    z=p&4;
   if(s==1)
   return 0;
   else if(z==4 && s==31 )
   return 1;
//  up arrow key

   else if(s==72)
   {
   if(cur>0)
   {
    lostfocus1(lf,tp,rh,bt,str[cur]);
    lostfocus(lf,tp,rh,bt,str[cur]);
    cur--;
    strcpy(s2,str[cur]);
    tp=tp-50;
    bt=tp+20;
   }
   }
// down arrow key

   else if(s==80)
  {
   if(cur<=max-1)
   {
    lostfocus1(lf,tp,rh,bt,str[cur]);
    lostfocus(lf,tp,rh,bt,str[cur]);
    cur++;
    strcpy(s2,str[cur]);
    tp=tp+50;
    bt=tp+20;
   }
  }

// enter key

   else if(a==13)
   {
   if(strlen(s2)!=0)
   {
   strcpy(str[cur],s2);

    if(max<n-1)
    {
    max++;
    }
   if(cur<=max-1)
   {
   cur++;
   lostfocus(lf,tp,rh,bt,s2);
   if(cur==max&&max<n-1)
   strcpy(s2,"");
   else
   strcpy(s2,str[cur]);

   tp=tp+50;
   bt=tp+20;
   }
   }
   }
   else
   {
     if(a==8)
     {

//code for backspace key
     if(strlen(s2)>0)
     s2[strlen(s2)-1]='\0';
     }
     else
     {
// code for any other alphabet

    s1[0]=a;
    s1[1]='\0';
    strcat(s2,s1);
    }
    }
   setfocus(lf,tp,rh,bt,s2);


  }
}

 // Function to write the string in the text box

void setfocus(int a,int b,int c,int d,char *f)
{
 setcolor(GREEN);
 rectangle(a,b,c,d);
 setfillstyle(SOLID_FILL,BLACK);
 floodfill(a+2,b+2,GREEN);
 setcolor(YELLOW);
 outtextxy(a+3,b+3,f);
}

 // Function to wash the rectangle in black

void lostfocus(int a,int b,int c,int d,char *f)
{
 setcolor(BLACK);
 rectangle(a,b,c,d);
 setfillstyle(SOLID_FILL,BLACK);
 floodfill(a+2,b+2,BLACK);
 setcolor(WHITE);
 outtextxy(a+3,b+3,f);
}

// Function called before lostfocus to wash the rectangle

void lostfocus1(int a,int b,int c,int d,char *f)
{
 setcolor(BLUE);
 rectangle(a,b,c,d);
 setfillstyle(SOLID_FILL,BLACK);
 floodfill(a+2,b+2,BLUE);
 setcolor(WHITE);
 outtextxy(a+3,b+3,f);
}

project of three dimensional calculator working with mouse

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<process.h>

int aaa=247,bbb=167,l2,status,rep=0,mul=0;
char ch,st2[50],st1[2];
double f1=0,f2=0,d1=0,d2=0,d3=0;
void buttan1(int,int,int,int);
void buttan(int,int,int,int);
void text();
void screen(char);
void scremt();
void main()
{         int d,mm,e,a,b,c,k;
      d=DETECT;
      initgraph(&d,&mm,"c:/tc");
      e=graphresult();

      if(e!=0)
      {
          cout<<"Graphics not inialised";
          getch();
          return;
       }

       setbkcolor(BLUE);
       setcolor(7);
       rectangle(aaa-10,bbb-50,aaa+153,bbb+150);
       setfillstyle(1,7);
       floodfill(aaa,bbb,7);

       setcolor(15);
       int f[]={aaa-15,bbb-55,aaa+158,bbb-55,aaa+153,bbb-50,aaa-10,bbb-50,aaa-10,bbb+150,aaa-15,bbb+155,aaa-15,bbb-55};
       drawpoly(7,f);
       setfillstyle(1,15);
       floodfill(aaa-12,bbb-42,15);

       setcolor(8);
       int h[]={aaa+158,bbb-55,aaa+158,bbb+155,aaa-15,bbb+155,aaa-10,bbb+150,aaa+153,bbb+150,aaa+153,bbb-50,aaa+158,bbb-55};
       drawpoly(7,h);
       setfillstyle(1,8);
       floodfill(aaa+156,bbb-40,8);

       for(int ii=1;ii<17;ii++)
       {
          buttan(aaa,bbb,15,8);
          aaa+=39;
          if(ii%4==0)
          {  bbb+=39;
         aaa=247;
          }
       }
       buttan1(236,75,15,8);
       buttan1(350,75,15,8);
       aaa=247;
       bbb=167;
       text();
       scremt();


    REGS n,m;
    n.x.ax=0;
    int86(0x33,&n,&m);
    k=m.x.ax;
    if(k==0)
    return;
    int aa,bb,t1,t2;
    while(1)
    {  n.x.ax=1;
       int86(0x33,&n,&m);
       n.x.ax=3;
       int86(0x33,&n,&m);
       a=m.x.cx;
       b=m.x.dx;
       c=m.x.bx;
       // FOR EXIT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       if(c==1 && a>350 && a<400 && b>75 && b<100)
       {    buttan1(350,75,8,15);
        delay(200);
        cleardevice();
        cleardevice();
        setcolor(RED);
        outtextxy(50,50,"MADE BY:");
        outtextxy(50,80,"UPINDER SINGH DHAMI");
        outtextxy(50,110,"B.TECH (FIFTH SEM)");
        outtextxy(50,140,"ELECTRONICS AND COMM ENGG");
        outtextxy(50,170,"GURU NANAK DEV UNIVERSITY (AMRITSAR)");
        outtextxy(50,200,"DATE: 17\\07\\2008");
        delay(7000);
        return;
       }
       // FOR RECET XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       if(c==1 && a>236 && a<286 && b>75 && b<100)
       {    rep=0;
        mul=0;
        buttan1(236,75,8,15);
        delay(200);
        buttan1(236,75,15,8);
        strcpy(st2,"");
        screen(' ');
        scremt();
       }

       // FOR  FIRST   ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       // FOR 7
       if(c==1 && a>aaa && a<(aaa+25) && b>bbb && b<(bbb+25))
       {
      buttan(aaa,bbb,8,15);
      delay(200);
      buttan(aaa,bbb,15,8);
      screen('7');
      mul=0;
      continue;
       }

       // FOR 8
       if(c==1 && a>(aaa+39) && a<(aaa+64) && b>bbb&&b<(bbb+25))
       {
       buttan((aaa+39),bbb,8,15);
       delay(200);
       buttan((aaa+39),bbb,15,8);
       screen('8');
       mul=0;
       continue;
       }

       // FOR 9
       if(c==1 && a>(aaa+78) && a<(aaa+103) && b>bbb&&b<(bbb+25))
       {
       buttan((aaa+78),bbb,8,15);
       delay(200);
       buttan((aaa+78),bbb,15,8);
       screen('9');
       mul=0;
       continue;
       }

       // FOR +
       if(c==1 && a>(aaa+117) && a<(aaa+142) && b>bbb&&b<(bbb+25))
       {   rep++;
       mul++;
       if(mul==2)
       { rep--;
         mul--;
       }
       if(rep==2)
       goto label;
       status=2;
       buttan((aaa+117),bbb,8,15);
       delay(200);
       buttan((aaa+117),bbb,15,8);
       d1=f1;
       strcpy(st2,"");
       scremt();
       continue;
       }

       //FOR SECOND ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       // FOR 4
       if(c==1 && a>aaa && a<(aaa+25) && b>(bbb+39) && b<(bbb+64))
       {
      buttan(aaa,bbb+39,8,15);
      delay(200);
      buttan(aaa,bbb+39,15,8);
      screen('4');
      mul=0;
      continue;
       }

       //FOR 5
       if(c==1 && a>(aaa+39) && a<(aaa+64) && b>(bbb+39) && b<(bbb+64))
       {
      buttan(aaa+39,bbb+39,8,15);
      delay(200);
      buttan(aaa+39,bbb+39,15,8);
      screen('5');
      mul=0;
      continue;
       }

       //FOR 6
       if(c==1 && a>(aaa+78) && a<(aaa+103) && b>(bbb+39) && b<(bbb+64))
       {
      buttan(aaa+78,bbb+39,8,15);
      delay(200);
      buttan(aaa+78,bbb+39,15,8);
      screen('6');
      mul=0;
      continue;
       }

       //FOR -
       if(c==1 && a>(aaa+117) && a<(aaa+142) && b>(bbb+39) && b<(bbb+64))
       {   rep++;
       mul++;
       if(mul==2)
       { rep--;
         mul--;
       }
       if(rep==2)
       goto label;
      status=3;
      buttan(aaa+117,bbb+39,8,15);
      delay(200);
      buttan(aaa+117,bbb+39,15,8);
      d1=f1;
      strcpy(st2,"");
      scremt();
      continue;
       }

       // FOR THIRD ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       // FOR 1
       if(c==1 && a>aaa && a<(aaa+25) && b>(bbb+78) && b<(bbb+103))
       {
      buttan(aaa,bbb+78,8,15);
      delay(200);
      buttan(aaa,bbb+78,15,8);
      screen('1');
      mul=0;
      continue;
       }

       //FOR 2
       if(c==1 && a>(aaa+39) && a<(aaa+64) && b>(bbb+78) && b<(bbb+103))
       {
      buttan(aaa+39,bbb+78,8,15);
      delay(200);
      buttan(aaa+39,bbb+78,15,8);
      screen('2');
      mul=0;
      continue;
       }

       //FOR 3
       if(c==1 && a>(aaa+78) && a<(aaa+103) && b>(bbb+78) && b<(bbb+103))
       {
      buttan(aaa+78,bbb+78,8,15);
      delay(200);
      buttan(aaa+78,bbb+78,15,8);
      screen('3');
      mul=0;
      continue;
       }

       //FOR *
       if(c==1 && a>(aaa+117) && a<(aaa+142) && b>(bbb+78) && b<(bbb+103))
       {   rep++;
       mul++;
       if(mul==2)
       { rep--;
         mul--;
       }
       if(rep==2)
       goto label;
      status=1;
      buttan(aaa+117,bbb+78,8,15);
      delay(200);
      buttan(aaa+117,bbb+78,15,8);
      d1=f1;
      strcpy(st2,"");
      scremt();
      continue;
       }

       // FOR FORTH ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       // FOR 0
       if(c==1 && a>aaa && a<(aaa+25) && b>(bbb+117) && b<(bbb+142))
       {
      buttan(aaa,bbb+117,8,15);
      delay(200);
      buttan(aaa,bbb+117,15,8);
      screen('0');
      mul=0;
      continue;
       }

       // FOR .
       if(c==1 && a>(aaa+39) && a<(aaa+64) && b>(bbb+117) && b<(bbb+142))
       {
      buttan(aaa+39,bbb+117,8,15);
      delay(200);
      buttan(aaa+39,bbb+117,15,8);
      screen('.');
      mul=0;
      continue;
       }

       // FOR =
       if(c==1 && a>(aaa+78) && a<(aaa+103) && b>(bbb+117) && b<(bbb+142))
       {
      buttan(aaa+78,bbb+117,8,15);
      delay(200);
      buttan(aaa+78,bbb+117,15,8);
      label:
      if(status==1)
      {  d2=f1;
         d3=d1*d2;
      }
      if(status==2)
      {  d2=f1;
         d3=d1+d2;
      }
      if(status==3)
      {  d2=f1;
         d3=d1-d2;
      }
      if(status==4)
      {  d2=f1;
         d3=d1/d2;
      }
      char temp[50];
      int sig = 10;

      gcvt(d3, sig, temp);
      strcpy(st2,"");
      strcpy(st2,temp);
      scremt();
      screen(' ');
      rep=0;
      mul=0;
      continue;
       }

       // FOR %
       if(c==1 && a>(aaa+117) && a<(aaa+142) && b>(bbb+117) && b<(bbb+142))
       {   rep++;
       mul++;
       if(mul==2)
       { rep--;
         mul--;
       }
       if(rep==2)
       goto label;
      status=4;
      buttan(aaa+117,bbb+117,8,15);
      delay(200);
      buttan(aaa+117,bbb+117,15,8);
      d1=f1;
      strcpy(st2,"");
      scremt();
      continue;
       }

    }
 getch();
closegraph();
}

       void buttan(int x, int y,int ltcolor,int rtcolor)
       {

           setcolor(7);
           rectangle(x,y,x+25,y+25);
           setfillstyle(1,7);
           floodfill(x+2,y+2,7);

           setcolor(ltcolor);
           int a[]={ x-2,y-2,x+27,y-2,x+25,y,x,y,x,y+25,x-2,y+27,x-2,y-2};
           drawpoly(7,a);
           setfillstyle(1,ltcolor);
           floodfill(x-1,y+5,ltcolor);

           setcolor(rtcolor);
           int b[]={x+27,y-2,x+27,y+27,x-2,y+27,x,y+25,x+25,y+25,x+25,y,x+27,y-2 };
           drawpoly(7,b);
           setfillstyle(1,rtcolor);
           floodfill(x+26,y+5,rtcolor);
        }
        void text()
        {  setcolor(4);
           outtextxy(aaa+9,bbb+10,"7");
           outtextxy(aaa+48,bbb+10,"8");
           outtextxy(aaa+87,bbb+10,"9");
           outtextxy(aaa+126,bbb+10,"+");
           outtextxy(aaa+9,bbb+49,"4");
           outtextxy(aaa+48,bbb+49,"5");
           outtextxy(aaa+87,bbb+49,"6");
           outtextxy(aaa+126,bbb+49,"-");
           outtextxy(aaa+9,bbb+88,"1");
           outtextxy(aaa+48,bbb+88,"2");
           outtextxy(aaa+87,bbb+88,"3");
           outtextxy(aaa+126,bbb+88,"*");
           outtextxy(aaa+9,bbb+127,"0");
           outtextxy(aaa+48,bbb+124,".");
           outtextxy(aaa+87,bbb+127,"=");
           outtextxy(aaa+126,bbb+127,"%");
           outtextxy(243,85,"RESET");
           outtextxy(361,85,"EXIT");
           settextstyle(7,HORIZ_DIR,1);
           outtextxy(aaa+50,bbb+250,"MADE BY: UPINDER SINGH DHAMI");

           settextstyle(0,0,1);
        }
        void screen(char ch)
        {  setcolor(15);
           rectangle(aaa-5,bbb-40,aaa+148,bbb-10);
           setfillstyle(1,15);
           floodfill(aaa,bbb-20,15);
       //    outtextxy(aaa+140,bbb,"0.");
           scremt();
           if(ch!='a')
           {
           setcolor(1);
           st1[0]=ch;
           st1[1]='\0';
           strcat(st2,st1);
           }
           l2=strlen(st2);
           if(l2>19)
           {        scremt();
            setcolor(BLUE);
            outtextxy(250,136," data overflow");
            return;
           }
           f1 = atof(st2);
           outtextxy(395-(l2*8),136,st2);

        }
        void scremt()
        {  setcolor(14);
           rectangle(aaa-5,bbb-40,aaa+148,bbb-10);
           setfillstyle(1,14);
           floodfill(aaa,bbb-20,14);
        }

        void buttan1(int x, int y,int ltcolor,int rtcolor)
        {

           setcolor(7);
           rectangle(x,y,x+50,y+25);
           setfillstyle(1,7);
           floodfill(x+2,y+2,7);

           setcolor(ltcolor);
           int a[]={ x-4,y-4,x+54,y-4,x+50,y,x,y,x,y+25,x-4,y+29,x-4,y-4};
           drawpoly(7,a);
           setfillstyle(1,ltcolor);
           floodfill(x-3,y-3,ltcolor);

           setcolor(rtcolor);
           int b[]={x+54,y-4,x+54,y+29,x-4,y+29,x,y+25,x+50,y+25,x+50,y,x+54,y-4};
           drawpoly(7,b);
           setfillstyle(1,rtcolor);
           floodfill(x+52,y+10,rtcolor);

           setcolor(1);

        }