Answer to Question #180173 in C++ for Saurabh Singh

Question #180173

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.


1
Expert's answer
2021-04-10T13:00:46-0400
#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;

};


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS