Modern Academy FOR Computer Science &
Management Technology in Maadi
Department of Computer Science
• Subject: (CS 101) Introduction to Computer Science
• Professors: Prof. Mahmoud Gadallah, and Dr. Mohamed Elnabawy
• Tutorial and Lab Coordinator: Instructor Teams
• CONTACT: ( LMS-MOODLE) & (WhatsApp: 01005586337).
E-Mail: m.elnabawy@eng.modern-academy.edu.eg
• COURSE RULES: GRADES/ LATE HW/ ATTENDANCE.
CS 101 Dr. Mohamed M. Elnabawy Fall 2025
General Objective of the Course
1. Define the basic concepts and components of
computer system (hardware and software).
2. Describe the computer organization and its
different hardware components.
3. Apply the methodologies of problem
solving and program development and
translate the solution to an algorithm or
flow chart.
4. Describe the basic structure of computer
networks and the associated hardware.
Chapter 2:
Problem Solving and Program Development
2- Pseudo code
pseudocode
Basic Guidelines for Pseudocode:
1- Do not use language-specific commands in your statements
Pseudocode should be universal. So, when creating the task list you would not include
commands that are for any specific language like C++, Java, C#. The point of
pseudocode is to design a program that can be translated into any language.
2- Write only one task/statement per line
Make sure you put only one task on each line. Including too much information on one
line can be confusing and increases the possibility of errors.
3- Capitalize Keywords
Capitalizing keywords like Read, Write, or Display helps to show when an action is
occurring or when a specific command or process will be necessary when coding in
your specific language.
4- Indent statements in a loop to better see the flow of your program
Pseudocode (Cont.)
The "structured" part of pseudocode is a notation for representing specific structured programming
constructs:
1. SEQUENCE: is a linear progression where one task is performed sequentially after another.
2. SELECTION:
❖ IF-THEN-ELSE: is a decision (selection) in which a choice is made between two alternative
courses of action.
❖ CASE: is a multiway branch (decision) based on the value of an expression. CASE is a
generalization of IF-THEN-ELSE.
3. REPETITION:
❖ WHILE: is a loop (repetition) with a simple conditional test at its beginning.
❖ REPEAT-UNTIL: is a loop with a simple conditional test at the bottom.
❖ FOR: is a "counting" loop.
• Sequential control is indicated by writing one action after another, each action on a line
by itself, and all actions aligned with the same indent.
• The actions are performed in the sequence (top to bottom) that they are written.
Example (non-computer)
Brush teeth
Wash face
Comb hair
Smile in mirror
Example
READ height of rectangle
READ width of rectangle
COMPUTE area as height times width
• Sequence Structure
Pseudo
code
Common Action Keywords:
Input: READ, OBTAIN, GET
Output: PRINT, DISPLAY, SHOW
Compute: COMPUTE, CALCULATE, DETERMINE
Initialize: SET, INIT
Add one: INCREMENT, BUMP
• Sequence Structure
Pseudo
code
IF-THEN-ELSE
A binary choice on a given Boolean condition is indicated by using four keywords:
IF, THEN, ELSE, and ENDIF.
The general form is:
IF condition THEN
Sequence 1
ELSE
Sequence 2
ENDIF
• The ELSE keyword and “sequence 2” are optional.
• If the condition is true, sequence 1 is performed, otherwise, sequence 2 is performed.
• Selection
Pseudo
code
Example
IF HoursWorked > NormalMax THEN
Display overtime message
ELSE
Display regular-time message
ENDIF
• Selection
Pseudo
code
CASE
• A CASE construct indicates a multiway branch based on mutually exclusive conditions.
• Four keywords, CASE, OF, OTHERS, and ENDCASE, and conditions are used to
indicate the various alternatives.
The general form is:
CASE expression OF
condition 1 : sequence 1
condition 2 : sequence 2
...
condition n : sequence n
OTHERS:
default sequence
ENDCASE
• Selection
Pseudo
code
• The OTHERS sentence with its default sequence is optional.
• Conditions are normally numbers or characters indicating the value of "expression",
but they can be English statements or some other notation that specifies the condition
under which the given sequence is to be performed.
• A certain sequence may be associated with more than one condition.
• Selection
Pseudo
code
Example:
CASE Title OF
Mr : Print "Mister"
Mrs : Print "Missus"
Miss : Print "Miss"
Ms : Print "Mizz"
Dr : Print "Doctor"
ENDCASE
• Selection
Pseudo
code
Example:
CASE grade OF
A : points = 4
B : points = 3
C : points = 2
D : points = 1
F : points = 0
ENDCASE
WHILE
• The WHILE construct is used to specify a loop with a test at the top.
• The beginning and ending of the loop are indicated by two keywords WHILE and
ENDWHILE.
• The general form is:
WHILE condition
sequence
ENDWHILE
The loop is entered only if the condition is true. The "sequence" is performed for each iteration.
After each iteration, the condition is evaluated and the loop continues as long as the condition is
true.
• Repetition (Loop)
Pseudo
code
Example
WHILE Population < Limit
Compute Population as Population + Births - Deaths
ENDWHILE
• Repetition (Loop)
Pseudo
code
REPEAT-UNTIL
• This loop is similar to the WHILE loop except that the test is performed at the
bottom instead of at the top.
• Two keywords, REPEAT and UNTIL are used.
The general form is:
REPEAT
sequence
UNTIL condition
• Repetition (Loop)
Pseudo
code
• The "sequence" in this type of loop is always performed at least once, because the
test is performed after the sequence is executed.
• After each iteration, the condition is evaluated, and the loop repeats if the condition
is false.
• The loop terminates when the condition becomes true.
• Repetition (Loop)
Pseudo
code
FOR
This loop is a specialized construct for iterating a specific number of times, often
called a "counting" loop.
Two keywords, FOR and ENDFOR are used.
The general form is:
FOR iteration bounds
sequence
ENDFOR
In cases where the loop constraints can be related it is best to describe the loop using
problem domain vocabulary.
• Repetition (Loop)
Pseudo
code
Examples
Develop an algorithm that calculates and prints the area of a
trapezoid with two bases of lengths base1 and base2 and height h.
Example:
1- The problem:
Writing an algorithm to calculate and print the area of a
trapezoid
Sequence structure
2- Reasoning:
In this step we describe the following:
Formal statement: trapezoid problem
Input(s): base1, base2, height
Output(s): area
Process(es): area = ((base1 + base2) / 2) x height
3- Solution (Design the algorithm):
In this step, the solution can be put in the form of a flow chart or an algorithm
written in a pseudo code language.
Sequence structure
Start
Input base1, base 2,
height
basesum = base1 + base2
area = (basesum / 2) x height
OUTPUT area
Stop
The Algorithm of the
trapezoid problem
• The Flow Chart
The Flow Chart (Cont.)
• The Algorithm in pseudo code:
START
Step 1: INPUT base1
Step 2: INPUT base2
Step 3: INPUT height
Step 4: basesum = base1 + base2
Step 5: area = (basesum / 2) x height
Step 6: OUTPUT area
Step 7: STOP
pseudocode
• Desk checks that this sequence
of steps is an algorithm whose
execution solves the intended
problem.
• Try the reasonable values:
base1 = 10
base2 = 20
Height = 15
Then
basesum = 10 + 20 = 30
and
Area = (30/2) x 15
= 225
START
Step 1: INPUT base1
Step 2: INPUT base2
Step 3: INPUT height
Step 4: basesum = base1 + base2
Step 5: area = (basesum / 2) x height
Step 6: OUTPUT area
Step 7: STOP
4- Test
Selection:
Is the choice of alternate paths (branches) depending on a possibility that may arise
in the logical flow of the algorithm.
Pseudo code
Flow Chart
IF Condition THEN
Process 1
ELSE
Process 2
ENDIF
Cond
ition
?
YES
NO
Process 2 Process 1
II- Selection
Problem
Write an algorithm that accepts a number representing either a Fahrenheit or a
Celsius temperature scale and converts it to the other scale.
Example
Reasoning:
Formal statement: temperature conversion problem
Input: temperature scale (Fahrenheit or Celsius), temperature
Output: converted temperature
Process: CelsTemp = 5/9 (FahrenTemp – 32)
FahrenTemp = 9/5 CelsTemp +32
Example (Cont.)
Solution (Design the algorithm)
a- The algorithm as a flow chart:
START
INPUT scale, temperature
ConvTemp = 9/5 x temperature +32
Is scale =
‘F' ?
ConvTemp = 5/9 x (temperature – 32)
OUTPUT ConvTemp
STOP
YES
NO
Example (Cont.)
Input: scale (F or C), temperature
Output: converted temperature
Process: CelsTemp = 5/9 (FahrenTemp – 32)
FahrenTemp = 9/5 CelsTemp +32
The Algorithm in pseudo code:
START
Step 1: INPUT scale
Step 2: INPUT temperature
Step 3: IF scale = ‘F’ THEN
ConvTemp = 5/9 x (temperature – 32)
ELSE
ConvTemp = 9/5 x temperature +32
ENDIF
Step 4: OUTPUT ConvTemp
Step 5: STOP
Example (Cont.)
Test:
Trace the algorithm for various values for temperatures such as 212 Fahrenheit
and 100 Celsius, which are equivalent.
Trace the Algorithm
Example (Cont.)
Example-4:
Assume that a salesperson is paid a commission based on the
number of sales made during the week. The salesperson is paid
a commission of $8 per sale for fewer than the established
quota of 15 sales, $12 per sale if the quota is reached, and $16
per sale if the quota is exceeded. Write an algorithm to find the
salesperson’s commission
Assignment
The Algorithm in pseudocode:
Step 1: INPUT sales
Step2 : INPUT quota
Step 3: IF sales < quota THEN
Rate = 8
ELSE IF sales = quota THEN
Rate = 12
ELSE
Rate = 16
Step 4: commission = rate x sales
Step 5: OUTPUT commission
Step 6: STOP
Draw the Flow
Chart
Assignment Solution
Definition of a loop:
It is a piece of code that repeats again and again until some condition, called an
exit condition, is met. There are different methods to implement loops such as:
For, While and Repeat…..Until.
This structure provides for repeated execution of part of the algorithm.
III- Repetition (looping)
For Loop:
Pseudo code
Flow Chart
FOR counter =1 to 5
PROMPT user “Enter input”
GET input
counter = counter +1
END FOR
Counter = 0
Get input
Counter=counter+1
Is
Counter
≤5?
YES
NO
III- Repetition (looping)
While Loop:
Pseudo code
Flow Chart
PROMPT “Enter total”
GET total
WHILE total <= 50
PROMPT “Enter Number”
GET Number
total = total +Number
Get Number
total = total +Number
Is total
≤50?
YES
NO
Get total
Repetition (looping) (Cont.)
REPEAT - UNTIL Loop:
Pseudo code
Flow Chart
Total = 0
REPEAT
PROMPT “Enter Number”
GET Number
total = total +Number
UNTIL total > 50
Get Number
total = total +Number
Is total
>50?
YES
NO
Total = 0
Repetition (looping) (Cont.)
Problem
Reconsider the problem in example 4 but allow for an entire sales staff.
Reasoning
Formal statement: sales commission problem (2)
Input: number of salespeople , quota
Number of sales for each salesperson
Output: commission for each salesperson
Process: commission = rate x number of sales
Where rate is determined as:
$ 8/sale for Number of sales < than 15
$12/sale for Number of sales = 15
$16/sale for Number of sales > than 15
Example 5
1- The Algorithm in pseudocode:
START
Step 1: INPUT numSalespeople , quota
Step 2: LOOP numSalespeople times
INPUT sales
IF sales < quota THEN
Rate = 8
ELSE IF sales = quota THEN
Rate = 12
ELSE
Rate = 16
ENDIF
Commission = rate x sales
OUTPUT commission
Step 3: STOP
Solution:
Example 5 (Cont.)
a) The Algorithm in Flow Chart:
Start
Input NumSalesperson
Count = 1
Is
Count < NumSalesperson?
Input Sales
Is Sales =
quota ?
?
NO
Rate = 8
Rate = 12
Rate = 16
Commission = rate x sales
Is Sales <
quota ?
YES
Count = Count + 1
YES
NO
YES
NO
Output commission
End
Loop
Exercise (3)
ECE 202 Dr. Mohamed M. Elnabawy Spring 2024
(Q.1) Design a flow chart and pseudo code that receives 2 integers
and calculates/displays their Sum and Average.
(Q.2) Design a flow chart and pseudo code that receives 2 integers
from the user and Calculate/display their Difference, Product, and
quotient.
(Q.3) Design a flowchart and pseudo code that will prompt for the
price of a computer and tax rate, calculate the tax and new price,
and display them on the screen.
Exercise (3) Cont.
ECE 202 Dr. Mohamed M. Elnabawy Spring 2024
(Q.4) Design a Flowchart and pseudo code that will prompt for the
length and width of a rectangle and the radius of a circle, receive
them, then calculate the area of the rectangle and the area of a
circle and its circumference and display them to the screen.
(Q.6) Design a flow chart and pseudo code that will prompt for 2
numbers and accept them then sort them into ascending order,
and then display them on the screen.
(Q.5) Design a flow chart and pseudo code that will receive 3
numbers then find the maximum and display it on the screen.
Exercise (3) Cont.
ECE 202 Dr. Mohamed M. Elnabawy Spring 2024
(Q.7) Design a flow chart and pseudo code that will ask for student
score in a subject, and receive it then match the score to a letter(s)
grade, then display grade to the screen. the letter grade is to be
calculated as follows:
Exercise (3) Cont.
ECE 202 Dr. Mohamed M. Elnabawy Spring 2024
(Q.8) Design a flow chart and pseudo code that accepts pairs of
integers from the user and Calculate / display their Sum,
Difference, Product and quotient. The program will terminate after
5 entries.
(Q.9) Design a flow chart and pseudo code that will ask for 10
temperatures expressed in degree Fahrenheit. Then it will accept
each Fahrenheit temperature, then convert it into Celsius, display
the converted temperature to the screen.
Celsius = (Fahrenheit - 32) * 5 / 9
Exercise (3) Cont.
ECE 202 Dr. Mohamed M. Elnabawy Spring 2024
(Q.10) Design a flow chart and pseudo code that will accept pairs of
numbers, and calculate the sum, if the sum is +ve then display a
message beside it says “The sum is positive” and if the sum is –ve
then display a message beside it says “the sum is negative”. The
program will terminate after 10 entries is entered.
(Q.11) Design a flow chart and pseudo code that will calculate the
factorial of a number and display the result.
Thanks
45
CS 101 Dr. Mohamed M. Elnabawy Fall 2025

More Related Content

PPTX
Computer Studies 2013 Curriculum framework 11 Notes ppt.pptx
PPTX
Draw the flowchart of the above algorithm.pptx
PPTX
Operators loops conditional and statements
PDF
algorithms and flow chart overview.pdf
PPTX
01 Introduction to analysis of Algorithms.pptx
PPTX
UNIT 1.pptx
PPTX
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
PPTX
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
Computer Studies 2013 Curriculum framework 11 Notes ppt.pptx
Draw the flowchart of the above algorithm.pptx
Operators loops conditional and statements
algorithms and flow chart overview.pdf
01 Introduction to analysis of Algorithms.pptx
UNIT 1.pptx
C_BASICS FOR C PROGRAMMER WITH SRIVATHS P
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT

Similar to LEC 5 [CS 101] Introduction to computer science.pdf (20)

PDF
VB PPT by ADI PART3.pdf
PDF
VB PPT by ADI PART3.pdf
PPT
3 algorithm-and-flowchart
PDF
Introductiontoflowchart 110630082600-phpapp01
PPTX
Data Structures_Introduction to algorithms.pptx
PPTX
Lecture 3
PPTX
Review of C programming language.pptx...
PPTX
Algorithms-Flowcharts for programming fundamental
PPTX
C# 101: Intro to Programming with C#
PPT
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
PPT
UNIT-2-PPTS-DAA.ppt
PDF
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
PPTX
Introduction to C ++.pptx
PDF
Introduction to c first week slides
PPT
for loops in C++ and their functions and applicability
PPTX
Vba Class Level 1
PPTX
Introduction to flowchart
PPT
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
PPTX
Flow chart programming
PPTX
Module_2_1_Building Python Programs_Final.pptx
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdf
3 algorithm-and-flowchart
Introductiontoflowchart 110630082600-phpapp01
Data Structures_Introduction to algorithms.pptx
Lecture 3
Review of C programming language.pptx...
Algorithms-Flowcharts for programming fundamental
C# 101: Intro to Programming with C#
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
UNIT-2-PPTS-DAA.ppt
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
Introduction to C ++.pptx
Introduction to c first week slides
for loops in C++ and their functions and applicability
Vba Class Level 1
Introduction to flowchart
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
Flow chart programming
Module_2_1_Building Python Programs_Final.pptx
Ad

Recently uploaded (20)

PDF
CHALLENGES FACED BY TEACHERS WHEN TEACHING LEARNERS WITH DEVELOPMENTAL DISABI...
PDF
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
PDF
FYJC - Chemistry textbook - standard 11.
PPTX
Approach to a child with acute kidney injury
PDF
Health aspects of bilberry: A review on its general benefits
PDF
GSA-Past-Papers-2010-2024-2.pdf CSS examination
PDF
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
PPTX
Math 2 Quarter 2 Week 1 Matatag Curriculum
PDF
Diabetes Mellitus , types , clinical picture, investigation and managment
PDF
Chevening Scholarship Application and Interview Preparation Guide
PDF
English 2nd semesteNotesh biology biopsy results from the other day and I jus...
PPTX
UCSP Section A - Human Cultural Variations,Social Differences,social ChangeCo...
PPTX
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
PPTX
Power Point PR B.Inggris 12 Ed. 2019.pptx
PPTX
GW4 BioMed Candidate Support Webinar 2025
DOCX
THEORY AND PRACTICE ASSIGNMENT SEMESTER MAY 2025.docx
PDF
Review of Related Literature & Studies.pdf
PDF
Unleashing the Potential of the Cultural and creative industries
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PPTX
PAIN PATHWAY & MANAGEMENT OF ACUTE AND CHRONIC PAIN SPEAKER: Dr. Rajasekhar ...
CHALLENGES FACED BY TEACHERS WHEN TEACHING LEARNERS WITH DEVELOPMENTAL DISABI...
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
FYJC - Chemistry textbook - standard 11.
Approach to a child with acute kidney injury
Health aspects of bilberry: A review on its general benefits
GSA-Past-Papers-2010-2024-2.pdf CSS examination
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
Math 2 Quarter 2 Week 1 Matatag Curriculum
Diabetes Mellitus , types , clinical picture, investigation and managment
Chevening Scholarship Application and Interview Preparation Guide
English 2nd semesteNotesh biology biopsy results from the other day and I jus...
UCSP Section A - Human Cultural Variations,Social Differences,social ChangeCo...
Cite It Right: A Compact Illustration of APA 7th Edition.pptx
Power Point PR B.Inggris 12 Ed. 2019.pptx
GW4 BioMed Candidate Support Webinar 2025
THEORY AND PRACTICE ASSIGNMENT SEMESTER MAY 2025.docx
Review of Related Literature & Studies.pdf
Unleashing the Potential of the Cultural and creative industries
hsl powerpoint resource goyloveh feb 07.ppt
PAIN PATHWAY & MANAGEMENT OF ACUTE AND CHRONIC PAIN SPEAKER: Dr. Rajasekhar ...
Ad

LEC 5 [CS 101] Introduction to computer science.pdf

  • 1. Modern Academy FOR Computer Science & Management Technology in Maadi Department of Computer Science • Subject: (CS 101) Introduction to Computer Science • Professors: Prof. Mahmoud Gadallah, and Dr. Mohamed Elnabawy • Tutorial and Lab Coordinator: Instructor Teams • CONTACT: ( LMS-MOODLE) & (WhatsApp: 01005586337). E-Mail: [email protected] • COURSE RULES: GRADES/ LATE HW/ ATTENDANCE. CS 101 Dr. Mohamed M. Elnabawy Fall 2025
  • 2. General Objective of the Course 1. Define the basic concepts and components of computer system (hardware and software). 2. Describe the computer organization and its different hardware components. 3. Apply the methodologies of problem solving and program development and translate the solution to an algorithm or flow chart. 4. Describe the basic structure of computer networks and the associated hardware.
  • 3. Chapter 2: Problem Solving and Program Development
  • 5. pseudocode Basic Guidelines for Pseudocode: 1- Do not use language-specific commands in your statements Pseudocode should be universal. So, when creating the task list you would not include commands that are for any specific language like C++, Java, C#. The point of pseudocode is to design a program that can be translated into any language. 2- Write only one task/statement per line Make sure you put only one task on each line. Including too much information on one line can be confusing and increases the possibility of errors. 3- Capitalize Keywords Capitalizing keywords like Read, Write, or Display helps to show when an action is occurring or when a specific command or process will be necessary when coding in your specific language. 4- Indent statements in a loop to better see the flow of your program
  • 6. Pseudocode (Cont.) The "structured" part of pseudocode is a notation for representing specific structured programming constructs: 1. SEQUENCE: is a linear progression where one task is performed sequentially after another. 2. SELECTION: ❖ IF-THEN-ELSE: is a decision (selection) in which a choice is made between two alternative courses of action. ❖ CASE: is a multiway branch (decision) based on the value of an expression. CASE is a generalization of IF-THEN-ELSE. 3. REPETITION: ❖ WHILE: is a loop (repetition) with a simple conditional test at its beginning. ❖ REPEAT-UNTIL: is a loop with a simple conditional test at the bottom. ❖ FOR: is a "counting" loop.
  • 7. • Sequential control is indicated by writing one action after another, each action on a line by itself, and all actions aligned with the same indent. • The actions are performed in the sequence (top to bottom) that they are written. Example (non-computer) Brush teeth Wash face Comb hair Smile in mirror Example READ height of rectangle READ width of rectangle COMPUTE area as height times width • Sequence Structure Pseudo code
  • 8. Common Action Keywords: Input: READ, OBTAIN, GET Output: PRINT, DISPLAY, SHOW Compute: COMPUTE, CALCULATE, DETERMINE Initialize: SET, INIT Add one: INCREMENT, BUMP • Sequence Structure Pseudo code
  • 9. IF-THEN-ELSE A binary choice on a given Boolean condition is indicated by using four keywords: IF, THEN, ELSE, and ENDIF. The general form is: IF condition THEN Sequence 1 ELSE Sequence 2 ENDIF • The ELSE keyword and “sequence 2” are optional. • If the condition is true, sequence 1 is performed, otherwise, sequence 2 is performed. • Selection Pseudo code
  • 10. Example IF HoursWorked > NormalMax THEN Display overtime message ELSE Display regular-time message ENDIF • Selection Pseudo code
  • 11. CASE • A CASE construct indicates a multiway branch based on mutually exclusive conditions. • Four keywords, CASE, OF, OTHERS, and ENDCASE, and conditions are used to indicate the various alternatives. The general form is: CASE expression OF condition 1 : sequence 1 condition 2 : sequence 2 ... condition n : sequence n OTHERS: default sequence ENDCASE • Selection Pseudo code
  • 12. • The OTHERS sentence with its default sequence is optional. • Conditions are normally numbers or characters indicating the value of "expression", but they can be English statements or some other notation that specifies the condition under which the given sequence is to be performed. • A certain sequence may be associated with more than one condition. • Selection Pseudo code
  • 13. Example: CASE Title OF Mr : Print "Mister" Mrs : Print "Missus" Miss : Print "Miss" Ms : Print "Mizz" Dr : Print "Doctor" ENDCASE • Selection Pseudo code Example: CASE grade OF A : points = 4 B : points = 3 C : points = 2 D : points = 1 F : points = 0 ENDCASE
  • 14. WHILE • The WHILE construct is used to specify a loop with a test at the top. • The beginning and ending of the loop are indicated by two keywords WHILE and ENDWHILE. • The general form is: WHILE condition sequence ENDWHILE The loop is entered only if the condition is true. The "sequence" is performed for each iteration. After each iteration, the condition is evaluated and the loop continues as long as the condition is true. • Repetition (Loop) Pseudo code
  • 15. Example WHILE Population < Limit Compute Population as Population + Births - Deaths ENDWHILE • Repetition (Loop) Pseudo code
  • 16. REPEAT-UNTIL • This loop is similar to the WHILE loop except that the test is performed at the bottom instead of at the top. • Two keywords, REPEAT and UNTIL are used. The general form is: REPEAT sequence UNTIL condition • Repetition (Loop) Pseudo code
  • 17. • The "sequence" in this type of loop is always performed at least once, because the test is performed after the sequence is executed. • After each iteration, the condition is evaluated, and the loop repeats if the condition is false. • The loop terminates when the condition becomes true. • Repetition (Loop) Pseudo code
  • 18. FOR This loop is a specialized construct for iterating a specific number of times, often called a "counting" loop. Two keywords, FOR and ENDFOR are used. The general form is: FOR iteration bounds sequence ENDFOR In cases where the loop constraints can be related it is best to describe the loop using problem domain vocabulary. • Repetition (Loop) Pseudo code
  • 20. Develop an algorithm that calculates and prints the area of a trapezoid with two bases of lengths base1 and base2 and height h. Example: 1- The problem: Writing an algorithm to calculate and print the area of a trapezoid Sequence structure
  • 21. 2- Reasoning: In this step we describe the following: Formal statement: trapezoid problem Input(s): base1, base2, height Output(s): area Process(es): area = ((base1 + base2) / 2) x height 3- Solution (Design the algorithm): In this step, the solution can be put in the form of a flow chart or an algorithm written in a pseudo code language. Sequence structure
  • 22. Start Input base1, base 2, height basesum = base1 + base2 area = (basesum / 2) x height OUTPUT area Stop The Algorithm of the trapezoid problem • The Flow Chart The Flow Chart (Cont.)
  • 23. • The Algorithm in pseudo code: START Step 1: INPUT base1 Step 2: INPUT base2 Step 3: INPUT height Step 4: basesum = base1 + base2 Step 5: area = (basesum / 2) x height Step 6: OUTPUT area Step 7: STOP pseudocode
  • 24. • Desk checks that this sequence of steps is an algorithm whose execution solves the intended problem. • Try the reasonable values: base1 = 10 base2 = 20 Height = 15 Then basesum = 10 + 20 = 30 and Area = (30/2) x 15 = 225 START Step 1: INPUT base1 Step 2: INPUT base2 Step 3: INPUT height Step 4: basesum = base1 + base2 Step 5: area = (basesum / 2) x height Step 6: OUTPUT area Step 7: STOP 4- Test
  • 25. Selection: Is the choice of alternate paths (branches) depending on a possibility that may arise in the logical flow of the algorithm. Pseudo code Flow Chart IF Condition THEN Process 1 ELSE Process 2 ENDIF Cond ition ? YES NO Process 2 Process 1 II- Selection
  • 26. Problem Write an algorithm that accepts a number representing either a Fahrenheit or a Celsius temperature scale and converts it to the other scale. Example
  • 27. Reasoning: Formal statement: temperature conversion problem Input: temperature scale (Fahrenheit or Celsius), temperature Output: converted temperature Process: CelsTemp = 5/9 (FahrenTemp – 32) FahrenTemp = 9/5 CelsTemp +32 Example (Cont.)
  • 28. Solution (Design the algorithm) a- The algorithm as a flow chart: START INPUT scale, temperature ConvTemp = 9/5 x temperature +32 Is scale = ‘F' ? ConvTemp = 5/9 x (temperature – 32) OUTPUT ConvTemp STOP YES NO Example (Cont.) Input: scale (F or C), temperature Output: converted temperature Process: CelsTemp = 5/9 (FahrenTemp – 32) FahrenTemp = 9/5 CelsTemp +32
  • 29. The Algorithm in pseudo code: START Step 1: INPUT scale Step 2: INPUT temperature Step 3: IF scale = ‘F’ THEN ConvTemp = 5/9 x (temperature – 32) ELSE ConvTemp = 9/5 x temperature +32 ENDIF Step 4: OUTPUT ConvTemp Step 5: STOP Example (Cont.)
  • 30. Test: Trace the algorithm for various values for temperatures such as 212 Fahrenheit and 100 Celsius, which are equivalent. Trace the Algorithm Example (Cont.)
  • 31. Example-4: Assume that a salesperson is paid a commission based on the number of sales made during the week. The salesperson is paid a commission of $8 per sale for fewer than the established quota of 15 sales, $12 per sale if the quota is reached, and $16 per sale if the quota is exceeded. Write an algorithm to find the salesperson’s commission Assignment
  • 32. The Algorithm in pseudocode: Step 1: INPUT sales Step2 : INPUT quota Step 3: IF sales < quota THEN Rate = 8 ELSE IF sales = quota THEN Rate = 12 ELSE Rate = 16 Step 4: commission = rate x sales Step 5: OUTPUT commission Step 6: STOP Draw the Flow Chart Assignment Solution
  • 33. Definition of a loop: It is a piece of code that repeats again and again until some condition, called an exit condition, is met. There are different methods to implement loops such as: For, While and Repeat…..Until. This structure provides for repeated execution of part of the algorithm. III- Repetition (looping)
  • 34. For Loop: Pseudo code Flow Chart FOR counter =1 to 5 PROMPT user “Enter input” GET input counter = counter +1 END FOR Counter = 0 Get input Counter=counter+1 Is Counter ≤5? YES NO III- Repetition (looping)
  • 35. While Loop: Pseudo code Flow Chart PROMPT “Enter total” GET total WHILE total <= 50 PROMPT “Enter Number” GET Number total = total +Number Get Number total = total +Number Is total ≤50? YES NO Get total Repetition (looping) (Cont.)
  • 36. REPEAT - UNTIL Loop: Pseudo code Flow Chart Total = 0 REPEAT PROMPT “Enter Number” GET Number total = total +Number UNTIL total > 50 Get Number total = total +Number Is total >50? YES NO Total = 0 Repetition (looping) (Cont.)
  • 37. Problem Reconsider the problem in example 4 but allow for an entire sales staff. Reasoning Formal statement: sales commission problem (2) Input: number of salespeople , quota Number of sales for each salesperson Output: commission for each salesperson Process: commission = rate x number of sales Where rate is determined as: $ 8/sale for Number of sales < than 15 $12/sale for Number of sales = 15 $16/sale for Number of sales > than 15 Example 5
  • 38. 1- The Algorithm in pseudocode: START Step 1: INPUT numSalespeople , quota Step 2: LOOP numSalespeople times INPUT sales IF sales < quota THEN Rate = 8 ELSE IF sales = quota THEN Rate = 12 ELSE Rate = 16 ENDIF Commission = rate x sales OUTPUT commission Step 3: STOP Solution: Example 5 (Cont.)
  • 39. a) The Algorithm in Flow Chart: Start Input NumSalesperson Count = 1 Is Count < NumSalesperson? Input Sales Is Sales = quota ? ? NO Rate = 8 Rate = 12 Rate = 16 Commission = rate x sales Is Sales < quota ? YES Count = Count + 1 YES NO YES NO Output commission End Loop
  • 40. Exercise (3) ECE 202 Dr. Mohamed M. Elnabawy Spring 2024 (Q.1) Design a flow chart and pseudo code that receives 2 integers and calculates/displays their Sum and Average. (Q.2) Design a flow chart and pseudo code that receives 2 integers from the user and Calculate/display their Difference, Product, and quotient. (Q.3) Design a flowchart and pseudo code that will prompt for the price of a computer and tax rate, calculate the tax and new price, and display them on the screen.
  • 41. Exercise (3) Cont. ECE 202 Dr. Mohamed M. Elnabawy Spring 2024 (Q.4) Design a Flowchart and pseudo code that will prompt for the length and width of a rectangle and the radius of a circle, receive them, then calculate the area of the rectangle and the area of a circle and its circumference and display them to the screen. (Q.6) Design a flow chart and pseudo code that will prompt for 2 numbers and accept them then sort them into ascending order, and then display them on the screen. (Q.5) Design a flow chart and pseudo code that will receive 3 numbers then find the maximum and display it on the screen.
  • 42. Exercise (3) Cont. ECE 202 Dr. Mohamed M. Elnabawy Spring 2024 (Q.7) Design a flow chart and pseudo code that will ask for student score in a subject, and receive it then match the score to a letter(s) grade, then display grade to the screen. the letter grade is to be calculated as follows:
  • 43. Exercise (3) Cont. ECE 202 Dr. Mohamed M. Elnabawy Spring 2024 (Q.8) Design a flow chart and pseudo code that accepts pairs of integers from the user and Calculate / display their Sum, Difference, Product and quotient. The program will terminate after 5 entries. (Q.9) Design a flow chart and pseudo code that will ask for 10 temperatures expressed in degree Fahrenheit. Then it will accept each Fahrenheit temperature, then convert it into Celsius, display the converted temperature to the screen. Celsius = (Fahrenheit - 32) * 5 / 9
  • 44. Exercise (3) Cont. ECE 202 Dr. Mohamed M. Elnabawy Spring 2024 (Q.10) Design a flow chart and pseudo code that will accept pairs of numbers, and calculate the sum, if the sum is +ve then display a message beside it says “The sum is positive” and if the sum is –ve then display a message beside it says “the sum is negative”. The program will terminate after 10 entries is entered. (Q.11) Design a flow chart and pseudo code that will calculate the factorial of a number and display the result.
  • 45. Thanks 45 CS 101 Dr. Mohamed M. Elnabawy Fall 2025