116k views
4 votes
Write a complete program that asks the user to input the height and radius of a cone (both of type double) and calls two individual functions to calculate the total area of the cone and the volume of the cone. The main function then prints these values with appropriate messages.

1 Answer

2 votes

Answer:

The program in C++ is as follows:

#include <iostream>

#include <math.h>

using namespace std;

double area(double r, double h){

double A = 3.14 * r * (r + sqrt(h*h + r*r));

return A;}

double volume(double r, double h){

double V = (1.0/3) * 3.14 * r*r * h;

return V;}

int main(){

double radius, height;

cout<<"Radius: "; cin>>radius;

cout<<"Height: "; cin>>height;

cout<<"Area: "<<area(radius,height)<<endl;

cout<<"Volume: "<<volume(radius,height);

return 0;

}

Step-by-step explanation:

This declares the area function

double area(double r, double h){

Calculate area

double A = 3.14 * r * (r + sqrt(h*h + r*r));

Return the calculated area

return A;}

This declares the volume method

double volume(double r, double h){

Calculate volume

double V = (1.0/3) * 3.14 * r*r * h;

Return the calculated volume

return V;}

The main begins here

int main(){

Declare radius and height

double radius, height;

Get input for radius

cout<<"Radius: "; cin>>radius;

Get input for height

cout<<"Height: "; cin>>height;

Call the area function and print the returned value for area

cout<<"Area: "<<area(radius,height)<<endl;

Call the volume function and print the returned value for volume

cout<<"Volume: "<<volume(radius,height);

return 0;

}

User ASteve
by
4.3k points