3

You might also like

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

Course: CPE 002A Experiment No.

: 3
Name: Lee Ann Imperial Section: CHE11S1
Date Performed: 4/13/21
Date Submitted: 4/15/21
Instructor: Ms. Cherry Casuat

LABORATORY
ACTIVITY NO.3

CONTROL
STRUCTURE
(Conditional
Structure)

1. Objective(s):

The activity aims to introduce a conditional structure using analytical tools


such as algorithm and flowchart to evaluate the output based on the
requirement whether true or false.
2. Intended Learning Outcomes (ILOs):

The students shall be able to:

1. Construct a program that applies conditional statements.


2. Apply appropriate conditional statement in a given problem.

3. Discussion:

Conditional statements are programming statement which allows


conditions to be stated and proper selection of output to be processed in
order to display values that meet the condition. It’s either true conditionals
or false conditionals. The conditional statements used in C++ are if
statement, if else statement.. , if.. and Else if (nested If). These statements
are capable in performing selection based on the given selection.
Conditional structure or selection structures also called the decision
structure, when you want to make a decision or comparison and then
select one of two paths, depending on the result of the decision or
comparison. Although the idea of using this structure in a program is new,
the concept of this structure is already familiar to you, because you use it
each day to make hundreds of decisions. Any condition true or false value
will have its respective course of action.
The If/else statement

The if statement allows statements to be execute conditionally.

Syntax:

if (<conditional expression>)

{
statement;
}

If the expression evaluates to true (non-zero), the statement executes. If the


expression evaluates to false, the else statement is executed if it exists.

Syntax:

if (<conditional
expression>))
statement1;
else
if (<conditional
expression>))
statement2;
else
if (<conditional
expression>))
statement3;
4. Resources:
DevC++
5. Procedure and Output

EXERCISE No. 1

A student took four quizzes in a term and would like to compute their
average. He also would like to know if the average has a passing mark. Note
that the passing mark is 75%.

REQUIREMENTS:

1. Write the corresponding algorithm


a. Narrative
b. Pseudocode
2. Create the equivalent flowchart based on the algorithm of the given
problem
3. Construct the program and record your screen display result
ALGORITHM
NARRATIVE
PSEUDOCODE
Step 1: Start Start
Step 2: Enter the marks obtained Define and read float q1,q2,q3,q4
In all four quizzes avg= (q1+q2+q3+q4)/4
Step 3: Divide it by four print (avg)
Step 4: If average is greater than equal if avg >=75, print (“Pass”)
75 = passed otherwise failed otherwise, print(“Fail”)

FLOWCHART
START

Define q1,q2,q3,q4, avg as


float

Read q1, q2, q3, q4

Avg=(q1+q2+q3+q
4)/ 4

Print avg

Avg >= 75

YES
NO Print PASSED
Print FAILED

END
Record your screen display:

QUESTIONS:

1. What statement in the program that determines that the average is


passing?
If (avg >=75) {
cout<<”PASSED”;
}
else{
cout<<”FAILED”;
}
2. What was the condition applied to satisfy the requirement?

avg >=75

3. What have you observed in using if-else statement in this program?


If the IF statement is true like avg >=75, then the student has Passed, otherwise the else
statement will
state that the student has failed.
EXERCISE No. 2

Mary Jane would like to invest her money amounting 100,000 at the bank.
Before investing her money, she would like to determine which type of
account that she will chose. The amount of interest that her money earns
depends on which type of account the money is in. The bank has 6 different
types of accounts and they earn interest as follows:

Account type Interest


earned
personal financial 1.5%
personal homeowner 2.0%
personal gold 2.5%
small business 3.0%
big business 3.5%
gold business 4.0%

Mary Jane as a programmer would like to make a program that computes


automatically the interest earned of her money in each type of account.
REQUIREMENTS:

1. Write the corresponding algorithm


a. Narrative
b. Pseudocode
2. Create the equivalent flowchart based on the algorithm of the given
problem
3. Construct the program and record your screen display result

ALGORIT
HM
NARRATI PSEUDOCODE
VE
FLOWCH
ART

Record your screen display:


QUESTIONS

1. What are the data needed for the solution of the program to produce the
desired output?

2. What statements in the program that determines interest earned of each


type of account?

3. What was the condition applied to satisfy the requirement?

4. What have you observed in using nested if statement in this program?

EXERCISE No.3

A student took four quizzes in a term and would like to compute their
average. He also would like to know what will be the remarks. Follow the
range of grades and its equivalent remarks, and then fill-up the table below:

100-95 - Excellent
94-90 – Very
Satisfactory
89-85 -
Satisfactory
84-80 - Fine
79-75 - Fair
74 and below –
Poor

REQUIREMENTS

1. Write the corresponding algorithm


a. Narrative
b. Pseudocode
2. Create the equivalent flowchart based on the algorithm of the given
problem
3. Construct the program and record your screen display result
ALGORIT
HM
NARRATI PSEUDOC
VE ODE

FLOWCH
ART
Record your screen display:

QUESTIONS:

1. What statement in the program that determines that the average is


passing?

2. What was the condition applied to satisfy the requirement?

3. What have you observed in using if-else statement in this program?

4. What have you observed in using nested if statement in this program?


SUPPLEMENTAL ACTIVITIES

1. Get the value of variable num assuming it is equal to 5.


if (num >=
6) cout
<< "Yes";
cout << No;

What will be the output?

_ Explain your answer.

2. What is the output of the following code fragment assuming num is


10?
if (num == 20)
cout <<
"teenager";
cout <<
"adult"

Record the output screen display:


Explain your answer.

3. After execution of the following code, what is stored in valueNum?


All variables are using data type int. Note that num1=3, num2=5, and
num3=7.

if (num2> num3)
if (num1 >
num2)
valueNum
=num2;
else
valueNum =num3;
else
if (num2 >
num3)
valueNum
=num1;
else
valueNum = num3;
Record the output screen display:
Explain your answer.
6. Conclusion:

You might also like