Question

In: Computer Science

I have a quick question about this C ++ problem in my intro class. I have...

I have a quick question about this C ++ problem in my intro class. I have been able to get the first answer consistently when I test it, but my second seems to either be high or low no matter how I change it. Can you show me how you would do this problem with the setprecision(2)

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. 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!

This is all of the information given by the question. So far this is what I have come up with, but I believe I am off with one of the calculations.

This is the information given from when I tested it:

Test Case Incomplete

Number and space for trees correctly output test 1

Input

200
8
24

Output

Enter the length of the yard: 200
Enter the radius of a fully-grown tree: 8
Enter the space between the fully grown tree: 24
The numbers of trees that can be planted in the yard is 5The total space that will be occupied by the fully grown trees 1e+03

Results

5

1005.31 (this is the number I am having a difficult time reaching).











Here is an example of my attempt and the test result right after.


#include
#include

using namespace std;

int main()

{

// declare variables as double type

double lengthofYard;

double radius;

double spaceBetween;

double areaofTrees;

double numberofTrees;

const float pi = 3.14159;

// Prompt the user to enter the length of the yard.
cout << setprecision(2) ;

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/((2*radius)+spaceBetween);

//calculate areaofTrees

areaofTrees = (pi*radius*radius)*numberofTrees;
  
cout << "The numbers of trees that can be planted in the yard is " ;

cout << numberofTrees;
  
cout << "The total space that will be occupied by the fully grown trees ";
  
cout << areaofTrees;
  
  
  
  
return 0;

}

Test CaseIncomplete

Number and space for trees correctly output test 1

Input

200
8
24

Output

Enter the length of the yard: 200
Enter the radius of a fully-grown tree: 8
Enter the space between the fully grown tree: 24
The numbers of trees that can be planted in the yard is 5The total space that will be occupied by the fully grown trees 1e+03

Results

5

1005.31

Solutions

Expert Solution

#include<iostream>
#include<iomanip>
using namespace std;

int main()

{

// declare variables as double type

double lengthofYard;

double radius;

double spaceBetween;

double areaofTrees;

double numberofTrees;

const float pi = 3.14159;

// Prompt the user to enter the length of the yard.
cout << setprecision(6) ;

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/((2*radius)+spaceBetween);

//calculate areaofTrees

areaofTrees = (pi*radius*radius)*numberofTrees;
  
cout << "The numbers of trees that can be planted in the yard is " ;

cout << numberofTrees<<endl;
  
cout << "The total space that will be occupied by the fully grown trees ";
  
cout << areaofTrees;
  
  
  
  
return 0;

}

Expected output:


Related Solutions

I have a question about C++ programming Language class. I am confused with these terms and...
I have a question about C++ programming Language class. I am confused with these terms and what they are for. 1. Unix 2. Terminal 3. Git 4. CLOC 5. Linux Please explain each words and what's their jobs for C++. Also, if you know some good sources/websites, could you please provide me a link where I can learn how to use Unix, Terminal, Git, etc.
This is a question for my biochemistry class. I have copied and pasted it below. This...
This is a question for my biochemistry class. I have copied and pasted it below. This is all that was given to me. Diagram the flow of genetic material in a cell.
This is a question for my problem-solving class. I am really stuck and I can't see...
This is a question for my problem-solving class. I am really stuck and I can't see much of a pattern so I would appreciate if someone could draw out for each thief and explain the pattern to get the answer for 40 thieves! Question: Forty thieves, all different ages, steal a huge pile of identical gold coins and must decide how to divide them up. They settle on the following procedure. The youngest divides the coins among the thieves however...
I have this question in my nursing class I just need someone to answer it for...
I have this question in my nursing class I just need someone to answer it for me Reflect on an occasion where you experienced ineffective leadership (doesn't have to be in the hospital/healthcare). What behaviors did they display? What factors may have influenced their leadership style?
This is a question for my stats class. Its a hypothesis problem with a conclusion.     A...
This is a question for my stats class. Its a hypothesis problem with a conclusion.     A forester studying diameter growth of red pine believes that the mean diameter growth will be different from the known mean growth of 1.35 inches/year if a fertilization treatment is applied to the stand. He conducts his experiment, collects data from a sample of 32 plots, and gets a sample mean diameter growth of 1.6 in./year with the standard deviation of  0.46 in./year. What did the...
this is my assignment for intro to java tha i could not figure out, my system...
this is my assignment for intro to java tha i could not figure out, my system just crashed wit a lot of errors. thank for your help Create a new Java class inside your project folder. The name of the class should be: TempConverter Note that this means you should have the following line at the top of your program: public class TempConverter Write a program that allows the user to convert a temperature given in degrees Celsius or Fahrenheit...
This is the code I have. My problem is my output includes ", 0" at the...
This is the code I have. My problem is my output includes ", 0" at the end and I want to exclude that. // File: main.cpp /*---------- BEGIN - DO NOT EDIT CODE ----------*/ #include <iostream> #include <fstream> #include <sstream> #include <iomanip> using namespace std; using index_t = int; using num_count_t = int; using isConnected_t = bool; using sum_t = int; const int MAX_SIZE = 100; // Global variable to be used to count the recursive calls. int recursiveCount =...
I have a term paper that I have to write for my microeconomics class. Economics is...
I have a term paper that I have to write for my microeconomics class. Economics is super new to me, this is the first class I've ever taken related to it. My subject is the economic impacts of the opioid epidemic. My outline is due next week and I have no idea what to even do research on or which direction to go. Where do I even start?
Hello, this question relates to a class I am taking called introduction to C++. I have...
Hello, this question relates to a class I am taking called introduction to C++. I have no experience writing programs and outside of learning out of a textbook, and studying on my own, have little understanding of logic. I have been assigned a problem that requires me to write a program for a Grocery Bill, where the consumer inputs the price for 5 items, that the program calculates the total with a 6% sales tax. I really am not sure...
I have 5 multiple choice question related to my accounting class. 1. In the "time interest...
I have 5 multiple choice question related to my accounting class. 1. In the "time interest earned" ratio, the numerator should be income before deducting (select the best answer): A. interest Expense B. Income tax expense C. Both A & B D. None of the above 2. A lender accepts real estate with a fair value of $15,000,000 in full settlement of a $20,000,000 loan. the real estate has a carrying value of $19,000,000 on the bond of the borrower....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT