Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Name: Date:

Section:

Fundamentals of Programming
Activity 2

Lab 2-1: Stop and Analyze


 Complete the desk-check table using two sets of input values. First, use 100, 5,
and 8 as the quantity sold, item cost, and item selling price, respectively. The use
650, 2.50, and 3.75. What will the algorithm display using the first set of input
values? What will the algorithm display using the second set of input values?
1st Set
quantity sold item cost item selling price and cost profit
price difference
100 5 8 3 300

8 (item selling price)


- 5 (item cost)
3 (price and cost difference)
300 (profit)

2nd Set
quantity sold item cost item selling price and cost profit
price difference
650 2.5 3.75 1.25 812.5

3.75 (item selling price)


- 2.5 (item cost)
1.25 (price and cost difference)
812.5 (profit)
 How would you modify the IPO chart to also display the difference between the
item cost and item selling price?
Input Processing Output

quantity sold, item cost, Processing items: profit


item selling price price and cost difference

Algorithm:
1. enter the quantity sold, item cost, and item selling price
2. calculate the price and cost difference by subtracting the Item cost from
the item selling price
3. calculate the profit by multiplying the price and cost difference by the
quantity sold
4. display the profit
 How would you modify the IPO chart and desk-check table to eliminate the use of
a processing items?
Input Processing Output

Quantity sold, item cost, Processing items: profit


item selling price none

Algorithm:
1. enter the quantity sold, item cost, and item selling price
2. calculate the profit by subtracting the item cost from the item selling price
and then multiplying the result by the quantity sold
3. display the profit
Lab 2-3: Modify
 Make the appropriate modifications to the IPO chart shown earlier in Figure 2-29.
INPUT PROCESS OUTPUT

number of doughnuts processing items: total number of items


ordered total doughnuts cost ordered
total muffins cost
number of muffins ordered total cost

doughnut price

muffin price

Algorithm:
1. enter number of doughnuts ordered, number of muffins ordered, doughnut
price, and muffin price
2. calculate the total doughnuts cost by multiplying doughnut price by number of
doughnuts ordered
3. calculate the total muffins cost by multiplying muffin price by number of muffins
ordered
4. calculate the total number of items ordered by adding together the number of
doughnuts ordered and the number of muffins ordered
5. calculate the total cost by adding the total doughnuts cost and the total muffins
cost.
6. display the total number of items ordered and total cost
 For the first desk-check, use 4, 2, 0.50, and 0.55 as the number of doughnuts
ordered, number of muffins ordered, doughnut price, and muffin price,
respectively.
number of number doughnut muffin total total total total
doughnut of price price doughnut muffins number cost
s ordered muffins s cost cost of items
ordered ordered

4 2 0.50 0.55 2 1.1 6 3.1

0.50 (doughnut price)


* 4 (number of doughnuts ordered)
2 (total doughnuts cost)

0.55 (muffin price)


* 2 (number of muffins ordered)
1.1 (total muffins cost)

4 (number of doughnuts ordered)


+ 2 (number of muffins ordered)
6 (total number of items ordered

2 (total doughnuts cost)


+ 1.1 (total muffins cost)
3.1 (total cost)
 For the second desk-check, use 0, 12, 0.60, and 0.70.
number of number doughnut muffin total total total total
doughnut of price price doughnuts muffins number cost
s ordered muffins cost cost of items
ordered ordered

0 12 0.60 0.70 0 8.4 12 8.4

0.60 (doughnut price)


* 0 (number of doughnuts ordered)
0 (total doughnuts cost)

0.70 (muffin price)


* 12 (number of muffins ordered)
8.4 (total muffins cost)

0 (number of doughnuts ordered)


+ 12 (number of muffins ordered)
12 (total number of items ordered

0 (total doughnuts cost)


+ 8.4 (total muffins cost)
8.4 (total cost)
Lab 2-4: What’s Missing
 Fill in the IPO chart and determine whether any items are missing from the list.
Next, put the instructions in the proper order and determine the one or more
missing instructions.
Input Processing Output
shortbread sold total cookie sales shortbread contribution
pecan sandies sold pecan sandies contribution
chocolate mint sold chocolate mint contribution

Algorithm:
1. enter the shortbread sold, pecan sandies sold, and chocolate mint sold
2. calculate the total cookie sales by adding the shortbread sold, pecan sandies
sold, and the chocolate mint sold
3. calculate the shortbread contribution by dividing shortbread sold by total cookie
sales, and then multiply the result by 100
4. calculate the pecan sandies contribution by dividing pecan sandies sold by
total cookie sales, and then multiply the result by 100
5. calculate the chocolate mint contribution by dividing chocolate mint sold by
total cookie sales, and then multiply the result by 100
6. display the shortbread contribution, pecan sandies contribution, and chocolate
mint contribution
Lab 2-5: Desk-Check
 Desk-check the algorithm twice. First, use $102.50 and $5.80 as the bill amount
and sales tax, respectively. Then, use $56.78 and $2.18.

1st Deck-Check

102.50 (restaurant bill) 102.50 (restaurant bill) 102.50 (restaurant bill)


- 5.80 (sales tax) - 5.80 (sales tax) - 5.80 (sales tax)
96.7 (bill) 96.7 (bill) 96.7 (bill)
x 0.1 (tip) x 0.15 (tip) x 0.20 (tip)
9.67 (bill amount) 14.505(bill amount) 19.34(bill amount)

2nd Deck-Check

102.50 (restaurant bill) 102.50 (restaurant bill) 102.50 (restaurant bill)


- 2.18 (sales tax) - 2.18 (sales tax) - 2.18 (sales tax)
54.6 (bill) 54.6 (bill) 54.6 (bill)
x 0.1 (tip) x 0.15 (tip) x 0.20 (tip)
5.46 (bill amount) 8.19(bill amount) 10.92(bill amount)
Lab 2-6: Debug
 In this lab, you will find and correct the errors in the algorithm.
INPUT PROCESS OUTPUT
first number processing items: average
second number sum
third number

Algorithm:
1. enter first number, second number, and third number
2. calculate the sum by adding together the first number, second number, and
third number
3. calculate the average by dividing the sum by 3
4. display the average

You might also like