At the end of this lesson, you will be able to:
B2.3 apply the principle of modularity to design reusable code (e.g., subprograms, classes) in computer programs;
understand and create your own functions with no parameters
With a pencil and paper, answer the following questions:
Create a flowchart, pseudocode OR code for a program that displays the following from 1 to 50 inclusive. It prints 5 numbers on the same line separated by a space. Then on the next line it prints the sum of those 5 numbers.
loops and if statements
main() function
from the online book Computer Based Problem Solving by Patrick Coxall, read:
subroutine / function - a block of code written by a programmer to perform a specific task
functions are usually named starting with a verb or action word
i.e. calculate_area(), display_results(), etc.
in Python, functions start with a small letter and each word is separated by an underscore ("_")
in C++, functions start with a capital letter and we use camel case when writing functions with more than one word.
Create a program called "Temperature Converter" that has a function called farenheit()
This function lets you enter a temperature in degrees Celsius (as a decimal), and converts and displays the temperature in Farenheit.
All the functionality needs to be written inside the function and not in main().
main() will just call the function farenheit()
Tf = (9/5)*Tc+32
Tc = temperature in degrees Celsius
Tf = temperature in Farenheit
you will still have a main() function, but now it will call another function
The top-down design should be for the entire program.
There should be a flowchart for each function.
in groups of 2, do the following on the board for today's daily assignment:
Top-Down Design
Flow Chart
Pseudocode
Test Cases
complete the Daily Assignment section in Hãpara Workspace for this day
if Hãpara is not working, make a copy of this document
move it to your IMH-ICS folder for this course
recreate the same program in C++