Question
In this assignment, the student will write a program that provides prompts and runs formulas for a variety of mathematical formulas based on a menu
In this assignment, the student will write a program that provides prompts and runs formulas for a variety of mathematical formulas based on a menu selection. When completing this assignment, the student should demonstrate mastery of the following concepts:
User Prompting
User Input with scanf()
Assignment Statements
Variable Declarations
Mathematical Expressions
Assignment:
Write a C program that starts with the following shell of code:
// Preprocessor Directives
#pragma warning(disable:4996) // To enable deprecated scanf()
#include
void main() {
// Declare Variables
int menuOption = 0;
// Prompts
printf("FORMULA SELECTION MENU ");
printf("1.) FORMULA 1 ");
printf("2.) FORMULA 2 ");
printf("3.) FORMULA 3 ");
printf("-------------------------- ");
printf("Which formula would you like to run\?: ");
scanf("%d", &menuOption);
// Run Appropriate Formula
if (menuOption == 1) {
// Declare variables for this formula...
// Prompt for this formula...
// Perform background mathematics...
// Display results on the screen...
}
else if (menuOption == 2) {
// Declare variables for this formula...
// Prompt for this formula...
// Perform background mathematics...
// Display results on the screen...
}
else if (menuOption == 3) {
// Declare variables for this formula...
// Prompt for this formula...
// Perform background mathematics...
// Display results on the screen...
}
else {
printf("That was not a valid menu option... ");
}
}
Begin by examining this code and taking note of the code blocks on the inside of the if-else chain in this program. Within each block, provide the declarations for needed variable and prompt the user in whatever way necessary to run the following mathematical equations:
MENU OPTION 1 CENTIMETERS TO INCHES
Prompt the user to enter a distance in centimeters and then display that same distance in inches. The following formula(s) will prove useful in developing your solution:
MENU OPTION 2 2D DISTANCE FORMULA
Prompt the user for a pair of 2D coordinates. Calculate and display the distance between a pair of arbitrary points on a 2D coordinate plane. The following formula(s) will prove useful in developing your solution:
Hint: Consider using the sqrt() and pow() functions in the
MENU OPTION 3 PYRAMID SURFACE AREA
Prompt the user for the edge length and height of a pyramid (you may assume the pyramid has a square base and central axis that runs perpendicular to the base). Calculate and display the surface area of the pyramid.
In this problem, the base of the pyramid is known to be a square. Therefore, you can prompt for a single value and use it for both l and w. The distance along the slant of the side of the pyramid could be determined with this information and the Pythagorean Theorem.
The following formula(s) will prove useful in developing your solution:
opposite triangle side^2 + adjacent triangle side^2 = hypotenuse^2
area of triangle = 1/2*base length*height
area of square = length*width
To solve this problem, you will need to develop a procedure to calculating the surface area of this pyramid. You will need to determine the surface area of the base on which the pyramid sits (area of a square). You will then need to determine the surface area of a single side. You will need to use the Pythagorean Theorem in a creative way to mathematically develop a procedure for making this determination with only the information provided by the user. Once you have determined the surface area for a single side of the pyramid, this value can be multiplied by four and added to the base area to get the complete surface area.
Hint: Be careful if you search for Surface Area of Pyramid or any other such query on the Internet as the full formula where l and w can differ renders a formula that is far more complicated than the one needed to solve this problem (you probably dont want to code that one). The best approach to solving this problem is drawing a picture of the pyramid and thinking about how to use the information you have to render the information you want. There is a very straightforward solution that can be seen by imagining an invisible right triangle on the side of the pyramid with a hypotenuse that runs directly along the center of one of the pyramids sides.
Keep the output aesthetic as consistent and clear as possible. Always remember to provide the user with prompts that clearly provide direction for the programs use. You may assume the user will enter the data in the correct format provided the instructions provided in the prompts that you write, but assume the user will strictly follow the directions you provide.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started