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.
#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;
}
Comments
Leave a comment