Deliverables:
To complete this assignment you must --
1.) Write the HTML and JavaScript page described below and demonstrate to
the lab instructor that it operates correctly.
2.) Complete the lab during the time provided or email your results to your lab instructor.
3.) Demonstrate youir program(s) to your lab instructor.
Introduction: The goal of this assignment is to give you experience working with arrays, IF-THEN-ELSE blocks, and DO-LOOPS. Remember, arrays allow one variable name to refer to multiple memory locations. IF-THEN-ELSE blocks let you choose what parts of your code execute based on input data. DO-LOOPS allow you to repeat sections of code. These three things exist in some form in all programming languages you are likely to encounter.
Procedures:
PART 1:
Section | Pseudocode | Comments | |
---|---|---|---|
INPUT: | Integer list[10]; | This represents a list of ten numbers. | |
OTHER VARIABLES: | Integer sum; Integer i; | ||
INITIALIZATION: | FOR i = 0 to 9 DO list[i] = random integer between 0 and 100; END DO sum = 0; |
This fills the array with ten random numbers from 0 - 100. Notice how we can use pseudo-code to avoid headache of having to build a random number generator. Most languages have predefined ones. | |
COMPUTATION: | FOR i = 0 to 9 DO sum = sum + list[i]; ENDDO |
This loop simply adds each list element to the sum one by one. | |
OUTPUT: | return(sum); | Remember to format your results in a sensible way. |
Compare(): compares numbers from two separate lists.
Section | Pseudocode | Comments | |
---|---|---|---|
INPUT: | Integer list1[10], list2[10]; | This represents two lists of ten numbers each. | |
OTHER VARIABLES: | Integer i; | We only need the loop variable (also called a counting variable. | |
INITIALIZATION: | FOR i = 0 to 10 DO list1[i] = random number between 0 - 100; list2[i] = random number between 0 - 100; ENDDO |
i = 0 to 10 not inclusive of 10. | |
COMPUTATION: | FOR i = 0 to 10 DO IF ( list1[i] > list2[j]) THEN print(list1[i] + "is greater than" + list2[i]); ELSE print(list1[i] + "is less than" + list2[i]); ENDIF ENDDO |
This simply compares two numbers from each list and prints out which one is bigger. | |
OUTPUT: | No output required since we have printed out the results in the loop body. |