Question: Consider the incomplete code. The purpose of this CODE IS TO REMOVE AND RETURN the front element of the queue MYQ . The main program

Consider the incomplete code.
The purpose of this CODE IS TO REMOVE AND RETURN the front element of the queue MYQ.
The main program calls the method ADDTOQ() to add elements to the queue MYQ and the function REMOVEANDRETURN() to remove and return the front element of the queue.
Indicate which of the following code (ii) will:- correctly return the front element from the queue to the calling program- remove the front element from the queue- return the updated queue to the calling program.
You can assume that the ADDTOQ() method works correctly.
#include
#include
int main()
{
std::queue myQ;
ADDTOQ(MYQ); //assume that this function works correctly
//....(II) CODE SHOULD GO HERE THAT WILL CALL THE REMOVEANDRETURN FUNCTION ....}
a. std::string REMOVEANDRETURN(std::queue& thisQ)
{
std::string frontElement;
frontElement = thisQ.front();
thisQ.pop();
return frontElement;
}
int main()
{
std::queue myQ;
addToQ(myQ); //assume that this function works correctly
std::string frontvalue;
frontvalue = removeAndReturn(myQ);
std::cout << "Front element: "<< frontvalue <<"
"; return 0;
}
b. std::string REMOVEANDRETURN(std::queue& thisQ)
{
thisQ.pop();
return thisQ.front();
}
int main()
{
std::queue myQ;
addToQ(myQ); //assume that this function works correctly
std::string frontvalue;
frontvalue = REMOVEANDRETURN(myQ);
std::cout << "Front element: "<< frontvalue <<"
";
return 0;
}
c. void REMOVEANDRETURN(std::queue& thisQ)
{
thisQ.pop();
std::string frontElement;
frontElement = thisQ.front();
}
int main()
{
std::queue myQ;
addToQ(myQ); //assume that this function works correctly
std::string frontvalue;
REMOVEANDRETURN(myQ);
std::cout << "Front element: "<< myQ.front()<<"
";
return 0;
}
d. std::string REMOVEANDRETURN(std::queue& thisQ)
{
thisQ.pop();
return thisQ.front();
}
int main()
{
std::queue myQ;
addToQ(myQ); //assume that this function works correctly
std::cout << "Front element: "<< myQ.removeAndReturn(myQ)<<"
";
return 0;
}
e. None of the options provided.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!