Page 296 - Computer_Science_F5
P. 296

a “function” to state a grade class      Write the C++ program that prints
                   mark. Apply Table 4.18 to display        all the elements in majumuisho. All
                   the grade class marks of students.       elements in the same row should
                                                            appear on the same line, and each      Chapter Four: Object oriented programming with C++
                  Table 4.18: Grade pass mark               successive row should appear on
          FOR ONLINE READING ONLY
                  AVERAGE CLASS          GRADE              its own line.
                  MARK
                                                         4.  Consider the declaration int
                        81 – 100            A
                                                            mayah[50][100][100][25];. How
                         61 –80             B               many elements does mayah hold?
                        41 – 60             C

                        21 – 40             D
                         0 – 20             F          String
                                                       A string can be defined as a collection
               2.  Use a multi-dimensional array to    of characters. It is a one-dimensional
                   create a C++ program that asks      array made by characters.  A string
                   a student to enter the order and    should be terminated by a null character
                   elements of the matrix. Then, the   represented by ‘/0’. Termination of the
                   program should display a matrix
                   and its transpose as represented in   string is essential to make the function
                   Figure 4.65.                        know the end of the string.

                                                       Declaration of a string
                                                       A string can be declared as char
                                                        stringName[stringSize] ;


                                                       Initialisation of the string
                                                       Initialisation of the a string is done by
                                                       introducing the string value to the string.
                                                       An example of string initialisation is:

                                                        char name[ ] = {‘J’,‘U’,‘M’,‘A’,‘/0’};.


                                                       String standard function

                   Figure 4.65: Output of the program  C++  programming  language  provides
                                                       different string standard library handling
               3.  Consider the declaration:  int      functions. Some of the string library
                   majumuisho[10][20];                 functions are represented in Table 4.19.


                                                    287
               Student’s Book  Form Five



     Computer Science Form 5.indd   287                                                     23/07/2024   12:34
   291   292   293   294   295   296   297   298   299   300   301