Page 116 - C++
P. 116

936=b+4*(34)
        B=800
        A[5][1]=800+4*((5-0)+8*(1-0))
        A[5][1]=852

        (c) Write a function in C++ to perform Insert operation in a circular Queue containing Player’s information
        (represented with the help of an array of structure PLAYER).
        Ans:
                struct player
               {
               long pid; //player id
               char pname[20]; //player name
               };
        player p[5];
        int f=-1,r=-1;
        void insert(player p[], int &f, int &r, int size)
        {
               if((f==0) && (r= =size-1) ) || (r+1= =f))
                       cout<<”overflow”;
               else
               {
                       if(r= =-1)
                              f=r=0;
                       else if(r= =size-1)
                              r=0;
                       else
                              r++;
                       int id;
                       char nm[30];
                       cin>>id;
                       gets(nm);
                       p[r].pid=id;
                       strcpy(p[r].pname,nm);
               }
        }

        (d) Write a function TRANSFORM(int A[4][3]) in C++ to swap the elements of the first column with the
        corresponding elements of last column of array A.
        Ans:  void transform(int A[4][3])
               {       int temp;
                         for (int i=0;i<4;i++)
                       {   temp=A[i][0];
                       A[i][0]=A[i][2];
                       A[i][2]=temp;
                       }
               }
        (e) Convert the expression (A-5)*6+(10/B)/2 to corresponding postfix expression. Also show the status of
        operator stack after each step.
        Ans:  Do the evaluation using stack but the final answer would be
               A 5 - 6* 10 B / 2 / +


        4(a) A binary file “Students.dat” contains data of 10 students where each student’s data is an object of the
        following class:
               class Student
               { int Rno;char Name[20];
   111   112   113   114   115   116   117   118   119   120   121