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.
#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;
};
Comments
Leave a comment