Bonus Assignment
Bonus Assignment
40. Pizza Pi
Joe’s Pizza Palace needs a program to calculate the number of slices a
pizza of any size can be divided into. The program should perform the
following steps:
A) Ask the user for the diameter of the pizza in inches.
B) Calculate the number of slices that may be taken from a pizza of that
size.
A) Display a message telling the number of slices.
To calculate the number of slices that may be taken from the pizza, you
must know the following facts:
• Each slice should have an area of 14.125 inches.
• To calculate the number of slices, simply divide the area of the
pizza by 14.125.
• The area of the pizza is calculated with this formula:
Area = πr2
NOTE: π is the Greek letter pi. 3.14159 can be used as its value. The
variable r is the radius of the pizza. Divide the diameter by 2 to get the
radius.
Make sure the output of the program displays the number of slices in
fixed-point notation, rounded to one decimal place of precision. Use a
named constant for pi.
41. How Many Pizzas?
Modify the program you wrote in Programming Challenge 20 (Pizza Pi)
so it reports the number of pizzas you need to buy for a party if each
person attending is expected to eat an average of four slices. The program
should ask the user for the number of people who will be at the party, and
for the diameter of the pizzas to be ordered. It should then calculate and
display the number of pizzas to purchase.
42. Angle Calculator
Write a program that asks the user for an angle, entered in radians. The
program should then display the sine, cosine, and tangent of the angle.
(Use the sin, cos, and tan library functions to determine these values.)
The output should be displayed in fixed-point notation, rounded to four
decimal places of precision.
43. Stock Transaction Program
Last month Joe purchased some stock in Acme Software, Inc. Here are
the details of
the purchase:
• The number of shares that Joe purchased was 1,000.
• When Joe purchased the stock, he paid $45.50 per share.
• Joe paid his stockbroker a commission that amounted to 2 percent
of the amount he paid for the stock.
Two weeks later, Joe sold the stock. Here are the details of the sale:
• The number of shares that Joe sold was 1,000.
• He sold the stock for $56.90 per share.
• He paid his stockbroker another commission that amounted to 2
percent of the amount he received for the stock.
Write a program that displays the following information:
• The amount of money Joe paid for the stock.
• The amount of commission Joe paid his broker when he bought the
stock.
• The amount that Joe sold the stock for.
• The amount of commission Joe paid his broker when he sold the
stock.
• Display the amount of profit that Joe made after selling his stock
and paying the two commissions to his broker. (If the amount of
profit that your program displays is a negative number, then Joe lost
money on the transaction.)
44. Planting Grapevines
A vineyard owner is planting several new rows of grapevines, and needs
to know how many grapevines to plant in each row. She has determined
that after measuring the length of a future row, she can use the following
formula to calculate the number of vines that will fit in the row, along
with the trellis end-post assemblies that will need to be constructed at each
end of the row:
𝑅 − 2𝐸
𝑉=
𝑆
The terms in the formula are:
V is the number of grapevines that will fit in the row.
R is the length of the row, in feet.
E is the amount of space, in feet, used by an end-post assembly.
S is the space between vines, in feet.
Write a program that makes the calculation for the vineyard owner. The
program
should ask the user to input the following:
• The length of the row, in feet
• The amount of space used by an end-post assembly, in feet
• The amount of space between the vines, in feet
Once the input data has been entered, the program should calculate and
display the number of grapevines that will fit in the row.
45. Word Game
Write a program that plays a word game with the user. The program
should ask the
user to enter the following:
• His or her name
• His or her age
• The name of a city
• The name of a college
• A profession
• A type of animal
• A pet’s name
After the user has entered these items, the program should display the
following story, inserting the user’s input into the appropriate locations:
There once was a person named NAME who lived in CITY. At the age of
AGE, NAME went to college at COLLEGE. NAME graduated and went
to work as a PROFESSION. Then, NAME adopted a(n) ANIMAL named
PETNAME. They both lived happily ever after!