In: Computer Science
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.
The required space between fully grown trees.
The program outputs the number of trees that can be planted in the yard and the total space that will be occupied by the fully grown trees.
Provided code is done as per your requirements.
Code Image:
Sample
Output:
Code to Copy:
#include <iostream>
using namespace std;
int main()
{
// declare variables as double type
double lengthofYard;
double radius;
double spaceBetween;
double areaofTrees = 0;
double numberofTrees;
// Declare count as integer type variable.
int count = 0;
// Prompt the user to enter the length of the yard.
cout << "Enter the length of the yard: ";
cin >> lengthofYard;
// Prompt the user to enter the radius of the fully grown tree.
cout << "Enter the radius of a fully-grown tree: ";
cin >> radius;
//Prompt the space between the fully-grown trees from user
cout << "Enter the space between the fully grown tree: ";
cin >> spaceBetween;
//calculate number of trees
numberofTrees = lengthofYard /spaceBetween;
//calculate areaofTrees
areaofTrees = 3.14*radius*radius*numberofTrees;
// Display the total Space occupied by the full grown trees.
cout << "The total space occupied by fully grown trees is: " << areaofTrees<<endl;
return 0;
}