In: Computer Science
IN C++ please
Paula and Danny want to plant evergreen trees along the back side of their yard. They do not want to have an excessive number of trees. Write a program that prompts the user to input the following: The length of the yard. The radius of a fully grown tree. (Use 3.14159 as the constant value for any calculations that may need \piπ). The required space between fully grown trees. The program outputs: The number of trees that can be planted in the yard The total space that will be occupied by the fully grown trees. Format your output with setprecision(2) to ensure the proper number of decimals for testing!
When the input is: 200, 8, 24
The output should be: Enter the length of the yard:
200
Enter the radius of full grown tree:
8
Enter the gap between trees:
24
Total Number of trees: 5
Area covered by trees: 1005.31
#include <iostream> #include <iomanip> using namespace std; int main() { int len, radius, gap; cout << "Length of yard: "; cin >> len; cout << "Enter the radius of fully grown tree: "; cin >> radius; cout << "Enter the gap between trees: "; cin >> gap; int numTrees = 0; if(gap >= 2*radius) { //len = len - 2*radius; //numTrees++; numTrees += (len / (2*radius + gap)); } cout << "numTrees: " << numTrees << endl; cout << "Area covered: " << (numTrees * 3.14159 * radius * radius) << endl; }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.