emboldened text
denotes sections of Program 3 that must be revised:
-------| PROGRAM P-CODE |--------------- -------| IN-LINE COMMENTS |-------
PROGRAM Proj4: ## CGS 3462 - Program 2: Selection
DECLARE prave : integer ## Main: variable typing
i,j : integer
price : array [1..10] of integer
cost : string
END-DECLARE
FOR i = 1 TO 3 DO:
WRITELN('Input Ten Prices [0-100] Separated by Spaces Below:')
FOR j = 1 TO 10 DO:
READLN(price[j]) ## Input 10 numbers (keybd.)
ENDFOR
Average(price,10, prave) ## Take mean of the numbers
Price2Cost(prave,cost) ## Convert the mean to cost
FOR j = 1 TO 10 DO:
WRITELN('price[',j,'] = ', price[j]) ## Display 10 input numbers
ENDFOR
WRITE " prave= ",prave," cost= ",cost ## Output results to screen
ENDFOR
END-PROGRAM
## CGS 3462 - Cost Category Selection Procedure
PROCEDURE Price2Cost(price,cost): ## CGS 3462 - cost Selection Proc.
DECLARE price : integer ## integer "price" - student price
cost : string ## string "cost" - letter cost
END-DECLARE
IF price > 85 THEN ## High cost exceeds $85
cost := 'High'
ELSEIF price <= 85 AND price > 60 THEN ## Medium cost is $60 to $85
cost := 'Medium'
ELSEIF price <= 60 AND price > 30 THEN ## Low cost is $30 to $60
cost := 'Low'
ELSEIF price <= 30 THEN ## Cheap prices are below $30
cost := 'Cheap'
END-IF
END-PROCEDURE
PROCEDURE Average(p,N,d): ## CGS3462 - find mean of 3 numbers
DECLARE N,d: integer ## Inputs and output are integers
sum: integer
p : array [1..10] of integer
END-DECLARE
sum := 0 ## Initialize sum
FOR j = 1 TO N DO:
sum := sum + p[j] ## Accumulate N numbers
ENDFOR
d := ROUND(sum/10) ## Compute mean using ROUND function
END-PROCEDURE
Step 2. Use the Price2Cost procedure that you developed
for Project #2. This implements the concept of reusable
code. The procedure called Average should have
the following PASCAL declaration:
PROCEDURE Average(p : array [1..10] of integer, N: integer; VAR d : integer);
Step 3. Based on your experience with errors in Projects 1-3
and our discussion in class, check to see if there are any errors in
the preceding program statements. We will discuss the code in detail
in class. However, you still need to check for missing semicolons, or
the wrong variables in the IF statement. Now, run the program and see
if the output is correct. Play with different values in the array
price. If the output is incorrect, why does this occur?
Fix any problems that may occur in the preceding code.
Step 4. Document the program produced in Step 1 by
inserting in-line comments using braces ( {FOR-loop
should produce output that looks like this (your input emboldened,
DOS prompt not included):
Input Ten Prices [0-100] Separated by Spaces Below:
10 20 30 40 50 60 70 80 90 50
price [1] = 10
price [2] = 20
price [3] = 30
price [4] = 40
price [5] = 50
price [6] = 60
price [7] = 70
price [8] = 80
price [9] = 90
price [10] = 50
prave= 50 cost= Low
Hardcopy. The completed program (Proj4 together with the output) should be printed on a CIRCA 24-pin printer, or a good-quality printer you may have at home. Laser printer output is acceptable, if you have access to a laser printer. Otherwise, a 24-pin dot matrix printer will do. Staple your two pages (one program, one output page) together and write your NAME, SSN, CGS3462, PROJECT #4, and today's DATE at the TOP RIGHT-HAND CORNER of the paper, in BIG BLOCK LETTERS (so I will not mistake it for someone else's). Be sure to print clearly, so I will know whose program it is.
Items Due. Give the instructor your completed project hardcopy in class on Thursday 30 October 97. Projects turned in a day late will be penalized -10%; two days late: -20%. Projects turned in after the Friday following the due date will not be accepted unless accompanied by a documented excuse (note from your physician or advisor).