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

Please use C++ language and i need output too. This is my 3rd question. So pleas

ID: 3816327 • Letter: P

Question

Please use C++ language and i need output too. This is my 3rd question. So please do it from scratch.

Task 1:

Implement a Queue on a char [] array. Do not use ::Queue:: class from the STD library for this example.

The user will input a string and the program will return the string with each letter in the string duplicated. Displaying correct Queue implementation.

Utilize the conventional static methods as needed.

empty()

push_back()

pop_front()



Sample Execution

Please input String:

happy

hhaappyy


Explanation / Answer

Sample output is inconsistent with the question statement. So, I am assuming that question statement is correct. And that output for 'happy' is 'hhaappppyy'.

Program:

#include<bits/stdc++.h>

using namespace std;

class my_queue
{
private:
   list<char> q;

public:
   void push_back(char x)
   {
       q.push_back(x);
   }

   char pop_front()
   {
       if(is_empty())
           return 0;
       else
       {   char temp = *(q.begin());
           q.pop_front();
           return temp;
       }
   }

   bool is_empty()
   {
       return q.size() == 0;
   }

   int size()
   {
       return q.size();
   }
};

int main()
{
   my_queue q;
   string str;
   cout<<"Please Input string: ";
   cin>>str;

   for(int i=0;i<str.size();i++)
   {
       q.push_back(str[i]);
       q.push_back(str[i]);
   }
   char temp;
   for(int i=0;i<q.size();i++)
   {
       temp = q.pop_front();
       cout<<temp;
       q.push_back(temp);
   }
   cout<<endl;
   return 0;
}

Sample execution:
1. input: abcde
output: aabbccddee
2. input: please
output: pplleeaassee

The class here represents the queue that you want and has all he functions that you mentioned. I hope this helps.

In case of any doubts, please feel free to comment.