Question

create a program that uses multiple inheritance by creating two base classes in C++ - an...

create a program that uses multiple inheritance by creating two base classes in C++

- an Alien class and a Soldier class.

-create three child classes from the Alien class and three child classes from the Soldier class.

-use multiple inheritance to create five unique classes that each have a child Alien class and a child Soldier class as parents.

-have the program print out each of the five class's characteristics when objects are created from the grandchildren classes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I'm posting the sample code in which the characteristic of each class is defined inside the default constuctor.

Below is the sample in which you will find

Alien , Soldier classes

Alien_1,Alien_2,Alien_3 child classes which are inherited from Alien.

Soldier_1,Soldier_2,Soldier_3 child classes which are inherited from Soldier.

Then You find 5 classes:

Test1 which is inherited from Alien_1,Soldier_1

Test2 which is inherited from Alien_2,Soldier_2

Test3 which is inherited from Alien_3,Soldier_3

Test4 which is inherited from Alien_2,Soldier_3

Test5 which is inherited from Alien_1,Soldier_2

----------------------------------------------------------------------CODE--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
class Alien
{
public:
   Alien(){
       cout<<"Inside Alien"<<endl;
   }
};

class Soldier
{
public:
   Soldier(){
       cout<<"Inside Soldier"<<endl;
   }
};

//Creating Three Alien child classes
class Alien_1:Alien
{
public:
   Alien_1(){
       cout<<"Inside Alien_1"<<endl;
   }
};

class Alien_2:Alien
{
   public:
   Alien_2(){
       cout<<"Inside Alien_2"<<endl;
   }
};
class Alien_3:Alien
{
   public:
   Alien_3(){
       cout<<"Inside Alien_3"<<endl;
   }
};

//Creating Three Soldier classes
class Soldier_1:Soldier
{
   public:
   Soldier_1(){
       cout<<"Inside Soldier_1"<<endl;
   }
};
class Soldier_2:Soldier
{
   public:
   Soldier_2(){
       cout<<"Inside Soldier_2"<<endl;
   }
};
class Soldier_3:Soldier
{
   public:
   Soldier_3(){
       cout<<"Inside Soldier_3"<<endl;
   }
};

//Creating 5 unique classes which are inherited from
//the chile classes of Alien and Soldier

class Test1:Alien_1,Soldier_1
{
   public:
   Test1(){
       cout<<"Inside Test1"<<endl;
   }
};

class Test2:Alien_2,Soldier_2
{
   public:
   Test2(){
       cout<<"Inside Test2"<<endl;
   }
};
class Test3:Alien_3,Soldier_3
{
   public:
   Test3(){
       cout<<"Inside Test3"<<endl;
   }
};
class Test4:Alien_2,Soldier_3
{
   public:
   Test4(){
       cout<<"Inside Test4"<<endl;
   }
};
class Test5:Alien_1,Soldier_2
{
   public:
   Test5(){
       cout<<"Inside Test5"<<endl;
   }
};

int main()
{
   cout<<"Creating Object 1:\n";
   Test1 T1;
   cout<<"Creating Object 2:\n";
   Test2 T2;
   cout<<"Creating Object 3:\n";
   Test3 T3;
   cout<<"Creating Object 4:\n";
   Test4 T4;
   cout<<"Creating Object 5:\n";
   Test5 T5;
}

-------------------------------------------------------------------------END------------------------------------------------------------------------

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
create a program that uses multiple inheritance by creating two base classes in C++ - an...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for...

    MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for data types, class definitions, and inheritance (check input/output of data below). You will create a super media class that will define a general form of media. A media properties will consist of the name and price. The media should be able to construct itself out of the arguments sent to it, virtually print both data fields labeled (price to two decimal places) and overload...

  • Define an example of inheritance with a base class that has 2 attributes, 2 derived classes...

    Define an example of inheritance with a base class that has 2 attributes, 2 derived classes that each have 2 attributes. Implement this in C++. Create a driver program that creates instances of both of the derived classes and exercises the classes’ member functionsl. Student answer should include the following: 1 base class with 2 attributes, 2 constructors (default and with parameters), get/set methods for each attribute, and display methods 2 derived classes with 2 attributes, 2 constructors (default and...

  • Write in C# Create an inheritance hierarchy that is: at least three levels deep (one parent...

    Write in C# Create an inheritance hierarchy that is: at least three levels deep (one parent class, two child classes, one child class of one the child classes) shares at least one property through all levels has at least one property or method that is modified inside of each child class

  • JAVA PROGRAMING - TESTING CLASSES AND INHERITANCE Create two classes - a vehicle class and gasguzzler...

    JAVA PROGRAMING - TESTING CLASSES AND INHERITANCE Create two classes - a vehicle class and gasguzzler class. Neither classes have I/O. Use a test class as well. Vehicle class has methods and properties that all vehicles have. This class has two properties - speed (rate of travel in miles per hour) and weight (in pounds) Vehicle Class Public Methods: Vehicle objects can be constructed 2 different ways: by specifying the weight and the speed, or by specifying the weight only...

  • C++ ONLY PLEASE Problem Description: Objective: Create Inheritance Hierarchy to Demonstrate Polymorphic Behavior Create a Rectangle...

    C++ ONLY PLEASE Problem Description: Objective: Create Inheritance Hierarchy to Demonstrate Polymorphic Behavior Create a Rectangle Class Derive a Square Class from the Rectangle Class Derive a Right Triangle Class from the Rectangle Class Create a Circle Class Create a Sphere Class Create a Prism Class Define any other classes necessary to implement a solution Define a Program Driver Class for Demonstration a) Create a Container to hold objects of the types described above b) Create and Add two(2) objects...

  • in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base cla...

    in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base classes. Circle int r; void area(); void perimeter(); void volume(); //No volume for circle Sphere int r; void area();//Sphere surface area= 4 × pi × radius2 void perimeter(); //No perimeter for Sphere void volume();//Sphere volume= 4/3 × pi × radius2 Cylinder int r, height; void area();// Cylinder surface area=perimeter of...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student...

    Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student will demonstrate the ability to use inheritance in Java programs. Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following: Person Automobile Animal Based on your choice: If you choose Person, you will create a subclass of Person called Student. If you choose Automobile, you will create...

  • {C++} Create a base class called Person with a public member function called sayHi which outputs...

    {C++} Create a base class called Person with a public member function called sayHi which outputs “Hi, I am a person.” Create a derived class called Student which inherits from the Person class (public inheritance) and overwrites the sayHi function and outputs “Hi, I am a student.” Create another derived class called EngineeringStudent which inherits from the Student class (public inheritance) and overwrites the sayHi function and outputs “Hi, I am an engineering student.” In the main program, create a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT