Create a class Employee with the data members such as name, id and total salary. Create a file as “Employee_Data” as binary file and write the information of four employees to that file. Open that file in reading mode and only display the record of 2nd and 3rd employees.
#include <iostream>
using namespace std;
class Employee
{
public:
// default constructor
Employee() {
emp_number = new int;
*emp_number = 1;
emp_age = new float;
*emp_age = 18;
}
// parameterized constructor
Employee (int n, float a){
emp_number = new int;
*emp_number = n;
emp_age = new float;
*emp_age = a;
}
// destructor
~Employee() {
delete emp_number;
delete emp_age;
}
void show() {
cout << "Employee number:" << *emp_number << endl;
cout << "Employee age:" << *emp_age << endl;
cout<<"*********************************"<<endl<<endl;
};
private:
int *emp_number;
float *emp_age;
};
int main()
{
// default constructor
Employee firstEmp;
firstEmp.show();
// parameterized constructor
Employee secondEmp(77, 20.5);
secondEmp.show();
return 0;
};
Comments
Leave a comment