Page 352 - C++
P. 352

CBSE AISSCE 2017-2018 Marking Scheme for Computer Science
                                       (2018-2019 Sub Code: 083       Paper Code: 91)

                           (½  Mark for adding odd elements)
                           (½ Mark for displaying the sum of even and odd elements)

                     (b)  Write definition for a function ​UpperHalf(int Mat[4][4]) in C++, which displays the                                 3
                          elements in the same way as per the example shown below.
                          For example, if the content of the array Mat is as follows:
                                           25 24 23 22

                                           20 19 18 17
                                          15 14 13 12

                                          10  9  8  7
                          The function should display the content in the following format:
                                          25 24 23 22
                                          20 19 18

                                           15 14
                                         10

                    Ans  void UpperHalf(int Mat[4][4])
                          {
                             for (int I=0;I<4;I++)
                             {
                               for (int J=0;J<4-I;J++)
                                   cout<<MAT[I][J]<< "  " ;
                                cout<<endl;
                             }
                          }
                          OR
                          void UpperHalf(int Mat[4][4])
                          {
                             for (int I=0;I<4;I++)
                             {
                                for (int J=0;J<4;J++)
                                  if ((I+J)<=3)
                                    cout<<MAT[I][J]<< "  " ;
                                cout<<endl;
                             }
                          }
                          OR
                          Any other correct alternative code in C++

                           (½  Mark for correctly writing loop for traversing rows)
                           (½  Mark for correctly writing loop for traversing columns in each row)
                           (1  Mark for correctly checking elements for display)
                           (½  Mark for correctly displaying the selected elements)
                           (½  Mark for correctly displaying line break after each row)

                     (c)   Let us assume Data[20][15] is a two dimensional array, which is stored in the                                     3
                          memory along the row with each of its element occupying 2 bytes, find the

                                                        Page #10/35
   347   348   349   350   351   352   353   354   355   356   357