Page 132 - C++
P. 132

Ans: Statement 1:   a.updatemobile();

                       Statement 2:   f.seekp( updt *sizeof(a), ios::beg);

                       b) Assuming that a text file named FIRST.TXT contains some text written into

                       it,  write  a  function  named  countAE(),  that  reads  the  file  FIRST.TXT  and

                       counts and display the occurrence of alphabet ‘A’ and ‘E’ ( both cases).          2
                        Ans: void countae()
                          {    int n=0;
                               ifstream if1;

                              if1.open(“FIRST.TXT”);
                              char ch;
                              while(! if1.eof())
                              {      ch=if1.getch();
                                     if( ch==’A’ || ch==’E’)
                                            n++;

                              }
                              if1.close();
                              cout<<” Number of A/E is “<<n;


                       c) Given a binary file “TOYS.DAT” containing records of TOYS. Consider the
                       class  given  below.  Display  those  toys  which  are  meant  for  children  of  age

                       range “5 to 8”                                                                    3
                       class TOYS
                       {             int toycode;
                                     char toyname[20];
                                     char agerange[10];
                              public:
                                     void enter()
                                     {      cin>>toycode;
                                            gets(toyname);
                                            gets(agerange);
                                     }
                                     void display()
                                     {cout<<toycode<<”:”<<toyname<<” :” <<agerange<<endl; }

                                     char *whatage()
                                     { return agerange; }
                       };
                       Ans: void displaytoys()
                        {
                              ifstream if1;
                              if1.open(“TOYS.DAT”, ios:;binary);



               XII / Comp. Sc.                                                             Page 11 of 17
   127   128   129   130   131   132   133   134   135   136   137