Need help for a c++ program comprising of multiple classes with class musical instrument as main class having sub classes type of instruments such as piano, brass etc which are further categorized as stringed, woodwind, percussion instruments with functions like play() and tune-up()that will be used by all instruments whereas polish() would only be used by brass instruments and strum() and pluck() would only be available to stringed instruments. The main functions can simply print out messages the action of the instrument.
Would be really grateful if could help me with the basic logic and structure of the code.
Any help is appreciated.
Thank you
Inheritance implements IS-A relationship. Violin is an instrument.
Your description created image that for example stringed instrument is a violin and violin is an instrument (so indirectly stringed instrument is an instrument too), but perhaps percussion instruments are violins too?
For the interface there are two angles:
1. All instruments can be polished, but for some it does nothing. The benefit is that you can use the base class everywhere. Polymorphism.
2. Only the brass have the polish(), so when you get an instrument you have to figure out whether it is a brass before you can try to polish it.
Thats exactly my query is.
all the instruments are under the main class instruments and the functions like play(), tune up () they are called for all or particular classes using inheritance, polymorphism and virtual functions.
I am not able to frame it thus required help..
You should think how they should be used. For example, will the user algorithms always operate on std::vector<Instrument *>, or do you toss a Piano around?
but you need something like a "ClassicalInstrument" class instead of a Shape class, and your other classes (for example "StringedInstrument") to inherit from ClassicalInstrument, like Rectangle and Triangle do from Shape in that example.
hope that helps a bit.