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
  • Create a base class and two derived classes. Also, create and call a member function named...

    Create a base class and two derived classes. Also, create and call a member function named communicate() that behaves differently when called by each class. Create a single C++ project (and CPP source file) named animal_communication as follows: Into this source, type the source code for Program 15-16, "Program Output," in Section 15.6, "Polymorphism and Virtual Member Functions," in Ch. 15, "Inheritance, Polymorphism, and Virtual Functions," of Starting Out With C++ From Control Structures Through Objects. Run and debug the...

  • 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...

  • C++ Format You are to write a program which is going to use inheritance. It should...

    C++ Format You are to write a program which is going to use inheritance. It should start off with the base classes Account: contains the string name, int accountnumber, double balance. Savings: Derived from Account class, it should contain double interest rate. Checkings: Derived from Account class, it should contain double overdraftlimit. CreditCard: Derived from Checkings class, it should contain int cardnumber. Create a program which will create an array of 3 Savings accounts, 3 Checkings accounts and 3 CreditCards....

  • Purpose: The main goal of this assignment is to practice Object Oriented Programming by creating classes,...

    Purpose: The main goal of this assignment is to practice Object Oriented Programming by creating classes, writing methods, and creating inheritance type relationships. Task: Create a Java project using the IDE Write a program using Object Oriented Programming Plan a program where two classes inherit from a single class and theme it in a way that makes sense. Create a super class with a non-constructor method Create two sub classes with their own non-constructor methods and have them inherit from...

  • 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...

  • using C# language This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery...

    using C# language This program will demonstrate inheritance. Your Pizza Shop expands and now handles delivery orders and sit down orders in a restaurant setting. There are differences in a SeatedPizzaOrder and a DeliveryPizzaOrder. These are more specialized versions of the PizzaOrders you have been creating all along and you decide to write a program that handles them the same as much as possible and reuses the code of a general PizzaOrder class as much as possible to demonstrate inheritance....

  • 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...

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