Slove using C++ 6. (6 points) Paula and Danny want to plant evergreen trees alon
ID: 3880045 • Letter: S
Question
Slove using C++
6. (6 points) Paula and Danny want to plant evergreen trees along the back side of their vard. They do not want to have an excessive number of trees. Write a program that prompts the user to input the following: a. The length of the yard. b. The radius of a fully grown tree. c. 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. Format your output to two decimal places.Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
double l,r,s;//variable declarations
//reading input
cout<<"Enter length of the yard:";
cin>>l;
cout<<"Enter radius of fully grown tree:";
cin>>r;
cout<<"Enter space between fully grown trees:";
cin>>s;
double n=0;//number trees can be placed
double t;//total space occupied..by trees
double st = 2*r+s;//space by tree+space between trees
while(l>0)
{
if((l-st)<=0)
break;
l=l-st;
n++;
}
if((l-2*r)>=0)
n++;
cout<<"Number of trees can be planted :"<<n<<endl;
cout<<"Total space occupied by trees :"<<n*r*2<<endl;
return 0;
}
output:
Enter length of the yard:10
Enter radius of fully grown tree:2
Enter space between fully grown trees:1
Number of trees can be planted :2
Total space occupied by trees :8
Process exited normally.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.