t 1 . age(); //Access the member function age of t 1, and its function is to output "The age of this tree is:";
t 1 . grow(3); //Access the member function grow of t 1 and pass in parameter 3, that is, set the age of t 1 and process its private data ages+= 3;; In fact, I really don't understand the membership function grow defined by the landlord. It takes a plastic year, and then
CIN & gt; & gt What do you mean, Nian doesn't understand?
Because there is no need to output the age value of t 1 and CIN >: > year, the sentence is output like this:
The age of this tree is:
Please enter the year: 3
The age of this tree is:
Supplementary estimation means that you want to pass in the parameters you want in the function of grow, and you must have output data to define the constructor in the class.
//# contains "StdAfx.h"
# include & ltiostream & gt
Use namespace std
Category tree
{
Public:
tree(int a){ age = a; }
Invalid growth (integer year);
void age();
Private:
int ages
};
Void tree:: Growth (integer year) {
Cout & lt& lt "Please enter the year:"
//CIN & gt; & gt year;
Age+= years old;
}
Void tree:: age ()
{
Cout & lt& lt "The age of this tree is:"
}
int main()
{
Tree t1(5);
t 1 . age();
//T2 . age();
t 1 . grow(3);
t 1 . age();
//T2 . grow(2);
//T2 . age();
System ("suspended");
Returns 0;
}
Output:
This tree is five years old.
Please enter the year: 3
This tree is eight years old.