Project: Tree Growth (Version 2)

Trees and Growth Patterns

Trees provide a number of benefits for the environment. Trees are able to absorb dangerous gases such as carbon dioxide (CO2) while, at the same time, producing oxygen for us to breathe. Trees also absorb and distribute water that otherwise may lead to runoff, thus reducing pollution and loss of topsoil. Some forms of trees even produce food for us to eat (think: apple trees). Watch the following animated video to learn more about the benefits of trees to our society:

As we plant trees strategically, we often want to know how tall a tree can be expected to grow. While there are environmental factors that impact tree growth patterns, we can approximate the height of tree if we know certain facts. As trees grow, they add approximately the same amount of mass each year. If we know this amount, we can compute the expected height of a tree over time. The height of a tree (h) can be approximated based on its age using the following formula:

Tree_Growth_Equation

where a = the amount of mass added to a tree each year and t is the age in years.

Tree02

 

C++ Project: Computing Tree Growth

This project will provide you with an introduction to the fundamentals of problem-solving in C++. The focus of this project is on how to solve simple problems using C++ data types, variables, for loops, functions, and arithmetic operations. In this project, you will…

  • Develop code to read data from the standard input and produce data to the standard output.
  • Translate a given mathematical expression into equivalent syntactically correct programming statements.
  • Write code that conforms to a programming style specified by the instructor.
  • Select and implement the appropriate control structure(s) for this problem.
  • Decompose the problem into a sequence of single-purpose functions that are highly cohesive and loosely coupled.

Create a program called TreeGrowth2.cpp to compute the approximate height of a tree based on the amount of mass added each year (a double value) and the age in years (an int value). Output should include a 10-row table listing the height for the present age and the next 9 years. All real numeric amounts should be precise to two decimal places. Hint: Use a for loop for the output, and a while loop to control the iterations of input.

Be sure that your program is decomposed into functions (2-3 input functions are mandatory; computation functions and output functions are optional). Validate both inputs to verify that they are numeric and a value greater than 0 (one validation loop for each input). Here are few sample tests you can run to check if your program is working correctly:

Test Case #1

Enter the Amount of Mass: 256.0
Enter the Age in Years: 81
You entered a mass of 256.00 and an age of 81 years.

At age 81 years, the approximate height of the tree is 12.00 meters.
At age 82 years, the approximate height of the tree is 12.04 meters.
At age 83 years, the approximate height of the tree is 12.07 meters.
At age 84 years, the approximate height of the tree is 12.11 meters.
At age 85 years, the approximate height of the tree is 12.15 meters.
At age 86 years, the approximate height of the tree is 12.18 meters.
At age 87 years, the approximate height of the tree is 12.22 meters.
At age 88 years, the approximate height of the tree is 12.25 meters.
At age 89 years, the approximate height of the tree is 12.29 meters.
At age 90 years, the approximate height of the tree is 12.32 meters.

Continue? (0=No, 1=Yes): 0

Press any key to continue . . .

Test Case #2

Enter the Amount of Mass: 5333.3333
Enter the Age in Years: 30
You entered a mass of 5333.33 and an age of 30 years.

At age 30 years, the approximate height of the tree is 20.00 meters.
At age 31 years, the approximate height of the tree is 20.16 meters.
At age 32 years, the approximate height of the tree is 20.33 meters.
At age 33 years, the approximate height of the tree is 20.48 meters.
At age 34 years, the approximate height of the tree is 20.64 meters.
At age 35 years, the approximate height of the tree is 20.79 meters.
At age 36 years, the approximate height of the tree is 20.93 meters.
At age 37 years, the approximate height of the tree is 21.08 meters.
At age 38 years, the approximate height of the tree is 21.22 meters.
At age 39 years, the approximate height of the tree is 21.36 meters.

Continue? (0=No, 1=Yes): 1

Enter the Amount of Mass: 2000.50
Enter the Age in Years: 123
You entered a mass of 2000.50 and an age of 123 years.

At age 123 years, the approximate height of the tree is 22.27 meters.
At age 124 years, the approximate height of the tree is 22.32 meters.
At age 125 years, the approximate height of the tree is 22.36 meters.
At age 126 years, the approximate height of the tree is 22.41 meters.
At age 127 years, the approximate height of the tree is 22.45 meters.
At age 128 years, the approximate height of the tree is 22.50 meters.
At age 129 years, the approximate height of the tree is 22.54 meters.
At age 130 years, the approximate height of the tree is 22.58 meters.
At age 131 years, the approximate height of the tree is 22.63 meters.
At age 132 years, the approximate height of the tree is 22.67 meters.

Continue? (0=No, 1=Yes): 0

Press any key to continue . . .

Test Case #3

Enter the Amount of Mass: BUMMER
ERROR: Your input must be a real number > 0. Please try again.
Enter the Amount of Mass: 256.0
Enter the Age in Years: -5.5
ERROR: Your input must be an integer > 0. Please try again.
Enter the Age in Years: BAMBAM
ERROR: Your input must be an integer > 0. Please try again.
Enter the Age in Years: 81
You entered a mass of 256.00 and an age of 81 years.

At age 81 years, the approximate height of the tree is 12.00 meters.
At age 82 years, the approximate height of the tree is 12.04 meters.
At age 83 years, the approximate height of the tree is 12.07 meters.
At age 84 years, the approximate height of the tree is 12.11 meters.
At age 85 years, the approximate height of the tree is 12.15 meters.
At age 86 years, the approximate height of the tree is 12.18 meters.
At age 87 years, the approximate height of the tree is 12.22 meters.
At age 88 years, the approximate height of the tree is 12.25 meters.
At age 89 years, the approximate height of the tree is 12.29 meters.
At age 90 years, the approximate height of the tree is 12.32 meters.

Continue? (0=No, 1=Yes): 0

Press any key to continue . . .

Deliverables

See the instructor for submission instructions and due date(s).

Powered by WordPress. Designed by WooThemes

Skip to toolbar