I\'m having difficulty in remembering where I need to delcare count in this prog
ID: 3805995 • Letter: I
Question
I'm having difficulty in remembering where I need to delcare count in this program. I'm a bit rusty on my coding. In my queue.h file, I have errors with the count(s) not being delcared properly, and that these member functions have already been declared. I'm lost on this part as to how I need to change up how they are declared.
queue.h
#ifndef H_stackType
#define H_stackType
#include <iostream>
#include <cassert>
using namespace std;
template <class Type>
class queueADT {
public:
virtual bool isEmptyQueue() const = 0;
virtual bool isFullQueue() const = 0;
virtual void initializeQueue() = 0;
virtual Type front() const = 0;
virtual Type back() const = 0;
virtual void addQueue(const Type& queueElement) = 0;
virtual void deleteQueue() = 0;
void print();
private:
int maxQueueSize;
int count;
int queueFront;
int queueRear;
Type *list;
};
template <class Type>
class queueType : public queueADT<Type> {
public:
const queueType<Type>& operator=(const queueType<Type>&);
bool isEmptyQueue() const;
};
template <class Type>
bool queueType <Type>::isEmptyQueue() const {
return (count == maxQueueSize);
}
// end is queueEmpty
template <class Type>
bool queueType<Type>::isFullQueue() {
return (const == maxQueueSize);
}
// end isFullQueue
// initialize queue
template <class Type>
void queueType<Type>::initializeQueue() {
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
}
// end initializeQueue
// begin front
template <class Type>
Type queueType<Type>::front() const {
assert(!isEmptyQueue());
return list[queFront];
}
// end front
// begin back
template <class Type>
Type queueType<Type>::back() const {
assert(!isEmptyQueue());
return list[queueRear];
}
// end back
// begin addQueue
template <class Type>
void queueType<Type>::addQueue(const Type& newElement) {
if (!isFullQueue()) {
queueRear = (queueRear + 1) % maxQueueSize;
count++;
list[queueRear] = newElement;
}
else
cout << "Cannot add to a full queue." << endl;
}
// end addQueue
// begin deleteQueue
template <class Type>
void queueType<Type>::deleteQueue() {
if (!isEmptyQueue()) {
count--;
queueFront = (queueFront + 1) % maxQueueSize;
}
else
cout << "Cannot remove from an empty queue.";
}
// end deleteQueue
// begin contructor
template <class Type>
queueType<Type>::queueType(int queueSize) {
if (queueSize <= 0) {
cout << "Size of the array to hold the queue must"
<< "be positive." << endl;
cout << "Creating an array of size 100." << endl;
maxQueueSize = 100;
}
else
maxQueueSize = queueSize;
queueFront = 0;
queueRear = maxQueueSize - 1;
count = 0;
list = new Type[maxQueueSize];
}
// end constructor
// destructor
template <class Type>
queueType<Type>::~queueTypr() {
delete[] list;
}
// end destructor
// definition of the node
template <class Type>
struct nodetype {
Type info;
nodeType<Type> *link;
};
#endif
Next, on my expression.cpp file, I have not declared queue, and I am not sure where to include it.
expression.cpp
int main(int argc, char *argv[]) {
ifstream fin;
ofstream fout;
expression exp;
queue<expression> q;
int = 0;
fin.open(argv[1]);
fout.open(argv[2]);
while (!exp.last) {
fin >> exp;
q.push(exp);
}
fin.close();
while (!q.empty()) {
exp = q.front();
fout << exp;
q.pop();
}
fout.close();
return 0;
}
Explanation / Answer
In queue.h file the position of count is not right. You have to declare it in public part of the class as:-
public:
virtual bool isEmptyQueue() const = 0;
virtual bool isFullQueue() const = 0;
virtual void initializeQueue() = 0;
virtual Type front() const = 0;
virtual Type back() const = 0;
virtual void addQueue(const Type& queueElement) = 0;
virtual void deleteQueue() = 0;
void print();
Int count=0;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.