Page 258 - Computer_Science_F5
P. 258

Operators, expressions and     operators, Relational operators, Logical
                        assignments                    operators, Increment and  decrement
                                                       operators,  Compound assignment
              Operators, expressions, and assignments   operators, and Short-hand assignment
              are fundamental components in            operator.                                   Chapter Four: Object oriented programming with C++
          FOR ONLINE READING ONLY
              programming languages, enabling the
              manipulation and evaluation of data.  (a) Arithmetic operators
              Operators perform operations on variables
              and values, forming expressions that     Arithmetic operators include arithmetic
              produce new values. Assignments then     operations such as addition, subtraction,
              store these resulting values into variables,   multiplication, and division. Table 4.7
              facilitating dynamic and efficient data   shows  arithmetic  operators  and their
              handling within a program.               meanings.

                                                       Table 4.7: Arithmetic operators
              Operators
              Once you have an idea of variables and     Operator      Meaning
              constants, you can decide to operate them       +        Addition
              in different ways. For that case, the C++       –        Subtraction
              programming language introduces signs           *        Multiplication
              or symbols used to link, join, or conduct       /        Division
              two or more data operations. Operators          %        Modulo division
              are required by the operands to conduct
              operations. There are binary operators that
              involve two operands and unary operators   Note:  Modulo division is the division
              that involve only one operand.                  that gives the remainder after one
                                                              integer  divide  another  integer.
              Types of operators                              Example 7%4 = 3.
              C++ programming languages use different   The  following C++ Program  Example
              types of operators depending on the      4.14 demonstrates how to change
              operation to be conducted. Such operators   seconds into minutes, hours and seconds.
              include: Arithmetic operators, Assignment   The output is shown in Figure 4.30.















                                                    249
               Student’s Book  Form Five



     Computer Science Form 5.indd   249                                                     23/07/2024   12:33
   253   254   255   256   257   258   259   260   261   262   263