Download presentation

Presentation is loading. Please wait.

Published byCadence Wragge Modified over 2 years ago

1
CS101: INTRODUCTION TO COMPUTER PROGRAMMING LECTURE-1: INTRODUCTION TO PROBLEM SOLVING - CS002: REVIEW -

2
Outline In this chapter you will learn about: Introduction to Problem Solving Software Development Method (SDM) 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

3
Introduction to Problem Solving Problem solving is the process of transforming the description of a problem into a solution by using our knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving strategies, techniques and tools. Computers can be used to help us solving problems

4
Software Development Method (SDM) Is a framework that is used to structure, plan, and control the process of developing an information system, which include the following steps: 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

5
Example (Problem) Lets have the following problem: Design a program to compute the car parking fee base on these rates: first 2 hours = SR 1 per hour, the following hours is SR 2 per hour.

6
Software Development Method (SDM) 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

7
Step-1: Specification of Needs To understand exactly: what the problem is what is needed to solve it what the solution should provide if there are constraints and special conditions.

8
Specification of needs (Example) What the problem is Need to calculate the parking fee What is needed to solve it Total time What the solution should provide The parking fee If there are constraints and special conditions. None

9
Software Development Method (SDM) 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

10
Step-2: Problem Analysis In the analysis phase, we should identify the following: Inputs to the problem, their form and the input media to be used Outputs expected from the problem, their form and the output media to be used Special constraints or conditions (if any) Formulas or equations to be used

11
Problem analysis (Example) Input: Total time (time) Output: Parking fees (fees) Formula: If time <= 2, fees = time If time > 2, fees = [(time – 2)X2] +2 Constraint None

12
Software Development Method (SDM) 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

13
Step-3: Design algorithm An algorithm is a sequence of a finite number of steps arranged in a specific logical order which, when executed, produces the solution for a problem. An algorithm must satisfy these requirements: It may have an input(s) It must have an output It should not be ambiguous (there should not be different interpretations to it)

14
14 Control Structures In 1966, two researchers, C. Bohn and G. Jacopini, demonstrated that any algorithm can be described using only 3 control structures : Sequence Selection Repetition Called control structures or logic structures

15
15 The Sequence Structure The sequence structure directs the computer to process the program instructions, one after another, in the order listed in the program

16
The Sequence Structure (continued) 16

17
17 The Selection Structure Selection structure: makes a decision and then takes an appropriate action based on that decision Also called the decision structure

18
18 The Selection Structure (continued)

19
19 The Repetition Structure Repetition structure: directs computer to repeat one or more instructions until some condition is met Also called a loop or iteration

20
The Repetition Structure (continued) 20

21
21 The Repetition Structure (continued) What could you do if you don’t know precisely how many steps separate Rob from the chair?

22
The Repetition Structure (continued) 22

23
Design Algorithm An algorithm can be represented using pseudocodes or flowcharts: 1. Pseudocode: 1. Pseudocode: is a semiformal, English-like language with limited vocabulary that can be used to design and describe algorithms. 2. Flowcharts: 2. Flowcharts: is a graph used to depict or show a step by step solution using symbols which represent a task prepared by NI, edited by MAF

24
Pseudocodes: The Sequence control structure A series of steps or statements that are executed in the order they are written in an algorithm. The beginning and end of a block of statements can be optionally marked with the keywords begin and end. Example-1: Begin Read the birth date from the user. Calculate the difference between the birth date and today’s date. Print the user age. End

25
Flowchart – example-1 Begin Read birth date Calculate Age = current year – birth date Display age End Flowchart Symbols Terminal symbol - indicates the beginning and end points of an algorithm. Process symbol - shows an instruction other than input, output or selection. Input-output symbol - shows an input or an output operation. Selection symbol - shows a selection process for two-way selection. Flow lines - indicate the logical sequence of execution steps in the algorithm.

26
Pseudocodes: The Selection control structure Defines two courses of action depending on the outcome of a condition. A condition is an expression that is, when computed, evaluated to either true or false. The keyword used are if and else. Format: if condition then-part else else-part end_if Example-2: if age is greater than 55 print “Retire” else print “Work Work Work” end_if

27
Flowchart – example-2 Begin Read age End Age > 55? NOYES print “retired” print “keep working”

28
Pseudocodes: The Repetition control structure Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied. Example-3: Summing up 1 to 10 set cumulative sum to 0 set current number to 1 while current number is less or equal to 10 add the cumulative sum to current number add 1 to current number end_while print the value of cumulative sum

29
Flowchart – example 3 Begin End current_number <= 10? NO YES sum = 0 current_number = 1 sum = sum + current_number current_number = current_number + 1 print sum

30
Our Problem Algorithm (Pseudocode )

31
Algorithm (Flowchart)

32
Software Development Method (SDM) 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

33
Step-4: Implementation The process of implementing an algorithm by writing a computer program using a programming language (for example, using C language) The output of the program must be the solution of the intended problem The program must not do anything that it is not supposed to do (Think of those many viruses, buffer overflows, trojan horses, etc. that we experience almost daily. All these result from programs doing more than they were intended to do)

34
Implementation (from pseudocodes)

35
Implementation (from flowchart)

36
Software Development Method (SDM) 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

37
Step-5: Testing and Verification Program testing is the process of executing a program to demonstrate its correctness Program verification is the process of ensuring that a program meets user-requirement After the program is compiled, we must run the program and test/verify it with different inputs before the program can be released to the public or other users (or to the instructor of this class)

38
Testing and Verification (Syntax)

39

40
Testing and Verification(Values)

41
Software Development Method (SDM) 1. Specification of needs 2. Problem analysis 3. Design algorithm 4. Implementation 5. Testing and verification 6. Documentation

42
Step-6: Documentation Contains details produced at all stages of the program development cycle. Can be done in 2 ways: Writing comments between your line of codes Creating a separate text file to explain the program Important not only for other people to use or modify your program, but also for you to understand your own program after a long time (believe me, you will forget the details of your own program after some time...)

43
Documentation

44

45
Summary This chapter introduced the concept of problem solving-a process of transforming the description of a problem into a solution. A commonly used method – SDM which consists of 6 steps 3 basic control structures : sequence, selection and repetition structures Pseudocode vs. Flow chart

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google