51.9k views
4 votes
Write the following functions. Each function needs function comments that describes function and its parameters double sphereVolume( double radius) double sphereSuface( double radius) double cylinderVolume( double radius, double height) double coneSurface( double radius, double height) double coneVolume( double radius, double height) That computes the volume and surface of the sphere with radius, a cylinder with a circular base with radius radius , and height height , and a cone with a circular base with radius radius , and height height . Then write a test program to prompt user to enter values of radius and height, call six functions and display the results c++

User ViaTech
by
4.7k points

1 Answer

3 votes

Answer:

Output

height: 10

radius: 2

Cylinder volume: 125.6

Cone Surface: 76.6037

Cone Volume: 41.8667

Sphere volume: 33.4933

Sphere surface: 50.24

Cylinder volume: 125.6

Step-by-step explanation:

//Declaring variables

#include <iostream>

#include <cmath>

using namespace std;

//Defining Pi value

const double PI=3.14;

//Decliring the functions

//volume function for cone

double volumeCone(double r,double h){

return PI * r * r * (h/3);

}

//volume function for sphere surface

double surfaceSphere(double r){

return 4 * PI * r * r;

}

//volume function for cylinderVol

double cylinderVol(double r,double h){

return PI * r * r * h;

}

//volume function for sphere volume

double sphereVol(double r){

return 4/3.0 * PI * r * r * r;

}

//volume function for cone surface

double surfaceCone(double r,double h){

return PI * r * (r+sqrt(h *h + r * r));

}

int main(){

double r,h;

//print the values of height and radius

cout<<"height: ";

cin>>h;

cout<<"radius: ";

cin>>r;

//print the values of geometric forms

cout<<"Cylinder volume: "<<cylinderVol(r,h)<<endl;

cout<<"Cone Surface: "<<surfaceCone(r,h)<<endl;

cout<<"Cone Volume: "<<volumeCone(r,h)<<endl;

cout<<"Sphere volume: "<<sphereVol(r)<<endl;

cout<<"Sphere surface: "<<surfaceSphere(r)<<endl;

cout<<"Cylinder volume: "<<cylinderVol(r,h)<<endl;

}

User GGleGrand
by
4.9k points