9th Class Computer Science Notes 2024 CH 1
9th Class Computer Science Notes 2024 CH 1
COMPUTER SCIENCE-9 1
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 2
Unit– 1 Problem Solving
Who: Students.
Why: To prepare the directory of students.
When: Within a week.
Where: School.
Metaphorical Representation:
The following figure shows the metaphorical representation of problem where the red
light presents a problem, the yellow light represents its analysis and the green light
presents the solution. It shows that problem analysis makes us closer to a solution.
COMPUTER SCIENCE-9 4
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 5
Unit– 1 Problem Solving
Ans: DRAW A PICTURE
„Draw a picture‟ is a strategy to define the problem. If the problem is not well-defined,
we can draw a picture and fill the undefined information.
Pictorial representation of a problem is a best and easy way to define the problem.
COMPUTER SCIENCE-9 6
Unit– 1 Problem Solving
Q.5 Solve the following problem. (A.B)
Ans: SOLUTION
Method 1:
Method 2:
Let pictures
=x =y =z
According to condition 1 According to condition 2 According to condition 3
x + x + x = 30 x + y + y = 18 y–z=2
3x = 30 x + 2y = 18 put y = 4
x = 10 put x = 10 4–z=2
10 + 2y = 18 –z=2–4
2y = 18 – 10 –z=–2
2y = 8 z=2
y=4
According to condition 4
=a= =b=
a+xb
= 1 + 10 2
= 1 + 20
= 21
COMPUTER SCIENCE-9 7
Unit– 1 Problem Solving
Q.6 What is the importance of understanding a problem? (K.B)
Ans: UNDERSTANDING A PROBLEM
It is very important to understand the problem before jumping into the solution of the
problem because no one can solve the problem without understanding it. A clear
understanding of a problem makes it easier to solve and helps to save money, time and
resources.
Example:
A riddle or a puzzle can be answered only after clear understanding.
Q.7 Define problem analysis. (K.B)
Ans: PROBLEM ANALYSIS
Definition:
Problem analysis is the process to figure out 5 W‟s (what, who, when, where, and why)
from a problem statement. Problem analysis helps to understand a given problem. These
are the basic elements which lead towards the solution of a given problem.
Q.8 What is meant by planning a solution? Name some strategies for planning a solution. (K.B)
Ans: PLANNING A SOLUTION
Definition:
After analyzing a problem, we formulate a plan that may lead us towards the solution of a
problem. This phase includes finding the right strategy for problem solving.
STRATEGIES FOR PLANNING A SOLUTION
Some of the strategies for planning a solution are:
Divide and Conquer
Guess, Check and Improve
Act it Out
Prototype (Draw)
Q.9 Define divide and conquer. (K.B)
Ans: DIVIDE AND CONQUER
Definition:
It is a strategy for planning a solution. In this strategy, divides a complex problem into
smaller problems.
Q.10 What is meant by prototype? (K.B)
Ans: PROTOTYPE
Definition:
It is a strategy for planning a solution. This technique draws a pictorial representation of
the solution. It is not the final solution. However, it may help a designer to understand the
important components of the solution.
Q.11 How can we select best strategy for planning a solution? (K.B+U.B)
Ans: SELECTION
The selection of a strategy depends upon the problem. It is quite important that one strategy
maybe more suitable to implement a solution than the other one. Very specifically, the
selection of the strategy depends upon the nature of a problem.
Q.12 What is candid and candid solutions? (K.B)
Ans: CANDID AND CANDID SOLUTIONS
The word candid refers to something spontaneous and unplanned. There are multiple
solutions for a problem. The one you think can work, is the candid solution. It is not
necessary that the candid solution is the actual solution of a problem.
COMPUTER SCIENCE-9 8
Unit– 1 Problem Solving
ACTIVITY QUESTIONS
Activity 1.1 (A.B)
Students are put in groups of two or three, and each group is provided two different lists of
students‟ names.
One list contains the marks of students in mathematics subject while the other list is for
physics subject. Each group is supposed to prepare the following lists.
a) Top 5% students in mathematics.
b) Top 5% students in physics.
c) Students having more than 90% marks in both subjects.
Identify 5 Ws for this problem.
SOLUTION
We can analyse the above problem by identifying 5Ws in the problem statement as given
below:
What: List of marks of students in two subjects physics and mathematics.
Who: Students.
Why: To prepare the marks list in descending order (top marks to bottom marks) and
to identify top 5% students of both subject and students having more than 90% marks
in both subjects.
When: Within a class time. (Approx 40 minutes)
Where: School.
Activity 1.2 (A.B)
Your task is to find average height of your class fellows. Give a candid answer and also the
method to find the exact solution.
One method is to use a measuring tape. Mark the height on the tape and then read the exact
measurement from the tape. After recording the height of every student, you can calculate the
average height of all the students in your classroom.
Or you can even find out the candid height of a student through some object of known height,
like a book. Let's say that the height of your textbook is 8cm. You can mark the height of the
book on a wall. Using the book several times, you can make a scale with intervals of 8cm.
Then, by standing next to the wall you can get a candid solution to the student's height.
SOLUTION
Method 1: (Candid Answer)
We can find out the candid height of a student through some object of known height, like a book.
Let's say that the height of textbook is 8cm. You can mark the height of the book on a wall.
Using the book several times, you can make a scale with intervals of 8cm. Then, by standing
next to the wall we can get a candid solution to the student's height.
Suppose there are 30 students in a class. We use a book or scale to mark on the wall and then
make three to four students stand against the wall and measure their height. The measurement of
heights of these students are 54, 58, 55 and 56. According to these measurements we
assume that average of all boys in the class is 55. This is a candid solution.
Candid solution: 55
Method 2: (Exact Solution)
To find out the exact solution, we use a measuring tape.
Suppose there are only three students in a class. Mark the height on the tape and then read the
exact measurement from the tape.
COMPUTER SCIENCE-9 10
Unit– 1 Problem Solving
Student Height
1 54
2 58
3 56
Total 166
After recording the height of every student, we calculate the average height of all the
students in classroom by the following formula:
COMPUTER SCIENCE-9 11
Unit– 1 Problem Solving
Figure: Flow from input to output
Q.3 Write a note on flowchart symbols. (K.B+U.B)
Ans: FLOWCHART SYMBOLS
Flowcharts explain a process clearly through symbols and text. They use special shapes
to represent different types of actions or steps in a process.
Some widely used symbols in flowcharts are as follows:
Symbol Name Description
Flow line It is used to determine the flow of steps in a flowchart.
COMPUTER SCIENCE-9 12
Unit– 1 Problem Solving
Following flowchart shows another solution to find a maximum value among three number
a,b and c.
Q.5 Draw a flowchart to assign grade to a subject based on total marks and obtained
marks.
(A.B)
Ans: FLOWCHART
COMPUTER SCIENCE-9 13
Unit– 1 Problem Solving
Q.6 Draw a flowchart to determine name of a week day from a given number where
weekdays are assumed from Monday to Sunday and their respective. (A.B)
Ans: FLOWCHART
COMPUTER SCIENCE-9 14
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 15
Unit– 1 Problem Solving
Q.7 Draw a flowchart to input 5 value one by one and determine if the given value is odd or
even.
(A.B)
Ans: FLOWCHART
Q.8 Draw a flowchart to find a sequence of odd numbers starting from a given number till
some limit. (A.B)
Ans: FLOWCHART
COMPUTER SCIENCE-9 16
Unit– 1 Problem Solving
SHORT QUESTIONS
Q.1 Define flowchart. (K.B)
Ans: FLOWCHART
Definition:
A flowchart is a graphical presentation of the steps to solve a problem.
Q.2 What is the importance of flowchart? (K.B)
Ans: IMPORTANCE OF FLOWCHART
The importance of flowchart are as follows:
Flowcharts are helpful to know about the steps used to solve a problem.
In problem solving, flowcharts can be used to plan a solution.
Q.3 What is meant by input/output? (K.B)
Ans: INPUT/OUTPUT
Input/Output:
It indicates the input of data from user or displaying results to user.
Q.4 What is meant by processing in flowchart? (K.B)
Ans: PROCESSING
A flowchart also contains processing steps. The processing steps are used for performing
calculations and storing the results of calculations. These may include increasing / decreasing
a value, adding / multiplying / dividing two values etc.
Symbol:
The following symbol is used for processing.
Q.7 Draw a flowchart to find acceleration of a moving object with given mass and force
applied. (A.B)
Ans: FLOWCHART
COMPUTER SCIENCE-9 18
Unit– 1 Problem Solving
Q.10 Draw a flowchart to find the sum, product and average of five given numbers. (A.B)
Ans: FLOWCHART
COMPUTER SCIENCE-9 19
Unit– 1 Problem Solving
Q.12 Draw a flowchart to determine whether a given number is odd or even. (A.B)
Ans: FLOWCHART
COMPUTER SCIENCE-9 21
Unit– 1 Problem Solving
ACTIVITY QUESTIONS
Activity 1.3 (A.B)
Investigate both the approaches presented to find a maximum value among three numbers and
compare them. Which approach has advantage(s) over the other? Write your findings and
discuss with your class teacher.
Flowchart 1 Flowchart 2
SOLUTION
Purpose
Both the flowcharts find the greatest number out of 3 input numbers .
Better (advantage over other)
Flowchart 2 is better.
Reasons (Findings)
while 2nd flowchart does not do this. It
The first flowchart declares the n0 (first number) as
does direct and simple comparison
greater and saves it in a variable (Large) and after
so
that starts comparing itself with the other two
For both these two reasons the above
numbers
flowchart is better in performance
So it is complex and consumption of space.
and memory consumption.
COMPUTER SCIENCE-9 22
Unit– 1 Problem Solving
Activity 1.4 (A.B)
In the following flowchart, a user is supposed to provide the input value from 1 to 7, but it is
possible that the input value is less than 1 or more than 7. We need to take care of such values
and display appropriate messages, like “Your value is less than 1” or “Your value is more than
7”. Modify the flowchart with respect to proper error messages.
To determine name of a week day from a given number where weekdays are assumed
from Monday to Sunday and their respective.
COMPUTER SCIENCE-9 23
Unit– 1 Problem Solving
SOLUTION
Print “Wrong
Day”
1.3 ALGORITHMS
LONG QUESTIONS
Q.1 Define algorithm and argue on its role and importance in problem solving. (Ex Q.3) (K.B)
Ans: ALGORITHM
Definition:
An algorithm is a set of steps to solve a problem. It is written in a natural language, so it
is easily understandable by humans.
Example:
To solve the problem of preparing tea, we can follow the following steps.
Start.
Take a kettle.
Pour water in it.
Put the kettle on fire.
COMPUTER SCIENCE-9 24
Unit– 1 Problem Solving
Add sugar and milk.
Wait till it boils.
Remove the kettle from fire.
End.
The above set of steps can be called an algorithm for tea preparation.
ROLE OF ALGORITHMS IN PROBLEM SOLVING
An algorithm has a vital role in problem solving as it provides a step-by-step guide to the
problem solver as follows:
It is a complete description of the solution.
Usually a computer programmer first writes an algorithm and then translates it into
the code of some programming language.
Sometimes, the designer of the program first makes a flowchart to solve a problem
and then encodes the flowchart into an algorithm.
The following figure shows the role of algorithm in problem solving.
COMPUTER SCIENCE-9 26
Unit– 1 Problem Solving
It is not suitable for very large problems. To solve a large problem, algorithms are helpful.
SHORT QUESTIONS
Q.1 Define algorithm. Also make an algorithm for preparing tea. (K.B+U.B+A.B)
Ans: ALGORITHM
Definition:
An algorithm is a set of steps to solve a problem. It is written in a natural language, so it
is easily understandable by humans.
Algorithm for Making Tea:
To solve the problem of preparing tea, we can follow the following steps:
Start.
Take a kettle.
Pour water in it.
Put the kettle on fire.
Add sugar and milk.
Wait till it boils.
Remove the kettle from fire.
End.
Q.2 Write some advantages of flowchart. (K.B)
Ans: ADVANTAGES OF A FLOWCHART
Advantages of a flowchart are as follows:
It is easy to draw.
It is easy to understand problem solving.
It is easy to identify errors (if any).
It makes easy to observe flow from one step to the other.
Q.3 Write some disadvantages of flowchart. (K.B)
Ans: DISADVANTAGES OF A FLOWCHART
Disadvantages of a flowchart are as follows:
More time is required to draw a flowchart.
Modifying a flowchart is not very easy every time.
It is not suitable for very large problems.
Q.4 Write some advantages of algorithm. (K.B)
Ans: ADVANTAGES OF AN ALGORITHM
Some advantages of an algorithm are as follows:
It is easy to write.
Techniques to write an algorithm are easy to understand.
To solve a large problem, algorithms are helpful.
Q.5 Write some disadvantages of algorithm. (K.B)
Ans: DISADVANTAGES OF AN ALGORITHM
Some disadvantages of an algorithm are as follows:
Modifying an existing algorithm is not very easy every time.
Showing the flow from one step to the other is not very easy.
Usage of Goto makes it difficult to identify errors.
Q.6 What is the use of „set‟ in writing algorithms? (K.B+U.B)
Ans: USE OF SET
It is used to give name to data in computer memory. It is also used to update the value of
COMPUTER SCIENCE-9 27
Unit– 1 Problem Solving
existing data.
Q.7 Write an algorithm to find the sum, product and average of five given numbers.
(A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, n0, n1, n2, n3, n4
Step 3. Set sum to n0 + n1 + n2 + n3 + n4
Step 4. Set product to n0 × n1 × n2 × n3 × n4
n 0 n1 n 2 n 3 n 4
Step 5. Set average to
5
Step 6. Output sum, product, average
Step 7. End
Q.8 Write an algorithm to find acceleration of a moving object with given mass and the
applied force. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, mass, force
force
Step 3. Set acceleration to
mass
Step 4. Output acceleration
Step 5. End
Q.9 Write an algorithm to find the volume of a cube. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input number, side
Step 3. Set volume to side × side × side.
Step 4. Output volume
Step 5. End
Q.10 Write an algorithm to find the area of a parallelogram. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, base, height
Step 3. Set area to base × height
Step 4. Output area
Step 5. End
Q.11 Write an algorithm to display the larger one out of the three given numbers. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, n0, n1, n2
Step 3. Set large to n0
Step 4. if nl > large Set large to nl
Step 5. if n2 > large Set large to n2
Step 6. Output large
Step 7. End
COMPUTER SCIENCE-9 28
Unit– 1 Problem Solving
Q.12 Write an algorithm to assign grade to a subject based on the achieved marks. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, obtained_marks, total_marks
obtained _marks
Step 3. Set percentage to 100
total _marks
Step 4. if percentage > 80 Set grade to A +
else
if percentage > 70 Set grade to A
else
if percentage > 60 Set grade to B
else
if percentage > 50 Set grade to C
else
if percentage > 40 Set grade to D
else
if percentage > 33 Set grade to E
else
Set grade to F.
Step 5. Output grade
Step 6. End
Q.13 Write an algorithm to find the interest on an amount. (A.B)
Ans: LGORITHM
Step 1. Start
Step 2. Input numbers, amount, rate, years
rate
Step 3. Set plain_interest to amount years
100
Step 4. Output plain_interest
Step 5. End
Q.14 Write an algorithm to convert Celsius to Fahrenheit temperature and vice versa. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input number, Celsius
celsius 9
Step 3. Set fahrenheit to 32
5
Step 4. Output fahrenheit
Step 5. Input number, fahrenheit
5
Step 6. Set Celsius to (fahrenheit –32)
9
Step 7. Output Celsius
Step 8. End
COMPUTER SCIENCE-9 29
Unit– 1 Problem Solving
Q.15 Write an algorithm to find even numbers in integers ranging from n1 to n2 (where
n2 is greater than n1). (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, n1, n2
Step 3. if (n1< n2) {
Step 4. if (n1 mod 2 equal 0) Output n1
Step 5. Set n1 to n1+1
Step 6. go to Step 3
}
Step 7. End
Q.16 How can we measure the efficiency of algorithms? (U.B)
Ans:
EFFICIENCY OF AN ALGORITHM
COMPUTER SCIENCE-9 30
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 31
Unit– 1 Problem Solving
ACTIVITY QUESTIONS
Activity 1.6 (A.B)
COMPUTER SCIENCE-9 32
Unit– 1 Problem Solving
Activity 1.8 (A.B)
Change the algorithm for finding the area of a triangle, rhombus, or trapezium.
To find the area of a parallelogram.
Step 1. Start
Step 2. Input numbers, base, height
Step 3. Set area to base × height
Step 4. Output area
Step 5. End
SOLUTION
Area of a Triangle:
Step 1. Start
Step 2. Input base, height
Step 3. Set area to base × height
Step 4. Output area
Step 5. End
Area of a Rhombus:
Step 1. Start
Step 2. Input d1, d2
Step 3. Set area to
Step 4. Output area
Step 5. End
Area of a Trapezium:
Step 1. Start
Step 2. Input a, b, height
Step 3. Set area to (a + b) × height
Step 4. Output area
Step 5. End
Activity 1.9 (A.B)
Compare the algorithm 9 presented in Section 1.3.4 with the following one and try to find
which one is efficient. Note that both are solving the same problem. In order to answer this
question, assume two values for nl and n2 and start count the number of steps used in both
algorithms.
Algorithm 1.9 Algorithm 9 (Section 1.3.4)
Step 1. Start Step 1. Start
Step 2. Input numbers, nl, n2 Step 2. Input numbers, n1, n2
Step 3. if nl is odd, set nl to nl + 1 Step 3. if (n1< n2) {
Step 4. Output nl Step 4. if (n1 mod 2 equal 0) Output n1
Step 5. Set nl to nl + 2 Step 5. Set n1 to n1+1
Step 6. if nl < n2 go to Step 4 Step 6. go to Step 3
Step 7. End }
Step 7. End
SOLUTION
Steps In the above algorithm (algorithm 1.9) In the above algorithm (algorithm 9)
Step 1. Algorithm starts. Algorithm starts.
Step 2. It inputs two numbers n1(starting value) It inputs two numbers n1(starting value)
COMPUTER SCIENCE-9 33
Unit– 1 Problem Solving
and n2(ending value). and n2(ending value).
Step 3. If n1 is odd, it increments 1 into n1 to It checks if n1 is less than n2 or not.
convert n1 into an even number.
Step 4. It displays n1 i.e. it displays first evenIt checks if n1 is even or not.
number. If n1 is even then display n1 as a first
even number.
Step 5. It increments 2 in n1. (jump to next even It increments 1 in n1. (jump to next
number) number)
Step 6. It repeats itself until the ending value. It repeats itself until the ending value.
(Step 4, 5, 6 is repeated) to display only (Step 3, 4, 5, 6 is repeated) to check if it
even number. is even or not and then display even
number.
Step 7. Algorithm ends. Algorithm ends.
So, Algorithm used in activity 1.9 is more efficient because it is very easy and uses less
number of steps.
1.4 TEST DATA
LONG QUESTIONS
Q.1 Describe the importance of testing. (K.B+U.B)
Ans: IMPORTANCE OF TESTING
Testing is essential to point out the defects and errors made during finding a solution to
some problem. It helps in improving a solution. If one solves a problem and someone else
uses that solution for commercial purposes, then the commercial activities depend upon
the correctness of that solution.
Example 1:
If we develop a solution for finance management and some bank starts using it then any
error in that solution may result in a financial loss. So, testing is important for a solution.
Example 2:
A car is delivered to a customer after testing. Upon launching a new car, it is usually
tested with a robot driver who hits the car with a wall. It is used to test whether the air
bags and other security systems are functioning or not. Moreover, it also allows the car
designers to suggest further security measures to reduce the damage. This test can help to
make a car safe. So, testing helps to improve quality.
Q.2 Explain types of test data. (Ex Q.6) (K.B)
Ans: TEST DATA
Definition:
After solving a problem, we need to test whether the solution is correct or not, and for
testing, we need “Test Data”.
TYPES OF TEST DATA
Creation of proper and sufficient test data is one of the key activities to improve quality
of a solution. Each type of solution requires different data.
Types of Test Data include:
Valid test data
Invalid test data
Boundary test data values
Wrong data formats
Absent data
COMPUTER SCIENCE-9 34
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 35
Unit– 1 Problem Solving
Valid Test Data:
It is the test data that complies with the input requirements of the algorithm. If an
algorithm is supposed to take a numeric value between 1 and 100 as input, then any value
between 1 and 100 is a valid test data.
Invalid Test Data:
It is the data that does not comply with the input requirements of the algorithm. It is
necessary to make sure that the solution correctly works for invalid values, shows the
relevant messages notifying the user that the provided input values are improper.
Boundary Test Data Values:
A solution is tested on extreme values. For example, to calculate interest we can consider
principal amount as 0 or a very huge amount.
Wrong Data Formats:
It is wise to check how the system reacts on entering data in an inappropriate format. For
example, giving an alphabet as input when a numeric value is expected.
Absent data:
It is also important to investigate that the solution still works if less number of inputs are
given than expected. For example, if a system asks to enter driving license number, then
every one cannot provide this information. It is important to see how the system reacts in
such situations.
SHORT QUESTIONS
Q.1 Define test data. (K.B)
Ans: TEST DATA
Definition:
After solving a problem, we need to test whether the solution is correct or not, and for
testing, we need “Test Data”.
Example:
If we want to test the algorithm to find the largest among three given numbers n0, n1 and
n2, then we need three values. These values can be positive, negative or zero, e.g., (n0 =
5, n1 = 15, n2 = 3), (n0 = 27, n1 = –6, n2 = 35), (n0 = 24, n1 = 0, n2 = 11), etc. So, for
thinking about testing, we also need to think about test data.
Q.2 Name the types of test data. (K.B+U.B)
Ans: TYPES OF TEST DATA
Creation of proper and sufficient test data is one of the key activities to improve quality
of a solution. Each type of solution requires different data.
Types of Test Data include:
Valid test data
Invalid test data
Boundary test data values
Wrong data formats
Absent data
Q.3 Differentiate between valid test data and invalid test data. (U.B)
Ans: DIFFERENTIATE
The difference between valid and invalid test data is as follows:
Valid Test Data Invalid Test Data
It is the test data that complies with the input It is the test data that does not comply with
requirements of the algorithm. the input requirements of the algorithm.
If an algorithm is supposed to take a numeric It is necessary to make sure that the solution
value between 1 and 100 as input, then any correctly works for invalid values, shows the
value between 1 and 100 is a valid test data. relevant messages notifying the user that the
provided input values are improper.
COMPUTER SCIENCE-9 36
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 37
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 38
Unit– 1 Problem Solving
COMPUTER SCIENCE-9 39
Unit– 1 Problem Solving
Step 5 2
Step 4 164
Step 5 3
Step 4 144
Step 5 3
Step 4 166
Step 5 4
Step 4 160
Step 5 5
Step 4 143
Step 5 5
Step 6
Step 7
SHORT QUESTIONS
Q.1 Why we use trace table? (U.B)
Ans: TRACE TABLE
A trace table is a technique used to test algorithms, in order to make sure that no logical
errors occur while the algorithm is being processed.
Q.2 Why we use invalid data for testing? (U.B)
Ans: INVALID DATA FOR TESTING
Testing an algorithm using invalid data ensures that the algorithm can gracefully handle
unexpected data inputs. If an algorithm requires your age in number of days but you give
date of birth as input then the algorithm may not work properly. The purpose of testing
using invalid test data is to detect such situations. In this case error messages are shown
as output. Moreover, this kind of testing helps you to improve the quality of solution.
MULTIPLE CHOICE QUESTIONS
1. The solution is working but not giving required results. This type of error is called:
(K.B+U.B)
(A) Syntax Error (B) Runtime Error (C) Logical Error (D) Random Error
2. A technique used to test algorithms is: (K.B+U.B)
(A) Design (B) Trace Table (C) Validation (D) Correctness
ACTIVITY QUESTIONS
Activity 1.11 (A.B)
Write all the above discussed algorithms keeping in mind the invalid test data inputs. Class teacher
may divide class in few groups and assign them one or more algorithm(s). Students are supposed to
discuss and rewrite algorithms so that upon invalid inputs, appropriate messages are displayed.
SOLUTION
Algorithm 1
To find the sum, product and average of five given numbers.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, n0, n1, n2, n3, n4 Step 2. Input numbers, n0, n1, n2, n3, n4
Step 3. Set sum to n0 + n1 + n2 + n3 + n4. Step 3. If (n0, n1, n2, n3, n4 are positive
Step 4. Set product to n0 × n1 × n2 × n3 × n4 integers) goto step 4
else print “Invalid input, Enter only
COMPUTER SCIENCE-9 40
Unit– 1 Problem Solving
Algorithm 4
To find the area of a parallelogram.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, base, height Step 2. Input numbers, base, height
Step 3. Set area to base × height Step 3. If (base and height are positive
Step 4. Output area integers) goto step 4
Step 5. End else print “Invalid input, Enter only
positive numbers” goto step 2
Step 4. Set area to base × height
COMPUTER SCIENCE-9 41
Unit– 1 Problem Solving
Step 5. Output area
Step 6. End
Algorithm 5
To display the larger one out of the three given numbers.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, n0, n1, n2 Step 2. Input numbers, n0, n1, n2
Step 3. Set large to n0 Step 3. Set large to n0
Step 4. if nl > large Set large to nl Step 4. if nl > large Set large to nl
Step 5. if n2 > large Set large to n2 Step 5. if n2 > large Set large to n2
Step 6. Output large Step 6. Output large
Step 7. End Step 7. End
Algorithm 6
To assign grade to a subject based on the achieved marks.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, obtained_marks, Step 2. Input numbers, obtained_marks,
total_marks total_marks
Step 3. Set percentage to Step 3. If (obtained_marks, total_marks are
obtained _marks positive integers) goto step 4
100 else print “Invalid input, Enter only
total _marks
Step 4. if percentage > 80 Set grade to A + positive numbers” goto step 2
else Step 4. if (total_marks is equal to 0) print
if percentage > 70 Set grade to A “cannot divide by zero” goto step 2
else else goto step 5
if percentage > 60 Set grade to B Step 5. Set percentage to
obtained _marks
else 100
if percentage > 50 Set grade to C total _marks
else Step 6. if percentage > 80 Set grade to A +
if percentage > 40 Set grade to D else
else if percentage > 70 Set grade to A
if percentage > 33 Set grade to E else
else if percentage > 60 Set grade to B
Set grade to F. else
Step 5. Output grade if percentage > 50 Set grade to C
Step 6. End else
if percentage > 40 Set grade to D
else
if percentage > 33 Set grade to E
else
Set grade to F.
Step 7. Output grade
Step 8. End
Algorithm 7
To find the interest on an amount.
Original Apply Test Data
COMPUTER SCIENCE-9 42
Unit– 1 Problem Solving
Step 1. Start Step 1. Start
Step 2. Input numbers, amount, rate, years Step 2. Input numbers, amount, rate, years
Step 3. Set plain_interest to Step 3. Set plain_interest to
rate rate
amount years amount years
100 100
Step 4. Output plain_interest Step 4. Output plain_interest
Step 5. End Step 5. End
Algorithm 8
To convert Celsius to Fahrenheit temperature and vice versa.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input number, Celsius Step 2. Input number, Celsius
celsius 9 celsius 9
Step 3. Set fahrenheit to 32 Step 3. Set fahrenheit to 32
5 5
Step 4. Output fahrenheit Step 4. Output fahrenheit
Step 5. Input number, fahrenheit Step 5. Input number, fahrenheit
5 5
Step 6. Set Celsius to (fahrenheit –32) Step 6. Set Celsius to (fahrenheit –32)
9 9
Step 7. Output Celsius Step 7. Output Celsius
Step 8. End Step 8. End
Algorithm 9
Find even numbers in integers ranging from n1 to n2 (where n2 is greater than n1).
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, n1, n2 Step 2. Input numbers, n1, n2
Step 3. if (n1< n2) { Step 3. if (n1< n2) {
Step 4. if (n1 mod 2 equal 0) Output n1 Step 4. if (n1 mod 2 equal 0) Output n1
Step 5. Set n1 to n1+1 Step 5. Set n1 to n1+1
Step 6. go to Step 3 Step 6. go to Step 3
} }
Step 7. End Step 7. End
COMPUTER SCIENCE-9 43
Unit– 1 Problem Solving
EXERCISE
1.1 Answer the following questions. (U.B)
1. In a farm there are some cows and birds. If there are total 35 heads and110 legs then how
many cows and birds are there?
Ans: SOLUTION
Each cow has 1 head and 4 legs. Each bird has 1 head and 2 legs.
Let x = number of cows and y = number of birds
Then x + y = 35
4x + 2y = 110
Multiply the first equation by –2
– 2x – 2y = – 70
Add the equations
– 2x – 2y = – 70
4x + 2y = 110
Then
2x = 40
Then x = 20
Put this in first equation
20 + y = 35
y = 35 – 20 = 15
So, x = number of cows = 20 and y = number of birds = 15
2. Define problem analysis. Explain your answer along with an example. (K.B+U.B)
See LQ .2 (Topic 1.1)
3. Define an algorithm and argue on its role and importance in problem solving. (K.B+U.B)
See LQ.1 (Topic 1.3)
4. Suppose a problem has multiple algorithms. How would you choose the most efficient
one? Explain with examples. (U.B+A.B)
See LQ.3 (Topic 1.3)
5. How do you determine requirements for a flowchart? (K.B+U.B)
See LQ.2 (Topic 1.2)
6. Explain types of test data. (K.B)
See LQ.2 (Topic 1.4)
7. Describe a trace table. (K.B)
See LQ. (Topic 1.6)
COMPUTER SCIENCE-9 44
Unit– 1 Problem Solving
1.2 Choose the correct option.
1. Which solutions are not reached through proper algorithms or work planning? (U.B)
(i) Prepared solution (ii) Candid solution
(iii)Strategized solution (iv) Best solution
2. __________ is a graphical representation of an algorithm. (K.B)
(i) Matrix (ii) Graph
(iii)Flowchart (iv) Solution
3. Which symbol in the flowchart is used to either start or end the flowchart? (U.B)
(i) Terminal (ii) Connector
(iii)Process (iv) Decision
4. __________ means to test if the required solution is there. (K.B)
(i) Verification (ii) Algorithm
(iii)Validation (iv) Flowchart
5. In a __________error, the solution is working but not giving required results. (K.B)
(i) Random error (ii) Logical error
(iii)Syntax error (iv) Runtime error
ANSWER KEY
1 (ii) 2 (iii) 3 (i) 4 (i) 5 (ii)
1.3 Fill in the blanks.
1. Before problem solving, we need to first_________ a problem. (K.B+U.B)
2. An algorithm produces a defined set of__________. (K.B)
3. A flowchart utilizes various________ and_____to map out the order of steps. (K.B+U.B)
4. In flowcharts symbol is used to show a_________. (K.B+U.B)
5. _________ is used to test the solutions. (U.B)
ANSWERS
1 Analyse 2 Steps 3 Symbols, text 4 Decision making 5 Verification
1.4 Draw the flowcharts for the following problems. (A.B)
1. Input two numbers nl and n2. Determine whether nl divides n2 or not.
Ans: SOLUTION
COMPUTER SCIENCE-9 45
Unit– 1 Problem Solving
2. Input a year and determine whether it is a leap year or not.
Ans: SOLUTION
COMPUTER SCIENCE-9 46
Unit– 1 Problem Solving
4. Find LCM (Least Common Multiple) of two numbers.
Ans: SOLUTION
COMPUTER SCIENCE-9 47
Unit– 1 Problem Solving
Activity 1.12 (A.B)
Design a flowchart to calculate fine amount for Pakistan motorway. Fine is imposed according
to the following coding scheme. Input a code and display the respective output.
Penalty
Code Offence Imprisonment
(Rs.)
A20 Driving when disqualified 1000 Upto 6 Months
Obtaining or Applying for a driving licence without
A21 500-1000 Upto 6 Months
disclosing particulars of endorsement
A22 Offence relating to construction of vehicle 500-1000 Upto 6 Months
A23 Offence relating to permits 1000-2000 Upto 6 Months
A24 Overloading of goods 15 % in excess of permissible limits. 1000-5000 Upto 1 Month
Overloading of passengers 30 % in excess of permissible
A25 1000-5000 Upto 1 Month
limits
For more codes, visit http://nhmp.gov.pk
Make the flowchart more comprehensive by adding more codes. Make your algorithm on a
chart. Display your chart in your school or community for further awareness on traffic related
crimes and their penalties.
Respective teachers can request school administration to arrange a traffic awareness campaign
for the community. Students can display their charts as part of the campaign.
SOLUTION
COMPUTER SCIENCE-9 48
Unit– 1 Problem Solving
ANSWER KEY
1.1 PROBLEM SOLVING STEPS
1 D 2 B 3 A 4 C 5 A
6 A 7 C 8 B 9 B 10 A
11 C 12 B 13 D 14 C 15 C
1.2 FLOWCHARTS
1 B 2 A 3 B 4 A 5 A
6 D 7 A 8 B 9 C 10 A
11 B
1.3 ALGORITHM
1 A 2 B 3 D 4 D 5 A
6 B 7 B 8 D 9 B 10 A
11 C
1.4 TEST DATA
1 C 2 C 3 D 4 A 5 B
1.5 VERIFICATION AND VALIDATION
1 B 2 C
1.6 IDENTIFICATION AND CORRECTION OF ERRORS
1 C 2 B
COMPUTER SCIENCE-9 49