Question

In: Computer Science

C++ Assignment Do an original example of hybrid inheritance. Throw in a has-a in at least...

C++ Assignment

Do an original example of hybrid inheritance. Throw in a has-a in at least one of your classes for good measure.

Solutions

Expert Solution

// Hybrid Inheritance

#include <iostream>

using namespace std;

// base class

class Vehicle

{

  public:

    Vehicle()

    {

      cout << "This is a Vehicle" << endl;

    }

};

//base class

class Fare

{

    public:

    Fare()

    {

        cout<<"Fare of Vehicle\n";

    }

};

// first sub class

class Car: public Vehicle

{

};

// second sub class

class Bus: public Vehicle, public Fare

{

     

};

// main function

int main()

{   

    // creating object of sub class will

    // invoke the constructor of base class

    Bus obj2;

    return 0;

}

Output:

This is a Vehicle
Fare of Vehicle

Related Solutions

Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
C++ Assignment Inheritance This uses some single arrays of doubles. We can use Vectors instead if...
C++ Assignment Inheritance This uses some single arrays of doubles. We can use Vectors instead if we want! Choice either vectors or arrays either one is fine We will implement a classic Inheritance hierarchy. A simple console based interface is all that is needed. Build your classes first, each in their own .h and .cpp files, then test them with the simple main method provided below. Phase 1 : Here is the following set of classes you will implement and...
Please code in C# (C-Sharp) Assignment Description A pirate needs to do some accounting and has...
Please code in C# (C-Sharp) Assignment Description A pirate needs to do some accounting and has asked for your help. Write a program that will accept a pirate’s starting amount of treasure in number of gold pieces. The program will then run one of two simulations, indicated by the user: 1) The first simulation runs indefinitely, until one of two conditions is met: the pirate’s treasure falls to 0 or below, or the pirate’s treasure grows to 1000 or above....
Class object in C++ programming language description about lesson inheritance multi level example.
Class object in C++ programming language description about lesson inheritance multi level example.
1. When do we use a z test? Give an original example that is relevant to...
1. When do we use a z test? Give an original example that is relevant to criminology or criminal justice. 2. Calculate the z score using the following data that reflect the number of support meetings attended weekly by current and historic mental health court participants. Show your work (three points). Data: Sample size is 50, sample mean is 12, sample standard deviation is 1.9 Population size is 295, population mean is 10, population standard deviation is 2 3. Is...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the opportunity to overload or override an inherited member function. What is the difference? and which one is the better?
Let’s model the inheritance of a genetic trait, for example eye color. Every individual has a...
Let’s model the inheritance of a genetic trait, for example eye color. Every individual has a pair of chromosomes for eye color, and an offspring gets one chromosome from each parent. Say a represents a brown-eye gene, and b represents a blue-eye gene, and that brown is dominant (meaning the eye will be brown if the individual carries at least one a gene, and only bb pair will result in blue eyes). The order in the pair does not matter....
Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create...
Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive a Square Class from the Rectangle Class 3. Derive a Right Triangle Class from the Rectangle Class 4. Create a Circle Class 5. Create a Sphere Class 6. Create a Prism Class 7. Define any other classes necessary to implement a solution 8. Define a Program Driver Class for Demonstration (Create a Container to hold objects of the types...
How do you handle your stress? Provide an original example of a stressful experience, and use...
How do you handle your stress? Provide an original example of a stressful experience, and use it to illustrate the definition of stress and the role of cognitive appraisal in stress.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT