Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**NEED ONLY SUPERHERO.H & SUPERHERO.CPP TO GET THE FOLLOWING OUTPUT Derive a class named SuperHero from the Hero class that you designed in the section.

**NEED ONLY SUPERHERO.H & SUPERHERO.CPP TO GET THE FOLLOWING OUTPUT

Derive a class named SuperHero from the Hero class that you designed in the section. Include in your design all of the statements and keywords necessary to compile and to run your code successfully under a standard C++ compiler.

SuperHeros behave the same as Heros, except that they have SuperPowers! A SuperHero still has a regular normal attack, and health...but he/she can also use his SuperPower to attack, and to defendbut only against other superheros. When a SuperHero fights against a Hero, he/she does not use his SuperPowers. They only uses their regular Hero attack.

Upon instantiation, a SuperHero object may receive no information, or it may receive five values:

The name, maximum health and attack values similar to the Hero class.

An unsigned integer for the SuperPowerAttack strength of the SuperHero.

A unsigned integer representing a The SuperPowerDefend strength for the SuperHero.

Fighting for the SuperHero is similar to the Hero class. Damage is calculated differently though. When Hero1 attacks Hero2

Build constructors to handle these instantiation types. Invalid input sets the object in the safe, empty state.

SuperHero should add the following new member variables.

m_superPowerAttack

unsigned

0

The SuperPower attacking strength

m_superPowerDefend

unsigned

0

The SuperPower defense strength

SuperHero also adds the following member functions: Note that they have the same names as the functions in Hero. They are supposed to shadow the functions in the Hero class.

unsigned getAttack() const -- This method should return the SuperPower Attack of the superhero instead of the regular Attack value.

Note that this method has the same name and prototype as the one in Hero.

You will also need a new global helper function, apply_damage. It will compute the damager both SuperHeros inflicts on each other. This should have the following prototype

friend void apply_damage ( SuperHero& A, SuperHero& B);

The following code uses your Hero and SuperHero classes and produces the output shown under it:

int main ()

cout << endl;

line(60); // print some dashes

cout << endl << "Greek Heros";

Hero hercules("Hercules",32, 4);

Hero theseus("Theseus",14, 5);

Hero oddyseus("Odysseus",15, 3);

Hero ajax("Ajax",17, 5);

Hero achilles("Achilles",20, 6);

Hero hector("Hector",30, 5);

Hero atalanta("Atalanta",10, 3);

Hero hippolyta("Hippolyta", 10, 2);

cout << endl << "Quarter Finals" << endl;

const Hero& greek_winner1 = achilles * hector;

const Hero& greek_winner2 = hercules * theseus;

const Hero& greek_winner3 = oddyseus * ajax;

const Hero& greek_winner4 = atalanta* hippolyta;

cout << endl << "Semi Finals" << endl;

const Hero& greek_winner_semifinal1 = greek_winner1* greek_winner2;

const Hero& greek_winner_semifinal2 = greek_winner3* greek_winner4;

cout << endl << "Finals" << endl;

const Hero& greek_final = greek_winner_semifinal1 * greek_winner_semifinal2;

cout << endl << "Comic book SuperHeros";

SuperHero superman("Superman",50, 9, 10, 9) ;

SuperHero hulk("The_Hulk",70, 6, 20, 3) ;

SuperHero wonderwoman ("WonderWoman",80, 5, 15, 10) ;

SuperHero raven("Raven",30, 10, 12, 5) ;

cout << endl << "Semi Finals" << endl;

const SuperHero& comic_winner1 = superman * hulk;

const SuperHero& comic_winner2 = wonderwoman * raven;

cout << endl << "Finals" << endl;

const SuperHero& comic_final = comic_winner1 * comic_winner2;

cout << endl << "Best Greeks Hero vs Best Comic Book SuperHero" << endl;

greek_final * comic_final;

------------------------------------------------------------

Greek Heros

Quarter Finals

Battle! Achilles vs Hector : Winner is Hector in 4 rounds.

Battle! Hercules vs Theseus : Winner is Hercules in 4 rounds.

Battle! Odysseus vs Ajax : Winner is Ajax in 3 rounds.

Battle! Atalanta vs Hippolyta : Winner is Atalanta in 4 rounds.

Semi Finals

Battle! Hector vs Hercules : Winner is Hector in 7 rounds.

Battle! Ajax vs Atalanta : Winner is Ajax in 2 rounds.

Finals

Battle! Hector vs Ajax : Winner is Hector in 4 rounds.

------------------------------------------------------------

Comic book SuperHeros

Semi Finals

Fight! Superman vs The_Hulk : Winner is The_Hulk in 5 rounds.

Fight! WonderWoman vs Raven : Winner is WonderWoman in 3 rounds.

Finals

Fight! The_Hulk vs WonderWoman : Winner is WonderWoman in 6 rounds.

------------------------------------------------------------

Best Greeks Hero vs Best Comic Book SuperHero

Battle! Hector vs WonderWoman : Winner is WonderWoman in 6 rounds.

Hero.h

#ifndef HERO_H #define HERO_H

#include

class Hero { char m_name[41]; unsigned m_attack; unsigned m_maximumHealth;

bool isEmpty() const; protected : int m_health;

public: // constructors Hero(); Hero(const char name[], unsigned maximumHealth, unsigned attack);

// member functions void respawn(); bool isAlive() const { return m_health > 0; } unsigned getAttack() const { return m_attack; }

// display function void display(std::ostream &) const;

// friend global helper function to assign damage to 2 heroes at the same time. friend void apply_damage(Hero& A, Hero& B); };

#endif

Hero.cpp

#include #include #include "Hero.h"

using namespace std;

////////////////////////////////////////////// // Default constructor // Hero::Hero () { m_name[0] = 0; m_health = 0 ; m_attack = 0 ; m_maximumHealth = 0 ;

}

Hero::Hero (const char name[], unsigned maximumHealth, unsigned attack) {

strcpy(m_name , name); m_maximumHealth = maximumHealth ;

m_health = maximumHealth; m_attack = attack ; }

///////////////////////////////////////////////////////// // // Hero::display function void Hero::display(ostream & out) const {

if (isEmpty()) { return;} else { out << m_name; }

}

///////////////////////////////////////////////// // Hero::isEmpty () // return true if the Hero object is uninitialized // bool Hero::isEmpty() const { if (m_name[0] == 0 && m_attack == 0 &&

m_maximumHealth == 0 && m_health == 0)

{ return true;

} else {

return false; }

}

///////////////////////////////////////////////// // sets the Hero object's health back to full // void Hero::respawn() { }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions