Wap to create One Base class Father data member fname. And Son class derived from Father dada member sname . And GrandSon derived from Son data member gname. Use appropriate function that GrandSon will display all name by it concatenating
Source code
#include <iostream>
using namespace std;
class Father{
private:
string fname;
public:
Father(string f){
fname=f;
}
string getFName(){
return fname;
}
};
class Son: public Father{
private:
string sname;
public:
Son(string f,string s):Father(f){
sname=s;
}
string getFnameSName(){
return getFName()+sname;
}
};
class GrandSon: public Son{
private:
string gname;
public:
GrandSon(string f,string s,string g):Son(f,s){
gname=g;
}
string getFnameSNameGName(){
return getFnameSName()+gname;
}
void display(){
cout<<"\nName: "<<getFnameSNameGName();
}
};
int main()
{
GrandSon g("John","Smith","Washington");
g.display();
return 0;
}
Output
Comments
Leave a comment