The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.
class QueueClass {
int queue[SIZE];
int head, tail;
public:
QueueClass(int, int);
~QueueClass();
void qu(int num);
int dequ();
int size();
int isEmpty();
};
QueueClass::QueueClass (int a, int b) {
head = a;
tail = b;
}
void QueueClass::qu(int num)
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0; // cycle around
queue[tail] = num;
}
int QueueClass::dequ()
{
if(head == tail) {
cout << "Queue is empty\n";
return 0; // or some other error indicator
}
head++;
if(head==SIZE) head = 0; // cycle around
return queue[head];
}
int QueueClass::size()
{
int j=0;
for (; j<tail; j++){
}
return j;
}
int QueueClass::isEmpty()
{
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
#include <iostream>
using namespace std;
#define SIZE 20
template <class t>
Class QueueClass
{
int queue[SIZE];
int head, tail;
public:
QueueClass(int, int);
~QueueClass();
void qu(int num);
int dequ();
int size();
int isEmpty();
};
#include "QUEUET.H"
template <class t>
b<t>:b()
QueueClass::QueueClass (int a, int b) {
head = a;
tail = b;
}
void QueueClass::qu(int num)
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0; // cycle around
queue[tail] = num;
}
int QueueClass::dequ()
{
if(head == tail) {
cout << "Queue is empty\n";
return 0; // or some other error indicator
}
head++;
if(head==SIZE) head = 0; // cycle around
return queue[head];
}
int QueueClass::size()
{
int j=0;
for (; j<tail; j++){
}
return j;
}
int QueueClass::isEmpty()
{
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
}
template <class t>
b<t>::~QueueClass () {}
{
}
#include <iostream>
#include "queuet.cc"
using namespace std ;
int main()
{
QueueClass<int> queue1 (1,1);
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i);
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
#include <iostream>
using namespace std;
#define SIZE 20
template <class T>
Class QueueClass //expected constructor, destroctor or type conversion before "QueueClass" //exptected ; before QueueClass
T queue[SIZE];
T head, tail;
public:
QueueClass(T, T);
~QueueClass();
void qu(T num);
int dequ();
T size();
T isEmpty();
};
#include "QUEUET.H"
template <class T>
QueueClass::QueueClass (T a, T b) { //error: clonficts with function deklsation template<class T> class QueueClass
head = a; //undeclered, first use in function, me: declared in h, so within the scoop
tail = b; //undeclered, first use in function
}
T QueueClass::qu(T num) //error template <class T? class QueueClass used without template parameters
{ //exptected , or ; bevor { token
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0;
queue[tail] = num;
}
T QueueClass::dequ() //does not have a name type
{
if(head == tail) {
cout << "Queue is empty\n";
return 0;
}
head++;
if(head==SIZE) head = 0;
return queue[head];
}
T QueueClass::size() //does not have a name type
{
T j=0;
for (; j<tail; j++){
}
return j;
}
T QueueClass::isEmpty() //does not have a name type
{
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
}
#include <iostream>
#include "queuet.cc"
using namespace std ;
int main()
{
QueueClass<int> queue1 (1,1);
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i);
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
#include "QUEUET.H" //<-- RX: Does this contain the class definition as per below?
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// <--- RX: You need to have header guards
#ifndef QUEUET_H
#define QUEUET_H
#include <iostream>
using namespace std;
#define SIZE 20
template <class T>
//Class QueueClass <-- RX: Syntax error
class QueueClass
{ //<-- RX: Missing brace
T queue[SIZE];
T head, tail;
public:
QueueClass(T, T);
~QueueClass();
void qu(T num);
//int dequ(); <-- RX: Should return T
T dequ();
T size();
T isEmpty();
};
// <--- RX: You need to have header guards
#endif
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// <-- RX: I take it you ionclude this into your code where it is needed?
// You know the compiler needs to see the full template defintion
// at the Point Of Instantiation (POI) right? It is normally simpler
// to implement all the template functions in the header, inine in
// the class rather than seperately, otherwise it makes life harder.
template <class T>
//QueueClass::QueueClass (T a, T b) { //error: clonficts with function deklsation template<class T> class QueueClass
QueueClass<T>::QueueClass (T a, T b) { //<-- RX: The class is a template, the signature includes the template parameter(s)
head = a; //undeclered, first use in function, me: declared in h, so within the scoop
tail = b; //undeclered, first use in function
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::qu(T num) //error template <class T? class QueueClass used without template parameters
void QueueClass<T>::qu(T num)//<-- RX: The class is a template, the signature includes the template parameter(s) (this also returns void)
{ //exptected , or ; bevor { token
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0;
queue[tail] = num;
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::dequ() //does not have a name type
T QueueClass<T>::dequ()//<-- RX: The class is a template, the signature includes the template parameter(s)
{
if(head == tail) {
cout << "Queue is empty\n";
return 0;
}
head++;
if(head==SIZE) head = 0;
return queue[head];
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::size() //does not have a name type
T QueueClass<T>::size()//<-- RX: The class is a template, the signature includes the template parameter(s)
{
T j=0;
for (; j<tail; j++){
}
return j;
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::isEmpty() //does not have a name type
T QueueClass<T>::isEmpty()//<-- RX: The class is a template, the signature includes the template parameter(s)
{
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
//} <-- RX: Rogue brace
#include <iostream>
#include "queuet.cc"
using namespace std ;
int main()
{
QueueClass<int> queue1 (1,1);
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i);
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
template <class T>
QueueClass<T>::QueueClass (T a, T b) { //expected ; befor < token
head = a;
tail = b;
}
template <typename T>
void QueueClass<T>::qu(T num) //init declarator before < token //expected ; befor < token
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0;
queue[tail] = num;
}
template <typename T>
T QueueClass<T>::dequ() //init declarator before < token //expected ; befor < token
{
if(head == tail) {
cout << "Queue is empty\n";
return 0;
}
head++;
if(head==SIZE) head = 0;
return queue[head];
}
template <typename T>
T QueueClass<T>::size()
{ //init declarator before < token //expected ; befor < token
T j=0;
for (; j<tail; j++){
}
return j;
}
template <typename T>
T QueueClass<T>::isEmpty()
{ //init declarator before < token //expected ; befor < token
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
///////////////////////
#include <iostream>
#include "queuet.cc"
using namespace std ;
int main()
{
QueueClass<int> queue1 (1,1); ////expected ; before int //QueueClass undeclared //expect primary expression before int
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i); // queue1 undecleared, first use
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
//#include "QUEUET.H" //<-- RX: Does this contain the class definition as per below?
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// <--- RX: You need to have header guards
#ifndef QUEUET_H
#define QUEUET_H
#include <iostream>
using namespace std;
#define SIZE 20
template <class T>
//Class QueueClass <-- RX: Syntax error
class QueueClass
{ //<-- RX: Missing brace
T queue[SIZE];
T head, tail;
public:
QueueClass(T, T);
~QueueClass(){};
void qu(T num);
//int dequ(); <-- RX: Should return T
T dequ();
T size();
T isEmpty();
};
// <--- RX: You need to have header guards
#endif
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// <-- RX: I take it you ionclude this into your code where it is needed?
// You know the compiler needs to see the full template defintion
// at the Point Of Instantiation (POI) right? It is normally simpler
// to implement all the template functions in the header, inine in
// the class rather than seperately, otherwise it makes life harder.
template <class T>
//QueueClass::QueueClass (T a, T b) { //error: clonficts with function deklsation template<class T> class QueueClass
QueueClass<T>::QueueClass (T a, T b) { //<-- RX: The class is a template, the signature includes the template parameter(s)
head = a; //undeclered, first use in function, me: declared in h, so within the scoop
tail = b; //undeclered, first use in function
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::qu(T num) //error template <class T? class QueueClass used without template parameters
void QueueClass<T>::qu(T num)//<-- RX: The class is a template, the signature includes the template parameter(s) (this also returns void)
{ //exptected , or ; bevor { token
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0;
queue[tail] = num;
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::dequ() //does not have a name type
T QueueClass<T>::dequ()//<-- RX: The class is a template, the signature includes the template parameter(s)
{
if(head == tail) {
cout << "Queue is empty\n";
return 0;
}
head++;
if(head==SIZE) head = 0;
return queue[head];
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::size() //does not have a name type
T QueueClass<T>::size()//<-- RX: The class is a template, the signature includes the template parameter(s)
{
T j=0;
for (; j<tail; j++){
}
return j;
}
template <typename T> //<-- RX: You need to define this as a member template function so you need this!
//T QueueClass::isEmpty() //does not have a name type
T QueueClass<T>::isEmpty()//<-- RX: The class is a template, the signature includes the template parameter(s)
{
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
//} <-- RX: Rogue brace
#include <iostream>
//#include "queuet.cc"
using namespace std ;
int main()
{
QueueClass<int> queue1 (1,1);
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i);
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
///////////////my queuet.h
#ifndef QUEUET_H
#define QUEUET_H
#include <iostream>
using namespace std;
#define SIZE 20
template <class T>
class QueueClass
{
T queue[SIZE];
T head, tail;
public:
QueueClass(T, T);
~QueueClass();
void qu(T num);
T dequ();
T size();
T isEmpty();
};
#endif
////////////////////////////////my queuet.cc
template <class T>
QueueClass<T>::QueueClass (T a, T b) { //expected ; befor < token
head = a;
tail = b;
}
template <typename T>
void QueueClass<T>::qu(T num) //init declarator before < token //expected ; befor < token
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0;
queue[tail] = num;
}
template <typename T>
T QueueClass<T>::dequ() //init declarator before < token //expected ; befor < token
{
if(head == tail) {
cout << "Queue is empty\n";
return 0;
}
head++;
if(head==SIZE) head = 0;
return queue[head];
}
template <typename T>
T QueueClass<T>::size()
{ //init declarator before < token //expected ; befor < token
T j=0;
for (; j<tail; j++){
}
return j;
}
template <typename T>
T QueueClass<T>::isEmpty()
{ //init declarator before < token //expected ; befor < token
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
/////////////////////////////my main.cc
#include <iostream>
#include "queuet.cc"
using namespace std ;
int main()
{
QueueClass<int> queue1 (1,1); ////expected ; before int //QueueClass undeclared //expect primary expression before int
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i); // queue1 undecleared, first use
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
///////////////my queuet.h
#ifndef QUEUET_H
#define QUEUET_H
#include <iostream>
using namespace std;
#define SIZE 20
template <typename T>
class QueueClass
{
T queue[SIZE];
T head, tail;
public:
QueueClass(T, T);
~QueueClass(){};
void qu(T num);
T dequ();
T size();
T isEmpty();
};
#endif
////////////////////////////////my queuet.cc
template <typename T>
QueueClass<T>::QueueClass (T a, T b) { //expected ; befor < token
head = a;
tail = b;
}
template <typename T>
void QueueClass<T>::qu(T num) //init declarator before < token //expected ; befor < token
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0;
queue[tail] = num;
}
template <typename T>
T QueueClass<T>::dequ() //init declarator before < token //expected ; befor < token
{
if(head == tail) {
cout << "Queue is empty\n";
return 0;
}
head++;
if(head==SIZE) head = 0;
return queue[head];
}
template <typename T>
T QueueClass<T>::size()
{ //init declarator before < token //expected ; befor < token
T j=0;
for (; j<tail; j++){
}
return j;
}
template <typename T>
T QueueClass<T>::isEmpty()
{ //init declarator before < token //expected ; befor < token
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
/////////////////////////////my main.cc
#include <iostream>
//#include "queuet.cc"
using namespace std ;
int main()
{
QueueClass<int> queue1 (1,1); ////expected ; before int //QueueClass undeclared //expect primary expression before int
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i); // queue1 undecleared, first use
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
////////////my .h
#include <iostream>
using namespace std;
#define SIZE 20
class QueueElement {
public:
int queue[SIZE];
int head, tail;
QueueElement();
QueueElement(int, int);
~QueueElement();
void qu(int num);
int dequ();
int size();
int isEmpty();
};
class QueueClass : public QueueElement{ // QueueClass is Subclass to QueueElement{
};
//// my main
#include <iostream>
#include "queueBase.h"
QueueClass::~QueueClass () {} //error: defintion of implicitly-declared QueueClass::~QueueClass()
QueueClass::QueueClass (int a, int b) { //error prototyp for QueueClass::QueueClass(int, int) does not match any in class QueueClass //.h line 22 Kanidates are QueueClass()
head = a;
tail = b;
}
void QueueClass::qu(int num) //no void QueueClass::qu member function declared in class QueueClass
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0; // cycle around
queue[tail] = num;
}
int QueueClass::dequ() //no int QueueClass::dequ member function declared in class QueueClass
{
if(head == tail) {
cout << "Queue is empty\n";
return 0; // or some other error indicator
}
head++;
if(head==SIZE) head = 0; // cycle around
return queue[head];
}
int QueueClass::size() //no int QueueClass::size member function declared in class QueueClass
{
int j=0;
for (; j<tail; j++){
}
return j;
}
int QueueClass::isEmpty() //no int QueueClass::isEmpty member function declared in class QueueClass
{
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
int main()
{
QueueClass queue1(0,0); //no matching function for call QueueClass::QueueClass(int int)
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i);
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
///Queuebase.h
#include <iostream>
using namespace std;
#define SIZE 20
class QueueElement {
public:
int queue[SIZE];
int head, tail;
QueueElement();
QueueElement(int, int);
virtual ~QueueElement();
virtual void qu(int num);
virtual int dequ();
virtual int size();
virtual int isEmpty();
};
class QueueClass : public QueueElement
{
public:
QueueClass(int a, int b) : QueueElement(a,b){} // Invoke base class constructor, passing parameters to it
};
///queuemain.cc
#include <iostream>
#include "queueBase.h"
QueueElement::~QueueElement() {}
QueueElement::QueueElement(int a, int b) {
head = a;
tail = b;
}
void QueueElement::qu(int num)
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0; // cycle around
queue[tail] = num;
}
int QueueElement::dequ()
{
if(head == tail) {
cout << "Queue is empty\n";
return 0; // or some other error indicator
}
head++;
if(head==SIZE) head = 0; // cycle around
return queue[head];
}
int QueueElement::size()
{
int j=0;
for (; j<tail; j++){
}
return j;
}
int QueueElement::isEmpty()
{
if(head == tail) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
int main()
{
QueueClass& queue1(0,0); //initiatilizer expression list treated as compond expression //invalid initialization of non const reference of type Queueclass& from a tempory typ e "int"
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
int i;
for(i=1; i <=10; i++) {
queue1.qu(i);
}
cout<<"If 1, Queue is Empty, else 0 aka Queue is not empty. Result: " <<queue1.isEmpty()<<endl;
cout<< queue1.size() <<" test" <<endl;
for(i=1; i <=10; i++)
cout << "Dequeue 1: " << queue1.dequ() << endl;
return 0;
}
You have not implemented your class contructor
QueueClass::~QueueClass () {}