In this lab, I created a C++ program that models musical instruments using object-oriented programming. The base class, Instrument, was provided and includes data members for the instrument’s name, manufacturer, year built, and cost, along with setter and getter functions and a PrintInfo() method that displays this information. I then created a derived class called StringInstrument, which inherits from Instrument and adds three new private members specific to string instruments: numStrings, numFrets, and isBowed (a boolean indicating if the instrument is played with a bow, like a violin). I wrote public setter and getter functions for each of these new members. In StringInstrument, I also overrode the PrintInfo() function to first call the base class’s PrintInfo() to show general instrument details, then added output for the string-specific details. The main() function creates two objects: one regular Instrument and one StringInstrument. It takes input from the user to populate both objects and then prints their information. For the string instrument, the output includes the number of strings, number of frets, and whether it is bowed, using true or false. This structure demonstrates how inheritance can be used to extend a base class while keeping related functionality organized and reusable.
-
Notifications
You must be signed in to change notification settings - Fork 0
takebackreality/string-instrument-inheritance
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published