Answer to Question #303311 in C++ for Becca

Question #303311

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:

  1. The length of the yard.
  2. The radius of a fully grown tree. (Use 3.14159 as the constant value for any calculations that may need \pi
  3. π).
  4. The required space between fully grown trees.

The program outputs:

  1. The number of trees that can be planted in the yard
  2. 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!



1
Expert's answer
2022-02-28T08:30:47-0500
using namespace std;


/*
	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!
*/


int main()
{
	float l, r, space;
	float PI = 3.14159;
	float num,totalspace,dia;
	
	cout<<"\n\tEnter length of the yard                          : "; cin>>l;
	cout<<"\n\tEnter Raius of fully grown trees                  : "; cin>>r;
	cout<<"\n\tEnter the required space between fully grown trees: "; cin>>space;
	
	num = floor(l/((2*r) + space));
	if(num>0) 
	{
		cout<<"\n\n\tNo. of Trees = "<<num;
		cout<<"\n\tTotal Space occupied by "<<num<<" trees = "<<((2*r) + space);	
	}
	else
	{
		cout<<"\n\n\tThe yard's length is less than the required space.";
	}
	return(0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog