Ples help complete this project in C++ language Tthanks. CSC211 Project 7 Create
ID: 3770258 • Letter: P
Question
Ples help complete this project in C++ language Tthanks.
CSC211 Project 7
Create a Temperature class Stack with the following functions:
Push () // push an element into the top
Pop () // pop an element from the top;
Isempty () // determines if the stack is empty
Isfull () //
The class declaration is
Class Stack
{
public:
Stack (int lngth); // constructor
bool Isempty (); // return true if top = -1;
bool Isfull (); // return true if top = length – 1
bool Push (int a); // push an element into the stack (array) – top is increased by one – if Isfull then
// return false
bool Pop (int & e); // pop an element into e – if Isempty return false
private:
int top = -1 // tells how many elements are in the stack
int length; // maximum number of elements in the stack
int * Stackarray; // dynamic allocation of the array
};
For this project create two objects of the class Stack:
Stack1 and Stack2;
For the Stack1 enter the numbers 1, 2, 3, 4, 5, 6, 7 using Push
For Stack2 enter 10, 11, 12, 13, and 15 using Push
The Pop one by one the elements of Stack1 and display them;
The Pop one by one the elements of Stack2 and display them;
Explanation / Answer
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
class Stack
{
private:
int *Stackarray;
int top;
int maxelem;
public:
Stack(int num) { top = -1; maxelem = num; Stackarray = new int[maxelem]; }
~Stack() { delete(Stackarray); }
bool push(int a)
{
if (top == maxelem)
return false;
Stackarray[++top] = a;
return true;
}
bool pop(int &e)
{
if (top == -1)
return false;
e = Stackarray[top--];
return true;
}
int empty() { return top == -1; }
int isfull() { return top == maxelem; }
};
int main()
{
Stack *Stack1 = new Stack(7);
Stack *Stack2 = new Stack(5);
Stack1->push(1);
Stack1->push(2);
Stack1->push(3);
Stack1->push(4);
Stack1->push(5);
Stack1->push(6);
Stack1->push(7);
Stack2->push(10);
Stack2->push(11);
Stack2->push(12);
Stack2->push(13);
Stack2->push(15);
int d;
while(Stack1->pop(d))
cout<<d<<" ";
cout<<" ";
while(Stack2->pop(d))
cout<<d<<" ";
cout<<" ";
return 1;
}