Grade 10 Q3 Module1 Operators in C
Grade 10 Q3 Module1 Operators in C
Quarter 4 – Module 1:
Operators in C++
Self-Learning Module
Learner’s Material
I Need to Know
In this module, you will be introduced to different learning activities preparing you
to be skillful before you take the plunge into the world of Programming.
This module is specifically crafted to focus on Programming Language C++
enriched with learning activities that will assess your level in terms of skills and knowledge.
2
Lesson
1 Operators in C++
Lesson Overview
Computer programs are widely used for mathematical calculations. We can write a
computer program which can do simple calculation like adding two numbers (2 + 3) and
we can also write a program, which can solve a complex equation like P(x) = x4 + 7x3 - 5x
+ 9. In the first expression, 2 and 3 are operands and + is an operator. Similar concepts
exist in Computer Programming.
Arithmetic/Mathematical Operators
Relational Operators
Logical Operators
Relational Operators
A relational operator is a programming language construct or operator that tests
or defines some kind of relation between two entities. These include numerical equality
(e.g., 5 = 5) and inequalities (e.g., 4 > 3). All of the relational operators result in a Boolean
value (TRUE or FALSE).
There are six relational operators used for data comparisons in C++. These
operators must always appear between 2 literals, 2 variables, 2 arithmetic expressions, or
a combination of these possibilities.
3
Assume variable A holds 10 and variable B holds 20
Logical Operators
Logical operators, sometimes called boolean operators, evaluate expressions and
decide what boolean should be expressed from the evaluation.
4
I Will Do This
Let’s Review. This is a Program Completion, just fill in the missing item to complete
the program.
//Miguelito Santos
//A program that computes the sum of three whole numbers.
#include 1. ________
using namespace std;
int main( )
2. ________
3. ________ num1, num2, 4. ________, 5. ________; //variable declaration
I Learned This
I have learned that C++ Programming Language is rich in built-in operators. Aside
from Arithmetic Operators, C++ supports Relational and Logical Operators. Relational
Operators are
______________________________________________________________________
______________________________________________________________________
_______________________________________________, while Logical Operators are
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________.
5
I Practice This
For each of the following statements, assign variable names for the unknowns and
rewrite the statements as relational expressions. Remember in writing relational
expressions, an operator is always in between a variable and a literal value.
For each of the following statements, assign variable names for the unknowns and
rewrite the statements as logical expressions.
Example: The current day is the 7th of the 4th month - D==7 && M==4
D and M are the assigned variables
== equal to and && logical and are used as relational and logical operators
7 and 4 are the given value for day and month respectively
1. The person's age is 65 or more and their sub total is more than $100.
2. A person is older than 55 or has been at the company for more than 25 years.
3. A width of a wall is less than 4 metres but more than 3 metres.
4. An employee's department number is less than 500 but greater than 1, and
they've been at the company for more than 25 years.
I Apply This
int i = 5, j = 7, k = 12;
6
Complete the table by writing its value (0 or 1) and its interpretation (True or False).
Post Test
Read each sentence carefully. Select the letter of the best answer.
5. Which of the following relational operator is used to check if the value of left
operand is less than or equal to the value of right operand?
A. <=
B. >=
C. ++
D. ==
7
6. What is the other term for Logical Operators?
A. Arithmetic Operators
B. Boolean Operators
C. Increment Operators
D. Binary Operators
7. If both the operands are non-zero in a logical expression, then one of the following
operator is applied
A. Logical OR
B. Logical NOT
C. Logical AND
D. None of the above
8. How do you write the statement, Voting age is 18 and above into relational
expression?
A. Age > 18
B. Age <= 18
C. Age == 18
D. Age >=18
9. Which of the following statement is TRUE about the Logical Operator OR?
A. If both the operands are non-zero
B. If the values of two operands are equal or not
C. If any of the two operands is non-zero
D. None of the above
10. This operator is used to reverses the logical state of its operand. If a condition is
true then this operator will make it false.
A. !
B. &&
C. ||
D. ++
REFERENCES
https://www.programiz.com/cpp-programming/relational-logical-operators
Mathbitz.com
https://www.tutorialspoint.com/computer_programming/computer_programming_operators
09173003745 / 09479469720