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
#include<iostream>
#include<string.h>
using namespace std;
class Father{
private:
string fname;
public:
void setFather(string s){
fname = s;
}
string getFname(){
return fname;
}
};
class Son: Father{
private:
string sname;
public:
void setSon(string s, string name){
setFather(s);
sname = name;
}
string getSname(){
return sname;
}
string getF(){
return getFname();
}
};
class GrandSon: Son{
private:
string gname;
public:
void setGSon(string name, string n, string m){
setSon(name, n);
gname = m;
}
void display(){
string name = getF() +" "+ getSname() + " "+ gname;
cout<<name<<endl;
}
};
int main(){
GrandSon g;
g.setGSon("Abraham","Robert", "Brown");
g.display();
}
Comments
Leave a comment