Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- /*Write a program to maintain an employee database in binary file with employee information such as empId,
- name, age, department, post and salary. Write function for adding new record, displaying all records,
- searching for a particular employee, updating employee salary and post.*/
- class employee{
- string emp_id;
- string name,department,post;
- string age,salary;
- public:
- void input(){
- cout<<"Enter the name of the employee"<<endl;
- cin>>name;
- cout<<"Enter the employee id "<<endl;
- cin>>emp_id;
- cout<<"Enter the age of employee"<<endl;
- cin>>age;
- cout<<"Enter the department for the employee"<<endl;
- cin>>department;
- cout<<"Enter the post for the employee"<<endl;
- cin>>post;
- cout<<"enter the salary of employee"<<endl;
- cin>>salary;
- }
- void display(){
- cout<<"The name of employee is "<<name<<endl;
- cout<<"The employee id is "<<emp_id<<endl;
- cout<<"The age of employee is "<<age<<endl;
- cout<<"The department of employee is "<<department<<endl;
- cout<<"The post for employee is "<<post<<endl;
- cout<<"The salary of employee is "<<salary<<endl;
- }
- void search(int id){
- if(emp_id==id){
- display();
- }
- else{
- cout<<"Data not found"<<endl;
- }
- }
- void update(){
- input();
- }
- };
- int main(){
- int ch=0;
- int id;
- fstream file;
- employee e;
- do{
- cout<<"\n1.enter the data for employee\n2.display the data for the employee\n3.search the data for employee"<<endl;
- cout<<"4.update the data for the employee\n5.exited"<<endl;
- cout<<"choose any choice"<<endl;
- cin>>ch;
- switch(ch){
- case 1:
- file.open("/home/pccoe/Desktop/employee.txt");
- e.input();
- file.write((char*)&e,sizeof(e));
- file.close();
- break;
- case 2:
- file.open("/home/pccoe/Desktop/employee.txt");
- file.read((char*)&e,sizeof(e));
- e.display();
- file.close();
- break;
- case 3:
- file.open("/home/pccoe/Desktop/employee.txt");
- file.read((char*)&e,sizeof(e));
- cout<<"enter the id of employee to be searched"<<endl;
- cin>>id;
- e.search(id);
- break;
- case 4:
- file.open("/home/pccoe/Desktop/employee.txt",ios::app);
- file.write((char*)&e,sizeof(e));
- e.update();
- break;
- case 5:
- cout<<"file closed"<<endl;
- break;
- }
- }while(ch!=5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement