Answer to Question #244818 in C++ for devi

Question #244818

Create a class MusicalInstruments which contains methods void play(), String getDescription(),float getPrice().play() need not be given a definition in MusicalInstrument. Derive classes StringInstr and Percurssion from MusicalInstruments. StringInstr contains method, int getNoOfStrings(). Percurssion contains method, String getType(). Create class Violin that inherits from StringInstr. Create class Tabla that inherits from Percurssion.

Write main() to test the classes and to illustrate run-time polymorphism.

In main() create an object of Tabla with appropriate data values and print it.


1
Expert's answer
2021-10-01T01:31:36-0400
#include<iostream>


using namespace std;
class MusicalInstruments{
	public:
	void play();
	string getDescription();
	float getPrice();
};
class StringInstr{
	public:
	int	getNoOfStrings();
	
}; 


class Percurssion{
	
	public:
		int a ;
		Percurssion(){
			
		}
		Percurssion(int c){
			a =c;
		}
		string getType();
		
	
};


class Violin: public StringInstr{
	
	
};
class Tabla: public Percurssion{
	public:
	Tabla(){
		Percurssion p;
	cout<<"The value of a is " <<p.a<<endl;	
	}
};
int main(){
	Percurssion p (3);
	 
	Tabla t;
	
}

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