Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

01. implement a class function in the cqueue class to print all the elements from thequeue (without dequeueing them!) [10 points] 02. implement a class

01. implement a class function in the cqueue class to print all the elements from thequeue (without dequeueing them!) [10 points] 02. implement a class function in the cqueue class to count the current size of the queue(if you have inserted 5 elements and dequeued 3, the current size is 2, initially the queue size is 0) [10 points] 03. implement a class function for dequeue class to dequeue all the elements from the queue (print each element as you delete them) [10 points]

04. modify the while loop in the main function to take the input from user while enqueuing new value. [05 Points]

Add 3 test cases for each completed task with your submitted code.

Bonus:

Pick any 2 out of Task 01, 02, and 03. Each carries 10 points. If you can complete all three (01, 02, 03), the third one will be bonus point and will be added to any of the previous recitation quiz of your choice (mention which one to pick!).

#include "cqueue.h" #include  using namespace std; cqueue :: cqueue() { front = rear = -1; } void cqueue :: enqueue(int x) { if ((rear+1) % 10 == front) { cout << "The queue is full"<< endl; return; } else { rear = (rear + 1) % 10; q[rear] = x; if (front == -1) front = 0; } } int cqueue :: dequeue () { if ((front == rear) && (rear == -1)) { cout << "The queue is empty!"<< endl; return -1; } else { int x = q[front]; if(front == rear) { front = rear = -1;} else front = (front + 1) % 10; return x; } } 
#ifndef cqueue_H #define cqueue_H class cqueue { int q[10]; int front; int rear; public: cqueue(); void enqueue(int); int dequeue(); }; #endif 
#include #include "cqueue.h" using namespace std; int main() { cqueue q; char c = 'c'; //enter 's' to end int j = 20; while(c != 's') { cout << "enter 'e' to enqueue "<< endl << "enter 'd' to dequeue" << endl << "enter 's' to stop"<< endl; cin >> c; if (c == 'e') q.enqueue(j++); else if (c == 'd'){ int v = q.dequeue(); cout << "Current Value: "<< v << endl; } else break; } return 0; } 

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

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago