Part II: Programming Fundamentals

CS 1150 PEEE — Spring 2017

Day 11: Simple Snap! Programs Exam

Logistics

Exam

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 12: Programming Fundamentals Intro

Logistics

The Basics of Programming

Thus far our learning activities have been designed to expose you to programming in a manner that you might use with your students. We are going to get a little more formal with our treatment of programming. The next several days will involve:

At least that's the plan right now. We'll see how it turns out :-)

Data & Actions

Snap! uses less data and more actions than most programming languages but it does make use of both. We've seen a good sampling of actions and a little bit of data. In most programming languages the actions are input of data, manipulation of data, and the output of resulting data. We'll get a little better taste of that in our next activity.

The key to programming is to organize the actions in a useful manner. There are four basic ways to organize actions—sequence, selection, repetition, and modularization.

Sequence

This seems super simple. Just put the actions in sequence one after the other. But sometimes the order matters and sometimes it does not. And sometimes you forget and action and have to figure out where it goes.

Also, when you start using the other organizing techniques you still have to sequence things but in a more complicated manner.

Selection

Selection is choosing actions. It might be simple, just choosing to do or not do an action. It might involve choosing between two actions. Selection is most often done by using an if statement. We are all familiar with "if" situations, if you are sleepy go to bed, if it is raining take a rain protector, etc. But the familiar concept gets more difficult when programming.

Perhaps the most difficult part of using selection is figuring out the test or question that allows you to choose. An added difficulty is that the action you choose might have another selection element in it and that selection element might have another, and so on and so on. Simple in theory a bit harder in practice on some problems.

Repetition

Sample Algorithm

I received the following request for assistance from a pair of students in our class.

We would like to list the names of numerous states and ask the student to write the name of the capital in the blank. We have imported the list of states and capitals and would like to keep track of how many capitals the student gets right. We would like to stop after maybe 20? Once the quiz is over, there will be another speaking part wrapping up the quiz. This is what we have in mind, but are unsure how to carry out the program after the speaking parts.

I suggested that they had all the ideas but that putting the ideas in pseudocode/algorithmic form might help them figure out how to proceed in Snap! The algorithm I suggested was:

    set correctCount to 0
    repeat 20 times
    |   set itemNumber to random between 1 & length of states list
    |   ask what is the capital of itemNumber of states
    |   if answer = itemNumber of capitals
    |   |   add 1 to correctCount
    |   |   say correct
    |   else
    |   |   say incorrect
    |   |===================
    |===============================

Next Learning Activity

We'll do pseudocode algorithms for one simple and one more complex exercise as a class, then pairs/groups work to develop algorithms/pseudocode for the other problems. Once the algorithms are done, the programs/scripts can be produced.

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Tuesday.

Day 13: Work on Data & Actions Activity

Logistics

Work on the data and actions activity

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 14: Continue Work on Data & Actions Activity

Logistics

Work on the data and actions activity

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 15: Boolean Data

Logistics

Basic data & actions

We've had an extra day to work on variables, I/O, data manipulation and other actions. Are there any questions about any of the items in the learning activity for basic data and actions? Are there any questions more generally?

Intro to Boolean data

We have worked with numbers and, to a lesser extent, with text. There is another kind of data often used in programming—Boolean data. There are lots of numeric values and lots of text values, there are only two Boolean values—true and false. Booleans are used to answer questions about data values or the state of the program. Typically, you use them in if and repeat until blocks but there can be used nearly anywhere you would use other data.

The goal of the next learning activity is to familiarize you with the conditional operators and expressions that result in Boolean values (true or false). Let's look at the learning activity and see what questions you have.

Work and example or two demonstrating how to code the activity. Then students work on the Boolean data and actions activity

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Thursday.

Day 16: Review Booleans; Introduce Selection

Logistics

Questions on Boolean Learning Activity

Review the Boolean data and actions activity to see what questions students have and/or what learning or insights they wish to share.

Introduction to Selection

We have worked with numbers, to a lesser extent, with text, and now with Boolean data. That prepares us to use data in a manner that allows us to choose actions rather than merely doing actions. We do that with selection statements/blocks—if and if...else... blocks.

The goal of the next learning activity is to become more adept at planning what needs to be done by when choices about actions are necessary. . Let's look at the learning activity and see what questions you have.

Work an example or two demonstrating how to code the activity. Then students work on the selection activity

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you Tuesday.

Day 17: Work on Selection; Introduce Repetition

Logistics

Questions on Selection Learning Activity

Review the selection learning activity. Respond to any questions students have.

Introduce Repetition

Review the repetition learning activity. Go over the example(s) given in the activity description. Respond to any questions students have.

The goal of the next learning activity is to become more adept at planning what needs to be done by when choices about actions are necessary. . Let's look at the learning activity and see what questions you have.

Work and example or two demonstrating how to code the activity. Then students work on the selection activity

Next Time:

Questions? Comments? Wonderings?   —   Have fun! See you After Spring Break.

Day 18: No Class Meeting; Work on Repetition

(Instructor out of town at a conference) Students are to work on the repetition learning activity with their partners. A better solution is for everyone to attend class so everyone can help everyone.

Next Time:

Day 19: Review Repetition Learning Activity

Logistics

Questions on Repetition Learning Activity

Review the repetition learning activity. Respond to any questions students have — there were no questions.

Ask: Are all of you ready for an exam that might include any one of these questions other than the sieve or Eratosthenes? Any questions? (Now there were some questions. Discussion and working of problems ensued. Contact you partner or classmates if you were absent.)

Next Time:

  • final chance for question about repetition activity; introduce formal examination of modularization.

Day 20: Introduce Modularization

Logistics

  • Roll
  • Wonderings? Comments?

Questions on Repetition Learning Activity

Last official chance ... Any questions, or wonderings concerning repetition in general or specific to the repetition learning activity? Respond to any questions students have.

Modularization

The final fundamental of programming is modularization. That's what we'll start on next time.

Next Time:

Day 21: Introduce Modularization

Logistics

  • Roll
  • Wonderings? Comments?

Questions on Repetition Learning Activity

Review the repetition learning activity. Respond to any questions students have

Modularization

The final fundamental of programming is modularization. One (perhaps the simplest) way to think of modularization is that you are just making up you own instructions. We just have to remember that the instructions must consist of instructions that the computer already knows how to accomplish. If we make up the new instructions correctly, then we expand what the computer knows how to do and can make programs out of the original instructions and any new instructions that have been created. Questions? Comments? Wonderings?

Now, let's get a little more formal (computer science-y) about modularization

  • What is it?
  • Why use it?
    • to reduce duplicated code (and need to change code in every place it exists when a change is needed)
    • to aid in abstraction of the problem solution
    • to illustrate problem decomposition/solution (part of abstraction)
    • to allow for similar but different outcomes of essentially same task
  • How does it work?
  • Considerations when using it

Examples

  • Draw initials
  • Draw rectangle
  • Considerations when using it

Next Time:

Day 22: Questions/Work on Modularization

Logistics

  • Roll
  • Wonderings? Comments?

Questions on Modularization Learning Activity

Respond to any questions students have. Use remaining class time for work on the activity

Modularization

The final fundamental of programming is modularization. That's what we'll start on next time.

Next Time:

  • Final Modularization questions;  Start robots stuff

Day 23: Modularization Wrap-up;   Robots Introduction

Logistics

  • Roll
  • Wonderings? Comments?

Questions on Modularization Learning Activity

Respond to any questions students have.

Questions Concerning Fundamentals Exam

Respond to any questions students have.

Introduce the Robots Activity & Get Started

See the robots notes.

Next Time:

  • Robots work