Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ The Tree class can represent various kinds of trees, including a null tree,

ID: 3691674 • Letter: C

Question

C++

The Tree class can represent various kinds of trees, including a null tree, i.e., a location in the forest that does not have a tree. The Tree class will have the following Private data members: type (string) the species of the tree (e.g., "Oak", "not a tree") probCatch (double) - the probability (0.0 to 1.0) of the tree catching on fire . status (int) - the tree's status as follows 0 not a tree (for a forest location without a tree) 1 - a live tree (i.e., not burning) 2 - a burning tree wetness (double) - a number between 1.0 and 100.0 to indicate wetness (default 1.0) burnTime (int) - the number of time steps for a tree to burn (default 1) * xpos (int)-the x position of the tree within a GraphX window (default 0) .ypos (int) - the y position of the tree within a GraphX window (default 0) . symbol (string) - the symbol used to draw the tree within a GraphX window (e.g. "solidtriangle")

Explanation / Answer

Answer -

//------tree.h file-------
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Tree
{
string type,symbol;
double probCatch,wetness;
int status,burnTime,xpos,ypos;
public:
Tree()
{
type="not_a_tree";
probCatch=1.0;
wetness=1.0;
symbol="solidtriangle";
status=0;
burnTime=1;
xpos=0;
ypos=0;
}
Tree(string type1,string symbol1, double probCatch1,double wetness1,int status1,int burnTime1,int xpos1,int ypos1)
{
type=type1;
probCatch=probCatch1;
wetness=wetness1;
symbol=symbol1;
status=status1;
burnTime=burnTime1;
xpos=xpos1;
ypos=ypos1;
}
void getprobCatch()
{
cout<<" Probability of tree catching fire(0.0 to 1.0) : "<<fixed<<setprecision(1)<<probCatch;
}
void setprobCatch()
{
cout<<" Enter Probability of tree catching fire(0.0 to 1.0) : ";
cin>>probCatch;
}
void getStatus()
{
cout<<" Status of Tree(0-not a tree,1-a live tree,2-burning tree) : "<<status;
}
void setStatus()
{
cout<<" Enter Status of Tree(0-not a tree,1-a live tree,2-burning tree) : ";
cin>>status;
}
void getWetness()
{
cout<<" Wetness of Tree(1.0 to 100.0) : "<<fixed<<setprecision(1)<<wetness;
}
void setWetness()
{
cout<<" Enter Wetness of Tree(1.0 to 100.0) : ";
cin>>wetness;
}
void getburnTime()
{
cout<<" burnTime of Tree : "<<burnTime;
}
void setburnTime()
{
cout<<" Enter burnTime of Tree : ";
cin>>burnTime;
}
};

//------tree.cpp file-------
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
Tree obj;
cout<<" ---------O/P OBJECT 1--------";
obj.getburnTime();
obj.getWetness();
obj.getStatus();
obj.getprobCatch();
Tree obj2("a_tree","solidtriangle",1.0,1.0,0,1,0,0);
cout<<" ---------O/P OBJECT 2--------";
obj2.getburnTime();
obj2.getWetness();
obj2.getStatus();
obj2.getprobCatch();
cout<<" ---------I/P OBJECT 3-------";
   Tree obj3;
   obj3.setburnTime();
   obj3.setWetness();
   obj3.setStatus();
   obj3.setprobCatch();
   cout<<" ---------O/P OBJECT 3-------";
obj3.getburnTime();
obj3.getWetness();
obj3.getStatus();
obj3.getprobCatch();
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote