Navigation

Home

Weekly Schedule

TA Schedule

Prof Harris Schedule

Prof Capaccio Schedule

General Policies

Resources

CodingBat, practice site

Tutorial directory

Lab directory

Objectives:

  • Learn the terminology of algorithms that will eventually translate to programs
  • Begin to think in terms of steps required to implement solutions
  • Provide an analogy with manual "programs" that will translate to programming

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
your work:

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

Background:

deskWe are simulating the execution of an algorithm with this lab.    Think of computer memory as a desktop.  When we start to execute a program, the program will obtain memory locations for each data item that we are manipulating.  Yesterday we used the term "label" to associate a name and a memory location.  Today we will represent these memory locations as sticky notes.

There are three kinds of memory locations that we use in programs:
Each memory location is defined with a name, a data type and a value.  The value may be empty to begin with but the type of data and the name of the location must be defined.

sticky noteFor this simulation, we will use "sticky notes" do define the storage locations needed by the algorithms.  When the instructions say "Create a ____ container", you will use a sticky note.  If it is a variable container, you will use pencil to write in the values.  When it is a literal or a constant, you will use a pen.  The container may be placed anywhere on the desk.  When we refer to a container later in the algorithm, we will use its name.  Containers should be labelled with the name and data type on the top and then when you provide values, you will place those values in the center.


Part 1: Follow an algorithm

You will work in pairs for this exercise.  Divide each classroom group into two parts so that we have groups of two or three students only.  

Take out two clean pieces of paper. PRINT your group members' names at the top of each page and label one paper INSTRUCTIONS and the other page OUTPUT.

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, obtain a number from the whiteboard "input streams".

When your algorithm generates output, use this algorithm:
  1. If the OUTPUT paper has no lines, starting 1/2 inch from the  leftmost side of the paper, write the values to be output from left to right.
  2. If the OUTPUT paper has lines, start at the leftmost margin of the paper, write the values to be output from left to right.

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 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):

  1. the container named numberOfYards
  2. the literal " yards is equal to "
  3. the container named numberOfFeet
  4. the literal " feet."

Part 2: Write an algorithm.

On your OUTPUT piece of paper, draw a line across your paper to separate your output for Part-1 from your output for Part-2. Using concepts from yesterday's class and the sample algorithm above, write the algorithm to solve the following problem on the INSTRUCTION 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 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.

Be sure that you test your algorithm.

Part 3: Write another algorithm.

On your OUTPUT piece of paper from Part-2, draw a line across your paper to separate your output for Part-2 from your output for Part-3. On your INSTRUCTION piece of paper, 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 in the order listed above.

2. The output should be a line like this "The weighted course average is " followed by the calculated average.

Again, test your algorithm.

 

Turn in both the OUTPUT and INSTRUCTION papers.