1.

Write the definition of a member function Ins_Player() for a class CQUEUE in C++, to add a Player in a statically allocated circular queue of PLAYERs considering the following code is already written as a part of the program:struct Player{long Pid;char Pname[20];};const int size=10;class CQUEUE{Player Ar[size];int Front, Rear;public:CQUEUE( ){Front = -1;Rear=-1;}void Ins_Player(); // To add player in a static circular queuevoid Del_Player(); // To remove player from a static circular queuevoid Show_Player(); // To display static circular queue};

Answer»

void CQUEUE : : Ins_Player( )

{

if((Front==0 && Rear==size-1) || (Front==Rear+1)

{

cout<< “Overflow”;

return;

}

else if(Rear = = -1)

{

Front=0;

Rear=0;

}

else if(Rear= =size-1)

{

Rear=0;

}

else

{

Rear++;

}

cout<< “Enter Player Id=”;

cin>>Ar[Rear].Pid;

cout<< “Enter Player Name=”;

gets(Ar[Rear].Pname);

}



Discussion

No Comment Found

Related InterviewSolutions