#include <iostream>
using namespace std;
class GrandFather //Abstract Class
{
char name1[20];
public:
virtual void read()=0;
virtual void show()=0;
};
class Father:public GrandFather
{
char name2[20];
public:
void read()
{
cout<<"Enter father name: ";
cin>>name2;
}
void show()
{
cout<<endl<<"Father name: "<<name2<<endl;
}
};
class Son:public Father
{
char name3[20];
public:
void read()
{
cout<<"Enter son name: ";
cin>>name3;
}
void show()
{
cout<<endl<<"Son name: "<<name3<<endl;
}
};
int main()
{
GrandFather *gf;
Father f;
Son s;
gf=&f;
gf->read();
gf->show();
gf=&s;
gf->read();
gf->show();
return 0;
}
using namespace std;
class GrandFather //Abstract Class
{
char name1[20];
public:
virtual void read()=0;
virtual void show()=0;
};
class Father:public GrandFather
{
char name2[20];
public:
void read()
{
cout<<"Enter father name: ";
cin>>name2;
}
void show()
{
cout<<endl<<"Father name: "<<name2<<endl;
}
};
class Son:public Father
{
char name3[20];
public:
void read()
{
cout<<"Enter son name: ";
cin>>name3;
}
void show()
{
cout<<endl<<"Son name: "<<name3<<endl;
}
};
int main()
{
GrandFather *gf;
Father f;
Son s;
gf=&f;
gf->read();
gf->show();
gf=&s;
gf->read();
gf->show();
return 0;
}
No comments:
Post a Comment