Answer to Question #235214 in C++ for SOM

Question #235214

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.


1
Expert's answer
2021-09-13T05:27:09-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS