C3. Coding
Specific Expectations
Coding Skills
C3.1
solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves the analysis of data in order to inform and communicate decisions
- possible mathematical situations:
- making financial choices and other decisions involving purchases, loyalty programs, and currency exchange rates
- applying proportional reasoning (e.g., use a sample of a schoolyard cleanup and apply an appropriate scale to make predictions about the entire cleanup)
- simulating a race around a track that is a composite shape, and comparing race times and distances
- applying geometric properties, including angle measures, and analysing data to strategize moves in sports (e.g., the best serve locations in volleyball and the best shot locations in basketball)
- analysing real-life patterns (e.g., heart rate, sleep patterns, daily steps)
- solving optimization problems involving surface area and volume
- control structures:
- sequential event
- concurrent event
- repeating event
- nested events
- conditional statements
- subprograms
- subprogram to analyse data:
The following subprogram determines how many items might be picked up in a large rectangular area of a schoolyard, and how long it would take, based on values input by students picking up items from a smaller rectangular area:
subprogram cleanUpCalculations |
smallArea = smallLength * smallWidth |
largeArea = largeLength * largeWidth |
scaleValue = largeArea / smallArea |
largeItems = smallItems * scaleValue |
largeMinutes = smallMinutes * scaleValue |
output “Small cleanup area (m2): ”, smallArea |
output “Large cleanup area (m2): ”, LargeArea |
output “Scale value: ”, scaleValue |
output “Expected number of items in the large cleanup area: ”, largeItems |
output “Expected minutes required to clean-up the large area: ”, largeMinutes |
Note:
- Pseudocode does not represent a specific programming language. It can be adapted to work with a variety of programming languages and/or environments.
Main program:
output “Please enter the width of the small area:” |
smallWidth = user input |
output “Please enter the length of the small area:” |
smallLength = user input |
output “Please enter the number of items collected in the small area:” |
smallItems = user input |
output “Please enter the number of minutes taken to clean up the small area:” |
smallMinutes = user input |
output “Please enter the width of the large area:” |
largeWidth = user input |
output “Please enter the length of the large area:” |
largeLength = user input |
run cleanUpCalculation |
- Data can be stored in lists, or input into a program, in order to find solutions to problems and make decisions.
- A flow chart can be used to plan and organize thinking. The symbols used in flow charts have specific meanings, including those that represent a process, a decision, and program input/output.
- Efficient code can include using the fewest number of instructions to solve a problem, using the smallest amount of space to store program data, or executing as fast as possible.
- Loops can be used to create efficient code.
- Conditional statements, like loops, can be nested to allow for a range of possible outcomes or to implement decision trees.
- Sub-programs are used to assemble a complex program by writing portions of the code that can be modularized. This helps to create efficient code.
Note
- By combining mathematical and coding concepts and skills, students can write programs to draw conclusions from data.
- Students can use data, coding, and math concepts and skills to generate a range of possibilities and likelihoods and decide upon a specific course of action (e.g., optimizing packaging, price points, sports performance).
- Coding can be used to automate simple processes and enhance mathematical thinking. For example, students can code expressions to recall previously stored information (defined variables), then input values (e.g., from a sensor, count, or user input) and redefine the value of the variable. (See SEs C2.2 and C2.3.)
Have students write code to look at trends in data so that they can make predictions or informed decisions. For example, have them collect data on their heart rate. Have them write a program that plots their total number of heartbeats for each minute during a ten-minute period on a graph and calculates their average number of beats per minute. Then, have them use the line on their graph to make predictions. The following is an example:
plotPoints subprogram
subprogram plotPoints |
xCoord = numMinutes |
yCoord = numBeats |
plot point at (xCoord, yCoord) |
calcAvgBeatsPerMinute subprogram
subprogram calcAvgBeatsPerMinute |
avgBeatsPerMinute = totalBeatsPerMinute/10 |
Main program
set totalBeatsPerMinute = 0 |
repeat 10 times |
output “Enter the number of beats.” |
store user input as numBeats |
output “Enter the number of minutes.” |
store user input as numMinutes |
run plotPoints subprogram |
run calcBeatsPerMinute subprogram |
run plotAvgBeatsPerMinute subprogram |
output “The average heartbeat per minute is” calcAvgBeatsPerMinute |
Note:
- Pseudocode does not represent a specific programming language. It can be adapted to work with a variety of programming languages and/or environments.
C3.2
read and alter existing code involving the analysis of data in order to inform and communicate decisions, and describe how changes to the code affect the outcomes and the efficiency of the code
- situations that involve altering code:
- enhancing mathematical learning
- simplifying code
- reinforcing that there is more than one way to generate a given outcome
- correcting code in order to get the desired outcomes
- Reading code is done to make predictions as to what the expected outcome will be. Based on that prediction, one can determine if the code needs to be altered prior to its execution.
- Reading code helps with troubleshooting why a program is not able to execute.
- Code is altered so that an expected outcome can be achieved.
- Code can be altered to be used for a new situation.
- Altering code to make it more efficient often involves refining algorithms so that there are no unnecessary steps and using control structures effectively.
- Using sub-programs makes it easier to debug programs since each sub-program can be tested individually.
Note:
- Altering existing code and describing how changes affect outcomes allows students to investigate relationships and pose and test what-if questions.
- By describing how changes affect outcomes, students are making predictions.
- By reading and describing code and algorithms, students are learning to articulate complex mathematical ideas and concepts.
- When students are provided with code and algorithms to solve complex problems, they can alter this code to solve similar problems, thereby gaining a deeper understanding of the mathematical and coding concepts involved.
Present students with the following pseudocode, which determines the volume of a cylinder when given its height and diameter. First, ask them if there are ways to make the pseudocode more efficient. Next, ask them to adapt the pseudocode so that it also determines the cost of a label that will cover the curved side of the cylinder.
calcRadius subprogram
subprogram calcRadius |
Radius = Diameter/2 |
calcCylinderVolume subprogram
subprogram calcCylinderVolume |
CylinderVolume =(3.14*Radius*Radius)*Height |
Main program
output "Enter the diameter of the cylinder in cm." |
store user input as Diameter |
run subprogram calcRadius |
output "Enter the height of the cylinder in cm." |
store user input as Height |
run subprogram calcCylinderVolume |
output "The volume of the cylinder is ", CylinderVolume, " mL or cm3." |
Adaptions to the code could include:
calcCylinderVolume subprogram
subprogram calcCylinderVolume |
CylinderVolume = 3.14*(diameter/2)*(diameter/2)*Height |
calcCurvedSurfaceAreaCylinder subprogram
subprogram calcCurvedSurfaceAreaCylinder |
CurvedSurfaceAreaCylinder = 3.14*Diameter*Height |
calcLabelCost subprogram
subprogram calcLabelCost |
LabelCost = CurvedSurfaceAreaCylinder*Cost |
Main program
output "Enter the diameter of the cylinder in cm." |
store user input as Diameter |
output "Enter the height of the cylinder in cm." |
store user input as Height |
run subprogram calcCurvedSurfaceAreaCylinder |
output "Enter the cost, in cents, of the label per cm2." |
store user input as Cost |
run subprogram calcLabelCost |
output "The cost of the label is ", LabelCost, " ¢." |
Note:
- Pseudocode does not represent a specific programming language. It can be adapted to work with a variety of programming languages and/or environments.
As an extension to Sample Task 1, explain that the company making the cylinders would like to adapt the cylinders so that the cost of labels is cheaper. Ask them to adapt the code in order to determine if decreasing the height or the diameter of the cylinder would be most cost effective.
Have students write code to look at trends involving personal data. The following is an example of a subprogram to analyse a list of stored data on amounts of sleep over a few nights. The subprogram below is designed to scan through the list and determine the minimum number of hours slept. Have students first read the subprogram and then alter it so that it can determine the maximum number of hours slept and the average number of hours slept.
findMinimum subprogram
subprogram findMinimum (numOfItems) |
minimum = value of the first item in the list |
itemNum = 2 |
repeat (numOfItems – 1) times |
if value of itemNum < minimum |
minimum = value of itemNum |
itemNum = itemNum + 1 |
Note:
- Pseudocode does not represent a specific programming language. It can be adapted to work with a variety of programming languages and/or environments.