Practical 8
Practical 8
void display(){
class Employee{
int emp_id,age;
cout<<"\n"<<emp_id<<"\
char name[30],department[30],post[30];
t"<<name<<"\t"<<salery<<"\
float salery; t"<<department<<"\t"<<post;
public: }
int getEmpId(){
int flag=0;
fin.open("emp.dat",ios::binary); fs.read((char*)&e, sizeof(e));
if (fs) {
Employee e;
if (id == e.getEmpId()) {
if(id==e.getEmpId()){
cout<<"\n\nEmployee Id e.read();
found..";
flag=1;
// placing the put(writing)
e.display(); pointer at the starting of the record
} fs.seekp(pos);
}
if(flag==0){ fs.write((char*)&e, sizeof(e));
fin.close(); break;
} }
} cout<<"\
n--------------------------------------------";
}
readFromFile();
fs.close();
break;
if (flag == 1)
case 3:
cout << "\nRecord successfully
modified \n"; cout<<"\n\nEnter Employee
Id to Find Employee:";
else
cin>>id;
cout << "\nRecord not found \n";
cout<<"\nEmpId\
tEmpName\tSalary\tDept\tPost";
}
cout<<"\
int main() n--------------------------------------------";
{ search(id);
while(1){
cout<<"\nSelect from below case 4:
choices";
cout<<"\nEnter employee
cout<<"\n1.Insert Data \n2.Display \ id for updateFile:";
n3.Search\n4.Update Reord\n5.Exit";
cin>>id;
cout<<"\nEnter Your Choice:";
updateFile(id);
cin>>ch;
break;
case 5:
switch(ch){
exit(0);
break;
case 1:
}
writeInFile();
break;
}
return 0;
case 2:
}
cout<<"\nEmpId\
Output
tEmpName\tSalary\tDept\tPost";
Select from below choices
1.Insert Data EmpId EmpName Salary Dept Post
2.Display --------------------------------------------
3.Search 101 sau 100 comp hod
4.Update Reord Select from below choices
5.Exit 1.Insert Data
Enter Your Choice:1 2.Display
3.Search
4.Update Reord
Enter Employee Id :101 5.Exit
Enter Your Choice:1
EmpId EmpName Salary Dept Post 101 saurabh 4000 comp hod
-------------------------------------------- Record successfully modified
Employee Id found..
101 sau 100 comp hod
Select from below choices
1.Insert Data
2.Display
3.Search
4.Update Reord
5.Exit
Enter Your Choice:4