Write a complete and most simplistic C++ code for: MetroP \'11-29% 4:29PM n the
ID: 3736836 • Letter: W
Question
Write a complete and most simplistic C++ code for:
Explanation / Answer
#include <iostream>
using namespace std;
class Tree {
public:
int age;
double height;
Tree(int age1, double height1) {
age=age1;
height=height1;
}
void setage(int age2) {
age=age2;
}
int getage() {
return age;
}
void setheight(int height2) {
height=height2;
}
int getheight() {
return height;
}
void display() {
cout<<"Age=" << age<<endl;
cout<<"Height=" << height<<endl;
}
void grow() {
cout<<"Growth rate=" << (height/age)<<endl;
}
};
class CoconutTree : public Tree {
private:
int nutNumber;
int leafHeight;
public:
CoconutTree(int nutNumber1, int leafHeight1, int age1, double height1) : Tree(age1, height1) {
nutNumber=nutNumber1;
leafHeight=leafHeight1;
}
void setnutNumber(int nutNumber2) {
nutNumber=nutNumber2;
}
int getnutNumber() {
return nutNumber;
}
void setleafHeight(int leafHeight2) {
leafHeight=leafHeight2;
}
int getleafHeight() {
return leafHeight;
}
void display() {
cout<<"Age=" << age<<endl;
cout<<"Height=" << height<<endl;
cout<<"Number of Nuts= " << nutNumber<<endl;
cout<<"Height of leaf= " << leafHeight<<endl;
}
void bendGrowth(){
cout<<"Bend Growth= " << (nutNumber/leafHeight)<<endl;
}
};
class Willow : public Tree {
private:
int numBranch;
int flexibility;
public:
Willow(int numBranch1, int flexibility1, int age1, double height1) : Tree(age1, height1) {
numBranch=numBranch1;
flexibility=flexibility;
}
void setnumBranch(int numBranch2) {
numBranch=numBranch2;
}
int getnumBranch() {
return numBranch;
}
void setflexibility(int flexibility2) {
flexibility=flexibility2;
}
int getflexibility() {
return flexibility;
}
void display() {
cout<<"Age=" << age<<endl;
cout<<"Height=" << height<<endl;
cout<<"Number of Branches= " << numBranch<<endl;
cout<<"Flexibility= " << flexibility<<endl;
}
void swing() {
cout<<"Swing=" << (numBranch/flexibility)<<endl;
}
};
int main() {
CoconutTree coco(6,4,1,2);
coco.display();
coco.grow();
coco.bendGrowth();
Willow ww(8,5,3,7);
ww.display();
ww.grow();
ww.swing();
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.