Question: There are 3 files in this C++ program, cperson.h, cperson.cpp, and main.cpp. When executing, this should be shown: Default Constructor Type Constructor Copy Constructor Here

There are 3 files in this C++ program, cperson.h, cperson.cpp, and main.cpp.

When executing, this should be shown:

Default Constructor

Type Constructor

Copy Constructor

Here are the three people

P1: Name: Clark Kent Age: 0

P2: Name: Elon Musk Age: 47

P3: Name: Elon Musk Age: 47

Enter your name and age (Hit enter after entering name): Here I entered: clark 20 clide 10

Here are the three people (revised):

P1: Name: clark 20 Age: 0

P2: Name: Elon Musk Age: 47

P3: Name: Elon Musk Age: 47

Elon Musk is the oldest at age 47 years old

Destructor

Destructor

Destructor

All you need to do is fill in the ??? in cperson.h and create a cperson.cpp file. You wont need to change anything in main.cpp. Get a feel for what the program is doing and study what has been given in main.cpp and cperson.h to know what the functions should have as input/output. Your code should mimic the output from the sample executable file.

An explanation of the functions are below:

Constructors:

Your program should have three constructors (default, type, and copy). Also, it should have a destructor as well.

Default: The default constructor will initialize your private data members. Age is assigned a zero value and a name will be assigned to your choosing (I picked Clark Kent)

Type: Will create an object and assign the private data members to the choosing of the caller.

Copy: Will copy another object.

Destructor: Release memory from the heap.

Functions:

GetAge / GetName: Will return the age and the name of the objects data members, respectively.

SetAge / SetName: Will assign the age and the name to the objects data members, respectively.

DisplayData: Will display the objects data members (Name and Age). By default, it will display to the monitor.

GetData: Will read the users input and assign them to the objects data members. By default, it will read from the keyboard.

operator==: Overload the equality operator

operator>: Overload the greater than operator

operator>>: Overload the extraction operator

operator<<: Overload the insertion operator

CPerson.h

#include using namespace std;

#ifndef CPERSON_HEADER #define CPERSON_HEADER

class CPerson { public: // constructors CPerson(); CPerson(???); CPerson(???); ~CPerson();

// accessor functions ??? GetAge(???) ??? GetName(???) ??? SetAge(???); ??? SetName(???);

// member functions ??? DisplayData(???) // default to cout ??? GetData(???) // default to cin ??? operator==(???) ??? operator>(???)

private: char *m_name; // a char pointer to store a name int m_age; // an int to store the age };

// function prototypes ??? operator>>(???) ??? operator<<(???)

#endif // CPERSON_HEADER

main.cpp

#include #include "cperson.h" using namespace std;

int main() { // Create an object (Default) CPerson P1;

// Invoke type constructor char name[] = "Elon Musk"; CPerson P2(name, 47);

// Copy Constructor CPerson P3(P2);

// Display the objects cout << " Here are the three people "; cout << "P1: " << P1 << endl; cout << "P2: " << P2 << endl; cout << "P3: " << P3 << endl << endl;

// Enter name and age for P1 cout << "Enter your name and age (Hit enter after entering name): "; cin >> P1;

// Display the objects again cout << " Here are the three people (revised): "; cout << "P1: " << P1 << endl; cout << "P2: " << P2 << endl; cout << "P3: " << P3 << endl << endl;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!