1. read the length of the window read the width of the window read delivery choice - y or n area = length * width glass cost = area * .50 perimeter = 2 * (length + width) frame cost = perimeter * .75 total cost = glass cost + frame cost if delivery == 'y' total cost = total cost + 50.00 print length, width, total cost 2. This algorithm shows a simple "if" statement. The test data for this particular problem needs to include the window information (length and width) and the delivery option. You would need to make up at least TWO sets of test data; one when the delivery is Yes and one when the delivery is No. length width delivery 10 40 n 15 20 y 3. read the length of the window read the width of the window area = length * width perimeter = 2 * (length + width) if area <= 1000 glass cost = area * .50 frame cost = perimeter * .75 else glass cost = area * .60 frame cost = perimeter * .80 total cost = glass cost + frame cost if delivery == 'y' total cost = total cost + 50.00 print length, width, total cost 4. As you make up test data for this problem, you must realize that smaller windows are 1 - 1000 square inches and larger windows are 1001 square inches or more. The 1000 and the 1001 become what is referred to as the "boundary" numbers. They are the numbers that determine the difference between the two prices. Test data ALWAYS involves using the boundary numbers. length width delivery 20 50 n 50 20.05 y Notice that the area of the first window is 1000, and the area of the second window is 1001. If the length and width are ints, we cannot choose data that will give us an area of 1001. In that case we should get as close to the boundary value as possible, for example, using values like 501 and 2 for the length and the width. 5. read the length of the window read the width of the window read the thickness of the window (s/d) area = length * width perimeter = 2 * (length + width) if thickness = 's' // USES TWO-WAY SELECTION glass cost = area * .50 else glass cost = area * 1.00 if glass cost < 350.00 // THIS IS ONE-WAY SELECTION INSIDE glass cost = 350.00 // THE TWO-WAY SELECTION frame cost = perimeter * .75 total cost = glass cost + frame cost if delivery == 'y' total cost = total cost + 50.00 print length, width, total cost 6. This problem has three cases: single pane, double pane with glass cost less than $350, and double pane with class cost of $350 or more. As in the previous problem, the best test data uses the boundary values. It's also a good idea to try a case of double pane with glass cost greater than $350. length width single/double delivery 10 34.9 d n 10 by 34.9 gives an area of 349, which gives a glass cost of $349 10 35 d y 10 by 35 gives an area of 350, which gives a glass cost of $350 10 15 s n 20 30 d n 7. grand total = 0 read the length of the window read the width of the window while length != -1 and width != -1 read the thickness of the window (s/d) area = length * width perimeter = 2 * (length + width) if thickness = 's' // USES TWO-WAY SELECTION glass cost = area * .50 else glass cost = area * 1.00 if glass cost < 350 // THIS IS ONE-WAY SELECTION INSIDE glass cost = 350 // THE TWO-WAY SELECTION frame cost = perimeter * .75 total cost = glass cost + frame cost if delivery == 'y' total cost = total cost + 50.00 print length, width, total cost grand total = grand total + total cost read the length of the window read the width of the window print grand total 8. For this problem, we can use the test data given for the previous algorithm. Instead of having to run the program four separate times, we can use this test data all in one execution. We just need to add -1 -1 to the end of the data to stop the loop.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2002