Question: C++ programming. Here is the question and I will post my vector class at the end. You will be using your own template Vector class

C++ programming. Here is the question and I will post my vector class at the end.

You will be using your own template Vector class to implement a minimal but complete templateStack data structure. What this means is that you will create a template Stack class using the services provided by your own template Vector class. Note that STL data structures were not permitted and cannot be used in this question.

To demonstrate that your Stack data structure works, write a test program that reads integer data from a file "data.txt". The data is entered into your Stack data structure. Once the data is read in, your program will then access data from the Stack data structure and print to the screen.

Here is my declaration in Stack.h, I tried but not sure how to do this. Fyi, We use g++ follow by C++11 ISO compiler (std=c++11)

#include "Vector.h"

#include

using namespace std;

class Stack

{

public:

Stack();

~Stack();

int size();

void push();

void pop();

T top();

private:

Vector stack;

int index=0;

};

#ifndef Vector_h #define Vector_h #include #include #include #include #include

using namespace std;

template

class Vector { public: Vector(); ~Vector(); void push_back(const T& i); T& at(int i); void resize(int newSize); int size();

private: int length; int arr; T *list; };

template Vector::Vector() { length=0; arr=100; list=new T[arr]; } template Vector::~Vector() { delete[]list; } template void Vector::resize(int newSize) { T *newList=new T[arr]; T *newList1=newList; T *oldList1=list; while(oldList1 != (list+length)) { *(newList1)=*(oldList1); newList1++; oldList1++; } arr=newSize; delete[] list; list=newList; }

template void Vector::push_back(const T& i) { if((arr/2)==length) { Vector::resize(arr*1.5); } list[length]=i; length++; } template T& Vector ::at(int i) { if((i>=0)&&(i int Vector::size() { return length; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!