Académique Documents
Professionnel Documents
Culture Documents
************************/
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<fstream.h>
#include<stdlib.h>
#include<ctype.h>
int c=1,r=8;
{ char name[22];
long staffid;
char doj[20];
char desig[22];
char raddress[100];
char sal[11];
public:
void readdata();
void showdata();
void display();
long returnnumber()
return(staffid); }
}st;
void createfile();
void addfile();
void deletefile();
void displayfile();
void main()
clrscr();
int ch1;
do
/****************************
****************************/
clrscr();
cout<<"\n\t\t\t ****************\n\n";
cout<<"\n \t\t\t5.Exit";
cout<<"\nEnter your choice:\n";
cin>>ch1;
switch(ch1)
case 1:
createfile();
break;
case 2:
addfile();
break;
case 3:
deletefile();
break;
case 4:displayfile();
break;
case 5:
break;
default:
} }
while(ch1!=5);
getch(); }
/******************************
******************************/
void employee::display()
gotoxy(3,r);
puts(name);
gotoxy(11,r);
cout<<staffid;
gotoxy(20,r);
puts(raddress);
gotoxy(35,r);
puts(doj);
gotoxy(60,r);
puts(desig);
gotoxy(74,r);
puts(sal);
r=r+1;
}
/*******************************
*******************************/
void employee::readdata()
clrscr();
cout<<"\n\t\t\t....Employee details....";
gets(name);
cout<<endl;
cin>>staffid;
gets(raddress);
gets(doj);
gets(desig);
gets(sal);
getch();
}
/*********************************
*********************************/
void employee::showdata()
clrscr();
cout<<"\n\t\t\t***********************";
cout<<"\n";
cout<<"\nEmployee code:";cout<<staffid;
cout<<"\n";
cout<<"\nResedential Address:";cout<<raddress;
cout<<"\n\n";
cout<<"\Date of joining:";cout<<doj;
cout<<"\n";
cout<<"\nDesignation:";cout<<desig;
cout<<"\n";
cout<<"\nSalary:";cout<<sal;
getch();
clrscr();
}
/*******************************
*******************************/
void addfile()
clrscr();
ofstream f1("empy.dat",ios::binary|ios::out|ios::app);
if(f1)
char a;
do
cin>>c;
for(int i=0;i<c;i++)
st.readdata();
f1.write((char*)&st,sizeof(st));
cout<<"\nPress(Y/N):\n";
cin>>a;
a=toupper(a);
}
while(a=='Y');
else
f1.close();
/******************************
******************************/
void createfile()
ofstream f("empy.dat",ios::binary|ios::out);
if(!f)
else
st.readdata();
f.write((char*)&st,sizeof(st));
}
/**************************
TO DELETE A RECORD
**************************/
void deletefile()
char q,ch;
do
ifstream fin;
fin.open("empy.dat",ios::binary|ios::in);
ofstream fout;
fout.open("temp.dat",ios::binary|ios::out);
int sr,flag=0;
cin>>sr;
fin.read((char*)&st,sizeof(st));
while(!fin.eof())
long c;
c=st.returnnumber();
if(sr==c)
st.showdata();
flag=1;
else
fout.write((char*)&st,sizeof(st));
fin.read((char*)&st,sizeof(st));
if(flag==0)
fin.close();
fout.close();
remove("empy.dat");
rename("temp.dat","empy.dat");
cin>>q; q=toupper(q);
}while(q!='N');
}
/**************************
**************************/
void displayfile()
db:
clrscr();
int ch,o;
ch=0;
o=0;
while(ch<4)
cout<<"\t\t\t ---------------\n\n";
cout<<"\n1.Employee Details";
cout<<"\n4.Back to menu"
cin>>ch;
char s4;
switch(ch)
case 1:
{
ifstream f3("empy.dat",ios::binary|ios::in);
if(f3)
clrscr();
gotoxy(30,3);
cout<<"PERSONNEL DETAILS";
gotoxy(3,5);
cout<<"NAME";
gotoxy(11,5);
cout<<"CODE";
gotoxy(20,5);
cout<<"ADDRESS";
gotoxy(34,5);
cout<<"JOINING DATE";
gotoxy(59,5);
cout<<"DESIGNATION";
gotoxy(74,5);
cout<<"SALARY";
gotoxy(1,6);
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^";
o=1;
while(!f3.eof())
f3.read((char*)&st,sizeof(st));
if(!f3.eof())
st.display();
getch();
clrscr();
if(o==0)
clrscr();
gotoxy(35,10);
getch();
clrscr();
else
getch();
clrscr();
f3.close();
break;
case 2:
char s2;
do
int sno,n1;
ifstream f5("empy.dat",ios::binary|ios::in);
if(f5)
int a=0;
cout<<"to be displayed"<<endl;
cin>>sno;
while(f5.read((char*)&st,sizeof(st)))
n1=st.returnnumber();
if(sno==n1)
a=1;
st.showdata();
cout<<endl;
if(a==0)
clrscr();
cin>>s2;
getch();
clrscr();
s2=toupper(s2);
f5.close();
else
while(s2=='Y');
break;
case 3:
int eno;
int flag=0;
cin>>eno;
ifstream fin("empy.dat",ios::binary|ios::in);
ofstream fout("temp.dat",ios::binary|ios::out);
if(!fin)
exit(0);}
fin.read((char*)&st,sizeof(st));
while(!fin.eof())
int x=st.returnnumber();
if(x==eno)
flag=1;
clrscr();
st.showdata();
st.readdata();
fout.write((char*)&st,sizeof(st));
fin.read((char*)&st,sizeof(st));
fin.close();
fout.close();
remove("empy.dat");
rename("temp.dat","empy.dat");
if(flag==0)
getch();
goto db;}
goto db;}
default:
getch();
break;
}
ENTERED VALUE:1
:NO ENTERED
--4- TO DISPYAL THE DETAILS OF THE EMPLOYEMENT
--IF ENTERING : 1
--IF ENTERING : 2
--ID—24
INTRODUCTION
www.google.com
www.slideshare.net
www.icbse.com
WORKING
follows:-
5.To exit.
CONCLUSION
In making of this program I learned the varios
aspects of C++ programming using the classes
,loops,array,etc.and their control over the source
code.
Thank you