/*
Hierarchical Inheritance
CRICKETER
BOWLER BATSMAN
ALLROUNDER
*/
#include<iostream>
using namespace std;
class Cricketer
{
protected:
char name[20];
};
class Bowler:public Cricketer
{
public:
void accept()
{
cout<<"\n\n Enter Bowler name: ";
cin>>name;
}
void display()
{
cout<<"\n\n Bowler : "<<name;
}
};
class Batsman:public Cricketer
{
public:
void accept()
{
cout<<"\n\n Enter Batsman name: ";
cin>>name;
}
void display()
{
cout<<"\n\n Batsman : "<<name;
}
};
class Allrounder:public Bowler,public Batsman
{
char name[10];
public:
void accept()
{
Bowler::accept();
Batsman::accept();
cout<<"\n\n Enter Allrounder name: ";
cin>>name;
}
void display()
{
Bowler::display();
Batsman::display();
cout<<"\n\n Allrounder : "<<name;
}
};
int main()
{
Allrounder a;
a.accept();
a.display();
return 0;
}
Hierarchical Inheritance
CRICKETER
BOWLER BATSMAN
ALLROUNDER
*/
#include<iostream>
using namespace std;
class Cricketer
{
protected:
char name[20];
};
class Bowler:public Cricketer
{
public:
void accept()
{
cout<<"\n\n Enter Bowler name: ";
cin>>name;
}
void display()
{
cout<<"\n\n Bowler : "<<name;
}
};
class Batsman:public Cricketer
{
public:
void accept()
{
cout<<"\n\n Enter Batsman name: ";
cin>>name;
}
void display()
{
cout<<"\n\n Batsman : "<<name;
}
};
class Allrounder:public Bowler,public Batsman
{
char name[10];
public:
void accept()
{
Bowler::accept();
Batsman::accept();
cout<<"\n\n Enter Allrounder name: ";
cin>>name;
}
void display()
{
Bowler::display();
Batsman::display();
cout<<"\n\n Allrounder : "<<name;
}
};
int main()
{
Allrounder a;
a.accept();
a.display();
return 0;
}
3 Comments
Click here for CommentsWhy you don't used virtual to avoid ambiguity
ReplyWhat is the output of this program?
ReplyOutput of program
Reply