Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Programming III

Uploaded by

cstitansol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Programming III

Uploaded by

cstitansol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Computer

Science O.L.
(New Syllabus)

“Everybody should learn to program a computer,


because it teaches you how to think.”
- Steve Jobs
Practical

01
Programming
pt.3
(Conditional)
Programming pt.3
● Conditional statement

● Validation
Programming Concepts
Programming is built on 3 main concepts

These concepts are grouped together to find


solutions.

Sequential Conditional Loops


Statements are executed Selective statement(s) are executed depending on One or more statements are repeated till a
one after another meeting certain criteria. test condition is met or whilst a test
according to their order. condition is TRUE.
Purpose: To allow different paths through a program
depending on meeting certain criteria. Purpose: To repeat same or similar code a
number of times, which allows for shorter
code.
Sequential VS
Conditional
Sequential Conditio
nal
Code
Conditional statement
It is statement which carries two possible IF [ ] Then
outcomes.
Depends on criteria
ELSE
Using one of the most used conditional statements
( IF Statements )
ENDIF
Conditional statement
First key is to know how to construct the
IF statement criteria which is called the
Condition

IF [ Weather is cold? ] THEN

ELSE

ENDIF
Conditional statement
How to develop the Condition for
computer logic
Computer Only understands numbers by
comparison
IF [ Temperature <= 10 ] THEN
Using Logical signs
<,
>,
=,
>=,
<=, ELSE
<>

ENDIF
Screen
Quick question
Write a program that take from user his
age and
Print weather he is adult or not
Code
Screen
Quick question
Create a program that ask the user to enter
number and show if it is zero or not.

Code
Screen
Quick question
Design a program that take from the user his
height in CM an decide whether he is “Tall” Or
“Short”
Tall users are more than 175 cm.
Code
Screen
Quick question
-Extend the previous program as if the user
considered Tall the show his height in meters
( 100cm: 1Meter) ,and if the user is considered Short
the show his height in inches( 1 inch: 2.54 cm).

Code
Logic statement
Its tool to combine two statements in one condition

AN O
D
True Only if the two statements are
R
True Only if the two statements are true or
true ,False otherwise either of them, False otherwise.

IF [ height >175 AND age>=18 ] THEN IF [ height>175 OR age>=18 ] THEN

ELSE ELSE

ENDIF ENDIF
Screen
Quick question
Create program to enter quiz grade as if grade is
between 70 to 100 then show “Great” as a message
otherwise, show “need to study”

Code
Screen
Quick question
Design a program that inputs a number and prints
“Correct range” if the number is between 1 and 20
(inclusive) or between -1 and -20 (exclusive),
otherwise the program outputs “Wrong range”.

Code
Re-Call
Flowchart
Screen
Quick question
Design program that show “You’re bluffing “in case
user entered his age less than 0 also if he entered age
more than 100, otherwise show “you are good”.

Code
Validation
It is a process of filtering data that user control from insensible
data
To prevent program from working or storing
incorrect values
Screen
Quick question
Create program for User that should enter age
make sure that the maximum age entered by user is
less than 100 . if not less than 100 print Error
message.

Code
Screen
Quick question
Design a pseudocode that will read the side length of a square and displays its
perimeter and area.
Note that
The perimeter = 4*side
The area = side * side
Display an error message if the side length is negative.

Code
Screen
Quick question
Design an algorithm that inputs a sphere's radius from the user
and the program calculates the surface area and then outputs the
result.
Note that the surface area = 4*π*radius 2 (π = 3.14)
Validate the inputs.
Code
Screen
Quick question
Create program that convert from minutes to hours,
and print the time in hours
Validate the inputs.

Code
Screen
Test
Design a program that inputs a binary digit from the user. The
program should output ON and OFF in case the user entered 1
and 0 respectively.
In case the user entered any other value than 1 or 0, the
program must display an error message.
Code
Next Session

Programming pt.4

HW
THANKS

You might also like