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

I m new to queue, and can someone help me to fix my code, the head source is bel

ID: 3750244 • Letter: I

Question

I m new to queue, and can someone help me to fix my code, the head source is below from my instructor, my code is second part.

-----------------------------------------------

#ifndef SIMPLEARRAYQUEUE_H
#define SIMPLEARRAYQUEUE_H

class SimpleArrayQueue {
private:
static const int MAXSIZE = 5; // max queue size
int size; // current number of values in the queue
int frontIndex; // index of front of queue
int values[MAXSIZE]; // queue values
  
public:

SimpleArrayQueue(); // initialize size and frontIndex to 0

bool isFull() const; // return true iff size == MAXSIZE

bool isEmpty() const; // return true iff size == 0

void enqueue(int v); // add v to the back of the queue or do nothing if queue is full

void dequeue(); // remove front value or do nothing if queue is empty

int front() const; // return front value or throw a logic_error exception if queue is empty

int getSize() const ; // return size

void clear(); // reset size and frontIndex to 0

void printQueue() const; // print queue items from front to back, enclosed by braces, followed by endl

int getFrontIndex() const; // return value of frontIndex

int getBackIndex() const; // return index of value at the back of queue

};

#endif

--------------------------------------------

#include "SimpleArrayQueue.h"
#include
#include
#define MAXSIZE 5;
using namespace std;

SimpleArrayQueue::SimpleArrayQueue() // initialize size and frontIndex to 0
{
int queue[SIZE];
int front = -1;
int rear = -1;
}

bool SimpleArrayQueue::isFull() const // return true iff size == MAXSIZE
{
if ((rear+1)%SIZE == front)
return true;
else false;
}

bool SimpleArrayQueue::isEmpty() const // return true iff size == 0
{
ir (front == -1 && rear == -1)
return true;
else false;
}

void SimpleArrayQueue::enqueue(int v) // add v to the back of the queue or do nothing if queue is full
{
if (rear == SIZE-1)
return;
else{
if (front == -1)
front = 0;
rear++;
queue[rear] = v;
}
}

void SimpleArrayQueue::dequeue() // remove front value or do nothing if queue is empty
{
if (front == rear)
return;
else{
printf(" Deleted." queue[front])
front++;
if (front == rear)
front = rear = -1;
}
}

int SimpleArrayQueue::front() const // return front value or throw a logic_error exception if queue is empty
{
if (front == -1)
{
throw logic_error(" Can't get front of an empty queue.")
return -1;
}
return queue[front];
}

int SimpleArrayQueue::getSize() const // return size
{
return(queue[MAXSIZE])
}

void SimpleArrayQueue::clear() // reset size and frontIndex to 0
{
  
}

void SimpleArrayQueue::printQueue() const // print queue items from front to back, enclosed by braces, followed by endl
{
for (int i = front; i <= rear; i++)
{
cout << queue[i] << " " << endl;
}
}

int SimpleArrayQueue::getFrontIndex() const //return value of frontIndex
{
  
}

int SimpleArrayQueue::getBackIndex() const // return index of value at the back of queue
{

}

Explanation / Answer

here is your modified File : -------------------->>>>>>>>>>>>

#include "SimpleArrayQueue.h"
#include<iostream>
#include<stdexcept>
using namespace std;
SimpleArrayQueue::SimpleArrayQueue() // initialize size and frontIndex to 0
{
size = 0;
frontIndex = 0;
}
bool SimpleArrayQueue::isFull() const // return true iff size == MAXSIZE
{
return size == MAXSIZE;
}
bool SimpleArrayQueue::isEmpty() const // return true iff size == 0
{
return size == 0;
}
void SimpleArrayQueue::enqueue(int v) // add v to the back of the queue or do nothing if queue is full
{
if (!isFull()){
values[size++] = v;
}
}
void SimpleArrayQueue::dequeue() // remove front value or do nothing if queue is empty
{
if (!isEmpty()){
frontIndex++;
if(frontIndex == size){
  clear();
}
}
}
int SimpleArrayQueue::front() const // return front value or throw a logic_error exception if queue is empty
{
if (isEmpty())
{
throw logic_error(" Can't get front of an empty queue.");
}
return values[frontIndex-1];
}
int SimpleArrayQueue::getSize() const // return size
{
return size - frontIndex;
}
void SimpleArrayQueue::clear() // reset size and frontIndex to 0
{
frontIndex = 0;
size = 0;
}
void SimpleArrayQueue::printQueue() const // print queue items from front to back, enclosed by braces, followed by endl
{
for (int i = frontIndex-1; i < size; i++)
{
cout << values[i] << " " << endl;
}
}
int SimpleArrayQueue::getFrontIndex() const //return value of frontIndex
{
return values[frontIndex-1];
}
int SimpleArrayQueue::getBackIndex() const // return index of value at the back of queue
{
return values[size-1];
}

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