Question: In C++ Create a class called SuperHero . The SuperHero class should have a default constructor (that prints Hero created) and a destructor (that prints

  • In C++
  • Create a class called SuperHero. The SuperHero class should have a default constructor(that prints Hero created) and a destructor(that prints a message saying the hero was defeated). Every Hero has a name member variable which is NOT public. Every Hero has member functions: saveTheDay(which prints Im here to save the day.), setName (which sets the name member variable) and getName.
  • Derive 2 classes from SuperHero: DCHero and MarvelHero. Both child classes inherit everything from the parent, but they all have their own version of the saveTheDay function(overriding the function). Both classes should have a constructor and destructor.

In main, create 3 objects and call the function to set their names;

DCHero superMan; //feel free to substitute your favorite heroes here

MarvelHero spiderMan;

SuperHero wordGirl;

Ask the user which Hero they would like to interview. Based on their answer, call this save function for that hero.

void save(SuperHero& hero) {

cout << "**************SuperHero ***************" << endl;

cout << hero.getName() << endl;

hero.saveTheDay();

}

Running the program at this point might look like

Which hero would you like to interview? (1=Superman, 2=SpiderMan, 3=WordGirl)

1

**************SuperHero ***************

Superman

Up, up and away!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!