Page 356 - C++
P. 356

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

                           (1 Mark for only the final answer as ​UV*WZ-X/+ ​)

              4.     (a)   A text file named ​MATTER.TXT contains some text, which needs to be displayed                                      3
                          such that every next character is separated by a symbol ‘#’.

                          Write a function definition for ​HashDisplay​() in C++ that would display the entire
                          content of the file ​MATTER.TXT​ in the desired format.
                          Example:
                          If the file MATTER.TXT has the following content stored in it:

                           THE WORLD IS ROUND

                          The function ​HashDisplay​() should display the following content:
                          T#H#E# #W#O#R#L#D# #I#S# #R#O#U#N#D#

                    Ans     void HashDisplay()
                            {
                              char ch;
                              ifstream F("MATTER.TXT" );
                              while(F.get(ch))
                                 cout<<ch<<'#';
                              F.close();  //IGNORE
                            }

                            OR
                            Any other correct function definition




                            (1 Mark for opening ​MATTER.TXT​ correctly)
                            (1  Mark for reading each character ​(using any method)​ from the file)
                            (½ Mark for displaying the character)
                            (½ Mark for displaying a # following the character)

                     (b)  Write a definition for function TotalTeachers( ) in C++ to read each object of a                                       2
                          binary file SCHOOLS.DAT, find the total number of teachers, whose data is stored
                          in the file and display the same. Assume that the file SCHOOLS.DAT is created
                          with the help of objects of class SCHOOLS, which is defined below:

                          class SCHOOLS
                          {
                            int SCode;       // School Code
                            char SName[20];  // School Name
                            int NOT;         // Number of Teachers in the school
                          public:
                            void Display()
                            {cout<<SCode<<"#"<<SName<<"#"<<NOT<<endl;}
                            int RNOT(){return NOT;}
                          };

                    Ans  void TotalTeachers()
                          {
                           ifstream F;
                           F.open("SCHOOLS.DAT",ios::binary);

                                                        Page #14/35
   351   352   353   354   355   356   357   358   359   360   361