Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

COMPUTER

PROGRAMMING
II
SESSION
II

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 1
Lesson Objectives:

• Decision Making Statements


• If statement,if else, nested if
• Switch statement
• Iteration Statements
• While Loop
• Do while Loop
• For Loop
Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 2
Decisions:

• A decision asks a question that can be answered true or


false, yes or no. Decisions are widely used in most
programs
• A decision can be thought of as having three parts: a test
condition to be examined, one or more instructions to
follow when the test condition is true, and one or more
instructions to follow when the test condition is false.
Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 3
Logical Operators:

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 4
if Statement:

• Its a conditional statement which is used to make


decision.
• It is used when a single condition is to be checked.
• A condition is enclosed in if statement which decides the
sequence of execution of instruction.
• If the condition is true, the statements inside if statement
are executed, otherwise they are skipped.
Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 5
If Statement:

• Structure syntax

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 6
If Example:

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 7
If Example:

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 8
If Else:

• It is used to control the program flow based on some


condition, only the difference is: it's used to execute some
statement code block if the expression is evaluated to true,
otherwise executes else statement code block.

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 9
If else structure:

• Structure Syntax

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 10
If Else Example:

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 11
If else example:

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 12
Nested if else:

• It is used for multiple branching.


• When there are two or more conditions that needs to be
checked to decide which block of statement is to be
executed, it is used.
• The number of else if statements depends upon the
number of conditions to be checked

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 13
Nested if Structure :

• Structure Syntax

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 14
Nested If Example :

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 15
Nested If Example :

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 16
Task :

• Write a program that captures a students mark and


displays the equivalent Division as shown

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 17
Switch..case Statement

• allows a variable to be tested for equality against a list of


values.
• Each value is called a case, and the variable being
switched on is checked for each case.

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 18
Switch Structure/syntax:

• Structure Syntax

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 19
If :

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 20
TASK :

1. Write a C++ program that requests an integer value from


the user. If the value is between 1 and 100 inclusive, print
“OK;” otherwise, do not print anything
2. Write a C++ program that requests an integer value from
the user. If the value is between 1 and 100 inclusive, print
“OK;” otherwise, print “Out of range.”

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 21
ITERATION

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 22
Iteration :

• Iteration repeats the execution of a sequence of code.


• Iteration is useful for solving many programming
problems.
• They include
• While statement
• Do while statement
• For statement
Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 23
loop Control Statements:

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 24
While Loop :

• allows to repeatedly run the same block of code until a


condition is met.
• It has one control condition, and executes as long the
condition is true.

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 25
While Example :

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 26
Do While :

• They are very similar to the while loops, but it always


executes the code block at least once and furthermore as
long as the condition remains true.

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 27
Do while Example :

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 28
for Loop :

• It is very similar to a while loops in that it continues to


process a block of code until a statement becomes false,
and everything is defined in a single line.

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 29
For Loop example :

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 30
Task:

• Using a loop of your choice, write a program that accepts


the quantity sold and unit price of 3 items and displays in
the format below

Click here to download this powerpoint template : Brown Floral Background Free Powerpoint Template
For more : Templates For Powerpoint

Page 31

You might also like