Quiz: Part C: Coding Question 1

Part C: Coding Question 1


Quiz instructions

This section of the exam will require you to write code into files and then submit these files to the appropriately named file upload points. Please make your code readable and use comments to explain what you are doing.


In this question you have to write C++ code for two classes a parent class: Band which represents musical groups and a child class: Metal which inherits from Band.

This whole question is worth 17 marks and you need to submit your answers to the file submission points below. Please match your file to the name on the hand-in point!

The Band class has:

two private member variables

an integer called members that represents the number of people in the band.

an integer that is the founding year of the band as a four digit year.

● a constructor that takes in the members and founding year as parameters.

● a constructor that takes in the members and sets the founding year to be the current year

● a function called get_members() which takes no parameters and returns the integer representing the members of this object.

● a virtual function called get_age() which takes no parameters and returns a string that gives the age of the band as text, where a band that is less than 5 years old is "young", and anything else is "old".

The Metal class inherits from Band and has:

● a private member variable which is an int variable called darkness which represents exactly how dark their metal is, where 1000 is "the most black metal ever" and 0 is Michael Bublé.

● a constructor which takes in the darkness of this Metal group as a parameter, along with the number of band members and their founding year. This constructor should call the constructor of the parent class with the appropriate values.

● a get_age() method that overrides the get_age() method the parent class. This method should concatenate:

○ the string "this "

○ the result of a call to the get_age() method of the parent class,

○ the string " metal band is"

○ a string representation of the darkness of this Metal object, based on:

darkness value 0-10: "not very dark at all."

■ darkness value 10-100: "dark."

■ darkness value 100-200: "very dark!"

■ darkness value 200-800: "extremely dark!!"

■ darkness value > 800: "profoundly dark!!!"

As an indication of how your code should behave the following driver code:

//

Band *bublegum = new Band(4,2019);

Metal *danzigwithtearsinmyeyes = new Metal(800,4,2019);


//

cout << bublegum->get_age() << endl;

cout << danzigwithtearsinmyeyes->get_age() << endl;


Should produce the output:

young

This young metal band is extremely dark!!