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.
- 7-8: The student can develop and use abstractions.
- 15-16: The student can develop and express an algorithm in Pseudocode and App Inventor.
- 20-22: The student can use abstractions (specifically functions) to manage complexity in programs and develop a
correct program (with functions).
Fahrenheit to Celsius Conversion
This activity builds on the functions
homework assignment, in which you developed a pseudocode algorithm
for a fahrToCelsius functions and then translated it into App
Inventor blocks. Your solution should look something like this:
# Comment: A function to convert celsius to fahrenheit
# Arguments: C, represents the temperature in celsius
To celsiusToFahrenheit(C):
Return: 9.0 / 5.0 × C + 32
|
(Click to enlarge.)
|
Inclass/Homework Exercises
Solutions
Identify a conversion function that you are interested in and write
an app that performs that conversion. For example,
- If you are a runner, you might want to convert kilometers to miles
or vice versa.
- If you are interested in baking or cooking, you might want to
convert tablespoons to ounces, or something in that area.
- If you are baseball player you might want to calculate earned
run average or slugging percentage.
- If you are a squash player, you might want to
convert wins and losses into winning percentage.
It's up to you to choose a conversion that you would find truly useful.
- Write a Pseudocode function for your conversion. Have you pseudocode
checked by the instructor or TA.
- Convert your Pseudocode into an App Inventor function. Use the
blocks editor to test that it is correct.
- 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.
- Describe your conversion algorithm and your app on a Portfolio page.
Homework
Finish for homework whatever you don't complete in class.