Description
The purpose of this challenge is to define a basic class that implements a copy constructor.
Requirements
- Define a class called Contact as below
class Contact { private: string first; string last ; string * aliases; public: // default constructor Contact() { aliases = new string[3]; } // copy constructor Contact(const Contact &contact) { // create the array // perform deep copy of data members } // you will need to complete the definitions for these string get_fullname(); void set_first(string f); void set_last(string l); // returns a comma-separated list of aliases string get_aliases(); // sets one element of aliases at position i void set_alias(string alias, int i); };
- Write a default constructor that will create a new array of strings that will hold 3 elements (see above)
- Write a copy constructor that will perform a deep copy of the object itself (its data members and its array data)
- Write a getter function that will return the person’s full name as a concatenation of first and last.
- Complete the other public functions whose prototypes are given in the class definition above
- In main, instantiate an object, person1
- Ask the user to enter first name, last name and 3 aliases into person1
- Instantiate another object, person2. Using object initialization, assign person1 to person2.
- None of the functions in the class should cout or cin. Do not ask for user input within the class (Using cout’s for debugging is ok)
- Ask the user to enter 3 aliases into person2. You don’t have to ask for first name and last name for person2.
- Display person1’s and person2’s full name and aliases. (Notice that both objects have the same first and last name, but different aliases)
- Create as many supporting private/public functions as you think you might need
Sample main()
// class definition here int main() { Contact person1; string first; person1.set_first(first); return 0; }
Sample Interaction
First name: Michael Last Name: Jordan Alias 1: MJ Alias 2: AirJordan Alias 3: TheGOAT Alias 1: Greatest Alias 2: Money Alias 3: Number23 Michael Jordan : MJ, AirJordan, TheGOAT Michael Jordan : Greatest, Money, Number23
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL0021
Print Requirements