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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.