![]() |
Computer Science Department |
Objectives: |
|
Background: |
This exercise will let
students simulate the operation of a program, where the desktop is
memory, sticky notes serve as memory locations, and actions are performed on the sticky note values. This exercise lays the groundwork for terminoloy and processes that will be required in later programs. |
New Terms: |
Container
- One of the sticky
notes.
All containers must have an identifier, a data type, and a type of
container. Identifier - A name that uniquely defines that container. Names are case sensitive. YARDS is different than yards. Data Type - The set of values that the container can hold. Container Type - One of "variable", "constant", or "literal" that describes how the container may be used. |
Materials: |
Desktop, a packet of
sticky notes of at least 2" square, pens, and pencils. |
Turning in
|
You will turn in your worksheet from the lab. You will work in groups and all group member's names must be listed at the top of the page. |
Reference: |
Lab by Nancy Harris |
You will work in groups for this exercise. Divide each classroom group into two parts so that we have groups of two or three students only.
Each time you "execute" an algorithm, begin by cleaning off one of the desks and each time you create a new container (sticky note), place it on that desk. Use pencil to write values into variables (variable values can change); use pen to write values in constants. (constant values cannot change). Whenever writing a value into a variable, you must first erase any previous value in that variable; variables can only store one value!
When your algorithm requires an input value, use this algorithm:
Take out a clean piece of paper. PRINT your group member's names at the top.
1. Create a variable container named numberOfYards, that can hold integers.
2. Input an integer value and store that value in the container named numberOfYards. (This should be written in pencil.)
3. Create a constant container named YARDS_TO_FEET that can hold integers.
4. Write the literal value 3 into the container named YARDS_TO_FEET.
5. Create a variable container named numberOfFeet, that can hold integers.
6. Write the literal value 0 into the container named numberOfFeet.
7. Multiply the value found in numberOfYards to the value found in YARDS_TO_FEET and write the result IN PENCIL in the container labeled numberOfFeet.
8. Output the value found in the following containers (in the order specified):
On your piece of paper from Part-1, draw a line across your paper to separate your output for Part-1 from your output for Part-2. Take out a second piece of clean paper and PRINT your group's names at the top. Using concepts from yesterday's lecture and the sample algorithm above, write the algorithm to solve the following problem on the second piece of paper. You may make use of the input and output algorithms simply by referring to them as input and output. Use the naming conventions for your containers as follows:
1. Variables - mixed case beginning with a small letter. No spaces or characters other than hyphen or underscore.
2. Constants - Upper case. No spaces or characters other than hyphen or underscore.
Make sure that you number each step and each step accomplishes one thing.
Create an algorithm which will calculate and output your weighted class average (labs and participation, programming assignments, midterm1, midterm2 and final exam).
1. The input stream will be five integer values representing the five scores.
2. The output should be a line like this "The weighted course average is " followed by the calculated average.
On your first piece of paper, draw a line across your paper to separate your output for Part-2 from your output for Part-3. On your second piece of paper, draw a line across your paper to separate your algorithm for Part-2 from your algorithm for Part-3.
Write the algorithm to solve the following problem. Create an algorithm to calculate the miles per gallon of a vehicle fill-up.
1. Miles per gallon is calculated by taking the number of miles driven and dividing by the number of gallons purchased.
2. Input to the process will therefore be the number of gallons (decimal numbers) and the number of miles (whole numbers only).
3. You should prompt for the input and label the output as described above.
Updated 08/27/09