CPSC 110-08: Computing on Mobile Phones
Spring 2012

Solutions to Conversion Function Exercises

CS Principles

This activity addresses the concept of abstraction, focusing on functions and parameters (or arguments). It introduces functions as re-usable programming abstractions and shows how parametrization can be used to generalize a specific solution. It addresses the following learning objectives.

Inclass/Homework Exercises

Write a function that converts temperature in Celsius to temperature in Fahrenheit.

Identify a conversion function that you are interested in and write an app that performs that conversion. For example,

# Comment: A function to convert Celsius to Fahrenheit
#  where F = 9/5C + 32
# Arguments:  C represents temp in Celsius

To celsiusToFahrenheit(C):
   Return: (9 / 5 * C) + 32
(Click to enlarge.)

It's up to you to choose a conversion that you would find truly useful.

  1. Write a Pseudocode function for your conversion. Have you pseudocode checked by the instructor or TA.

  2. Convert your Pseudocode into an App Inventor function. Use the blocks editor to test that it is correct.

  3. Design and implement a simple app that peforms that conversion.
    You app should have a simple interface. For example, your app could use a simple Input-Process-Output design, similar to the Leap Year app. It could have 1 or 2 TextBoxes where the user can enter the value(s) needed as the input to the function, a Button that is clicked to perform the conversion, and a Label to display the result. You could copy and adapt the Leap Year app for this purpose.

  4. Describe your conversion algorithm and your app on a Portfolio page.

Homework

Finish for homework whatever you don't complete in class.