Loops
exercises (start in class for in class students - distance learning students
must complete on their own):
Problem #1: Amazon frequently sends separate packages for the books that you order. Lets assume that they have a policy to determine location and availability and enter the number of packages that must be sent with the order. We are now going to do the logic for the program to generate the labels needed. I also want to write a total for the total number of packages sent. Follow the flowchart and process the data. Show me the output that would be produced. You can just write John Doe label information or Susan Ash label information for the label since I did not give you the address information.
Field |
Name of Field |
Example of Data |
1 - 5 |
IDNO (Identification Number) |
11111 |
5 - 25 |
NAME (Customer Name) |
John Doe |
26 - 100 |
Other information |
… |
101-102 |
NUMPKG (Number of Packages) |
3 |
IDNO |
NAME |
Other information |
NUMPKG |
11111 |
John Doe |
|
3 |
12345 |
Susan Ash |
|
5 |
22222 |
Mary Jones |
|
1 |
23456 |
Arthur South |
|
6 |
33333 |
June Lee |
|
2 |
34567 |
Robert Costa |
|
3 |
close files Set up total line open files set data
N CT=1 Set up basic N/A info for label
Problem #2: Your favorite store is having a sale. This pseudocode shows how the sale works. Generate a report that shows the price for each item on each day of the sale. The layout of the file and some sample data are shown below.
ITEMNO (item number) |
ITEMNAME (item name) |
Other information not used |
PRICE (price of the item before the sale) |
11111 |
Ceramic Vase |
|
50 |
12121 |
Pewter Bowl |
|
100 |
12345 |
Victorian Lamp |
|
200 |
13456 |
China Dog |
|
20 |
Mainline -
Start
Wrapup()
Housekeeping() Close files
Process() Return
Wrapup() End-wrapup
Stop
End-mainline
Housekeeping()
Set data
Open files
Return
End-housekeeping
Process()
Read a record
While not EOF
Loop()
End-loop
Return
End-process
Loop()
Set up line with file information (itemnno
& itemname)
Counter = 1
workPrice = price of item on file
While counter < 4
workPrice = workPrice * .9
put workPrice on line
print line
counter = counter + 1
end-while-innerloop
Read a record
Return
End-loop