• Forum
  • Lounge
  • Can't figure this stack/deque assignment

 
Can't figure this stack/deque assignment out!!

Hi, I'm new to posting on here and was hoping I could get some help from someone...

My professor gave us this assignment that involves stacks and deques, the following is this:

"Develop your own custom C++ Stack class which satisfies the following requirements:

Uses a std::deque of type double under the hood to store the data
Implements the following member functions:
Default constructor
Copy constructor OR copy assignment operator
bool empty()
void pop()
void push(double value)
int size()
void swap(Stack & rhs)
double top()

Develop a main() function which tests out the class you created above"

I'm really unsure of how to implement a class to create a stack, this is what I have so far:

Source.cpp:
#include "Header.h"

using namespace std;

int main()
{
Stack* s = new Stack(0.0);
s->push(12.3);
s->pop;
s->isEmpty;
delete s;

return 0;
}
Stack.h:
#pragma once
#include <iostream>
#include <string>

using namespace std;

class Stack {

public:
Stack(double); //constructor
~Stack(); //destructor
void push(double x); //pushes in element
void pop(); //pops out element
bool isEmpty() const &; //tests if empty
int size();

private:
double top;
double* stackArray;
int stackSize;

};
Stack.cpp:
#include "Stack.h"

Stack::Stack(double) {
//initialize to be empty
top = NULL;

}

Stack::~Stack()
{
if (top == NULL) {
cout << "There is nothing here yet." << endl;
}
else {
//deconstructor to delete all of the dynamic variables
cout << "deleting..." << endl;
}

}

void Stack::push(double x) {
push(x);
stackSize++;

}

void Stack::pop()
{

}

bool Stack::isEmpty() const &
{
if (stackSize == 0)
{
return true;
}
else {
return false;
}


}

int Stack::size()
{
return stackSize;
}

Sincerest apologies if this isn't the right place to post this, as I said I've never posted here until now
Last edited on
> Sincerest apologies if this isn't the right place to post this
https://www.cplusplus.com/forum/beginner/

And please use code tags when posting code.
https://www.cplusplus.com/articles/jEywvCM9/

> Uses a std::deque of type double under the hood to store the data
Do you know what one of these is?
https://www.cplusplus.com/reference/deque/deque/
Topic archived. No new replies allowed.