0% found this document useful (0 votes)
2 views

COMPUTER PROGRAMMING M5

This document outlines a laboratory exercise for a Computer Programming 1 course focused on conditional control structures in C++. It includes program outcomes, course learning outcomes, intended learning outcomes, background information on conditional statements, and specific activities for students to complete. Additionally, it provides a rubric for evaluating the completed exercises.

Uploaded by

guzmandeyani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

COMPUTER PROGRAMMING M5

This document outlines a laboratory exercise for a Computer Programming 1 course focused on conditional control structures in C++. It includes program outcomes, course learning outcomes, intended learning outcomes, background information on conditional statements, and specific activities for students to complete. Additionally, it provides a rubric for evaluating the completed exercises.

Uploaded by

guzmandeyani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

COLLEGE OF COMPUTER STUDIES AND MULTIMEDIA ARTS

CCS0006L
(COMPUTER PROGRAMMING 1)

EXERCISE

5
CONDITIONAL CONTROL STRUCTURES

Student Name / Group


Anaiah O. De Guzman
Name:

Name Role
Members (if Group):

Section:
TD04
Professor:
Sir John Benedict Legaspi
I.​ PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE
●​ Analyze a complex problem and identify and define the computing requirements appropriate to its solution.
[PO: B]
●​ Design, implement and evaluate computer-based systems or applications to meet desired needs and
requirements. [PO: C]

II.​ COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE


●​ Select and apply appropriate program constructs in developing computer programs. [CLO: 2]
●​ Develop, test and debug computer programs based on a given specification using the fundamental
programming components. [CLO: 3]

III.​ INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY EXERCISE


At the end of this exercise, students must be able to:
●​ Know the importance of each type of conditional control structures and how to implement it in a
C++ program.
●​ Write C++ programs that use different conditional control structures to solve problems.

IV.​ BACKGROUND INFORMATION

Conditional control statements are at the very core of programming, in almost any language. The idea
behind conditional control is that it allows you to control the flow of the code that is executed based on
different conditions in the program, input taken from the user, the internal state of the machine the
program is running on, etc.

Conditional statements specify whether another statement or block of statements should be executed
or not. These are often called "selection constructs". A conditional expression is an expression that
produces a true or false result. There are three major structures related to the conditional execution of
code in C/C++ - the if statement, the if-else statement, and the switch-case statement.

A.​ if-statement

Syntax:

CCS0003L-Computer Programming 1​ ​ Page 2 of 10



​ if(condition_expression)
​ ​ ​ statement;

Where condition is the expression that is being evaluated. If this condition is true, statement is
executed. If it is false, statement is ignored (not executed) and the program continues right after this
conditional structure.

Example:

​ if (x == 0)
​ ​ System.out.println(“The no. is zero.”);

B.​ if-else statement

Syntax:

if(Condition_Expression)​
Statement_TRUE;​
else​
Statement_FALSE;

​ If the if statement evaluates to true, then all the statements inside the if block are executed and the
else if will be ignored. When the if statement is false, it will then check the condition in the else if
statement.

Example No. 1

if (x >= 0)
​ System.out.println(“The no. is a whole number.”);
else
​ System.out.println(“The no. is a negative number.”);

Example No. 2

if (x %2 == 0)
​ JOptionPane.showMessageDialog(“It is EVEN.”);
else
​ JOptionPane.showMessageDialog(“It is ODD.”);

CCS0003L-Computer Programming 1​ ​ Page 3 of 10



C.​ if-ladder statement

Syntax:

if(Condition_Expression1)​
​ Statement1;​
else if(Condition_Expression2)​
Statement2;​
else if(Condition_Expression3)​
Statement3;​
else​
Statement-n;

Reminders:
●​ condition_expression contains the test expression. If the test expression evaluates to true (ie.
non-zero), StatementBlock is executed, otherwise the ElseStatementBlock is executed.
●​ If there is more than one statement to be executed within the ThenStatementBlock or
ElseStatementBlock branch, the blocks must be enclosed with {}'s.
●​ It is not necessary to have an else statement within each if() conditional.
●​ Multiple expressions can be evaluated by using conjunctions (e.g. &&, ||).
●​ Indent your programs to increase readability.
●​ Do not confuse the uses of assignment (=) and equality (==) operators, especially within the test
condition. They can have adverse effects on your program.

D.​ switch statement



The syntax of the switch statement is:

switch(expression) {​
case constant_value_1:​ statement1;
​ ​ ​ ​ break;​
case constant_value_2: statement2;
​ ​ ​ ​ break; ​
case constant_value_3: statement3;
​ ​ ​ ​ break;
case constant_value_n: statement_n;

CCS0003L-Computer Programming 1​ ​ Page 4 of 10



​ ​ ​ ​ break; ​
default: statement_default;​
}

​ When defining an expression whose result would lead to a specific program execution, the switch
statement considers that result and executes a statement based on the possible outcome of that
expression, this possible outcome is called a case.
​ The different outcomes are listed in the body of the switch statement and each case has its own
execution, if necessary. The body of a switch statement is delimited from an opening to a closing curly
brackets: “{“ to “}”.

V.​ LABORATORY ACTIVITY

ACTIVITY 5.1: Whatta Grade!!!

Get three exam grades from the user and compute the average of the grades. Output the average of the
three exams. Together with the average, also include a smiley face in the output if the average is greater
than or equal to 70, otherwise output :-(. Note: Use if-statement in the program.

Program: (save as [surname_5_1.cpp])

CCS0003L-Computer Programming 1​ ​ Page 5 of 10



Output:(screenshot of the output)

ACTIVITY 5.2: Compute Salary

Using if/else structure. Write a C++ program that will calculate an employee's salary. If the employee is
fulltime get his monthly salary ,Then display his name and salary.if the employee is part tim,get his rate per
hour and the total number of hours worked for the entire month. Then display his name and wage.

Sample output:
Enter Employee name: Shiela de guzman
Enter employee status (F or P):
Enter Salary: 34000 (in decimal)

(Output if the employee is Fulltime)


Employee name: Shiela de guzman
Status: Fulltime
Employee Salary: 34000.00

(Output if the employee is Partime)


Employee name: Shiela de guzman
Enter rate: 600
Enter hours worked: 12

Employee name: Shiela de guzman


Employee wage: 7200.00

CCS0003L-Computer Programming 1​ ​ Page 6 of 10



Output:(screenshot of the output)

CCS0003L-Computer Programming 1​ ​ Page 7 of 10



Activity 5.2b Using above code write a switch state? Note: use Employee status to in switch F or P (Using
switch statement)

Program: (save as [surname_5_2b.cpp])

Output:(screenshot of the output)

CCS0003L-Computer Programming 1​ ​ Page 8 of 10



VI.​ QUESTION AND ANSWER

Directions: Briefly answer the questions below.

●​ For you, which is preferably the most convenient control structure to be used in comparisons,
IF-ELSE or SWITCH?

If the variables to be compared is two, it is more convenient to use the IF-ELSE statement.
However, if there are more variables declared to be compared, then it is more convenient to use
the SWITCH statement.

●​ What do you think is the importance of having different if structures such as if statement, if-else
statement and nested-if statement?

Having different structures such as if statement, if-else statement, and nested-if statement is easier
for to have to executed with different conditions in making a program. For example, if the
conditions for the if-statement have not been met, then we could still manage to create the
program using the other structures.

VII.​ REFERENCES​
●​ Abraham (2015). Coding for dummies. John Wiley and Sons: Hoboken, NJ
●​ Zak, D (2015). An Introduction to Programming with C++. 8th Edition
●​ Cadenhead, R et. Al. (2016). C++ in 24 Hours, Sams Teach Yourself (6th Edition).Sams Publishing
●​ McGrath, M. (2017). C++ programming in easy steps (5th ed.). Warwickshire, United Kingdom: Easy
Steps Limited
●​ Tale, T. (2016). C++: The Ultimate Beginners Guide to C++ Programing. CreateSpace Independent
Publishing Platform​
●​ http://cs.uno.edu/~jaime/Courses/2025/devCpp2025Instructions.html

RUBRIC:

Criteria 4 3 2 1 Score

CCS0003L-Computer Programming 1​ ​ Page 9 of 10



A completed
A completed solution is An incomplete
A completed
solution is implemented solution is
solution runs
tested and runs on the required implemented
without errors.
but does not platform, and on the required
It meets all the
meet all the uses the platform. It
specifications
specifications compiler​ does not
and works for
nd/or work for specified. It compile and/or
all test data.
all test data. runs, but has run.
Solution(x5) logical errors.

The program Not all of the


The program Few of the
design selected
design uses selected
generally uses structures are
appropriate structures are
appropriate appropriate.
structures. The appropriate.
structures. Some of the
overall Program
Program program
program elements are
elements elements are
design is not well
exhibit good appropriately
Program appropriate. designed.
design. designed.
Design(x3)

All required There are few


All required
parts of the parts of the Most of the
parts in the
document are document are parts of the
document are
complete and missing but the document are
present and
correct(code, rest are missing and
correct but not
output of complete and incorrect.
Completeness complete.
screenshots) correct.
of
Document(x2)
Total

CCS0003L-Computer Programming 1​ ​ Page 10 of 10


You might also like