Write a C++ Program Description You and a friend want to plant evergreen trees a
ID: 3753443 • Letter: W
Question
Write a C++ Program
Description You and a friend want to plant evergreen trees along the back side of your yard. You 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 back side of the yard (double) . The diameter of a fully grown tree (double) The required space between fully grown trees (double) The program outputs the number of trees that can be planted in the yard (int) and the total space that will be occupied by the fully gown trees (double) Specifications To get full credit you program must contain/perform the following Declare variables with meaningful names and correct types Document all your variables Document portions of your code (parts that perform nput, output, calculations etc.) Program must compile and run with various inputsExplanation / Answer
Code
#include <iostream>
using namespace std;
int main()
{
double lengthOfBacksideYard;
double diameterOfTree;
double spaceBetweenTree;
//taking inputs
cout<<"Enter length of backside yard: ";
cin>>lengthOfBacksideYard;
cout<<"Enter diamater of fully grown tree: ";
cin>>diameterOfTree;
cout<<"Enter space between trees: ";
cin>>spaceBetweenTree;
//calculating number of trees that can be planted
int numberOfTrees = (int)(lengthOfBacksideYard + spaceBetweenTree)/(diameterOfTree + spaceBetweenTree);
double totalSpaceOccupiedByTrees = numberOfTrees * diameterOfTree;
//printing result
cout<<"Number of trees that can be planted : "<<numberOfTrees<<endl;
cout<<"Total space occupied by the fully grown trees: "<<totalSpaceOccupiedByTrees<<endl;
return 0;
}
Sample output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.