A problem can be simple or complex according to its nature. It is rather difficult to perceive and understand a complex problem when compared with a simple problem. It is essential to understand a problem thoroughly before going to solve it. So it will be easier to find a solution to a complex problem after decomposing it into smaller sub-problems.
Likewise, a complex problem that seems difficult to solve at once can be broken into several smaller sub-problems as much as possible. Then these sub-problems can be solved easily one by one.
eg:- In grade o6, you have learnt about the basic mathematical function which include addition, substraction, multiplication and division of a whole number. Additionally in the first term of graded 07, you have learnt about solving sums when more than one mathematical functions are used with a whole number. Consider the following sum (Refer Figure 5.3).
Symbols in flow chart to represent algorithm have been explained in grade six. An algorithm may include one or more control structures out of three. Three types of control structures are shown below.
Execution of instructions in an algorithm sequentially from top to the bottom is called sequence. Let’s see how it is represented in a flow chart.
e.g. : Covering a textbook
Let's represent covering a textbook in a flow chart.
e.g. 2 :Finding the area and perimeter of a rectangle
Here it is expected to make a making decision on which step to follow depending on the condition given by the algorithm. In a selection, the condition is checked first and the flow direction is chosen based on whether the condition is true or false.
For example, let's consider an instance where a ceiling fan is operated. When the switch is on, the ceiling fan operates if there is power. If there is no power, the ceiling fan does not operate.
Execution of an instruction or several instructions in an algorithm repeatedly until a condition is satisfied is called repetition. A repetition will take place depending on whether a condition is satisfied or not satisfied. For example, natural water cycle is a process that takes place repeatedly.
As an example, do you know that since your childhood, you used to save moneyby using a till to put money? The one who is used to save money in a till, will always put money (again and again) repeatedly until the till fills.So, here the process of putting money is repeated until the condition that is ‘till becomes full’ is satisfied.
Checking of condition for repetition can take place in two ways.
1. Check the condition before repetion starts.
2. Check the condition after functioning once.
Scratch which is a visual programme development software is an interactive, attractive and a simple programme with command blocks. This is a Free and Open Source Software (FOSS) and therefore it can be downloaded freely from the following website. http://www.scratch.mit.edu
Sprite and blocks control tools
Note: All these interfaces are in Scratch 2.0 (version 2).
Follow the instructions given bellow to create a programme using scratch
1. Playing basic notes with piano
Connect the control blocks (scripts) shown below sequentially. Then change the values of the control blocks as shown in the figure below. Run the programme and check the voice.
2. Expressing days of the week in order by Sprite
In programming, variables are used to store a value in memory temporarily. Let’s study the following activity to understand the nature of a variable.
Let’s consider a situation where two types of coloured liquid have been poured into two separate glass vessels.
Now let’s consider changing liquid in A vessel into B vessel and liquid in B vessel into A vessel.
In this way, in order to change the liquid from one vessel to the other, it is necessary to have an extra vessel.
Let’s name that vessel as C vessel.
step 1 : Changing liquid in A vessel to C vessel
step 2 : Changing liquid in B vessel to A vessel
step 3 : Changing liquid in C vessel to B vessel
As a vessel can store liquid, so a variable can store a value. The above vessels named as A, B and C can be considered as variables and the liquid poured into them can be considered as values of the variables.
Assign Values to Variables
When assigning values to variables, variable name is written on the left to the equal sign and the value is written on the right to the equal sign.
Changing values of variables
e.g.
Let’s change the values of variables maths and science.
Building variable in scratch
assign value to a variable
change value of a variable
1. Multiplication of two numbers
Create two variables (n1, n2) to store values of two numbers and another variable to store the multipication of the two numbers.Then join the control blocks shown below one by one sequentially in the given order. Change the value of control blocks as shown.
Figure 6.12 – Flow chart: Multiplication of two numbers
2. Find Perimeter and Area of a Rectangle
The length and width of a rectangle is needed to find the perimeter and the area of that rectangle. Accordingly, four variables should be used in order to develop this programme. The length, width, perimeter and the area are shown as variables L, W, perimeter and area respectively.
Figure 5.13 – Flow chart: Area and perimeter of a rectangle
3. Change the size of the Sprite from 10 to 100 at random
Develop the following programme to randomly change the normal size of the Sprite that we see. A value randomly chosen from one to ten is stored in the variable X. The size of the Sprite changes up to the value obtained by multiplying the value of variable X by 10. In addition, the colour too changes in proportion to the value of variable X.
Figure 5.14 - Flowchart: Changing size of the Sprite
Bugs may occur when developing a programme. Errors in a programme are called bugs, while the elimination of such bugs is called debug. In such a situation, unexpected problems are to be faced when a program with bugs run. Programmes with bugs may not run properly. Therefore before running a programme, bugs that may occur in that program should be eliminated.
Elimination of Bugs
Bugs may occur in such situations as change of order in the instructions (block), omission of instructions (block) or non-mentioning of correct variables and their values. Bugs in a programme can be eliminated by correcting bugs in the instructions(block) or arranging the order of the instructions (block) sequentially.
Let’s compare the following programme with bugs and the programme without bugs developed to draw a rectangle with length and width 200 and 100 respectively.
The above programme on the left has been developed to draw a rectangle. However the expected output cannot be achieved due to bugs in the programme. Therefore there is a possibility to get an erroneous output. It is proved by the programme on the right that a correct output can be achieved after eliminating those bugs.