0% found this document useful (0 votes)
3 views

9th Computer

Uploaded by

amnaarif135
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

9th Computer

Uploaded by

amnaarif135
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

SARDAR KAUREY KAHN PUBLIC H/S/S MUZAFFARGARH

COMPUTER CLASS 9TH


Ist Term Notes Unit # 1
By : Muhammad Qasim
Syllabus Breakup 2020-2021
Month Week Days W.Days Topic/Content Lab Days
Lecture No.1 :
 Problem Solving
 Problem Solving Steps
 Defining a Problem
 Understanding a Problem
 Solve Activity 1.1
Lecture No. 2 :
 Planning a Solution
 Defining Candid Solutions
 Solve Activity 1.2
Lecture No. 3 :
 Selecting the Best Solution
June 1 1-6 6  Flowcharts
 Flowchart definition
 Importance of Flowcharts in Problem
Solving
Lecture No. 4 :
 Determining Requirements for a
Flowchart
 Flowchart Symbols
Lecture No. 5 :
 Examples of Flowcharts
 Example No.1
 Example No.2
 Example No. 3
Lecture No. 6
 Example No.4
 Example No.5
 Example No.6
Lecture No.7 :
 Flowcharts
 Example No.7
 Example No.8
Lecture No. 8 :
June 2 1-6 6  Flowcharts
 Example No.9
 Example No.10
Lecture No. 9 :
 Flowcharts
 Example No.11
 Example No.12
Lecture No. 10 :
 Algorithm
 Definition of Algorithm
 Role of Algorithms in Problem Solving
Lecture No. 11 :
 Algorithm
 Formulation of an Algorithm
 Example No.1
 Activity No. 1.6
Lecture No. 12
 Revisions
Lecture No.13 :
 Algorithm
 Example No.2
 Example No.3
 Activity No. 1.7
Lecture No. 14 :
 Algorithm
 Example No.4
 Example No.5
 Activity No. 1.8
Lecture No. 15 :
 Algorithm
 Example No.6
June 3 1-6 6  Example No.7
Lecture No. 16 :
 Algorithm
 Example No.8
 Example No.9
Lecture No. 17 :
 Algorithm
 Efficiency of Algorithms Example No.1
 Example No. 2
Lecture No. 18
 Algorithm
 Activity No. 1.9
Lecture No.19 :
 Difference between an Algorithm and a
Flowchart
 Advantages of Flowchart
 Disadvantages of Flowchart.
 Advantages of Algorithm
 Disadvantages of Algorithm
Lecture No. 20 :
 Test Data
 Activity No. 1.10
 Importance of Testing
June 4 1-6 6 Lecture No. 21 :
 Types of Test Data
 Verification and Validation
 Example No.1
 Example No.2
Lecture No. 22 :
 Identification and Correction of Errors
 Trace Table
 Using Invalid Data for Testing
Lecture No. 23 :
 Activity No. 1.11
 Solve Exercise No.1 to 7
Lecture No. 24
 Solve MCQ’s
 Solve Fill in the Blank
 Solve Exercise 1.4
Lecture No.1 :
 Problem Solving
 Problem Solving Steps
 Defining a Problem
 Understanding a Problem
 Solve Activity 1.1
PROBLEM SOLVING
INTRODUCTION
Dear students :
We face different problem every day in different places like.
 At home.
 work place
 play ground
 study place
 And even in general store.
There are different steps to solve a problem.
1. Defining a problem
2. Understanding a problem
3. Planning a solution
4. Define Candid solution
5. Selecting the best solution
1- Defining a problem
A well defined problem is :
 It does not contain any ambiguities.
 All the conditions are clearly specified.
 It has clear goal.
 It is easy to understand. It is easy to solve.
What is a Problem statement ?
We are given a problem statement. How we solve it ?
 First of all we need to see whether the problem is defined well or not.
 If the problem is not defined well the we can use one of the following strategies to define the problem.
1- Gain background knowledge.
 We try to know the situation and circumstances in which the problem is happening ?
 We can identify the given state.
 By identifying problem state helps us to know what a good solution will look.
 And also we shall be able to measure the solution.
2- Use Guesses.
 We try to guess the unknown information through appropriate guesses.
 These guesses may be bases upon our past experiences.
3- Draw a picture.
 If the problem is not well- defined , we can draw a picture and fill the undefined information.
 Following picture shows the pictorial representation of a problem.
2- Understanding a problem
 It is important to understand the problem before jumping into the solution of problem.
 A clear understanding of problem makes it easier to solve and helps to save money , time and resources.
 Understanding of problem usually includes identification of the 5 Ws.
 What are 5 Ws ? These are :
 What ?
 Who ?
 When ?
 Where ?
 Why ?
 Problem analysis is the process to figure out these 5 Ws from the problem statement.
 These are the basic elements which lead towards solution of a given problem.

Example of Understanding a problem


We can analyze this problem by identifying 5Ws in the problem statement as given below.
 What : List of student’s naming starting with letter ‘A’
 WHO : Student
 Why : To prepare the directory of students.
 When : with in a week
 Where : School
Figure 1-2 shows representation of problem
 Red light shows problem
 Yellow light shows analysis
 Green light shows solution.

Solution of activity 1.1


We can analyze this problem by identifying 5Ws in the problem statement as given below.
 What : 1- Top 5% students in Mathematic
2- Top 5% students in Physics
3- Students having more than 90% marks in both subjects.
 WHO : Student
 Why : To prepare the subject %age.
 When : with in period
 Where : School
Lecture No. 2 :
 Planning a Solution
 Defining Candid Solutions
 Solve Activity 1.2

3- Planning a solution
 In this phase , we formulate a plan that may lead us towards the solution of a problem.
 This phase includes finding the right strategy for problem solving. Some of strategies are :
1- Divide and conquer
2- Guess Check and improve
3- Act it Out
4- Prototype (Draw)
1- Divide and conquer

 Break the problem into smaller parts.


 Each part is solved independently
 The problem became simple and easier with
this method.
 The technique of dividing problem in smaller parts is called TOP DOWN DESIGN.
 It is also known as DIVIDE and CONQURE RULE.
2- Guess Check and improve
 The designer guesses a solution to a problem and then checks the correctness of the solution.
 If the solution is not according to its expectations then he refines the solution.
 The refinement is a iterative process.

3- Act it Out
 In this strategy the designer defines the list of “to do” tasks.
 Afterwards he performs the task.

4- Prototype (Draw)

 This technique is used to draw a pictorial representation of the solution.


 It is not final solution.
 It only helps the designer to understand the important component of the solution.

1.1.4 Defining Candid Solutions :


 The word candid refers to something spontaneous and unplanned.
 For example , if you ask to find the number of student in
your school who can play cricket.
 You can estimate by finding cricket players in your class
and then multiplying it by the total number of classes in
your school.
 Your answer in this way is candid solution.
 Your thinking about any object is called candid solution.
 Candid solution can help to save time.
Solve this activity if problem arises to solve this activity contact Muhammad Qasim
Whatsapp No. 0300-0236917
Lecture No. 3 :
 Selecting the Best Solution
 Flowcharts
 Flowchart definition
 Importance of Flowcharts in Problem Solving

1.1.5 Selecting the Best solution


 We find more than one solutions of a problem.
 We have to choose the best one.
 For example the names of student are available on your school
website.
 Your are asked to search a particular name.
 You can solve this problem by using the following method.
Method No.1 :
 Look at each name on the website one by one until the name is found or list is over.
Method No.2 :
 Take printout and search the required name.
Method No.3 :
 Copy all name and send to MS-Excel sheet and sort there name in alphabetically order.
Searching in a sorted list comparatively easy.
Method No. 4:
 Press CTL +F and type the required name in the web browser to search automatically.
 Here Method 4 is the best solution.
1.2 Flowcharts
 Flowchart is a combination of two words flow and chart.
 A chart is consists of different symbols to display information about any program.
 It is a graphical representation of a problem.
 It helps to understand problem easily.
 It is also helpful in understanding the flow of control and data in algorithm.
1.2.2 Importance of flowchart in Problem solving
 It is used to plan a solution.
 If the flowchart is developed ,we can find the way how a problem can be solved.
 Flowchart is more effective to visualize a solution graphically than text.
 It helps us whether a solution is correct or not .
 It is a good way to communicate the solution of a problem to an other people.
Lecture No. 4 :
 Determining Requirements for a Flowchart
 Flowchart Symbols
1.2.3 Determining Requirements for a flowchart
Following are the requirements to develop a flowchart.
 Inputs : It means taking data from the user. It is very important to know how many and
what type of inputs are required.
 Processing : It means how calculation performed and storing results of calculation
 Decision making: To determine whether a statement is true or False and taking
appropriate steps accordingly, is called decision making.
 Outputs: The outputs are used to display information.

1.2.4 Flowchart Symbols


1- Start / Terminal

Oval is used to represent the start or end of the flowchart. It is also called Terminal.

2- INPUT / OUTPUT

Parallelogram represent the Input or output of the flowchart.

3- PROCESS

Rectangle is used to represent a processing or computational operation in the flowchart.

4- FLOWLINES
Arrows are used to represent the direction of flow in the flowchart .
There are four flow lines.
1- up arrow
2- Down arrow
3- Right arrow
4- Left arrow
5- DECESION
 Diamond symbol is used to represent decision step in the flowchart.
 Condition is given in the diamond box.
 Flow of control from diamond box may go in two possible
direction.
 If condition is TRUE or YES go to one direction.
 If ondition is FALSE or NO go to other direction.
6- CONNECTOR
 Connector is used to connect different lines.
 It is used when different flow lines come from
different directions and move to one direction.

7- OFF PAGE /ON PAGE CONNECTOR


 It is used when the flowchart is bigger than one page.
 This symbol at the end of page indicates that the remaining
part of the flowchart is on the next page.
8- Predefined Process ( Function/subroutine)
 It is used to indicate a function or subroutine.

9- Remarks The Annotation symbol is used to


indicate remarks in the flowchart.
Lecture No. 5 :
 Examples of Flowcharts
 Example No.1
 Example No.2
 Example No. 3
Lecture No. 6
 Example No.4
 Example No.5
 Example No.6
Lecture No.7 :
 Flowcharts
 Example No.7
 Example No.8
Lecture No. 8 :
 Flowcharts
 Example No.9
 Example No.10
Lecture No. 9 :
 Flowcharts
 Example No.11
 Example No.12
Lecture No. 10 :
 Algorithm
 Definition of Algorithm
 Role of Algorithms in Problem Solving

1.3 Algorithm :

 An algorithm is a step-by-step procedure to solve a problem.


 It is better to write algorithm before writing the actual computer program.
Algorithm to make a Tea
1. Start
2. Take a kettle
3. Pour water in it,
4. Put the kettle on fire.
5. Add sugar and Milk
6. Wait till boils
7. Remove the kettle from fire.
8. End

1.3.2 Role of Algorithm in Problem Solving.


 An algorithm has vital role in problem solving as it provides a step by step guide to the
problem solver.
 It is a complete description of the solution.
 A computer programmer first write an algorithm and then translates it into the code of
some programming language.
 Sometime the designer of the program first convert algorithm into flowchart and then
then translates it into the code of some programming language.
Lecture No. 11 :
 Algorithm
 Formulation of an Algorithm
 Example No.1
 Activity 1.6

1.3.3 Formulation of an Algorithm


There are different notations (keywords) to write an algorithm.
 Start : It is the starting point of an algorithm. Every algorithm must have one starting
(entry) point.
 Input : It is used to get input from a user and store it in computer memory with some
name.
 Set : It is used to give name to data in computer memory. It is also used to update the
value of existing data.
If – else :
 It is used to check the condition. For example, the condition .
 If (a < b) A condition is evaluated as true or false.
 In case the condition is true then the statements related with if part are executed.
 otherwise the statements of else part are executed.
Usage:
 Suppose a=5 and b=7, if(a<5) Set c to 1O else Set c to 20.
Writing else part is optional.
Goto :
 It is used to transfer control to a certain step of an algorithm.
 It is usually required in loops.
Output:
It is used to display values.
Stop:
It is the termination point of an algorithm.
1- To find the sum, product and average of five given numbers.
Step 1 : Start
Step 2 : Input numbers, n0 , nl , n2 , n3 , n4
Step 3 : Set sum to n0 + nl + n2 + n3 + n4.
Step 4 : Set product to n0 x nl x n2 x n3 x n4
Step 5 : Set average to n0 + nl + n2 + n3 + n4
5
Step 6 : Output sum, product, average
Step 7 : End
Step 1 : Start
Step 2 : Set sum to 25 + 45 + 65
Step 3 : Set average to (25 + 45 + 65)/3
Step 4 : Output 135 ,45
Step 5 : End
Lecture No.12 :
Revision of previous syllabus
Lecture No.13 :
 Algorithm
 Example No.2
 Example No.3
 Activity No. 1.7

2- To find acceleration of a moving object with given mass and the applied force.
Step 1 : Start
Step 2 : Input numbers, mass, force
Step 3 : Set acceleration to Force
mass
Step 4 : Output acceleration
Step 5 : End
3- To find the volume of a cube.
Step 1 : Start
Step 2 : Input numbers, side
Step 3 : Set volume to side x side x side.
Step 4 : Output
volume
Step 5 : End

Step 1 : Start
Step 2 : Input numbers, r ,h
Step 3 : Set volume of Sphere to 4/3 x π r3
Step 3 : Set volume of cylinder to π r2h
Step 4 : Output volume
Step 5 : End

Lecture No. 14 :
 Algorithm
 Example No.4
 Example No.5
 Activity No. 1.8

4- To find the area of a parallelogram.


Step 1 : Start
Step 2 : Input numbers, base, height
Step 3 : Set area to base x height
Step 4 : Output area
Step 5 : End
5- To display the larger one out of the three given numbers
Step 1 : Start
Step 2 : Input numbers, n0 , n1 ,n2
Step 3 : if nl > large Set large to n1
Step 4 : if n2 > large Set large to n2
Step 5 : Output
large
Step 5 : End

1- Area of Triangle
Step 1 : Start
Step 2 : Input numbers, base, height
Step 3 : Set area to 1/2 x base x height
Step 4 : Output area
Step 5 : End
2- Area of rhombus
Step 1 : Start
Step 2 : Input numbers, p,q
Step 3 : Set area to p x q
2
Step 4 : Output area
Step 5 : End
3- Area of trapezium
Step 1 : Start
Step 2 : Input numbers, base , height
Step 3 : Set area to 1/2 ( base + height) x h
Step 4 : Output area
Step 5 : End

Lecture No. 15 :
 Algorithm
 Example No.6
 Example No.7

6- To assign grade to a subject based on the achieved marks.


Step 1 : Start
Step 2 : Input numbers, obtained_marks, total_marks
Step 3 : Set percentage to obtained_marks x 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

7- To find the interest on an amount.


Step 1 : Start
Step 2 : Input numbers, amount, rate, years
Step 3 : Set plain interest to ( amount x rate ) x years
100
Step 4 : Output plain interest
Step 5 : End
Lecture No. 16 :
 Algorithm
 Example No.8
 Example No.9

8- To convert Celsius to Fahrenheit temperature and vice versa.


Step 1 : Start
Step 2 : Input numbers, Celsius
Step 3 : Set Fahrenheit to Celsius x 9 + 32
5
Step 4 : Output Fahrenheit
Step 5 : Input numbers, Fahrenheit
Step 6 : Set Celsius to (Fahrenheit -32 ) x 5/9
Step 7 : output Celsius
Step 8 : End

9- Find even numbers in integers ranging from n1 to n2 (where n2 is greater than n1).
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 5 : go to step 3
}
Step 6 : End
Lecture No. 17 :
 Algorithm
 Efficiency of Algorithms
1.3.5 : Efficiency of Algorithms
 There can be more than one algorithms to solve the same problem.
 Which one is better, depends upon the efficiency of the available solution algorithms.
 Efficiency of an algorithm is measured on the basis of two metrics.
1. Number of steps: An algorithm is considered more efficient if it takes less number of
steps to reach the results.
2. Space used in computer memory: We have observed in algorithms that some data is
stored in computer memory which is latter used to give results. An algorithm using less
space in computer memory is considered more efficient with respect to memory space

Lecture No. 18
 Algorithm
 Activity No. 1.9

Lecture No.19 :
 Difference between an Algorithm and a Flowchart
 Advantages of Flowchart
 Disadvantages of Flowchart.
 Advantages of Algorithm
 Disadvantages of Algorithm

Compare flowchart and algorithm

FLOWCHART ALGORITHM
The symbols are used to draw flowchart. Simple English is used to write algorithm.
Flowchart is more time consuming. Algorithm is less time consuming.
It is difficult to modify. It is easy to modify.
It is graphical representation. It is a step by step procedure.
It is a movie. It is a story.

Advantages of Flowchart :
 Easy to draw.
 Easy to understand problem solving.
 Easy to identify errors (if any).
 Easy to observe flow from one step to the other.
Disadvantages of Flowchart :
 More time is required to draw a flowchart.
 Modifying a flowchart is not very easy every time

Advantages of Algorithm :
 Easy to write.
 Techniques to write an algorithm are easy to understand.
 To solve a large problem, algorithms are helpful.
Disadvantages of Algorithm :
 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.

Lecture No. 20 :
 Test Data
 Activity No. 1.10
 Importance of Testing

1.4 Test Data :


 After solving a problem, we need to test whether the solution is correct or not, and
for testing, we need "Test Data".
 For example, if we want to test the algorithm to find the largest among three given
numbers n0 ,n1 , and n2.
 We need three values. These values can be positive, negative or zero.
 For Example : (n0 = 5 , n1 = 15, n2 = 3), So, for thinking about testing, we also
need to think about test data.

1.4.1 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.
 For example, 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.
 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.
Lecture No. 21 :
 Types of Test Data
 Verification and Validation
 Example No.1
 Example No.2
1.4.2 Types of Test Data
Types of Test Data include:
1. Valid test data:
2. Invalid test data:
3. Boundary test data values:
4. Wrong data formats:
5. Absent data
1- 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.
2- 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.
3- 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.
4- 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.
5- 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.
1.5 Verification and Validation
Verification :
 Verification means to test if the solution is actually solving the same problem for which
it was designed.

 For example, if you are asked to give a solution for calculating compound interest then
verification means to know that it is giving results for compound interest not for the plain
interest.
Validation :
 Validation means to test whether the solution is correct or not.
 For example, if you are asked to give a solution for calculating compound interest then
validation means to know whether it is finding the correct compound interest or not.
 If a solution is verified, then it is validated with the help of test data .
Example no.1 of Verification and Validation
 Let's assume that you go to a pizza shop
 and order a chicken pizza.
 You state your requirement that it should be less spicy.
 You also expect that it would taste good.
 When the pizza arrives,
 you can observe that it is a chicken pizza.
 This is called verification.
 Now, when you eat the pizza,
 you can check whether it is less spicy or not,
 it tastes good or not. This is called validation.

Example no.2 of Verification and Validation


 Let's assume that you are asked to write an algorithm that takes as input a list of
numbers.
 The algorithm should display the list arranged in ascending order.
 After writing the algorithm you submit it to your teacher.
 Your teacher provides a list of numbers to the algorithm.
 If your algorithm displays a list of numbers then it is verified.
 Instead if your algorithm displays an answer in yes or no, or displays something else,
then it is not verified.
 If your algorithm is verified, your teacher moves to the next step of validation.
 He checks whether the list of numbers displayed are actually in ascending order or not.
 If the list is in ascending order and no element is missing then your solution is also
validated.
Lecture No. 22 :
 Identification and Correction of Errors
 Trace Table
 Using Invalid Data for Testing

1.6 Identification and Correction of Errors


 If an algorithm is failed during verification, then it is important to identify the root cause
of failure and then to correct it.
 Sometimes the error is logical. It means the solution is working but not giving required
results.
 For example, to recruit students for our school volleyball team,
 we need students having height between 144 cm and 164 cm.
 To count qualified students, we develop the following algorithm.
 Step 1. Start
 Step 2. Set count to 0
 Step 3. Set all_heights to [154,140,155,164,144,166,160,143]
 Step 4. For each height in the list all_heights
 Step 5. If height > 144 and height < 164 then
 Set count to count + 1
 Step 6. Output count
 Step 7. Stop

1.6.1 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.
 The table usually takes the form of a multi-column, multi-row table;
 with each column showing names of data, and each row showing values of the data at
each step.
 Table 1-3 shows a trace table for the algorithm presented in Section 1.6
 The blank means there is no change and — means that a value is not concerned.
 In the following table Step 1 has no effect on data.
 Step 2 is assigning 0 to count.
 and in Step 3, list all_heights is introduced.
 In Step 4, there is no change in both count and all_heights
 but the data 154 is stored in height It is compared
 in Step 5 and the value in count is updated if data is in given range.
 Steps 4 and 5 are repeated for each value as shown in Table 1-3.
1.6.2 Using 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.
Activities

Lecture No. 23 :
 Activity No. 1.11
 Solve Exercise No.1 to 7

Lecture No. 24
 Solve MCQ’s
 Solve Fill in the Blank
 Solve Exercise 1.4

You might also like