CPSC 110-08: Computing with Mobile Phones

Reading: App Inventor, Create Your Own Apps, Chapter 21
Due: Wednesday 10/12 (before class)

CS Principles

This reading and homework activity focuses on abstraction again, this time focusing on functions and parameters. The student will be introduced to functions as re-usable programming abstractions and will see how parameterization can be used to generalize a specific solution. It begins to address the following learning objective.

Textbook

You can purchase a copy of the text book Wolber, Abelson, Spertus, and Looney, App Inventor: Create Your Own Android Apps. It costs around $25. We will be having reading assignments from this text throughout the semester.

There is a pre-publication version of this book available for free download. However, it is not as complete as the published version.

Reading Assignment

Read Chapter 21, Defining Procedures, especially pages 296-303 on parameters and functions.

Reading Questions. Provide answers to the following two questions on a Portfolio page for this reading assignment.

  1. Consider the following function definition, written in Pseudocode:
    # Comment: Figure out what this function does
    # Notice how we put the parameters, X and Y, in a list enclosed in parentheses
    # Notice that a function definition ends with a Return statement
    
    To mysteryFunction(X, Y):
       Let S be 0
       While X <= Y do:
          Let S be S + X
          Let X be X + 1
       Return S
    

    What value would this function return if it is called with mysteryFunction(1, 5)? Note: The convention here is that the value 1 would be substituted for the parameter X and the value 5 would be substituted for the parameter Y. Given that convention, trace the code to figure out the result. In general what does this function compute?

  2. Consider the following function definition:
    # Comment: Figure out what this function does
    # Notice that the  parameter list is empty in this case
    
    To computeSomething():
       Let P be 1
       Let N be 4
       While N >= 1 do:
          Let P be P * N
          Let N be N - 1
       Return P
    

    What value would this function return when it is called with computeSomething()? In general what does this function compute? How would you modify this function, using a parameter, to make it more general?

In Class on Wednesday

We will discuss several examples of functions and parameters.