Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iostream>
- using namespace std;
- struct item
- {
- double height;
- double width;
- double weight;
- string name;
- string stateOfMatter;
- bool flammable;
- /**
- *Item is the base structure for all subclasses.
- *Every item should have these properties.
- *@param height - The height of the object (feet).
- *@param width - The width of the object (feet).
- *@param weight - The weight of the object. (Pounds)
- *@param name - The GENERIC name of the item. Birch wood, for example, would be wood.
- *@param state - The state of matter. The common states of matter are liquid, solid, and gas.
- *@param flame - Whether or not the item is flammable.
- */
- item(double h, double w,double weight, string n,
- string state, bool flame)
- {
- this->height=h;
- this->width=w;
- this->weight=weight;
- this->name=name;
- this->flammable=flame;
- this->stateOfMatter=state;
- }
- };
- struct wood:item
- {
- string type;
- double age;
- wood(string type, double age, double h, double w,double weight, string n,
- string state, bool flame):item(h,w,weight,n,state,flame)
- {
- this->type=type;
- this->age=age;
- }
- /**
- *This will set the wood on fire, destroying it.
- *Only flammable items can be burned, but all wood should be declared as flammable.
- *@param the wood to burn.
- *@return 1 if the wood is burnt, 0 if it was not burnt.
- */
- short burn(wood toBurn) {
- if(toBurn.flammable==true)
- {
- this->type="Charcoal";
- height/=5.;
- width/=5.;
- weight/=5;
- name="Burnt wood";
- stateOfMatter="Solid";
- flammable=true;
- return 1;
- }
- else return 0;
- }
- /**
- *Returns information regarding the status of the wood.
- *@param the wood to retrieve.
- *@return A string representing the stats.
- */
- string getStats(wood toGet)
- {
- string toReturn;
- //Substruct specific variables.
- toReturn+="Type: ";
- toReturn+=toGet.type;
- toReturn+="\nAge: ";
- toReturn+=toGet.age;
- //Superstruct variables.
- toReturn+="\nHeight: ";
- toReturn+=toGet.height;
- toReturn+="\nWidth: ";
- toReturn+=toGet.width;
- toReturn+="\nWeight: ";
- toReturn+=toGet.weight;
- toReturn+="\nGeneric name: ";
- toReturn+=toGet.name;
- toReturn+="\nState of Matter: ";
- toReturn+=toGet.stateOfMatter;
- toReturn+="\nFlammable: ";
- toReturn+=toGet.flammable;
- toReturn+="\n";
- return toReturn;
- }
- };
- int main()
- {
- wood w("Birch", 15,5,2,100,"wood","solid",true);
- cout << endl<<w.getStats(w)<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement