machine problems for computer programming

3
Midterm Case Study Fundamentals of Programming Database Theory C Machine Problems and Application 1. Write a program that will prompt the user to input item’s price and its discount value. It will then output its discounted price. Sample Run: Enter item’s price: 585 Enter the discount value (%): 10 Discounted price: 526.6 2. Write a program that will compute the amount of interest that is earned on P17, 000 invested at an interest rate of 0.07 for one year. The interest and the value of the investment after one year are printed to standard output. Sample Run: The interest earned is: P1190 The value of the investment after one year is: P18190 3. If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left over. Write a program that asks the user how many eggs he has and then tells the user how many dozen eggs he has and how many extra eggs are left over. For example, if the user says that he has 100 eggs, then your program would respond with: Your number of eggs is 8 dozen, and 4 Sample Run: Enter the number of eggs: 100 Your number of eggs is 8 dozen, and 4 4. Rewrite Machine Problem # 2 where it computes the amount of interest that is earned on an investment over a period of one year. The initial amount of the investment and the interest rate are input by the user. The value of the investment at the end of the year is output. The rate must be input as a decimal, not a percentage (for example, 0.05 rather than 5). Sample Run: Enter the initial investment: 17000 Enter the annual interest rate (decimal, not percentage!):0.07 The value of the investment after one year is: P18190 5. Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator and the result. (For division, if the denominator is zero, output an appropriate message). Sample Run: Enter two integers and the operation to be performed separated by spaces: 3 * 7 3 * 7 = 21 Note: Use switch structure cabatbatmark

Upload: sherwin

Post on 12-Dec-2015

215 views

Category:

Documents


0 download

DESCRIPTION

For educational purposes only. FUNDAMENTALS OF PROGRAMMING DATABASE THEORY.

TRANSCRIPT

Page 1: Machine Problems for Computer Programming

Midterm Case Study Fundamentals of Programming Database Theory

CMachine Problems and Application1. Write a program that will prompt the user to input item’s price and its discount value. It will then

output its discounted price.

Sample Run:

Enter item’s price: 585

Enter the discount value (%): 10

Discounted price: 526.6

2. Write a program that will compute the amount of interest that is earned on P17, 000 invested at an interest rate of 0.07 for one year. The interest and the value of the investment after one year are printed to standard output.

Sample Run:

The interest earned is: P1190

The value of the investment after one year is: P18190

3. If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left over. Write a program that asks the user how many eggs he has and then tells the user how many dozen eggs he has and how many extra eggs are left over.

For example, if the user says that he has 100 eggs, then your program would respond with:

Your number of eggs is 8 dozen, and 4

Sample Run:

Enter the number of eggs: 100

Your number of eggs is 8 dozen, and 4

4. Rewrite Machine Problem # 2 where it computes the amount of interest that is earned on an investment over a period of one year. The initial amount of the investment and the interest rate are input by the user. The value of the investment at the end of the year is output. The rate must be input as a decimal, not a percentage (for example, 0.05 rather than 5).

Sample Run:

Enter the initial investment: 17000

Enter the annual interest rate (decimal, not percentage!):0.07

The value of the investment after one year is: P18190

5. Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator and the result. (For division, if the denominator is zero, output an appropriate message).

Sample Run:

Enter two integers and the operation to be performed separated by spaces: 3 * 73 * 7 = 21

Note: Use switch structure6. At the Urdaneta City Fiesta 2011 Pie Eating Contest all contestants must weigh 250 pounds below. Write a

program that asks for a contestant's weight in kilograms and then says if the contestant is allowed in the contest.

7. The cost of an international call from United States of America to Philippines is calculated as follows: connection fee, $1.99; $2.00 for the first three minutes; and $0.45 for each additional minute. Write a program that prompts the user to enter the number of minutes the call lasted and outputs the amount due. Format your output with two decimal places.

Sample Run:

Enter the number of minutes the call lasted: 7

cabatbatmark

Page 2: Machine Problems for Computer Programming

Midterm Case Study Fundamentals of Programming Database Theory

CMachine Problems and Application

The amount due of the call is: $5.798. Write a program that would determine the fare per kilometer. Every 1 - 4 kilometer, the fare is P8.00 and in

every succeeding kilometer, you will add P2.50.

Sample Run # 1:

Enter kilometer(s): 4

You will pay P8.00 only. You succeeded 0 kilometer(s).

Sample Run # 2:

Enter kilometer(s): 6

You will pay P13.00 only. You succeeded 2 kilometer(s).

9. Mark and Gracia's Delicatessen wants a program to take orders from the internet. The program will ask what item the user wants, will ask its price, and will ask if the user wants overnight shipping. Regular shipping for items under P500 is P100.00; for items P500 or more shipping is 150.00. For overnight delivery add P250.00.

Sample Run:

Enter the item:Tuna SaladEnter the price: 200Overnight delivery? (0==No, 1==Yes):1

Invoice: Tuna Salad 200 Shipping 7.00 Total 350.00

10. A bank in your town updates its costumers’ accounts at the end of each month. The bank offers two types of accounts: savings and checking. Every customer must maintain a minimum balance. If a customer’s balance falls below the minimum, there is a service charge of $10.00 for savings accounts and $25.00 for checking accounts. If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:

Savings accounts receive 4% interest. Checking accounts with balances of up to $5000 more than the minimum balance receive 3%

interest; otherwise, the interest is 5%.

Write a program that reads a customer’s account number (int type), account type (char; s for savings, c for checking), minimum balance that the account should maintain, and the current balance. The program should the output the account number, account type, current balance, and an appropriate message. Test your program by running it five times, using the following data:

46728 S 1000 2700

87324 C 1500 7689

79873 S 1000 800

89832 C 2000 3000

98322 C 1000 750

Sample Run #1:

Enter the account number:46728Enter the account type: [S / C]SEnter the minimum balance:1000Enter the current balance:2700The account number is: 46728The account number is: Savings Account [S / s]The current balance for this month is: $2808.00

Sample Run # 2:

cabatbatmark

Page 3: Machine Problems for Computer Programming

Midterm Case Study Fundamentals of Programming Database Theory

CMachine Problems and ApplicationEnter the account number:87324Enter the account type: [S / C]CEnter the minimum balance:1500Enter the current balance:7689The account number is: 87324The account number is: Savings Account [C / c]The current balance for this month is: $7919.67

cabatbatmark