Sie sind auf Seite 1von 3

Programming Exercises

1) Movie Ticket

A movie in a local theater is in great demand. To help a local charity, the theater owner
has decided to donate to the charity a portion of the gross amount generated from the
movie. This example designs and implements a program that prompts the user to input
the movie name, adult ticket price, child ticket price, number of adult tickets sold,
number of child tickets sold, and percentage of the gross amount to be donated to the
charity. The output of the program is as follows.

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Movie Name: .......................................... Journey to Mars
Number of Tickets Sold: ........................ 2650
Gross Amount: ..................... $ 9150.00
Percentage of Gross Amount Donated: 10.00%
Amount Donated: .................................. $ 915.00
Net Sale: ................................................ $ 8235.00

Note that the strings, such as "Movie Name:” in the first column are left-justified, the
numbers in the right column are right-justified, and the decimal numbers are output with
two decimal places.

Input

The input to the program consists of the movie name, adult ticket price, child ticket
price, number of adult tickets sold, number of child tickets sold, and percentage of the
gross amount to be donated to the charity.

Output

The output is as shown above.

To calculate the amount donated to the local charity and the net sale, you first need to
determine the gross amount. To calculate the gross amount, you multiply the number of
adult tickets sold by the price of an adult ticket, multiply the number of child tickets sold
by the price of a child ticket, and then add these two numbers. That is:

grossAmount = adultTicketPrice * noOfAdultTicketsSold + childTicketPrice *


noOfChildTicketsSold;
Next, you determine the percentage of the amount donated to the charity and then
calculate the net sale amount by subtracting the amount donated from the gross
amount. The formulas to calculate the amount donated and the net sale amount are
given below. This analysis leads to the following algorithm:

Page 1 of 3
1. Get the movie name.
2. Get the price of an adult ticket.
3. Get the price of a child ticket.
4. Get the number of adult tickets sold.
5. Get the number of child tickets sold.
6. Get the percentage of the gross amount donated to the charity.
7. Calculate the gross amount using the following formula:
grossAmount=adultTicketPrice*noOfAdultTicketsSold+childTicketPrice*noOfChil
dTicketsSold;
8. Calculate the amount donated to the charity using the following formula:
amountDonated = grossAmount * percentDonation / 100;
9. Calculate the net sale amount using the following formula:
netSaleAmount = grossAmount – amountDonated;

Sample run

Sample Run: In this sample run, the user input is shaded.


Enter movie name: Journey to Mars
Enter the price of an adult ticket: 4.50
Enter the price of a child ticket: 3.00
Enter number of adult tickets sold: 800
Enter number of child tickets sold: 1850
Enter the percentage of donation: 10

=================================================
Movie Name : Journey to Mars
Number of Tickets Sold : 2650
Gross Amount : $ 9150.00
Percentage of Gross Amount Donated : 10.00%
Amount Donated : $ 915.00
Net Sale : $ 8235.00
=================================================

2) Write a program that takes length as input in feet and inches. The program should
then convert the lengths in centimeters and display it on screen. Assume that the
given lengths in feet and inches involved fractional part.

1) Based on the problem, you need to design an algorithm as follows:


2) Get the length in feet and inches.
3) Convert the length into total inches.
4) Convert total inches into centimeters.
5) Output centimeters.

Page 2 of 3
3) Write a program that displays the following prompts:
Enter the length of the swimming pool:
Enter the width of the swimming pool:
Enter the average depth of the swimming pool:

After the depth of the swimming pool is entered, your program should calculate and
display the volume of the pool. The volume should be included in an appropriate
message and calculated using the equation volume = length * width * average depth.
Check the volume displayed by the program written by calculating the result manually.

4) Write a program that calculates and prints the monthly pay check for an employee.
The net pay is calculated after taking the following deductions:
Income Tax : 18.50%
Land Tax : 3.5%
Social Security System : 5.75%
Medicare : 2.75%
Pension Plan : 5%
Health Insurance : 75.00

Your program should prompt the user to input the gross amount. A sample output
follows:
s
Gross Salary : 3575.00
Income Tax : 536.25
Land Tax : 125.13
Social Security Tax : 205.56
Medicare : 98.31
Pension Plan : 178.75
Health Insurance : 75.00
Net Pay : 2356.00

Page 3 of 3

Das könnte Ihnen auch gefallen