1.

Write a declaration for a class Person which has the following: data members name, phone set and get functions for every data member a display function a destructor(i) For the Person class above, write each of the constructor, the assignment operator, and the getName member function. Use member initialization lists as often as possible.(ii) Given the Person class above, write the declaration for a class Spouse that inherits from Person and does the following:has an extra data member spouseName redefines the display member function.(iii) For the Spouse class above, write each of the constructors and the display member function. Use member initialization lists as often as possible. 

Answer»

class Person

{

char name[20];

long phone;

 public:

void set()

{ strcpy(name,"NULL");

 phone=7878963522;

}

void get()

{ cout<<"Enter name: ";

 gets(name);

 cout<<"Enter phone: ";

 cin>>phone;

}

void display()

{ cout<<"Name: "<<name<<end1;

 cout<<"Phone: "<<phone<<end1;

}

Person()

{ strcpy(name,"Rahul");

 phone=9965869922;

}

Person(char na[20],long ph)

{ name=na;

phone=ph;

}

void getName()

{

cout<<"Enter name:";

gets(name);

}

};

class Spouse:public Person

{

char spouseName[20];

 public:

void getName()

{

cout<<"Enter name:";

gets(spousename);

}

void display()

{ cout<<"Name: "<<name<<end1;

 cout<<"Phone: "<<phone<<end1;

 cout<<"spouse name: "<<spousename<<end1;

}

Spouse()

{ strcpy(spouseName,"NULL");

}

Spouse(char sn[20])

{ spouseName=sn;

}

};



Discussion

No Comment Found

Related InterviewSolutions