Question

In: Computer Science

Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter...

Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter a radius. Then present a menu of choices for quantities to be calculated from that radius:

                        A         Area of a Circle

                        C         Circumference of a Circle

                        S          Surface Area of a Sphere

                        V         Volume of a Sphere

Prompt the user to enter the character corresponding to the quantity to be calculated. Use a switch statement to handle the calculations. Use the appropriate equation in each case.

Allow for inclusion of both upper case and lower case letters and present an error message for an improper choice. Print the quantity calculated with 2 decimal digits.

When the program is working, modify it using a while or do…while loop so that the program will continue prompting the user to see if another quantity is to be calculated. For example, suppose that a radius is entered and the user specifies that the circumference is to be calculated. After the result is printed, the user will be asked if he or she wants to do another calculation. He might enter Y to continue or N to quit.   Include entry of the radius as well as the switch statement in the loop.

In C++

Solutions

Expert Solution

CODE-

#include <iostream>
#include<cmath>

using namespace std;
//Main block starts
int main() {
//declaring variables
double r, p = M_PI, c = 4 / 3;
char inp, ch;
//do while loop begins
do {
//taking radius input from user
cout << "Enter a radius" << endl;
cin >> r;
//Taking input according to menu
cout << "Enter the choice according to quantities to be calculated from that radius:" << endl;
cout << "A - Area of a Circle" << endl;
cout << "C - Circumference of a Circle" << endl;
cout << "S - Surface Area of a Sphere" << endl;
cout << "V - Volume of a Sphere" << endl;
cin >> ch;
//switch block begins
switch (ch) {
//case to calculate area of circle
case 'A':
case 'a':
printf("%.2f", p * r * r);
break;
//case to calculate circumference of circle
case 'C':
case 'c':
printf("%.2f", 2 * p * r);
break;
//case to calculate surface area of sphere
case 'S':
case 's':
printf("%.2f", 4 * p * r * r);
break;
//case to calculate Volume of sphere
case 'V':
case 'v':
printf("%.2f", c * p * r * r * r);
break;
//case for invalid input
default:
cout << "Not a valid input kindly make an appropiate choice from the given menu" << endl;
break;
}
cout << endl << "If you wish to do any other calculation enter Y else enter N to stop the program" << endl;
cin >> inp;
} while ((inp != 'n') && (inp != 'N'));

return 0;
}

CODE SCREENSHOTS-

OUTPUT-


Related Solutions

Write a program using switch statement that asks user to enter the month number and then...
Write a program using switch statement that asks user to enter the month number and then it prints out the number of days for that month. For simplicity reasons have your program print 28 days for February no matter if it is a leap year or not. Your program should also handle any invalid month numbers that user could enter (hint use default for the switch). Use a while loop to allow user to test for different month entries till...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
Write a Python program that has the user enter their name.   Using the user's name calculate...
Write a Python program that has the user enter their name.   Using the user's name calculate the following: 1. How many letters are in the user's name? 2. Print the user's name in REVERSE both in capital letters and lowercase letters 3. Print the ASCII value for each letter of the user's name. 4. Print the SUM of all of the letters of the user's name (add each letter from #3)
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT