Page 250 - Computer_Science_F5
P. 250

Questions.
                    (a)  What is the output if the input is Akilimali J?

                    (b)  What is the output if the input is Salome A?
                    (c)  What is the output if the input is Abas H?                                Chapter Four: Object oriented programming with C++
          FOR ONLINE READING ONLY
               4.  Write a program that asks the user to enter the length of the sides of a triangle
                   and outputs the shape of the triangle.
               5.  What is the difference between the character ‘n’ and the character ‘\n’?




                         Variables and constants       A variable is a name that defines a specific
                                                       location in the computer memory. It is
              Variables and constants are fundamental  used to store data or information within
              concepts  in  programming that  enable  a computer program. They are called
              you to store and manipulate  data.  variables simply because their values
              Variables are containers that hold values  can be changed. Usually, variables store
              that can change during execution,  data of a specific data type; this means,
              allowing flexibility in our code. On the  to store a value into variable, you need
              other  hand,  constants  are  fixed  values  to know its data type. Each variable in a
              that  cannot  be  modified  once  defined,  program needs an identifier (unique name)
              providing stability and consistency in  to differentiate it from other variables.
              your programs. Understanding how to  For example, from the given scenario x, y
              effectively  use  variables  and constants  and “result” stands as variable identifiers.
              is  essential  in  developing  robust  and
              dynamic software solutions.              Rules for  naming  variables  in  C++
                                                       programming
              Variables                                (a) Commas and blank spaces are not

              Consider that you have been told to store     required in the variable name.
              the number 5 and 2 respectively in the   (b)  The  first  character  must  be  an
              computer memory. Then, you are asked          alphabet  or underscore,  but  not  a
              to  add  1  to  the  first  number  and  store   number.
              the results to the memory.  Afterward,   (c)  Variables should not be too long.
              you subtract  the second number from          Make sure it does not exceed eight
              the result you have obtained.  To the         characters.
              computer, the same process can be        (d) Special symbols such as $, &, and #
              conducted as follows:                         are not allowed within the variable
                       x=5;                                 names.
                       y=2;                            (e) Combination of numbers, alphabets,
                       x=x+1                                and underscores are allowed in the
                       result=x - y;                        variable names.

                                                    241
               Student’s Book  Form Five



     Computer Science Form 5.indd   241                                                     23/07/2024   12:33
   245   246   247   248   249   250   251   252   253   254   255