Assignment 1 2 Computer Programming
Assignment 1 2 Computer Programming
1. A program will ask the user to enter integer numbers six (6) times. After getting those input
numbers, the program will produce the sum of all the ones, tens and hundreds of all the input
numbers. Create a program that satisfies the said events.
Sample output:
Enter Six Integers: 51 1282 2236 229 120 17
Sum of all Ones: 1 + 2 + 6 + 9 + 0 + 7 = ___
Sum of all Tens: 5 + 8 + 3 + 2 + 2 + 1 = ___
Sum of all Hundreds: 0 + 2 + 2 + 2 + 1 + 0 = ___
2. The manager of a football stadium wants you to write a program that calculates the total ticket
sales after each game. There are four types of tickets—box, sideline, premium, and general
admission. After each game, data is stored in a file in the following form:
ticketPrice numberOfTicketsSold
…
Sample data are shown below:
250.75 5750
100.50 28000
50.25 35750
25.00 18750
The first value indicates that the ticket price is Php 250.75 and that 5750 tickets were sold at that
price. Output the total number of tickets sold and the total sale amount. Format your output with
two decimal places.
3. A rectangle is 4 times as long as it is wide. If the length is increased by 4 inches and the width
is decreased by 1 inch, the area will be X_AREA square inches. If X_AREA is entered by the
user, create a program that will determine what were the dimensions (length and width) of the
original rectangle?
4. Interest on a credit card’s unpaid balance is calculated using the average daily balance.
Suppose that netBalance is the balance shown in the bill, payment is the payment made, d1 is the
number of days in the billing cycle, and d2 is the number of days payment is made before billing
cycle. Then, the average daily balance is:
netBalance x d 1− payment x d 2
averageDailyBalance=
d1
If the interest rate per month is, say, 0.0152, then the interest on the unpaid balance is:
Interest=averageDailyBalance∗0.0152
Write a program that accepts as inputnetBalance, payment, d1,d2, and interest rate per month.
The program outputs the interest. Format your output to two decimal places.
5. Linda is starting a new cosmetic and clothing business and would like to make a net profit of
approximately 10% after paying all the expenses, which include merchandise cost, store rent,
employees’ salary, and electricity cost for the store. She would like to know how much the
merchandise should be marked up so that after paying all the expenses at the end of the year she
gets approximately 10% net profit on the merchandise cost. Note that after marking up the price
of an item she would like to put the item on 15% sale. Write a program that prompts Linda to
enter the total cost of the merchandise, the salary of the employees (including her own salary),
the yearly rent, and the estimated electricity cost. The program then outputs how much the
merchandise should be marked up so that Linda gets the desired profit.
6. There are b boys in the class. This is three more than four times the number of girls. If the
number of boys in the class is entered by the user, create a program that will identify how many
girls and total population in the class.
7. Write a program that accepts as input the mass, in grams, and density, in grams per cubic
mass
centimeters, and outputs the volume of the object using the formula: ume= . Format your
density
output to two decimal places.