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

(C++ program) Polymorphism program This the code that needs to be completed

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.

: #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

( please comment and show output)

1. You are to implement the Consumables and the Accessories class, create files for each containing any number of consumables and accessories. (make sure they contain all the information needed). 2. All files have_(underscores) for the spaces. I show how you remove the spaces for the weapons, you should remove the spaces for all of the words. "challenge is placing them back when you write to the file 3. In the main, have the ability to show all the (weapon /armor / accessories/consumables) depending what the user wants to see. display those items only. 4. When the program exits, save all the items back in their respective file. To know what each item is, you will need to create a variable in ltem called whatlslt which holds a string holding the item type, so if your object is a weapon, it will say weapon. This variable should go between the name and the description. You will need to UPDATE all files, all the classes, the way you infile and outfile in order for the program to work well with this new variable. ** also, make sure you start your files with the number of items in the file, so when you are saving everything back to the file, you need to know how many of those items there are... (maybe sort based on item type?) 1. You are to implement the Consumables and the Accessories class, create files for each containing any number of consumables and accessories. (make sure they contain all the information needed). 2. All files have_(underscores) for the spaces. I show how you remove the spaces for the weapons, you should remove the spaces for all of the words. "challenge is placing them back when you write to the file 3. In the main, have the ability to show all the (weapon /armor / accessories/consumables) depending what the user wants to see. display those items only. 4. When the program exits, save all the items back in their respective file. To know what each item is, you will need to create a variable in ltem called whatlslt which holds a string holding the item type, so if your object is a weapon, it will say weapon. This variable should go between the name and the description. You will need to UPDATE all files, all the classes, the way you infile and outfile in order for the program to work well with this new variable. ** also, make sure you start your files with the number of items in the file, so when you are saving everything back to the file, you need to know how many of those items there are... (maybe sort based on item type?)

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!