/*PROGRAM OF DATA HANDILING*/
#include<fstream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> void void void void create(); displayall(); modify(int); delrec(int);
class emp { int eno; char ename[20]; float esalary; public: void accept(); void display(); void modi(); int geteno(); }; void insert(emp); void emp::accept() { cout<<"\nemployee no.:"; cin>>eno; cout<<"employee name:"; cin>>ename; cout<<"employee salary:"; cin>>esalary; } void emp::display() { cout<<"\n\nEmployee no. :"<<eno; cout<<"\nEmployee name :"<<ename; cout<<"\nEmployee salary :"<<esalary; } int emp::geteno() {
return eno; } void main() { char ch, ans; int status=0, no; emp e2; do { clrscr(); cout<<"\n***EMPLOYEE MENU***"; cout<<"\n1. Create file"; cout<<"\n2. Insert Record"; cout<<"\n3. Modify Record"; cout<<"\n4. Delete Record"; cout<<"\n5. Display all Records"; cout<<"\n6. Exit"; cout<<"\nEnter your choice (1-6):-"; cin>>(ch); switch(ch) { case '1':clrscr(); if(status==0) { create(); status=1; } else cout<<"\n!!File already exists!!"; break; case '2':clrscr(); cout<<"Enter employee details to be inserted:-"; [Link](); insert(e2); break; case '3':clrscr(); cout<<"\n Enter employee no. to be modified:-";
cin>>no; modify(no); break; case '4' :clrscr(); cout<<"\n Enter employee no. to be deleted:-"; cin>>no; delrec(no); break; case '5':displayall(); break; case '6':exit(0); break; default : cout<<"\n!!Wrong Choice!!"; break; }//switch cout<<"\n\n Back to Employee Menu?(y/n):-"; cin>>ans; }while(ans=='y' || ans=='Y'); } void create() { emp e; char ans; fstream obj("[Link]",ios::out|ios::binary); do { [Link](); [Link]( (char *)&e, sizeof(e)); //obj>>"\n"; using this only one record is written to the file; cout<<"\nWant to enter more records(y/n)?:-"; cin>>ans; }while(ans=='y' ||ans=='Y'); }//create
void displayall()
{ emp e; fstream obj("[Link]", ios::in|ios::binary); if(obj==NULL) { cout<<"\nFile does not exists!!"; return; } clrscr(); while([Link]((char *)&e, sizeof(e))) { [Link](); } }//display void modify(int no) { emp e; int rec=0,flag=0; fstream obj("[Link]",ios::in|ios::out|ios::binary); if(obj==NULL) { cout<<"\nFile does not exists!!"; return; } while([Link]((char *)&e, sizeof(e))) { rec++; if(no==[Link]()) { cout<<"\nthe record is:"; [Link](); cout<<"\nEnter new details:"; [Link](); [Link]((rec-1)*(sizeof(e)), ios::beg); [Link]((char *)&e, sizeof(e)); flag=1; break; } } if (flag==0) cout<<"record does not exists!";
else cout<<"**Modified**"; }//modify void delrec(int no) { emp e; int flag=0; fstream obj("[Link]",ios::in|ios::binary); if(obj==NULL) { cout<<"\nFile does not exists!!"; return; } fstream object("[Link]",ios::out|ios::binary); while([Link]((char *)&e, sizeof(e))) { if(no!=[Link]()) [Link]((char *)&e,sizeof(e)); else flag=1; } if(flag==0) cout<<"\n!!The record does not exists!!:"; else cout<<"\n!!Record deleted!!"; [Link](); [Link](); remove("[Link]"); rename("[Link]","[Link]"); }//delete void insert(emp e1) { emp e; int pos=0, ctr=1; fstream obj("[Link]", ios::in|ios::binary); while([Link]((char *)&e, sizeof(e))) { pos++; if ([Link]()<=[Link]()) break; }
[Link](); if([Link]()>[Link]()) pos++; // [Link](0,ios::beg); [Link]("[Link]", ios::in|ios::binary); fstream object("[Link]",ios::out|ios::binary); while(ctr<pos) { [Link]((char *)&e, sizeof(e)); [Link]((char *)&e, sizeof(e)); ctr++; } [Link]((char *)&e1, sizeof(e1)); while([Link]((char *)&e, sizeof(e))) { [Link]((char *)&e, sizeof(e)); } [Link](); [Link](); remove("[Link]"); rename("[Link]","[Link]"); }