Question

Problem 3 (5 points) Write a program that prompts the user for the radius of a sphere. Your program should then compute value

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>

using namespace std;

double getVolume(double radius){
   return (4.0/3.0)*3.141592*radius*radius*radius;
}

double getArea(double radius){
   return 4*3.141592*radius*radius;
}

int main() {
   double radius;
   double volume, area;
   cout<<"Enter the radius of the sphere as a real number?\n";
   cin>>radius;
   volume = getVolume(radius);
   area = getArea(radius);
   
   cout<<"The area of a sphere with radius "<<radius<<" is "<<area<<endl;
   cout<<"The volume of a sphere with radius "<<radius<<" is "<<volume<<endl;
   return 0;
}

Output:

Enter the radius of the sphere as a real number? 10.5 The area of a sphere with radius 10.5 is 1385.44 The volume of a sphere

Note: Please comment below if you have any doubts. upuote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
Problem 3 (5 points) Write a program that prompts the user for the radius of a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

  • Problem: Write a short C++ program that gets the side of a cube and the radius...

    Problem: Write a short C++ program that gets the side of a cube and the radius of a sphere from the keyboard and writes to a file the surfaces of these shapes.             ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79 points) Algorithm solution (in pseudocode): To accomplish this task, your program will have to take the following steps: 1. Declare a variable named outFile that represents an output stream. 2. Declare a...

  • Name : StarryArrays Write a program called StarryArrays which prompts user for the number of items...

    Name : StarryArrays Write a program called StarryArrays which prompts user for the number of items in an array (a non-nega- tive integer), and saves it in an int variable called numltems. It then prompts user for the values of all the items (non-negative integers) and saves them in an int array called items. The program shall then print the contents of the array in a graphical form, with the array index and values represented by number of stars For...

  • Write a C++ Program Write a program that prompts the user to input a number. The...

    Write a C++ Program Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative, or zero. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: 1 Name: Your Name ID: Your ID #include <iostream> using namespace std; din main YOUR CODE HERE

  • 1) Write a Python program that prompts the user to enter the current month name and...

    1) Write a Python program that prompts the user to enter the current month name and prints the season for that month. Hint: If the user enters March, the output should be "Spring"; if the user enters June, the output should be "Summer". 2 )Write a Python program using the recursive/loop structure to print out an equilateral triangle below (double spacing and one space between any two adjacent asterisks in the same row).          *      * * * *...

  • You are required to write an interactive program that prompts the user for seven (7) real...

    You are required to write an interactive program that prompts the user for seven (7) real numbers and performs the following tasks: Reads and stores the numbers into one-dimensional array called A. Calculates the sum of the numbers. Find the average of the numbers. Finds the smallest value of the numbers. Prints all the results with proper headings. Program requirements: -     The program must contain at least five functions using necessary parameters. These functions should read the data, perform the...

  • don't use continuity and break in python 3: (In python3) Exercise # 4: Write a program...

    don't use continuity and break in python 3: (In python3) Exercise # 4: Write a program that prompts for and reads the number ? of spheres to be processed. If ?≤0 your program must display an error message and terminate; otherwise it does the following for ? times: Prompts for and reads the volume of a sphere, it then displays the surface area of the sphere with that volume. Assume that each volume is in cubic centimeters. The program finally...

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to...

    write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to enter a positive integer in the range [100, 100000]. If the integer is not in the specified range the program prompts the user again. The program prints whether the integer is a prime number or not. Sample input/output nter an integer in the range [10e, 10eeee]: 39 nter an integer in the range [100, 100000]: 120453 Enter an integer in the range [10e, 10e000e]:...

  • C++ please Problem 3: Write a C++ program that prompts the user to enter an integer...

    C++ please Problem 3: Write a C++ program that prompts the user to enter an integer of any length (but not more than 8- digits), the program then extracts and prints each digit in its respective column. For example, in the integer 436, 4 should be printed in the 4th column, 3 in the 3rd and 6 in the 6th column. Hint: you can use setw to solve this problem. Sample Input/Output Enter an integer of any length. 9836472 ...Printing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT