CS 1150 PEEE   Fundamentals—Data & Actions

Overview

We have discussed the fundamentals of programming as consisting of data & actions (often on data) and organizing the actions via sequence, selection, repetition and modularization. This practice/learning activity will revisit those ideas in more detail focussing on data and actions. (Some simple selection or repetition may be used but is not expected to add any complexity or confusion.) The learning activity is described after the Process Reminders below.

Process Reminders

Pair Programming

Keep the "pair programming" process in mind as you work. One person types and the other person watches and corrects, questions, etc. After a bit (at most 30 minutes) you change roles.

Grading

This activity is for you to learn, so it is not graded. The learning will be inferred in the PARR (Programming Activity and Reflection Report) document you (eventually) submit and in one of the in-term exams. Remember to add to your notes for the PARR.

If you have questions or difficulties

If you have questions about the assignment send me an e-mail or drop by my office. If you have a question while working on the assignment do the same. Keep in mind that when you encounter something you can't figure out you can/should think, explore, seek answers on google, etc. but, do not spend more than 15-30 minutes trying to overcome a particular error or problem.

Extra Credit

The syllabus noted a couple ways you might earn extra credit. I am adding another.

One is to share some aspect(s) of programming or Snap! you think others might not have experienced. You should annotate your program using the program notes (File icon | Program notes) and/or comments blocks (see p.68 of the Snap! Reference Manual. The annotation should describe or explain the learning/insight(s) you want to share.

To receive extra credit for such an annotated program on this activity you will also need to submit a copy of your algorithms. Either create a PDF of a document or include the text in your submission message.

The alternative method to work for extra credit is that the partnership could suggest additions to our how to do it page. You might suggest a revision to clarify (or finish) something that is there already or an entirely new topic. Please indicate how/why you think the would be helpful. Be sure you fully and clearly describe what you are talking about.

The third method to receive a bit of extra credit is to submit the "Create your own problems ..." that you created and solved. Include all three problems and a pseudo-code algorithm of each solution.

Submitting something for either kind of extra credit is as simple as sending an e-mail message. The message should:

Learning Activity

The goal here is to create a pseudo-code algorithm for any of the little problems described below for which the code is not obvious to you and then to create a script to implement the algorithm. I prefer you develop algorithms for all of them, but will expect that you create algorithms for any script that requires more than five blocks. The scripts will be included in a single program, each invoked by the user entering the number of the problem s/he wants to work. I suggest you use the following script in the Stage to control the program action.

Snap! repeat until 0 entered code

Then for each problem there will a matching script that gets executed by some sprite. The code for that would replace the "say" block in the following script and perhaps use a different number in the "when I receive __" block.

Snap! when I receive block

The Problems

Arithmetic (mostly) problems

  1. Celsius to Fahrenheit

    Ask the user for a Celsius temperature value and report (via a "say" block) its equivalent Fahrenheit value. Report the equivalent value to the nearest degree.

  2. Pay without overtime

    Accept input from the user for the number of hours worked and the pay rate and report (using a say block) the gross pay for those values.

  3. Pay with overtime

    Accept input from the user for the number of hours worked and the pay rate and report (using a say block) the gross pay for those values including overtime pay (half again as much pay for any time over 40 hours per week).

  4. Area of circle

    Accept input from the user indicating the radius of a circle. Report the area of the circle. (Use 3.14159 as the value for pi.)

  5. Volume of a sphere

    Accept input from the user indicating the radius of a sphere. Report the volume of the sphere. (Use 3.14159 as the value for pi.)

  6. Die roll (text)

    Generate a random value for a single die roll. Report the value using a "say" block.

  7. Craps roll—two dice (text)

    Generate two random dice roll values and report the total value.

  8. Level up

    Maintain values for score and level. Scores are incremented by 1 each time a desired activity occurs. The levels will be as follows: level 1 (for scores 0-4), level 2 (for scores 5-9), level 3 (for scores 10-14), etc. (normally there would be more scores per level but this will make testing easier). I suggest you have the stage handle this task. Perhaps have one of the sprite broadcast "score" whenever it is clicked on and stage have a script to increment the score and set the value for level.

  9. create (and solve) your own simple data related problem

Graphical (mostly) problems

  1. Spiral

    Have a sprite draw a spiral. For example, a spiral with squares would increase the size of the move each time before (or after) turning 90°

  2. Dice roll (image)

    Report the value of a single dice roll setting a sprite's costume appropriately. You can download and import 6 images as costumes for a sprite. Be sure to do them in order. I have some images in our notes directory. (You can "import" them or just drag them into Snap! as costume files.)

  3. Craps roll (image)

    Roll two different dice (probably two different sprites, one a duplicate of the other perhaps) and report the total of the two rolls. (You'll have to come up with some mechanism to report the total.)

  4. Dice total competition

    Repeatedly (4 times) roll two different dice (probably two different sprites) and calculate the total of each die's rolls. Include some wait time between each roll so the change of rolls can be seen. After the four rolls, report the total for each die.

  5. (new) Proportional size

    Have the sprite set its size depending on its y-coordinate value. You may define your own mechanism for doing this or use mine. My approach is to set the size of the sprite equal to ((100 - (y position / 2)) + 10). The 100 represents 100%. The expression "y position / 2" reflects a scale value involving the current position. The "+ 10" represents a minimal value at the top of the screen. I suggest you have the sprite change its position to that of the cursor whenever the "mouse is down".

  6. Create (and solve) your own more complex data-related problem

Textual (mostly) problems

  1. Simple interaction

    Ask the user's name, then use the name when saying hello and asking some question for which your sprite will have some sort of response that also includes the name.

  2. Word lengths

    Have the user type words or phrases to which the sprite will respond by repeating the word/phrase and indicating how many characters it contains.

  3. Simple start to hangman

    Pretend you have two different users. One will enter a word and the other will guess letters to which the computer will respond by saying it is or is not in the word.

  4. Create (and solve) your own more textual problem