728x90 AdSpace

Latest Article



C C++ Employee Class Implementation with Menu or graphics





Employee Class Implementation with Menu or graphics in C C++ Programming Language code example code assignment home work


#include <iostream.h>
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include<graphics.h>
#include<stdlib.h>
#define NMAX 30
void  showmouseptr();
void  restrictmouseptr(int x1,int y1,int x2,int y2);
void  getmousepos(int *button,int *x,int *y);
union REGS i,o;
 initmouse();
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
void showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void  restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}
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 butt()
{
setfillpattern(0*55, RED);
   bar(200,200,350,220);
   rectangle(200,200,350,220);
   outtextxy(210,196,"1: Add New");
      bar(200,225,350,245);
   rectangle(200,225,350,245);
   outtextxy(200,221,"2 :modify");
     bar(200,250,350,270);
   rectangle(200,250,350,270);
    outtextxy(200,246, "3: delete");
      bar(200,275,350,295);
   rectangle(200,275,350,295);
   outtextxy(200,271, "4: display");
      bar(200,300,350,320);
   rectangle(200,300,350,320);
   outtextxy(200,296, "5: exit");
  // outtextxy(200,296, "5: exit");

}
int mouseclick()
    {int button,x,y;
    char flag;
     while(!kbhit())
{
 getmousepos(&button,&x,&y);
if((button & 1)==1)
{
if((x>200)&&(x<350)&&(y>200)&&(y<220))
{ flag='1' ;
 break;}
 if((x>200)&&(x<350)&&(y>225)&&(y<245))
{  flag='2';
 break;}
 else if((x>200)&&(x<350)&&(y>250)&&(y<270))
{ flag='3';
 break;}
 else if((x>200)&&(x<350)&&(y>275)&&(y<295))
 {flag='4';
 break;}
 else if((x>200)&&(x<350)&&(y>300)&&(y<320))
 {flag='5';
  break;}
  else if((x>200)&&(x<350)&&(y>380)&&(y<400))
   break;

 }}
 return(flag);
 };

struct edate
  {
    int dd;
    int mm;
    int yy;
  };

class box
{
 private:
int row;
int col;
int rowwidth;
int colwidth;
int startx;
int starty;
char *text[10];
 public:
box(int r,int c,int rw,int cw,int x,int y)
      {
row=r;
col=c;
rowwidth=rw;
colwidth=cw;
startx=x;
starty=y;
}
      ///////////////////////////Draw Box
      void draw()
      {
int i, j,y,x;

// Draw rows
y = starty;
gotoxy(startx,starty);
// Rows Display




for(i=1;i<=row+1;i++)
{
   for(j=startx;j<startx+col+col*colwidth;j++)
     {
cout << "Í";
     }
   y=starty+i+i*rowwidth;
   gotoxy(startx,y);
}

///////// Col Display
x=startx;
gotoxy(startx,starty);

 for(i=1;i<=col+1;i++)
{

   for(j=starty;j<starty+1+row+row*rowwidth;j++)
     {
cout << "º";
gotoxy(x,j);
     }
   x=startx+i+i*colwidth;
   gotoxy(x,starty);
}

      // Set Four Corners
 gotoxy(startx,starty);
 cout << "É";
 gotoxy(startx+col+col*colwidth,starty);
 cout << "»";
 gotoxy(startx,starty+row+row*rowwidth);
 cout << "È";
 gotoxy(startx+col+col*colwidth,starty+row+row*rowwidth);
 cout << "¼";

// Upper Middle Conectors
 for(i=1;i<=col-1;i++)
 {
    gotoxy(startx+i+colwidth*i,starty);
    cout << "Ë";
 }
 // Lower Middle Conectors
 for(i=1;i<=col-1;i++)
 {
    gotoxy(startx+i+colwidth*i,starty+row+row*rowwidth);
    cout << "Ê";
 }


 // Left Side Middle Conectors
 for(i=1;i<=row-1;i++)
 {
    gotoxy(startx,starty+i+rowwidth*i);
    cout << "Ì";
 }

 // Left Side Middle Conectors
 for(i=1;i<=row-1;i++)
 {
    gotoxy(startx+col+col*colwidth,starty+i+rowwidth*i);
    cout << "¹";
 }

/// Middle Conectors
for(i=1;i<=row-1;i++)
{
    for(j=1;j<=col-1;j++)
    {
gotoxy(startx+j+colwidth*j,starty+i+rowwidth*i);
cout <<"Î";
    }
}// Outer For

      }};// End OF Function
    /////////////////////////////////////////////
   /* void settext(char *t[10],int s)
    {
int i;
for(i=0;i<s;i++)
  text[i]= t[i];
    }};
    // Display Text On the Screen
    void displaytext()
    {
int i;
for(i=1;i<=row;i++)
{
  gotoxy(startx+1,starty+i+rowwidth/2+rowwidth*(i-1));
  cout << text[i-1];
}

    } };  */

class employee
   {
     private:

     int empno;
     char name[NMAX];
     char fname[NMAX];
     char address[NMAX];
     char jobtitle[NMAX];
     edate edob;
     public:
   void getdata();
   void showdata(int);
   void setscreen();
   void enteremp();
   void displayemp(int);
   void deleteemp();
   void modifyemp();
   void modnew();

   char findemp();

   };

//////////////////////////////////////////////////////////////////////////
//////////////////////   SET SCREEN
/////////////////////////////////////////////////////////////////////////


void employee::setscreen()
{
 int i;
 struct date d;
 int d1,m1,y1;


 gotoxy(25,2);
 cout<<"Employee Registeration List";
 gotoxy(25,3);
 cout <<"==========================";

 getdate(&d);
 gotoxy(50,3);
 d1= d.da_day;
 m1= d.da_mon;
 y1= d.da_year;
 cout << "Date : " << d1 << "/" << m1<< "/"<< y1 ;

 gotoxy(2,4);

 for(i=2;i<=78;i++) cout << "=";

 gotoxy(2,5);
 cout << "Emp NO";
 gotoxy(10,5);
 cout << "Name";
 gotoxy(20,5);
 cout << "Address";
 gotoxy(40,5);
 cout << "F-Name";
 gotoxy(60,5);
 cout << "DOB";
 gotoxy(70,5);
 cout << "JOB_Title";

 gotoxy(2,6);
 for(i=2;i<=78;i++) cout << "=";

 }

//////////////////////////////////////////////////////////////////////////
//////////////////////   GET DATA
/////////////////////////////////////////////////////////////////////////

void employee::getdata()
{
     char ch;

     gotoxy(20,6);
     cout << "Employee ENTRY FORM";
     gotoxy(20,7);
     cout << "==================";

     /////////Display
     gotoxy(10,9);
     cout << "Employee no : ";
     gotoxy(10,11);
     cout << "NAME : ";
     gotoxy(10,13);
     cout << "Father's Name : ";
     gotoxy(10,15);
     cout << "Address : ";
     gotoxy(10,17);
     cout << "Job Title : ";
     gotoxy(10,19);
     cout << "Date of Birth : ";

     // Get Value  Unique VAlue Of Emp NO
     do
     {
     box b2(6,2,1,18,8,8);
      b2.draw();
     gotoxy(30,9);
     cout << "         ";
     gotoxy(30,9);
     cin >> empno;
      ch= findemp();
 }while(ch=='y');

     gotoxy(30,11);
     gets(name);
     gotoxy(30,13);
     gets(fname);
     gotoxy(30,15);
     gets(address);
     //strupr(taddress);
     gotoxy(30,17);
     gets(jobtitle);
     gotoxy(30,19);
     cin>>edob.dd;
     gotoxy(34,19);
     cin>>edob.mm;
     gotoxy(38,19);
     cin>>edob.yy;

}

//////////////////////////////////////////////////////////////////////////
//////////////////////   SHOW DATA
/////////////////////////////////////////////////////////////////////////

void employee::showdata(int r)
{

   gotoxy(3,r);
   cout << empno;
   gotoxy(10,r);
   puts(name);
   gotoxy(20,r);
   puts(address);
   gotoxy(40,r);
   puts(fname);
   gotoxy(60,r);
   cout << edob.dd <<"\\"<<edob.mm<<"\\"<<edob.yy;
   gotoxy(70,r);
   puts(jobtitle);

}

//////////////////////////////////////////////////////////////////////////
//////////////////////   FIND LOCATION OF EMPLOYEE RECORD
/////////////////////////////////////////////////////////////////////////
char employee::findemp()
{

  employee s1;
  fstream sfile;
  sfile.open("employee.txt",ios::in|ios::binary);
  sfile.seekg(0,ios::beg);


  while(sfile.read((char *)(&s1),sizeof(s1)) )
  {

    if(s1.empno==empno)
    {
       sfile.close();
       return 'y';
    }

  }
  sfile.close();

  return 'n';
}

//////////////////////////////////////////////////////////////////////////
//////////////////////   Enter NEw EMPLOYEE RECORD
/////////////////////////////////////////////////////////////////////////

void employee::enteremp()
{
    employee s1;
    s1.getdata();
    fstream sfile;

   sfile.open("employee.txt",ios::out|ios::app|ios::binary);
   //ofstream ff("sha.txt",ios::out|ios::app);
   sfile.write((char *)(&s1),sizeof(s1));
   sfile.close();

};
//////////////////////////////////////////////////////////////////////////
//////////////////////   Display EMPLOYEE RECORD
/////////////////////////////////////////////////////////////////////////


void employee::displayemp(int n)  // ZERO FOR ALL AND ONE FOR SINGLE
{
int tempno;
int flag=0;
employee s1;

if (n==1)
{
  gotoxy(20,7);
  cout<< "enter Emp No : ";
  cin>> tempno;
}

setscreen();

fstream  sfile;

sfile.open("employee.txt",ios::in|ios::binary);
sfile.seekg(0,ios::beg);
int r=7;
while(sfile)
{
  sfile.read((char *)(&s1),sizeof(s1));
  if (!sfile) break;
  flag=0;
  if(tempno!=s1.empno && n==1) continue;
  s1.showdata(r);

  if (r==23)
   {
    flag=1;
    r=6;
    gotoxy(4,24);
    cout << "Press Any Key TO Continue";
   setfillpattern(0*55, RED);
  bar(200,350,380,700);
   rectangle(200,350,380,0);
   outtextxy(200,346, "main");
   mouseclick();
  getch();
  }
  r++;

}

sfile.close();


 gotoxy(2,23);
 for(int i=2;i<=78;i++) cout<<"=";
 if(!flag)
 {
   gotoxy(4,24);
   cout << "Press Any Key TO Continue";
/*  bar(200,350,380,400);
   rectangle(200,350,380,400);
   outtextxy(200,346, "main");
 mouseclick();*/
 getch();
 }



}// End of function

//////////////////////////////////////////////////////////////////////////
//////////////////////   MOdify EMPLOYEE Record
/////////////////////////////////////////////////////////////////////////
void employee::modnew()
{
   char ch2;
   int tempno,flag =0;


   employee s1;

   gotoxy(20,3); cout << "Enter emp No :";  cin >> tempno;
     box b3(7,2,1,18,15,4);
      b3.draw();

   fstream sfile;
   sfile.open("employee.txt",ios::in|ios::binary);
   sfile.seekg(0,ios::beg);
   int count = 0,x=20,y=5;
   while(sfile.read((char *)(&s1), sizeof(s1)) )
   {
       count++;
       if(s1.empno==tempno)
       {
 gotoxy(22,7);gotoxy(x,y);  cout << "Name is  ";x=40;gotoxy(x,y); puts(s1.name);y=7      ;
 gotoxy(22,8);x=20;gotoxy(x,y);  cout << "Address is  ";x=40;gotoxy(x,y); puts(s1.address);y=9;
 gotoxy(22,9);x=20;gotoxy(x,y);  cout << "FName is  ";x=40;gotoxy(x,y); puts(s1.fname);    y=11;


 flag=1;

 gotoxy(22,12);x=20;gotoxy(x,y);  cout << "Enter Name  ";x=40;gotoxy(x,y); gets(s1.name);y=13;
 gotoxy(22,13);x=20;gotoxy(x,y);  cout << "Enter Address  ";x=40;gotoxy(x,y); gets(s1.address);y=15;
 gotoxy(22,14);x=20;gotoxy(x,y);  cout << "Enter FName  ";x=40;gotoxy(x,y); gets(s1.fname);
 break;
       }

   }// END OF WHILE
   sfile.close();

   if(flag==1)
   {
     gotoxy(22,20);
     s1.modifyemp();
     cout << "Record Modify";

   }
   else
   {
      gotoxy(22,20);
      cout << "Record Not Modified";
   }

   gotoxy(20,22);
   cout << "Press any Key to continue";
   getch();
}
//////////////////////////////////////////////////////////////////////////
//////////////////////   Modify EMPLOYEE
/////////////////////////////////////////////////////////////////////////
void employee::modifyemp()
{

  employee s2;

  int flag =0;

  fstream sfile;
  sfile.open("employee.txt",ios::in|ios::binary);
  fstream temp;
  temp.open("temp.dat",ios::out|ios::binary);

  sfile.seekg(0,ios::beg);

  while(sfile)
  {
     sfile.read((char *)(&s2),sizeof(s2));
     if(!sfile)break;
     if(empno!=s2.empno)
temp.write((char *)(&s2),sizeof(s2));
      else
      {

if(flag==0)
{
  temp.write((char *)this,sizeof(employee ));
  flag=1;
}
else
   temp.write((char *)(&s2),sizeof(s2));
      }
   }// ENd of WHILE
  sfile.close();
  temp.close();

  sfile.open("employee.txt",ios::out|ios::binary);
  temp.open("temp.dat",ios::in|ios::binary);

  temp.seekg(0,ios::beg);

  while(temp)
  {
     temp.read((char *)(&s2),sizeof(s2));
     if(!temp)break;
     sfile.write((char *)(&s2),sizeof(s2));
   }
     sfile.close();
     temp.close();


}

//////////////////////////////////////////////////////////////////////////
//////////////////////   Delete Rec
/////////////////////////////////////////////////////////////////////////

void employee::deleteemp()
{
  int tempno;
  employee s1;

  int flag =0;
  fstream sfile;
  sfile.open("employee.txt",ios::in|ios::binary);
  fstream temp;
  temp.open("temp.dat",ios::out|ios::binary);

  sfile.seekg(0,ios::beg);
  gotoxy(20,10);
  cout << "ENTHER THE REGISTRATION NUMBER TO BE DELETED " ;
  cin >> tempno;

  while(sfile)
  {
     sfile.read((char *)(&s1),sizeof(s1));
     if(!sfile)break;
     if(s1.empno!=tempno) temp.write((char *)(&s1),sizeof(s1));
     if(s1.empno==tempno)
     {
flag=1;
     }

  }// ENd of WHILE
  sfile.close();
  temp.close();
  sfile.open("employee.txt",ios::out|ios::binary);
  temp.open("temp.dat",ios::in|ios::binary);

  temp.seekg(0,ios::beg);

  while(temp)
  {
     temp.read((char *)(&s1),sizeof(s1));
     if(!temp)break;
     if(s1.empno!=tempno) sfile.write((char *)(&s1),sizeof(s1));
   }
     sfile.close();
     temp.close();

   if(flag==1)
   {
      gotoxy(22,13);
      cprintf( "RECORD DELETE ");
      gotoxy(20,17);
      cout << "Press any key to contntinue ";
  getch();
   }
   else
   {
      gotoxy(20,16);
      cout << "Record NOT DELETED ";
      getch();
   }

};

////////////////////////////////////////////////////////////////////
/////////////////   MAIN
////////////////////////////////////////////////////////////////////

void main()
{/* char  *c[3] = {
{ "1 for \0" },
{ "2 for \0" },
{ "3 for \0" }
    };*/

box b1(5,2,1,12,20,4);
int i,y=15;
char ch,ch1,c;
employee s1;
char str[]={"EMPLOYEE MANAGEMENT SYSTEM" };
int gd = DETECT ,gm,maxx,maxy,button,midx,midy;
initgraph(&gd,&gm,"D:\\tc\\bgi");
midx=getmaxx()/10;
midy=getmaxy()/2;
/*for(y=50;y<midy;y++)
{
setcolor(BLUE);
settextstyle(10,0,1);
outtextxy(midx,y,str);
delay(25);
sound(25);
cleardevice();
} */
maxx=getmaxx();
maxy=getmaxy();
char str1[]={"EMPLOYEE MANAGEMENT SYSTEM" };
do
{
cleardevice();
   setcolor(BLUE);
settextstyle(7,0,1);
outtextxy(midx+10,30,str1);
 setfillpattern(0*33,RED);
  bar(13,75,175,470);
   rectangle(13,75,175,470);
  bar(400,75,605,470);
   rectangle(400,75,605,470);

     rectangle(10,70,maxx-10,maxy-10);
   setcolor(WHITE);
   settextstyle(3,0,1);
   if(initmouse()==0)
{
closegraph();
restorecrtmode();
exit(1);
}
restrictmouseptr(1,57,maxx-5,maxy-5);
showmouseptr();
butt();
ch=mouseclick();
switch(ch)
    { case '1':
      {cleardevice();
      s1.enteremp();
      break;}
    case '4':
    {cleardevice();
 outtextxy(150,200," PRESS [A] FOR  ALL  [S] FOR SINGLE  => ");
 ch1=getch();

if(ch1=='S'||ch1=='s')
{cleardevice();
s1.displayemp(1);
break;
      }
      else
      {cleardevice();
      s1.displayemp(0);
}break;}
       case '2':
       {  cleardevice();
 s1.modnew();
 break;}
       case '3':
       {cleardevice();
 s1.deleteemp();
       break;}}

 }while(ch!='5');
 }



no image
  • Title : C C++ Employee Class Implementation with Menu or graphics
  • Posted by :
  • Date : 04:01
  • Labels :






  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment