Page 131 - C++
P. 131

else
                                   {
                                      node * temp=front;

                                      cout<<” deleted element is “<<temp->rollno<<temp->name;
                                        temp=temp->link;
                                        if ( temp==NULL)
                                          front=rear=NULL;
                                    }}


               4.      a) Fill in the blanks marked as statement 1 and statement 2 in the program

                       segment given below with appropriate function for the required task.              1
                       class agency
                       {      int ano;             // agent code
                              char aname[20];      // agent name
                              char mobile[12];     // mobile number
                       public:
                              void enter();        // function to enter details of agent
                              void disp();                 //function to display details of agent
                              int rano(){ return ano;}
                              void updatemobile()          // function to update mobile
                              {      cout<<” updated mobile: “;
                                     gets(mobile);    }
                       };
                       void agentupdate()
                       {      fstream f;
                              f.open(“agent.dat”, ios::binary|ios::in|ios::out);
                              int updt=0;
                              int uano;
                              cout<<” agent number to update “;
                              cin>>uano;
                              agency a;
                              while(!updt && f.read((char *)&a, sizeof(a)))
                              {      if(a.rano()==uano)
                                     {
                              // statement 1 :  to call the function to update mobile number
                                            _________________________________________
                             //  statement  2:  to  reposition  file  pointer  to  rewrite  the  updated  object
                             //back in the file
                                            _________________________________________
                                            f.write((char *)&a, sizeof(a));
                                     updt++;               }
                              if(updt)
                                     cout<<” mobile updated for the agent “<<uano<<endl;
                              else
                                     cout<<” agent not found “<<endl;
                              f.close();
                       }



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