Question
Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int
Write a code in C++ by considering the following conditions :-
Tasks :-
1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy. 6. Overload the stream insertion operator << to print the values of member variables. 7. Use of constant reference parameters is mandatory 8. Test the functionality of class in main function. Note : Use of this pointer is mandatory where required. You are not allowed to use any cin and cout in implementation of functions except in task 6.
USE strcpy_s instead of strcpy because the second one is not working in my case.
-> The class definition for the code is probably as under. Please follow the desired pattern :-
class Employee { private: int id = 0; double age = 0; char* name; public: Employee(char * name, int id, double age); // This is constructor. Employee(const Employee&); // This is Overloaded constructor. ~Employee(); // This is Destructor. // Overload assignment operator here. // Overload " << " here to print Employee. };
*** Apply all proper Testing cases or Checks in each case.
Test the destructor also. All the tests must be present in the main.
Thanks in Advance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started