Answer to Question #188274 in C++ for Ramakrishna

Question #188274

Create two classes named Mammals and Marine Animals. Create another class named Blue Whale which inherits both the above classes. Now, create a function in each of these classes which prints "I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as well as Marine Animals" respectively. Now, create an object for each of the above class and try calling


function of Mammals by the object of Mammal

function of Blue Whale by the object of Blue Whale

function of each of its parent by the object of Blue Whale

function of Marine Animal by the object of Marine Animal


1
Expert's answer
2021-05-02T17:48:05-0400
#include <iostream>
#include <string>




using namespace std;


class Mammals{
public:
	void printMammal(){
		cout<<"\nI am mammal\n";
	}
};




class Marine{
public:
	void printMarine(){
		cout<<"\nI am a marine animal\n";
	}
};


class BlueWhale:public Marine, public Mammals{
public:
	void printBoth(){
		cout<<"\nI belong to both the categories: Mammals as well as Marine Animals\n";
	}
	 
};


int main(){
	
	//create an object for each of the above class and try calling
	Mammals mammal;
	Marine marine;
	BlueWhale blueWhale;
	//function of Mammals by the object of Mammal
	mammal.printMammal();
	cout<<"\n";
	//function of Blue Whale by the object of Blue Whale
	blueWhale.printBoth();
	cout<<"\n";
	//function of each of its parent by the object of Blue Whale
	blueWhale.printMammal();
	blueWhale.printMarine();
	cout<<"\n";
	//function of Marine Animal by the object of Marine Animal
	marine.printMarine();
	cout<<"\n";


	system("pause");
	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