



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























class Person{
char * name;
public:
Person(char * = NULL); const char * GetName() const; ~Person();
};
Student::Student(char *_name, char *_maj) : Person(_name), major(NULL)
{
if (_maj != NULL) { major = new char [strlen(_maj)+1]; strcpy(major,_maj); }
}
void Student::Print() const{
cout << “Name: ”<< GetName() <<endl; cout << “Major: “ << major << endl;
}
Name: Ali Major: Computer Science
Person::Person(const Person& rhs){ // Code for deep copy }
int main(){ Student sobj1(“Ali”, “Computer Science”); Student sobj2 = sobj1; sobj2.Print(); return 0; }
Name: Ali Major: Computer Science
...
major
name
sobj
A L I
...
major
name
sobj
C O M ...
A L I
Person::Person(const Person& rhs) { // Code for deep copy } Student::Student (const Student& rhs) { // Code for deep copy }
Name: Major: Computer Science
...
major
name
sobj
A L I
...
major
name
sobj
C O M ...
C O M ...
Person Constructor Name: Major: Computer Science