117 Homework Assignment #5
03/20/06
Write a perl program to do the following:
- Create an array with these initial values:
5.6, 3.7, 20.1, 6.2
- Do the following in a loop:
- show the contents of the array
- ask the user to enter another value for the array
- if the user enters the word "quit", end the loop
- else add the new value to the end of the array
- start the loop over
- Loop through all the members of the array
- calculate the sum of all the members
hint: keep a running sum
- calculate a count of all the members
can be done in a variety of ways
- calculate the maximum value
If $maximum is not defined,
then let $maximum = current array value.
Then check each array value as you loop thru the array,
and see if this value is larger than the current maximum.
If so, save that value as the new maximum.
- calculate the minimum value
Use a similar technique to the maximum value.
- Display the following results
- show the contents of the array
- show the following about the array
- total number of elements
- sum of all the elements
- average value in the array
- maximum value in the array
- minimum value in the array
- submit this as you did homework 4
but call it: prog5.pl
Hint: here is an example to test for the word "quit"
if ($input eq "quit") { ... }
Some deductions that I have given out:
-1 incorrect program name
-1 did not make prog5.pl executable (use chmod)
-1 use longer, more descriptive variable names
-1 missing or incorrect magic first line
-1 or more: initial loop to add new values does not follow spec
-1 did not output the results in the correct order
-1 or more: incorrect indentation
hint: program should end back at the left margin