Page 303 - C++
P. 303

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

                   (b)    Write a definition for function COUNTPICS ( ) in C++ to read each object of a                                           2
                          binary file PHOTOS.DAT, find and display the total number of PHOTOS of type
                          PORTRAIT. Assume that the file PHOTOS.DAT is created with the help of objects of
                          class PHOTOS, which is defined below:
                          class PHOTOS
                          {
                            int PCODE;
                            char PTYPE[20];//Photo Type as “PORTRAIT”,”NATURE”

                          public:
                            void ENTER()
                            {
                                  cin>>PCODE;gets(PTYPE);
                            }
                            void SHOWCASE()
                            {
                              cout<<PCODE<<":"<<PTYPE<<endl;
                            }
                            char *GETPTYPE(){return PTYPE;}
                          };
                   Ans    void COUNTPICS()
                          {
                             ifstream F;
                             F.open("PHOTOS.DAT",
                                               ios::binary);
                             int count=0;
                             PHOTOS obj;
                             while(F.read((char*)&obj,
                                                sizeof(obj)))

                             {
                               if(strcmp(obj.GETPTYPE(),“PORTRAIT”)==0)
                                   count++;
                             }
                             cout<<”Number of PORTRAIT photos :”<<count;
                             F.close(); //IGNORE
                          }
                          OR
                          Any other correct function definition
                          (½ Mark for opening PHOTOS.DAT correctly)
                          (½  Mark for reading records from PHOTOS.DAT)
                          (½ Mark for comparing  PHOTOS of type PORTRAIT(ignore case sensitive
                          checking) with strcmp or strcmpi)
                          (½ Mark for displaying counter for matching records)
                   (c)     Find the output of the following C++ code considering that the binary file                                     1
                           CLIENTS.DAT exists on the hard disk with a data of 200 clients.
                           class CLIENTS
                           {
                               int CCode;char CName[20];
                           public:

                                                     Page #13 of 28
   298   299   300   301   302   303   304   305   306   307   308