Sale!

COP3223C Small Program 2 Solved

Original price was: $35.00.Current price is: $30.00.

Download Details:

  • Name: smallprogram2-oi92wj.zip
  • Type: zip
  • Size: 206.87 KB

Category:

Description

5/5 - (1 vote)

Problem 1

Write a user defined function definition called coneSurfaceArea. This function calculates the
surface area of a cone. The formula for calculating the surface area is described below:
SA = π × r × (r +
p
h
2 + r
2)

The function has three parameters. The first parameter is the radius of the base of the cone
which can be represented as a double type value. The second parameter is the height of the
cone which is also double type.

The last parameter is the value of pi (defined as π = 3.14) which
is also double type. For this problem you will need to collect input from the user inside the main
function of your program. After collecting the input, you will then call the user defined function
to have it perform the calculation and display the result up to two decimal places.

The function
does return the result and displays it in the main function. Make sure your output matches as
expected from the following output sample in the figure. Do not worry about invalid input. We
have not covered conditions yet.

Figure 1: Sample output for question 1. Make sure your output matches exactly for the test
script.

Problem 2

A parking garage charges customers to park their car at a rate $4.21 per hour. Write code that
welcomes the users and prompts them to enter the amount hours they plan to leave their cars
parked. The program will display the number of hours and the amount charged to the user.

The
system deals with whole number hours only. The monetary value displayed has to include $ and
two decimal places. Check out the following figure for sample output that the script expects. All
of this is to be completed in a user defined function called parkingCharge.

The function will
not return anything. Do not worry about invalid input. We have not covered conditions yet.
Figure 2: Sample output for question 2. Make sure your output matches exactly for the test
script.
Small Program 2 Page 4

Problem 3

After studying the population growth of the area Wakanda in the last decade of the 20th century,
we have modeled Wakanda’s population function as
P(t) = 51.451 + 4.239t

Where t is years after 2016, and P is population in thousands. Write a user defined function
called wakandaPopulation that predicts Wakanda’s population in the year after 2016 and
displays it to the user. The user defined function does not return a value. The user defined
function also takes one parameter argument of type int called year, which is the year after 2016.

Inside the main function, you will ask the user for the year after 2016. Do not worry about invalid
input. We have not learned conditions yet. Check out the following figure for the sample output
that the script expects.
Figure 3: Sample output for question 3. Make sure your output matches exactly for the test
script.

Problem 4

For any integer n > 0, n! is defined as the product n ∗ n − 1 ∗ n − 2. . . ∗ 2. 1! is defined to be 1. It
is sometimes useful to have a closed-form definition instead; for this purpose, an approximation
can be used. R.W. Gosper proposed the following such approximation formula:
n! ≈ n
n
e
−n
r
(2n +
1
3

For this problem, define a user defined function that performs the calculation. The user defined
function takes one argument of type int and will return the result of the computation of type
double to display in the main function. The result is displayed up to four decimal places. Name
the user defined function factorialApprox.

Use the same value of π from problem 1. Do not
worry about invalid input. Check out the following figure for the sample output that the test script
expects. Note: You don’t need to define Euler’s Number. Use the math library’s natural
exponent function.

Figure 4: Sample output for question 4. Make sure your output matches exactly for the test
script.
Small Program 2 Page 5