0% found this document useful (0 votes)
10 views15 pages

PF Lecture 3

The document outlines flowchart symbols and their uses in programming, particularly focusing on structures like looping and decision-making. It includes exercises for creating pseudocode and flowcharts for various programming tasks, such as printing odd numbers, calculating employee bonuses, and obtaining averages. The content is part of a lecture for a programming fundamentals course at FAST – NUCES, Faisalabad Campus.

Uploaded by

acernitro88588
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)
10 views15 pages

PF Lecture 3

The document outlines flowchart symbols and their uses in programming, particularly focusing on structures like looping and decision-making. It includes exercises for creating pseudocode and flowcharts for various programming tasks, such as printing odd numbers, calculating employee bonuses, and obtaining averages. The content is part of a lecture for a programming fundamentals course at FAST – NUCES, Faisalabad Campus.

Uploaded by

acernitro88588
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

CS118 –

Programming
Fundamentals
Lecture # 04
Friday, September 25, 2020
FALL 2020
FAST – NUCES, Faisalabad Campus

Saqib Hayat
Flowchart Common Symbols
2

Name Symbol Use in flowchart

Oval Denotes the beginning or end of the program

Parallelogram Denotes an input

Denotes a process to be carried out


Rectangle (e.g. addition, subtraction etc.)

Denotes a decision (or branch) to be made.


The program should continue along one of two
Diamond routes. (e.g. IF/THEN/ELSE)

Hybrid Denotes and output operation

Denotes the direction of logic flow in the


Flow Line program
CS118 - FALL 2020
Looping flowchart
3

CS118 - FALL 2020


The Repetition Structure
4

 In flowcharting one of the more confusing things is to


separate selection from looping
 This is because both structures use the diamond as
their control symbol
 In pseudocode we avoid this by using specific
keywords to designate looping

WHILE/ENDWHILE
REPEAT/UNTIL

CS118 - FALL 2020


WHILE / ENDWHILE
5
Start
count = 0
WHILE count < 10
ADD 1 to count
count = 0
WRITE count
ENDWHILE
WRITE “The End”

count <10 Mainline


count = 0
Write WHILE count < 10
add 1 to “The End”
count DO Process
ENDWHILE
Stop
write count WRITE “The End”

Process
ADD 1 to count
CS118 - FALL 2020
WRITE count
REPEAT/UNTIL
6
Start count = 0
REPEAT
count = 0
ADD 1 to count
WRITE count
UNTIL count <= 10
add 1 to WRITE “The End”
count

Mainline
write count count = 0
REPEAT
DO Process
count
<=10 UNTIL count >= 10
WRITE “The End”

Write Process
“The End”
ADD 1 to count
CS118 - FALL 2020
WRITE count
Exercise Programs using
7
Loop Structures

CS118 - FALL 2020


Exercise Program 1
8

 Write pseudocode and draw a flowchart that will


 Print first 10 odd numbers starting from the number
provided by the user.
 If it is even number then start from the next odd
number if it is odd number then start with the current
number
 E.g. the user input 10 then the out put will be
 11 13 15 17 19 21 23 25 27 29
 If the user input 5 then the output will be
 5 7 9 11 13 15 17 19 21 23
 Hint: Use number mod 2 = 0 to determine the even
number

CS118 - FALL 2020


Pseudocode for printing 10 of numbers
9
1. START
2. declare count, num
3. input num
4. if num mod 2 = 0 then
4.1 num = num + 1
5. end if
6. count = 0
7. while count < 10
7.1 print num
7.2 num = num + 2
7.3 count = count +1
8. end while
9. END
CS118 - FALL 2020
Flow chart for prtinting 10 odd numbers
10
START 1

Declare
count, num count = 0

Input num
count False
num < 10
False
mod 2
True
=0
True Print num
num = num +1
num = num + 2
count = count +1

1
END

CS118 - FALL 2020


Exercise Program 2
11

 Write a pseudocode and draw a flowchart to


 Read an employee number (EMPNO), employee
name (NAME), overtime hours worked (OVERTIME),
hours absent (ABSENT) and
 Determine the bonus payment (PAYMENT) for 10
employees one by one

Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid

>40 hours $50


>30 but  40 hours $40
>20 but  30 hours $30
>10 but  20 hours $20
CS118 - FALL 2020  10 hours $10
Exercise Program 3
12

 Write a pseudocode and draw a flowchart to


 Read an employee number (EMPNO), employee
name (NAME), overtime hours worked (OVERTIME),
hours absent (ABSENT) and
 Determine the bonus payment (PAYMENT)
 The program will keep on taking input and
calculating until the user enters a –ve EMPNO
Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid

>40 hours $50


>30 but  40 hours $40
>20 but  30 hours $30
>10 but  20 hours $20
CS118 - FALL 2020  10 hours $10
Exercise Program 4: Average
13

 Write a pseudocode and draw a flowchart


 that will get 10 numbers from the user and print their
average.
 Use only one number as input i.e. n1

 Hint: Use loop to get input in n1 and add it to Sum.

CS118 - FALL 2020


Exercise Program 5: Square/cube
14

 Write a pseudocode and draw a flowchart for a


program that will
 Get one number from user
 Print its square if it is an even number
 Print its cube if it is and odd number
 The loop will end if the provided number is a –ve
number (Do not print square or cube of this –ve
number)

CS118 - FALL 2020


Questions
15

CS118 - FALL 2020

You might also like