Question

In: Computer Science

please complete the following program in c++: In this homework assignment you will modify the program...

please complete the following program in c++:


In this homework assignment you will modify the program you have developed in Homework Assignment

1 by implementing the following:

1- Your program will ask the user to choose to either Compute and Display Surface Areas of Hemispheres and their Average (Choice 1) or to Compute and Display Volumes of Hemispheres and their Average (Choice 2). The program will only perform the chosen operation. (Hint: use a character variable to read the character 1 or 2 to safeguard against improper entries)

2- Your program will ask the user to specify how many Hemispheres’ Surface Areas or Volumes they would like to be computed; your program then will prompt for and read as many input information as needed based on how many Hemispheres’ Surface Areas or Volumes the user want to be computed. The program will then compute and display the Surface Areas or Volumes, and their average. The results must be clearly labeled with proper units and format (same format as specified in Homework Assignment 1) – See Sample Run below.

3- Once the results are displayed, the program must ask its users if they want to compute more Hemispheres’ Surface Areas or Volumes (Enter Y or y to Run the Hemisphere Surface Area / Volume Calculator) or if they want to quit (Enter N or n to Quit). If the users want to compute more Hemispheres’ Surface Areas or Volumes the program will repeat until the users quit.

Note:

For modifications 1 and 3 above when the users enter anything other than 1 or 2 for part 1, or anything other Y/y or N/n for part 3 then they will repeatedly receive an error message prompting them to enter a proper value until they enter such a value.

Similarly, for modification 2, the users must enter 1 or more Hemisphere information to be computed otherwise they should be repeatedly prompted with an error message until they provide a valid entry. Also, for input information (Hemisphere Diameter) the input must be greater than or equal to zero, otherwise the user will receive an error message repeatedly until they enter proper values.

Do NOT use any programming statements and/or techniques that have not been covered in this class (i.e., functions, classes, arrays, pointers ... etc.)

Sample Run:

********** Welcome to The Hemisphere Surface Area / Volume Calculator **********

Enter 1 to Calculate Surface Area of Hemispheres
Enter 2 to Calculate Volume of Hemispheres
1┘
How Many Hemispheres’ Surface Areas Would You Like to Calculate? -3┘

The Number of Hemispheres Must be One or More!

How Many Hemispheres’ Surface Areas Would You Like to Calculate? 0┘

The Number of Areas Must be One or More!
How Many Hemispheres’ Surface Areas Would You Like to Calculate? 3┘

Enter the Diameter for Hemisphere 1 in meters: 5┘

The Surface Area of the Hemisphere with Diameter: 5.000 meters is: 58.905 meters^2

Enter the Diameter for Hemisphere 2 in meters: -5.8┘

The Diameter Value Must NOT be Negative!
Enter the Diameter for Hemisphere 2 in meters: -1┘
The Diameter Value Must NOT be Negative!
Enter the Diameter for Hemisphere 2 in meters: 7.4┘
The Surface Area of the Hemisphere with Diameter: 7.400 meters is: 129.025 meters^2 Enter the Diameter for Hemisphere 3 in meters: 2.8┘
The Surface Area of the Hemisphere with Diameter: 2.800 meters is: 18.473 meters^2 The Average Surface Area for All 3 Hemispheres is 68.801 meters^2

Would you Like to Run the The Hemisphere Surface Area / Volume Calculator again?
Enter Y or y For YES or N or n For NO: r┘
Enter Y or y For YES or N or n For NO: 4┘
Enter Y or y For YES or N or n For NO: Y┘
Enter 1 to Calculate Surface Area of Hemispheres
Enter 2 to Calculate Volume of Hemispheres
5┘
Enter 1 to Calculate Surface Area of Hemispheres
Enter 2 to Calculate Volume of Hemispheres
9┘

Enter 1 to Calculate Surface Area of Hemispheres
Enter 2 to Calculate Volume of Hemispheres
2┘
How Many Hemispheres’ Volumes Would You Like to Calculate? 3┘Enter the Diameter for Hemisphere 1 in meters:-2┘

The Diameter Value Must NOT be Negative!
Enter the Diameter for Hemisphere 1 in meters: 5┘
The Volume of the Hemisphere with Diameter: 5.000 meters is: 32.725 meters^3 Enter the Diameter for Hemisphere 2 in meters: 7.4┘
The Volume of the Hemisphere with Diameter: 7.400 meters is: 106.087 meters^3 Enter the Diameter for Hemisphere 3 in meters: 2.8┘
The Volume of the Hemisphere with Diameter: 2.800 meters is: 5.747 meters^3 The Average Volume for All 3 Hemispheres is 48.186 meters^3

Would you Like to Run the The Hemisphere Surface Area / Volume Calculator again?
Enter Y or y For YES or N or n For NO: N┘
Thank You ... Good Bye!

Solutions

Expert Solution

Hey, Following is the Cpp code for the given question

Please do rate my answer and do revert back if you have any doubts

*************************************************************************************************************************************

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
// Intializing varibales for storing various values
int n = 0,i=1;
char choice;
float dia=0;
// Entering into calculator
cout<<"********** Welcome to The Hemisphere Surface Area / Volume Calculator **********\n";
// Infinte loop
while (1) {
l1: // Label for getting to starting of the program
cout<< "Enter 1 to Calculate Surface Area of Hemispheres\n";
cout<< "Enter 2 to Calculate Volume of Hemispheres\n";
cin>> n; // Getting choice from the user
// Calculating area
if(n==1) {
l2:
cout << "How Many Hemispheres’ Surface Areas Would You Like to Calculate? ";
cin >> n;
// If proper value is not entered
if (n <= 0){
cout << "Number of spheres must be one or more\n";
goto l2; //Ask again
}
else {
// Calculating surface area of each sphere
for(i=1;i<=n;i++) {
l5:
cout << "Enter the diameter of hemisphere "<< i << " in meters: ";
cin >> dia;
if (dia < 0) {
cout << "Diameter cannot be negative";
goto l5;
}
cout << "The Surface Area of the Hemisphere with Diameter: " << dia << " meters is: "<< 0.25*3.14*(pow(dia,2))<<"\n"; // Surface Area
}
}
  
}
// Calculating Voulme
else if(n == 2){
l3:
cout << "How many hemispheres’ volumes would you like to calculate?: ";
cin >> n;
if (n <= 0){
cout << "Number of spheres must be one or more";
goto l2;
} else {
for(i=1;i<=n;i++) {
l6:
cout << "Enter the diameter of hemisphere "<< i << " in meters: ";
cin >> dia;
if (dia < 0) {
cout << "Diameter cannot be negative";
goto l6;
}
cout << "The Voulme of the Hemisphere with Diameter: " << dia << " meters is: "<< 2*3.14*0.125*(pow(dia,3))<<"\n";
}
}
  
}
// Go to starting if proper chocie is not entered
else {
goto l1;
}
// Asking user if he wishes to continue
cout << "Would you Like to Run the The Hemisphere Surface Area / Volume Calculator again?\n";
l4:
cout << "Enter Y or y For YES or N or n For NO: ";
cin >> choice;
cout << "\n";
if (choice == 'Y' || choice == 'y') {
goto l1; // Goto starting of the program
}
else if (choice == 'N' || choice == 'n') {
break; // Break the infinite loop
}
else {
goto l4; // Ask again
}
}
return 0;
}

***********************************************************************************************************************************************

Output of the porgram:



Related Solutions

Please complete in only C++, using loops Assignment: For this assignment you’ll be designing a program...
Please complete in only C++, using loops Assignment: For this assignment you’ll be designing a program which can take the input of a decimal number and a numerical base, and convert the decimal number to that base. For example, if given the decimal number seven and the base two, your program should output it as 111, which is how seven is represented in binary. Another example, 8,943 in base 10, is 13,236 in base 9. You’ll need to perform these...
In C++ please modify the following program and add characters (char) and names (strings) to be...
In C++ please modify the following program and add characters (char) and names (strings) to be added to the linked list along with integers. The current demo program accepts only integer data, so you would ask the user to select the data type to be added to the linked list. The user should be given the following three choices: (a) whole numbers (b) single characters (c) strings Once the user makes a selection from the list above then your program...
WEEK 1 HOMEWORK (based on your week 1 assignment) Please answer the following questions in complete...
WEEK 1 HOMEWORK (based on your week 1 assignment) Please answer the following questions in complete sentences. Identify and define at least 5 fallacies about racism. What areas of life does racism affect? Define the two types of racism (institutional and interpersonal). What is symbolic violence when it comes to race? At one time Jews dominated basketball; now it is a game almost exclusively for African Americans. The text authors identify at least two reasons why both of these groups...
In this assignment, you shall create a complete C++ program that will read from a file,...
In this assignment, you shall create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student. Below...
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
C++ please Instructions Download and modify the Lab5.cpp program. Currently the program will read the contents...
C++ please Instructions Download and modify the Lab5.cpp program. Currently the program will read the contents of a file and display each line in the file to the screen. It will also display the line number followed by a colon. You will need to change the program so that it only display 24 lines from the file and waits for the user to press the enter key to continue. Do not use the system(“pause”) statement. Download Source Lab 5 File:...
C++ Please For this assignment, you will write a program that lets the user play against...
C++ Please For this assignment, you will write a program that lets the user play against the computer in a variation of the popular blackjack car game. In this variation of the game, two-six sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computer's hidden total without going over 21. Here are some suggestions for the game's design: Each round of the game is performed as an iteration of a loop...
In this paper, please discuss the following case study. For you to complete this assignment you...
In this paper, please discuss the following case study. For you to complete this assignment you must: Explain your approach to the problem. Support your approach with references, and execute your approach. Provide an answer to the case study’s questions with a recommendation. This case continues following the new project of the WePROMOTE Company, that you and your partner own. WePROMOTE is in the promotional materials business. The project being considered is to manufacture a very unique case for smartphones....
3. For this week’s assignment, you are asked to modify the above Java program to include...
3. For this week’s assignment, you are asked to modify the above Java program to include the following: - When the user clicks on the help menu, a drop-down list will appear with an item called About, then when the user clicks on it, the window will show some instructions about the functionality of the menu, e.g, what the edit menu does, etc. - When the user clicks on the File menu, a drop-down list will appear with one item...
C++ PLEASE This will be a multi-part assignment. Later homework will expand upon what is developed...
C++ PLEASE This will be a multi-part assignment. Later homework will expand upon what is developed in this assignment. 1. Create a class called MyComplex to represent complex numbers. Each part (Real and Imaginary parts) should be stored as a double. Data members should be private and you need to supply appropaiate accessor and mutator methods. 2. Supply a default constructor (both parts zero), a constructor that allows the real part to be set and a third constructor that allows...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT