c hapter 1 pseudocode & flowcharts

17
CHAPTER 1 PSEUDOCODE & FLOWCHARTS 1 st Semester 2014/2015 King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Noor Alhareqi & Alaa Altheneyan

Upload: aysha

Post on 06-Jan-2016

17 views

Category:

Documents


1 download

DESCRIPTION

C hapter 1 Pseudocode & Flowcharts. 1 st Semester 2014/2015. Levels of Program Development. Define the problem.  Human thought Plan the problem solution.  writing the algorithm [pseudo-natural language (English, Arabic) or drawing the flowchart diagram). - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: C hapter 1 Pseudocode & Flowcharts

CHAPTER 1PSEUDOCODE & FLOWCHARTS

1st Semester 2014/2015

King Saud University College Of Applied Studies and Community Services CSC 1101Computer Programming-1Done By: Asmal AlosaimiEdited By: Noor Alhareqi & Alaa Altheneyan

Page 2: C hapter 1 Pseudocode & Flowcharts

Levels of Program Development

Asma Alosaimi

2

1. Define the problem. Human thought

2. Plan the problem solution. writing the algorithm [pseudo-natural language (English, Arabic) or drawing the flowchart diagram).

3. Code the program. High Level Programming Language (C, C++, Java, …)

4. Compile the program. Machine Code

5. Run the program.6. Test and debug the program.

Page 3: C hapter 1 Pseudocode & Flowcharts

From Lec1 we learn that

Asma Alosaimi

3

When planning for a problem solution, algorithms are used to outline the solution steps using English like statements, called pseudocode.

or A flowchart , which is a graphical

representation of an algorithm.

Page 4: C hapter 1 Pseudocode & Flowcharts

Pseudocode

Pseudocode is a detailed description of what a computer program must do, expressed in an English like language rather than in a programming language.

Asma Alosaimi

4

Page 5: C hapter 1 Pseudocode & Flowcharts

Pseudocode Example

Asma Alosaimi

5

Write a Program to Print the Sum of two integer Numbers

1. Start the program2. Read the first number and save in the variable

( N1 )3. Read the second number and save in the

variable ( N2 )4. Sum the both numbers and save the result in

the variable ( Sum ) Sum = N1 + N2 5. Print the variable ( Sum ) 6. End the program

Page 6: C hapter 1 Pseudocode & Flowcharts

Flowchart

A flowchart is a type of diagram that represents an algorithm , showing the steps as boxes of various kinds [ex: rectangles, diamonds, ovals], and their order by connecting these with arrows. 

Asma Alosaimi

6

Page 7: C hapter 1 Pseudocode & Flowcharts

Flowcharts Symbols

7

Move from step to step

Start/End

Read/Print (input/output)

Arithmetic Operations (process)

Decision , can be used with loops

Start

Read n1

N2 = 5

End

Print n1

N2 = n1+3

n1 > 3

Page 8: C hapter 1 Pseudocode & Flowcharts

Asma Alosaimi

8

Draw a flowchart for a program that calculates

and print the area and the perimeter of a rectangle. Input

Length width

Processing Area = length*width Perimeter = 2*( length + width)

Output Area Perimeter

start

Read L, W

perimeter = 2 (L+W)

Print area

End

area = L * W

Print perimeter

Solution

Page 9: C hapter 1 Pseudocode & Flowcharts

Example 2

Draw the flow chart for a program that calculates the total salary for an employee using this equation:

Total_Sal = Salary +Overtime

Asma Alosaimi

9

Page 10: C hapter 1 Pseudocode & Flowcharts

Asma Alosaimi

10

start

Read Salary

Print Total_Sal

End

Total_Sal = Salary +Overtime

Solution

Input Salary Overtime

Processing Total_Sal = Salary +Overtime

Output Total_Sal

Read Overtime

Page 11: C hapter 1 Pseudocode & Flowcharts

Example 3

Asma Alosaimi

11

Draw a flowchart for a program that determine if the temperature degree is above or below freezing.

Input Temp.

Processing Check if Temp is below the 32 below freezing. Check if Temp is above the 32 above freezing.

Output

Print “below freezing” or “above freezing”

Page 12: C hapter 1 Pseudocode & Flowcharts

Solution

Asma Alosaimi

12

Page 13: C hapter 1 Pseudocode & Flowcharts

Example 4

Asma Alosaimi

13

Draw a flowchart for a program that calculates the Zakat, where the user enter the amount of money then the program show the zakat.

Zakat =(2.5/100) * amount. Zakat is not calculated if the amount is less

than 1000 S.R

Page 14: C hapter 1 Pseudocode & Flowcharts

Solution

Input amount.

Processing Check if amount is below 1000 Zakat =0. Check if amount is above 1000 Zakat

=(2.5/100) * amount Output

Zakat

Asma Alosaimi

14

Page 15: C hapter 1 Pseudocode & Flowcharts

Solution

Asma Alosaimi

15

StartStart

EndEnd

Amount > 1000Amount > 1000

Zakat =0.Zakat =0.

Print ZakatPrint Zakat

yesyesnono

Read amountRead amount

Zakat =(2.5/100)*amountZakat =(2.5/100)*amount

Page 16: C hapter 1 Pseudocode & Flowcharts

Example 5

Asma Alosaimi

16

Draw a flowchart to find the sum of first 50 natural numbers.

1+2+3+ ….. +50

Page 17: C hapter 1 Pseudocode & Flowcharts

Asma Alosaimi

17