We have already worked on drawing squares using Pro-Bot. We used Repeat Loops to create a square in our previous assignment here
Now, let’s work a bit more with squares, first breaking it down into smaller parts and then building up compound figures using squares as our basic building blocks.
Computer Science concepts involved: Sequential programming, Repeat loops, Nested Loops, Modular programming
Math concepts involved: Polygons (squares, rectangles), Measurement, Fractions, Compound figures, Angles
Grade levels: 3, 4, 5
Hours required: 2 or more
Breaking Down Squares
Building Up with Squares as the Basic Building Blocks
2. Now, let’s create a rectangular shape with the following dimensions, using the above 6 cm square as our building block:
Length = 3 x length of one side of the square
Width = length of one side of the square
Can you write a program for Pro-Bot to draw this figure, using the program for the 6 cm side square that you wrote earlier?
Can you write a program for Pro-Bot to draw this figure, using the program for the 6 cm side square that you wrote earlier?
3. Can we use Nested Loops to draw the above figure? Explain why.
4. Next, let’s create a bigger square with the following dimensions:
Side of big square = 2 x Side of the 6 cm square
Can you write a program for Pro-Bot to draw this figure, using the program for the 6 cm side square that you wrote earlier?
5. Can we use Nested Loops to draw the above figure? (Tip: It is easier to start drawing from the midpoint of the figure while using Nested Loops.)
Here is a set of possible solutions to the above assignments.
Modular Programming
From the two examples above, you can see how a small module that performs one distinct function (in this case, our program to draw the 6 cm side square) can be used to build bigger components. The big components that we created in turn can work as modules for an even bigger program.
This activity provides a quick peek into modular programming, a principle that is widely used in most programming languages. Modular programming is the process of dividing a program into smaller, separate sub-programs.
Let's look at an example that is familiar to you. Do you play with Lego construction sets? A lot of times, when you buy Lego sets, the box comes with several small bags inside of it, each labeled with a number. There will be an instruction booklet that tells you how to use the tiny pieces inside each bag to create a small component of the big toy that you plan to make. Once you have created a couple of such components from the different bags, the book tells you how to put them together to create a slightly bigger unit... and the process goes on till you get to the completed product...
Just like you build large Lego toys using multiple smaller units, each of which in turn was made of still smaller pieces, we can build large programs using smaller components or modules, which in turn can be made of even smaller modules.
So, why do we prefer to use modular programming rather than develop one giant program? Here are some reasons...
- Reusing the code. You write a module just once, but it can be used multiple times by different programs. In the above examples, you wrote the code for the 6 cm side square just once, but you used it multiple times while developing two different programs.
- Breaking up the program into smaller modules makes it easier to maintain the program. For example, if you decide to change the larger programs to be using 10 cm side squares, all you need to do is make one change in your smallest module for the square from 6 cm to 10 cm. The change is easily reflected in all the bigger modules that use it.
- It is easier to find and fix errors in smaller modules.
- Smaller modules ensure that the code is short, simple, easy to read and understand.
- It makes it easier for different people to develop different modules independent of each other. You could have one person write the program for the 6 cm square, another person write the program for the rectangle using the 6 cm square and yet another person write the program for the bigger square. And then, all of these could be put together to create an even bigger program as seen below...
1. Elmo and his friends are planning to play hopscotch. Elmo suggests a figure that looks like the following and draws it out using Pro-Bot. Each square in this hopscotch figure has 6 cm sides. Can you write a program for Pro-Bot to draw this figure? Can you re-use the programs that you wrote above to draw this figure?
- You can also store each of the programs that you wrote above (for the rectangle and the big square) as separate Procedures and call them from your Main program for Pro-Bot to draw the hopscotch figure.
A Different Approach to the above Program
If you have an even number of students/ groups working on this project, you could try the following exercise with the hopscotch figure:
- Divide the class into an even number of teams, so that each team pairs with another. Let’s call the teams in each pair as Team A & Team B.
- Team A in each pair would create the procedure for the big square. Team B in each pair would create the procedure for the large rectangle.
- The pairs then exchange the Pro-Bots.
- So now, each team has the procedure that they created themselves plus the procedure that was created by the other team. They do not need to know how the other team created their procedure; they just need to know what it does (a black box).
- Each team shall give clear instructions to their partner team as to how their procedures work. They can even draw a picture to show what their procedure would create, specifying the start & end points, and give it to the other team.
- Each team now integrates the procedures/modules (their own work + the other team’s work) to create the required final result & test it.
- This could be a good activity to introduce the kids to the concepts of real world engineering projects: division of work among different teams, testing & integration of results.
No comments:
Post a Comment