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;
}