To write a C++ program to illustrate hybrid inheritance concept using student data base creation as an example.
ALGORITHM:
Step 1:Create a class with some methods and variables.
Step 2:Create a new class that extends this class.
Step 3:Create a new class with some new methods.
Step 4:Create a new class again which inherits from classes defined in step 2 and step 3.
Step 5.Create an object of class defined in step 4 and Create it call methods defined in step 2 and step 3.
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person(string name, int age)
:m_name(name), m_age(age)
{ }
void getAge()
{
cout << "Name: " << m_age;
}
string m_name;
int m_age;
};
class Schoolboy: public Person
{
public:
Schoolboy(string name, int age, int numberSchool, int averageScore)
: Person(name, age),
m_numberSchool(numberSchool),
m_averageScore(averageScore)
{}
void getSchool()
{
cout << "Number School: " << m_numberSchool;
}
void getScore()
{
cout << "Average Score:" << m_averageScore;
}
int m_numberSchool;
int m_averageScore;
};
class PersonalInfo
{
public:
PersonalInfo(string adress, string tel)
:m_adress(adress), m_tel(tel)
{}
void getTelephone()
{
cout << "Number Telephone: " << m_tel;
}
void getAdress()
{
cout << "Adress:" << m_adress;
}
string m_adress;
string m_tel;
};
class Student: public Schoolboy, public PersonalInfo
{
public:
Student(string name, int age, int numberSchool,
int averageScore, string adress, string tel,
string college)
:Schoolboy(name, age, numberSchool, averageScore),
PersonalInfo(adress, tel),
m_college(college)
{}
void getCollege()
{
cout << "College "<<m_college;
}
string m_college;
};
int main()
{
Student stud("Bob",24,102,79,"town","+111....","College");
stud.getSchool();
cout <<endl;
stud.getTelephone();
return 0;
}
Comments
Leave a comment