Answer to Question #173882 in C++ for P. Gokul

Question #173882

Declare the class Employee, consisting of data members are emp_number and emp_age. Invoke a null constructor Employee() when an object is created, the parameterized constructor Employee(en, eg) to assign values for the data members, show() member function is used to display the information of Employee. Finally free the resources of data objects using destructor member function.


1
Expert's answer
2021-03-24T04:30:15-0400
#include <iostream>
using std::cout;
using std:: endl;
class Employee 
{
public:
	Employee() {}
	Employee (int number, float age):
		emp_number(number), emp_age(age)
	{}
	~Employee() {}
	void show() 
	{
		cout << "Employee number:" << emp_number << endl;
		cout << "Employee age:" << emp_age << endl; 
	};
private:
	int emp_number{ 0 };
	float emp_age{ 0};
};
int main()
{
	// standart constructor
	Employee t_defolt;
	t_defolt.show();
	// parametr constructtor
	Employee t_parametr(10, 35.8);
	t_parametr.show();
	// destructor call for dynamically allocated memory
	Employee*t_example = new Employee(15,10);
	t_example->show();
	delete t_example;
    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