Download presentation
1
Chapter 2: General Problem Solving Concepts
Computer Programming Skills-2 1435/1436 Place photo here Chapter 2: General Problem Solving Concepts Department of Computer Science Foundation Year Program Umm Alqura University, Makkah
2
The Objectives and the outcomes
To be able to understand the problem. To be able to analyze the problem. To be able to produce an algorithm that solves the problem. The Outcomes: Students should be able to understand the problem. Student should be able to analyze the problem. Students should learn how to solve the problem.
3
Introduction to Programming and Programming language
Programming language is an artificial language that specifies instruction to be executed on a computer. There are two types of programming languages : Low level languages High level languages
4
Introduction Computer Languages: There are many types of computer languages, which can be categorized into the following four types: Low-Level Languages (1st & 2nd Generation Languages) High-Level Languages (3rd Generation Languages) User-Friendly Languages (4th Generation Languages) Object-Oriented Languages (5th Generation Languages)
5
introduction Main Operations of High Level Language Program
Input operations: Like input, read Output operations: Like write, print Arithmetic operations: Like adding, subtracting, multiplying etc.... Control transferring operations: Like “GO TO”, conditional, non-conditional, etc.... Looping: Like repeat, do while, for, etc...
6
introduction Analyze the problem Identify the variables involved
Main Steps in Developing a Program: Analyze the problem Identify the variables involved Design the solution Write the program Enter the program into a computer Compile the program and correct errors Correct the logical errors if any Test and debug program with data Document the program
7
An Algorithm: A sequence of precise instructions, which leads to a solution, is called an algorithm. Examples: Steps (algorithm) to solve a first degree equation. Steps (algorithm) to solve a second degree equation using delta. In other words, algorithm is a method of representing the step-by-step logical procedure for solving a problem.
8
According to D.E. Knuth, an algorithm must possess the following properties:
Finiteness: An algorithm must terminated. Definiteness: Each step of the algorithm must be precisely and unambiguously stated. Effectiveness: Each step must be effective, Generality: The algorithm must be complete in itself Input/output: Each algorithm must take zero, one or more quantities as input data produce one or more output values.
9
Example: Find the algorithm for solving a first degree equation, in the form Ax=B. Sol. Read the values A, B Check if A=0 (if yes there is no equation) therefore no equation to be solved (end processing). Check if B=0 (if yes X=0 and end processing). Calculate the value of X= B/A Print the value of: X
10
Algorithm Representation
There are many techniques in which we may represent an algorithm when thinking of writing a computer program. The techniques that are to be studied are: Flowchart: The flowchart represents a graphical representation of the steps required for an algorithm or program. Pseudocode: It is an informal high level description of the operating principle of a computer program or other algorithm.
11
Pseudocode: It is an informal high level description of the operating principle of a computer program or other algorithm. Example 1: Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Set the class average to the total divided by ten Print the class average.
12
Example 2: Initialize passes to zero Initialize failures to zero
Initialize student to one While student counter is less than or equal to ten Input the next exam result If the student passed Add one to passes Else Add one to failures Add one to student counter Print the number of passes Print the number of failures If eight or more students passed Print "raise tuition"
13
Flowchart: The flowchart represents a graphical representation of the steps required for an algorithm or program. The flowchart is characterized by: Clarifying the program logic Identifying alternative processing methods Serving as guide for program coding Serving as documentation There are some principals that should be followed up when putting the Flowchart, such as: Simplicity Organization Planning
14
Flowchart: General Concepts: Flow chart must be characterized by:
The major element of the project. Elements are clearly labeled. Sequence of elements must be clear. No gap or dead ends. Sequence of elements must be in logical form. Flowchart must be used correctly.
15
Flowchart: General Concept Levels of Program Flowchart:
Simple sequential flowchart: Branched flowchart. Simple-loop flowchart. Multi-loop flowchart.
16
Flowchart: Simple sequential flowchart: It is simplest level which contain the sequence of steps without loops or branch and the flowchart comes in straight line from the beginning to the end.
17
Flowchart: Branched flowchart: It is branched flowchart, when there is a condition statement in the program.
18
Flowchart: Simple-loop flowchart: It is a flowchart, which contain iteration or repetitions. It is usually called loop flowcharts. In this type we need to repeat some operation several times using the same set of operation.
19
Flowchart: Multi-loop flowchart: Looping is used to manage a loop to fulfill a repetition under a definite condition. It takes the following special symbol.
20
Table 2.1 represents the symbols that are used to draw the flow chart.
21
Examples
22
Example1: Algorithm for reading student name
23
Example2: Algorithm for calculating the area of circle
24
Example 3: Draw flow chart for evaluating the following functions: F(x) = x if x>=0 F(x) = -x if x<0
25
Example 3: Draw flow chart for evaluating the following functions: F(x) = x if x>=0 F(x) = -x if x<0
26
Example 4: Write an algorithm and draw the flow chart to find the circumference of circle.
27
Example 5: Write an algorithm and draw a flowchart to print 10 integers starting from 1.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.