![]() |
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. Students have a related homwork assignment to write an algorithm to calculate a weighted grade average which they are to bring to lab. |
Turning in
|
You will turn in your worksheet from the lab. You will work in groups and both partner's names must be listed at the top of the page. |
You will work in pairs for this exercise. Solo workers should join with a pair to finish this exercise.
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 or literals (constant and literal 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, obtain the input from a different team or the instructor. When your algorithm generates output, write it on your paper horizontally from left to right starting at the leftmost edge of the page.
Take out a clean piece of paper. PRINT your partner's names at the top.
Execute this algorithm
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 literal container named, 3, and store the value 3 in the container. (This should be written in pen.)
4. Create a constant container named YARDS_TO_FEET that can hold integers.
5. Copy the value in the container named 3 into the container named YARDS_TO_FEET.
6. Create a variable container named numberOfFeet, that can hold integers.
7. Create a literal container named 0 and write the value 0 in the container.
8. Copy the value in the container named 0 into the container named numberOfFeet.
9. 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.
10. Create a literal container that holds the string value " yards is equal to ".
11. Create a literal container that holds the string value " feet.".
12. 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. 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.
3. Literals - The name is the same as the value. Numbers are written as numbers; strings are written with surrounding double quotes.
Make sure that you number each step and each step accomplishes one thing.
Create an algorithm which will calculate and output your GPA.
1. The input stream will be five text values representing the scores from 5 courses this semester.
2. The output should be a line like this "The semester GPA is " followed by the calculated GPA.
Test your algorithm with a couple of different data samples.
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 gallons purchased and dividing by the number of miles driven.
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 09/02/2014 nlh