Question
C++ (QUEQUE). I ALREADY CREATED MY QUEQUE CLASS AND DECLARED THE FUNCTIONS, NOW I JUST NEED SOMEONE TO CHECK IF WHAT I'VE DONE SO FAR
C++ (QUEQUE). I ALREADY CREATED MY QUEQUE CLASS AND DECLARED THE FUNCTIONS, NOW I JUST NEED SOMEONE TO CHECK IF WHAT I'VE DONE SO FAR IS CORRECT, AND ALSO TO HELP ME TO WRITE THE CODE FOR THE DRIVER PROGRAM. INSTRUCTIONS FOR THE PROGRAM AND MY CODE BELOW.
Implement the following specification for an integer function in the client program that returns the number of items in a queue. The queue is unchanged. int GetLength(QueType queue) Function: Determines the number of items in the queue. Precondition: queue has been initialized. Postconditions: queue is unchanged Function value = number of items in queue.
CODE:
#pragma once
#include
//HEADER FILE
//create Qtype class
class FullQueue {};
class EmptyQueue{};
typedef char ItemType;
class QueType
{
public:
QueType(int max);
QueType();
~QueType();
void MakeEmpty();
bool IsEmpty() const;
bool IsFull() const;
void Enqueue(ItemType item);
void Dequeue(ItemType& item);
private:
int front;
int rear;
ItemType* items;
int MaxQue;
}
;
.........................................................................
// declaration of queque
#include"QueType.h"
#include
//
QueType::QueType(int max) {
MaxQue = max + 1;
front = MaxQue - 1;
rear = MaxQue - 1;
items = new ItemType[MaxQue];
}
QueType::QueType() {
MaxQue = 501;
front = MaxQue - 1;
rear = MaxQue - 1;
items = new ItemType[MaxQue];
}
QueType::~QueType() {
delete[] items;
}
void QueType::MakeEmpty() {
front = MaxQue - 1;
rear = MaxQue - 1;
}
bool QueType::IsEmpty() const {
return (rear == front);
}
bool QueType::IsFull() const {
return ((rear + 1) % MaxQue == front);
}
void QueType::Enqueue(ItemType newItem) {
if (IsFull())
throw FullQueue();
else {
rear=(rear + 1) % MaxQue;
items[rear] = newItem;
}
}
void QueType::Dequeue(ItemType& item) {
if (IsEmpty())
throw EmptyQueue();
else {
front = (front + 1) % MaxQue;
item =items[front];
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started