Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition, In if-else statements, indent statements to be executed for if

Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition,

In if-else statements, indent statements to be executed for if or else condition three spaces. Align else or else if with corresponding if.

Indent statements within loops.

Do not use global variables.

1. 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 dowhile 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 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.

2. The height h of a ball thrown upward at an angle A with initial velocity is given by the following formula:

Suppose in a given situation a table of values of time t and height h are to be printed in a table beginning at time 0 and continuing at intervals of 0.05 second until the ball reaches the ground. Use preprocessor commands or declare constants to define g with a value of 9.81 and pi with a value of 3.14159265. Prompt the user to input first the initial velocity v0 (a value between 10 and 15 meters per second inclusive) and then the angle of launch (a value between 30 and 60 degrees inclusive). Use while or do while data validation loops to assure that the initial velocity and angle of launch are in the proper range.

Use a while loop to print a labeled table of values of time t and height h, beginning at time 0 and continuing at intervals of 0.05 second until the ball reaches the ground. (Remember to convert the angle to radians to implement the equation.) Place time in the column on the left and height in the column on the right. Do not print any negative values of height. Use 2 digits after the decimal point for time and 2 digits after the decimal point for height.

Extra Credit (2 points):

One numerical method for calculating the cubic root of a number, , is in iterations. The process starts by choosing a value as a first estimate of the solution. Using this value, a second, more accurate value can be calculated with , which is then used for calculating a third, still more accurate value , and so on. The general equation for calculating the value of is . Write a program to calculate the cubic root of a number by this method. In the program use =P for the first estimate of the solution. Then, by using the general equation in a while loop, calculate new, more accurate values. Stop the looping when the estimated relative error E defined by is smaller than 0.00001.

Print the estimate of the cube root of the number entered with 6 decimal digits and also print the actual value of the cube root of the same number from the math library

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago