Page 253 - C++
P. 253

CBSE AISSCE 2016-2017 Marking Scheme for Computer Science
                                         (Sub Code: 083 Paper Code 91/1 Delhi)


                           A SENTENCE

                   Ans      void JTOI()
                            {
                              char ch;
                              ifstream F("WORDS.TXT" );
                              while(F.get(ch))
                              {
                                if(ch==’J’)
                                    ch=’I’;
                                 cout<<ch;
                              }
                              F.close();  ​//IGNORE
                            }

                            OR
                            Any other correct function definition

                            (1 Mark for opening WORDS.TXT / WORD.TXT correctly)
                            (1  Mark for reading each character ​(using any method)​ from the file)
                            (1  Mark for displaying ‘I’ in place of ‘J’)
                   (b)    Write a definition for function COUNTDEPT( ) in C++ to read each object of a                                         2
                          binary file TEACHERS.DAT, find and display the total number of teachers in the
                          department MATHS. Assume that the file TEACHERS.DAT is created with the help
                          of objects of class TEACHERS, which is defined below:
                          class TEACHERS

                          {
                            int TID; char DEPT[20];
                          public:
                            void GET()
                            {
                                 cin>>TID;gets(DEPT);
                            }

                            void SHOW()
                            {
                              cout<<TID<<":"<<DEPT<<endl;
                            }
                            char *RDEPT(){return DEPT;}
                          };

                   Ans    void COUNTDEPT()
                          {

                             ifstream F;
                            F.open("TEACHERS.DAT",
                                            ios::binary);
                             int count=0;
                             Teachers obj;

                                                     Page #12 of 28
   248   249   250   251   252   253   254   255   256   257   258