Page 81 - C++
P. 81

char To[20];           // Bus Destination
                                      public:
                             char * StartFrom ( ); { return From; }
                                           char * EndTo( ); { return To; }
                                           void input() { cin>>Bno>>; gets(From); get(To); }
                                      void show( ) { cout<<Bno<< “:”<<From << “:” <<To<<endl; }
                             };

                                                                OR
                             Write a function in C++ to add more new objects at the bottom of a binary
                             file "STUDENT.dat", assuming the binary file is containing the objects of
                             the following class :
                             class STU
                             {
                             int Rno;
                             char Sname[20];
                             public: void Enter()
                             {
                             cin>>Rno;gets(Sname);
                             }
                             void show()
                             {
                             count << Rno<<sname<<endl;
                             }
                             };

                      Ans.  void Read_File( )
                             {
                                     BUS B;
                                     ifstream Fin;
                                     Fin.open(“Bus.Dat”, ios::binary);
                                     while(Fin.read((char *) &B, sizeof(B)))
                                     {
                                                 if(strcmp(B.EndTo(), “Cochin”)==0)
                                                 {
                                                          B.show( )  ;
                                                 }
                                    }
                                    Fin.close( );
                             }
                                                                OR
                             void Addrecord()
                             {
                             ofstream ofile;
                             ofile.open("STUDENT.dat", ios ::out);
                             STU S;
                             char ch='Y';
                             while (Ch=='Y' || Ch = = 'y')
                             {

                                                             17
   76   77   78   79   80   81   82   83   84   85   86