Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the body of this function. Use a queue of characters to store the input

ID: 666693 • Letter: C

Question

Complete the body of this function. Use a queue of characters to store the input line as it is being read.

size_t counter( )

    // Precondition: There is a line of input waiting to be read from cin.

    // Postcondition: A line of input has been read from cin, up to but not

    // including the newline character. The return value of the function

    // is the number of times that the LAST character of the line appeared

    // somewhere in this line.

    // EXAMPLE Input: ABBXDXXZX

    // The value returned by counter would be 4 for this input since there

    // are 4 X's in the input line.

    {

        size_t answer = 0;

        queue q;

Explanation / Answer

size_t counter()
{
queue<char> q;
char c;
size_t answer=0;
while(cin.peek()!=' ')
{
c= cin.peek();
c.ignore();
q.push(c);
}
while(!q.empty())
{
if(c==q.front())
answer++;
q.pop();
}
return answer;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote