Question

In: Computer Science

Write a C++ program for the following problem: Calculate and print the area and volume of...

Write a C++ program for the following problem:

Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5)

Note: Your loop variable will need to be a double data type

Use two decimal places on all numbers that are double data type.

This will be a table with 3 columns. Don't worry about borders or grid lines on the table.

print column headings outside the loop

Use r as the loop counter and as the radius. Let the height of the cone be twice the radius.

Below the while loop, print the sum of all 3 columns

Solutions

Expert Solution

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

int main () {
   double r = 1,h,a,v,pi=3.14159;
   cout << fixed << setprecision(2);
      
   cout<<"Radius\tArea\tVolume"<<endl;
   while(r<=20){
      h = 2*r;
      a = pi*r*(r+sqrt(h*h+r*r));
      v = pi*r*r*h/3;
      cout<<r<<"\t"<<a<<"\t"<<v<<endl;
      r += 0.5;
   }
   return 0;
}


Related Solutions

Write a program in C++ that solves this problem Calculate the area and volume of a...
Write a program in C++ that solves this problem Calculate the area and volume of a sphere problem. Inside a for loop, vary the radius from 10 to 40  with a step or increment of 5 and calculate the area and volume Your radius will be equal to your loop counter. All calculations should have 2 decimal places, but the radius should have zero decimal places and any number of 1,000 or more should have a comma. Print the radius, area,...
Write a C++ program to calculate the sphere volume and surface area. Provided that the sphere...
Write a C++ program to calculate the sphere volume and surface area. Provided that the sphere volume = and the sphere surface area = , where r is the radius. 1. Read r from the user using cin statement. 2. Calculate the volume (Vol) and the surface area (Area) of a sphere. 3. Print r, Vol, and Area in a suitable messages.
1) Write a functional program in Java that can calculate the volume and surface area of...
1) Write a functional program in Java that can calculate the volume and surface area of a sphere and a cube 2) Write a procedural program in Java that can calculate the volume and surface area of a sphere and a cube 3) Write an Object Oriented Program in Java that can find the volume and surface area of a sphere and cube
Part One: Write an interactive program to calculate the volume and surface area of a three-dimensional...
Part One: Write an interactive program to calculate the volume and surface area of a three-dimensional object. Use the following guidelines to write your program: Create a word problem that involves calculating the volume and surface area of a three-dimensional object. Choose one of the following: Cube: surface area 6 s2 , volume s3 Sphere: surface area 4πr2 , volume (4.0/3.0) π r3 Cylinder: surface area 2π r2 + 2 π r h, volume π r2 h Cone: surface area...
IN C++ Modify the above program to compute the side area, total area, and volume of...
IN C++ Modify the above program to compute the side area, total area, and volume of a cylinder and the area and volume of a sphere, depending on the choice that the user makes. Your program should ask users to enter 1 to choose cylinder or 2 for sphere, and display an "invalid choice error" for other values. For a cylinder, we want to compute: Side area: (2*PI*r) * h Total Area: 2*(PI*r2) + Side area Volume: (PI*r2)*h For a...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle    3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle then display it's area using the following formula: area = PIr2 Use 3,14159 for PI and the radius of the circle for r. If the...
Programming Language C++ Task 1: Write a program to calculate the volume of various containers. A...
Programming Language C++ Task 1: Write a program to calculate the volume of various containers. A base class, Cylinder, will be created, with its derived classes, also called child classes or sub-classes. First, create a parent class, Cylinder. Create a constant for pi since you will need this for any non-square containers. Use protected for the members. Finally, create a public function that sets the volume. // The formula is: V = pi * (r^2) * h Task 2: Create...
Write a program in C that computes the area of a circle (Area = pi *...
Write a program in C that computes the area of a circle (Area = pi * r2) and the volume of a sphere (Volume = 4/3 * pi * r3). Both formulas use r which is the radius. Declare a float variable pi = 3.14159. Get the value of r from the keyboard and store it in a float variable. Display both the area of the circle and the volume of the sphere.
Write most basic C++ program possible that calculates volume and surface area of five shapes (Cube,...
Write most basic C++ program possible that calculates volume and surface area of five shapes (Cube, Sphere, Prism, Cylinder, Cone), where each shape has its own class (with a volume function, surface area function, constructor, as well as get and set functions), and the shape dimensions are private class members. Include input and display functions.
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT