Page 106 - C++
P. 106

100, 40, 8, +, 20, 10, -, +, *

             4   (a) Observe the program segment given below carefully and fill the blanks marked in statement 1 using
                 seekg( ) or seekp( ) functions for performing the required task.                              [1]
          #include<fstream.h>
          class FILE
          {
          int Num;
          char Name[30];
          public:

          void GO_Record(int);
          };
          //function to read Nth record from the file

          void FILE::GO_Record(int N)

          {

          FILE Rec; Fstream
          File;

          File.open(“STOCK”,ios::binary|ios::in);

          ______________________________ //statement
          File.read((char*)&Rec,sizeof(Rec));
          cout<<Rec.Num<<Rec.Name<<endl;

          File.close( );

          }

          (b)  Write a function to count and print the number of complete words as “to” and “are” stored in a text file
          “ESSAY.TXT”.                                                                                         [2]
           void CWORDS( )

          {
          ifstream fin(“ESSAY.TXT”); char
          st[80];
          int count=0;
          while(!fin.eof())

          {

          fin>>st;

          if(!fin)

          break;

          if(strcmpi(st,”to”) = =0 || strcmpi(st,”are”)= =0)
          count++;

          }

          cout<<”\nTotal ‘to’ & ‘are’ words = <<count;
          fin.close( );
   101   102   103   104   105   106   107   108   109   110   111