Divine Programming
Allah’s Messenger (peace be upon him) said:
“The first thing which Allah created was the Pen.
He commanded it to write (program).
It asked: What should I write (program)?
He said: Write the Decree (al-Qadr, the fate (code) of
all things).
So it wrote (programmed) what had happened
and what was going to happen up to eternity.
(Tirmidhi)
Computer
Programming
Zain Ul Abideen Tariq
BE (Computer Engineering, NUST)
MS (Computer & Communications Security, NUST)
Week 4 | Lecture 6 & 7
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Air University, Islamabad
Presentation Outline
Relational Operators
Logical Operators
if statement
if-else statement
Nested if-else statement
Questions & Answers
Operators
Relational Operators
Relational Operators:
Used for Comparison between two quantities or qualities.
Result is Boolean value i.e. either TRUE or FALSE.
Relational Operators
Examples:
17 < 1 is false
17 <= 17 is ?
if x is 50, then
x == 50 is true,
x != 80 is true
x == 80 is ?
Logical Operators
Logical Operators:
Used for Logical operations.
Result is Boolean value i.e. either TRUE or FALSE.
Logical Operators
Conditional Statements
if Statement
Conditional Statement
Allows statements to be conditionally
executed or skipped over
Models the way we mentally evaluate
situations:
“if it is raining, take an umbrella."
“if it is cold outside, wear a coat."
if Statement
General Format
if (expression)
Statement;
If the expression is true, then
statement is executed.
If the expression is false, then
statement is skipped.
if Statement
General Format
if (expression)
Statement;
If the expression is true, then
statement is executed.
If the expression is false, then
statement is skipped.
if Statement
if Statement
if Statement Expansion
• To execute more than one statement as part of
an if statement, enclose them in { }:
if (score > 90)
{
grade = 'A';
cout << "Good Job!\n";
}
• { } creates a block of code
Featured Video
Hour of Code:
Bill Gates
Explains
if Statement
1 min 46 seconds
Challenge
Question:
Code this Flowchart
if-else Statements
If-else Statement
If-else Statement
General Format
if (expression)
Statement1;
else
Statement2;
If the expression is true, then
statement1 is executed.
If the expression is false, then
statement2 is executed.
If-else Statement
Q&A
Useful Link for Online Practice
Online Programming Platform for Learning and
Practicing in Multiple Programming Languages
http://ide.geeksforgeeks.org
Useful Resource
Brian Overland,
“C++ without Fear: A
Beginner’s Guide that
make you feel Smart ”
(3rd Edition or onwards),
• Available as pdf e-book
Download Link:
http://tinyurl.com/yb4ljzzg
Course Reources
Reference Books:
• Deitel and Deitel, “C++ How to Program” (8th or 9th
Edition), Available as e-book and paper book
• Robert Lafore, “Object-Oriented Programming in C++”,
3rd or 4th Edition
• Stephen R Davis, “C++ for Dummies”, 7th Edition or
onwards
• Gaddis, Walters & Muganda, “Starting Out with C++:
Early Objects”, 7th Edition or onwards
• Brian Overland, “C++ without Fear: A Beginner’s Guide
that make you feel Smart ”,3rd Edition or onwards
Useful Links:
http://scratch.mit.edu
http://studio.code.org
https://snap.berkeley.edu
http://www.cplusplus.com
http://ide.geeksforgeeks.org
Thankyou