CP2 Module 6 - Operators and Strings
CP2 Module 6 - Operators and Strings
COMPUTER PRORAMMING 2 2
What is a C++ Operator?
• are used to perform operations on variables and values
• use the + operator to add together values
COMPUTER PROGRAMMING 2 3
What are the types C++ Operators?
• Arithmetic – perform common mathematical operations
• Assignment – used to assign values to variables.
• Comparison - used to compare two values (true or false).
• Logical – used to determine the logic between variables or
values (and, or, not)
COMPUTER PROGRAMMING 2 4
Arithmetic Operators:
- perform common mathematical operations
Source: https://www.w3schools.com/cpp/cpp_operators.asp
COMPUTER PROGRAMMING 2 5
Assignment Operators:
COMPUTER PROGRAMMING 2 6
Source: https://www.w3schools.com/cpp/cpp_operators_assignment.asp
Comparison Operators:
- The return value of a comparison is either true (1) or false (0)
COMPUTER PROGRAMMING 2 7
Source: https://www.w3schools.com/cpp/cpp_operators_assignment.asp
Logical Operators:
AND OR NOT
TT = T TT = T TT = F
TF = F TF = T TF = F
FT = F FT = T FT = F
FF = F FF = F FF = T
COMPUTER PROGRAMMING 2 8
Source: https://www.w3schools.com/cpp/cpp_operators_assignment.asp
What are Strings?
• Strings are used for storing text
• How to concatenate strings?
• Use the + operator between strings to add them together
to make a new string
Output:
Juan Dela Cruz
COMPUTER PROGRAMMING 2 9
What are Strings?
• How to concatenate strings?
• Use the append() function between strings to add them together
to make a new string
• To use the append() function, add the <string> library in the
header portion
Output:
Juan Dela Cruz
COMPUTER PROGRAMMING 2 10
References:
• Pomperada, Jake. 2019. Beginner’s Guide to C++ Programming.
Manila: Mindshapers Co., Inc.
• Pepito, Copernicus. 2009. Introduction to C++ 2008 programming.
Manila: National Bookstore.
• https://www.codecademy.com/courses/learn-c-plus-plus
• https://www.w3schools.com/cpp/default.asp
• https://www.tutorialspoint.com/cplusplus/index.htm
COMPUTER PROGRAMMING 2 11
COMPUTER PROGRAMMING 2 12
COMPUTER PRORAMMING 2