You are on page 1of 14

TOPIC 3

PROGRAM CONTROL
STRUCTURE (Part 2)
By end of this class :

• Understand Program Control Structure


• Solve problems using selection control structures
• Solve problems using loops control structures
Differentiation of
Assignment and Relational operators
= is NOT the same as the operator ==

Used to assign a value to a Used to test whether two


variable operands are equal in value

If a=3, b = 5
a=b would give a new value
which is 5
≠ If a=3, b = 5
a==b would return a FALSE value
Class Activity
In group of TWO :
1. Write algorithm
2. Convert into
program code
using given
selection
statement

Activity 1
Activity 1
multiple if statement
Write a program to test the input of
TWO numbers.
i. Print the message "SAME" if the two numbers have
Tips: equal value.
Use the
simple logical
ii. Print the message "THE FIRST NUMBER IS BIGGER" if
operators the first number is greater than the second number.
that you have iii. Print the message "THE SECOND NUMBER IS BIGGER"
learn. if the second number is greater than the first number.
(<,>, <=, =>,
==,! =)
Class Activity
In group of TWO :
1. Write algorithm
2. Convert into
program code
using given
selection
statement

Activity 2
Activity 2
multiple if statement
Write a program using multiple if statement to
receive grade from a user and display the output as
below
Grade Message
A Min marks is 80
B Min marks is 60
C Min marks is 40
D Min marks is 25
Ungraded Min marks is 0-24
Class Activity
In group of TWO :
1. Write algorithm
2. Convert into
program code
using given
selection
statement

Activity 3
Activity 3
nested if statement
Write a program using nested if statement to receive
grade from a user and display the output as below

Grade Message
A Min marks is 80
B Min marks is 60
C Min marks is 40
D Min marks is 25
Ungraded Min marks is 0-24
Class Activity
In group of TWO :
1. Write algorithm
2. Convert into
program code
using given
selection
statement

Activity 4
Activity 4
switch statement
Write a program using switch statement to receive
grade from a user and display the output as below

Grade Message
A Min marks is 80
B Min marks is 60
C Min marks is 40
D Min marks is 25
Ungraded Min marks is 0-24
Exercise

Base on your workbook of DFC2073 workbook

<Complete Lab Activity 3A>


References
• http://www.learncpp.com/
• http://www.tutorialspoint.com/cplusplus/
Next Class
TOPIC 3 :
Program Control
Structures (Part
3)

Do you have any question??

DFC2073 Programming Fundamentals


Astri

You might also like