Good evening. I am doing an assignment for my class. I am using codeblock. My assigment is to implement a circular queue. My code is below, as well the error. From reading previous forum it seems is a syntax error but I cant tell what wrong with that lines.
Error:
E:\CodeBlocks\cirstack.cpp||In function 'int main()':|
E:\CodeBlocks\cirstack.cpp|126|error: expected unqualified-id before '.' token|
E:\CodeBlocks\cirstack.cpp|127|error: expected unqualified-id before '.' token|
E:\CodeBlocks\cirstack.cpp|128|error: expected unqualified-id before '.' token|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|
#include <iostream>
usingnamespace std;
class CircStack
{
public:
CircStack(int cap); // stack capacity
void push(double d); // push new number on stack
double pop(); // remove and return a double
double peek(); // return stack top without removing
int size(); // return how many elements on stack
private:
double *data; // pointer to array of doubles
int capacity; // the size of the array
int top; // index of next open spot
int bottom; //index of the deletion
int count; // number of items on stack
};
//Class Implementation
//Capacity parameter
CircStack::CircStack (int cap)
{
capacity=cap;
cout << "The Capacity of the Circular Buffer is: " << capacity << endl;
//Allocating a pointer to the array (data)
top = bottom = -1;
CircStack::capacity = capacity- 1;
data = newdouble[cap];
count = 0;
for(int i = 0; i <= cap; i++)
{
data[i] = 0;
}
//showing staring point
for ( int i = 0; i < 5; i++ )
{
cout << data[i] << " ";
}
}
//Push number into stack
void CircStack::push(double d)
{
if (top == 0 && bottom == capacity || top == bottom + 1)
{
cout << "Queue is full\n";
}
elseif (top == -1 && bottom == -1)
{
top = 0;
bottom = 0;
data[top] = d;
count++;
}
elseif (bottom == capacity)
{
bottom = 0;
data[bottom] = d;
count++;
}
else
{
bottom++;
data[bottom] = d;
count++;
}
}
//remove a number
double CircStack::pop()
{
if (top == -1 && bottom == -1)
{
cout << "Queue is empty\n";
}
else
{
if (top == bottom)
{
data[top] = 0;
top = -1;
bottom = -1;
count--;
}
elseif (top == capacity)
{
data[top] = 0;
top = 0;
count--;
}
else
{
data[top] = 0;
top++;
count--;
}
}
}
//return top of stack
double CircStack:: peek()
{
cout << data[4];
}
//return how many number on stack
int CircStack:: size()
{
cout<< count;
}
int main()
{
CircStack cap(5);
CircStack.push(5.0);
CircStack.size();
CircStack.peek();
return 0;
}