Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

Students also viewed these Databases questions

Question

BPR always involves automation. Group of answer choices True False

Answered: 1 week ago

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago