Question: (C++ program) Polymorphism program This the code that needs to be completed : #include #include #include using namespace std; // This is the base class
(C++ program) Polymorphism program

This the code that needs to be completed :
#include
#include
#include
using namespace std;
// This is the base class
class Item
{
private:
string name;
//whatIsIt goes here
string description;
double weight;
public:
//these two are the constructors, they will be changed once you include the
//whatIsIt variable.
Item(){name = "NULL"; description = "NULL"; weight = 0;}
Item(string name, string description, double weight)
{
this->name = name;
this->description = description;
this->weight = weight;
}
string getName(){return name;}
void setName(string name){this->name = name;}
string getDescription(){return description;}
void setDescription(string description){this->description=description;}
double getWeight(){return weight;}
void setWeight(double weight){this->weight = weight;}
virtual void display()
{
cout
//what is it display goes here.
cout
cout
cout
}
};
//gear is derived from Item. There are no gear in our program, but weapon, armor and accessories
//are derived from Gear.
class Gear:public Item
{
private:
int dmg;
int def;
int spd;
public:
Gear():Item(){dmg = 0; def = 0; spd = 0;}
//make sure to add the whatIsIt here too.
Gear(string name, string description, double weight,int dmg, int def, int spd)
:Item(name,description,weight)
{
this->dmg = dmg;
this->def = def;
this->spd = spd;
}
int getDmg(){return dmg;}
int getDef(){return def;}
int getSpd(){return spd;}
void setDef(int def){this->def = def;}
void setDmg(int dmg){this->dmg = dmg;}
void setSpd(int spd){this->spd = spd;}
virtual void display()
{
cout
//something missing here..
cout
cout
cout
cout
cout
cout
}
};
class Weapon : public Gear
{
private:
int range;
public:
Weapon():Gear(){range = 0;}
//whatIsIt missing in this overloaded constructor too.
Weapon(string name, string description, double weight,int dmg, int def, int spd, int range)
:Gear(name,description,weight,dmg,def,spd)
{this->range = range;}
int getRange(){return range;}
void setRange(int range){this->range = range;}
virtual void display()
{
cout
//missing here too.
cout
cout
cout
cout
cout
cout
cout
}
};
class Armor : public Gear
{
private:
string type;
public:
Armor():Gear(){type = "NULL";}
//add the whatIsIt here too.
Armor(string name, string description, double weight,int dmg, int def, int spd, string type)
:Gear(name,description,weight,dmg,def,spd)
{this->type = type;}
string getType(){return type;}
void setType(string type){this->type = type;}
virtual void display()
{
cout
//missing here too.
cout
cout
cout
cout
cout
cout
cout
}
};
int main()
{
//lets create a backpack with 30 size MAX
Item *inventory[30];
int lastitemlocation = 0; //this keeps track of how many items we have currently in inventory
int size; //used when infile to know how many objects are in the file.
string name;
//whatIsIt variable goes here.
string description;
double weight;
int dmg;
int def;
int spd;
int range;
string type;
ifstream inFile;
int choice; // first original choice to select item.
int choice2; // what you want to do with first item.
int choice3;// select second item
inFile.open("weapons.txt");
//FOR ALL THE INFILES, whatIsIt IS ALSO IN THERE, MODIFY THESE.
inFile>>size;
getline(inFile,type);
cout
for (int x=0; x { inFile>>name>>description>>weight>>dmg>>def>>spd>>range; //changes all the _ to a space for the names. ( please comment and show output)


Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
