Question

For C++ Write a C++ program of an original example of hybrid inheritance.

For C++

Write a C++ program of an original example of hybrid inheritance.

Homework Answers

Answer #1

#include <iostream>
using namespace std;

class A
{
    public:
    int p;
};
class B : public A
{
    public:
    B() //constructor to initialize p in base class A
    {
    p = 100;
    }
};
class C
{
    public:
    int q;
    C() //constructor to initialize q
    {
    q = 40;
}
};
class D : public B, public C //D is derived from class B and class C
{
    public:
    void mul()
    {
    cout << "Multiply= " << p * q;
    }
};

int main()
{
D obj1; //object of derived class D
    obj1.mul();
    return 0;
}    //end of program

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This question is about the C program(NOT C++ program) Please write the C program to find...
This question is about the C program(NOT C++ program) Please write the C program to find out the largest and the smallest number in 32bits For example ,the smallest number in 32 bits is -2147483648
Write a program to prepare the ‘payroll’ of an employee by using single inheritance. The base...
Write a program to prepare the ‘payroll’ of an employee by using single inheritance. The base class contains employee Name and Id while the derived class ‘allowance’ has float members for basic_pay, medical_allowance and transport_allowance. It then calculates gross pay of the employee through a member function (for both classes there should be getinput() and getoutput() functions with same name) use c++
What are hybrid securities? Give an example of a hybrid security.
What are hybrid securities? Give an example of a hybrid security.
Why is sex-linked inheritance an example of non-Mendelian inheritance?
Why is sex-linked inheritance an example of non-Mendelian inheritance?
write a c++ program that can take an input file with string as for example "i...
write a c++ program that can take an input file with string as for example "i saw 5 teddy bears" and in a created output file create a new string to just change a digit to a word. To " I saw five teddy bears" . output should be located in an output file thank you
2. Write short notes on the ff a. Matrilineal inheritance (5 marks) b. Patrilineal inheritance (5...
2. Write short notes on the ff a. Matrilineal inheritance b. Patrilineal inheritance c. State 3 reasons why matrilineal or patrilineal inheritance is your preferred choice
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
An array of characters contains a few letters. Write a complete C program that will display...
An array of characters contains a few letters. Write a complete C program that will display the output as shown below. Lets assume the array contains =”abcde”. The program should be able to work with any array size, configurable in the program. Expected output Original array = [ a b c d e] a a b a b c a b c d a b c d e
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
Write a program in C that extracts the tokens from a string. Given a string as...
Write a program in C that extracts the tokens from a string. Given a string as input, the program should print on the screen each token on a new line. For example given the following string as input: “hello there my friends” the program should generate: I am a programmer