Sie sind auf Seite 1von 4

New Page 1

http://scitec.uwichill.edu.bb/cmp/online/cs11k/revision/problem%20so...

Problem 1
You are required to write an algorithm that will receive two integer items from a terminal operator, and display to the screen their sum, difference, product and quotient.

Defining Diagram INPUT PROCESSING Prompt for two integer items OUTPUT Sum, difference, product, quotient

Integer_item_1 Get two integer items Integer_item_2 Calculate sum, difference, product, quotient Display sum, difference, product, quotient

Solution Algorithm

This algorithm accepts two integer values and calculates their sum, difference, product, quotient. BEGIN Prompt for two integer items Get Integer_item_1, Integer_item_2 Sum = Integer_item_1 + Integer_item_2 Difference = Integer_item_1 - Integer_item_2 Product = Integer_item_1 * Integer_item_2 Quotient = Integer_item_1 / Integer_item_2 Output sum, difference, product, quotient to the screen END Desk Checking

1 of 4

13/04/2006 8:14 AM

New Page 1

http://scitec.uwichill.edu.bb/cmp/online/cs11k/revision/problem%20so...

Input Data First Data Set Integer_item_1 2 Integer_item_2 1 Expected Results Sum, difference, product, quotient Statement First Pass Get Sum Difference Product Quotient Output Second Pass Get Sum Difference Product Quotient Output 20 10 First Data Set 3, 1, 2, 2

Second Data Set 20 10 Second Data Set 30, 10, 200, 2

Integer_item_1 Integer_item_2 Display 2 1 3 1 2 2 Yes

30 10 200 2 Yes

Problem 2
You are required to develop an algorithm that will read in tax rate (as a percentage) and the prices of five items. The program is to calculate the total price, before tax, of the items, then the tax payable on those items. The tax payable is calculated by applying the tax rate percentage to the total price. Print the total price and the tax payable as output.

2 of 4

13/04/2006 8:14 AM

New Page 1

http://scitec.uwichill.edu.bb/cmp/online/cs11k/revision/problem%20so...

Input Tax_rate

Processing Read, Tax_rate, Price_item_1, Price_item_2, Price_item_3, Price_item_1 Price_item_4, Price_item_5 Price_item_2 Calculate total_price Price_item_3 Calculate payable_tax Price_item_4 Print total_price, payable_tax Price_item_5

Output Total_price Payable_tax

Solution Algorithm Calculate total_price, payable_tax Read tax_rate, price_item_1, price_item_2, price_item_3, price_item_4, price_item_5 Total_price = price_item_1 + price_item_2 + price_item_3 + price_item_4 + price_item_5 Payable_tax = tax_rate * total_price Print total_price, payable_tax END Desk Checking Input Data Tax_rate Price_item_1 Price_item_2 Price_item_3 Price_item_4 Price_item_5 First Data Set 0.5 1 2 3 4 5 Second Data Set 0.25 10 20 30 40 50

3 of 4

13/04/2006 8:14 AM

New Page 1

http://scitec.uwichill.edu.bb/cmp/online/cs11k/revision/problem%20so...

Expected Results First Data Set Total_price 15 Payable_tax 7.5


Statement First

Second Data Set 150 37.5

Tax_ratePrice_item_1Price_item_2 Price_item_3Price_item_4Price_item_5Print

Pass

0.5

5 15 7.5 Yes

Read Total_price Payable_tax Print Second Pass Read Total_price Payable_tax Print

0.25

10

20 30 40 50

150 37.5 Yes

Exercises:

1. Design an algorithm that keeps reading numbers until the user enters a zero
value, and outputs the sum of the numbers. 2. Design an algorithm that keeps reading positive numbers until the user enters a zero value, and determines and outputs the largest number. 3. Design an algorithm that reads an arbitrary number of numbers and outputs their arithmetic average.

4 of 4

13/04/2006 8:14 AM

Das könnte Ihnen auch gefallen