Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to figure out what is wrong with my C++ code. This code is implementing the stack structure within a class. The output

I am trying to figure out what is wrong with my C++ code. This code is implementing the stack structure within a class. The output should be: X = 3, Y = 9, 7, 13, 4, 7 in a stacked form. My code outputs x = 3 and y = 9 but does not output 7,13,4,7, and instead outputs random numbers and zeros.

My Output:

image text in transcribed

Header File:

#include

class stackType { private: int arrayStack[]; int stackTop; int stackSize; public: stackType(); bool isEmpty(); bool isFull(); void push(int newData); void pop(); int top(); void intStack(); };

stackType::stackType(){ stackTop = 0; stackSize = 100; }

bool stackType::isEmpty(){ return (stackTop == 0); }

bool stackType::isFull(){ return (stackTop == stackSize); }

void stackType::push(int newData){ if (!isFull()){ arrayStack[stackTop] = newData; stackTop++; } else{ cout

void stackType::pop(){ if (!isEmpty()){ stackTop--; } else{ cout

int stackType::top(){ assert (stackTop != 0); return arrayStack[stackTop-1]; }

CPP File:

#include using namespace std;

#include "arrayStack.h"

int main() { stackType stack; int x; int y;

// Show what is output by the following segment of code: x = 4; y = 0; stack.push(7); stack.push(x); stack.push(x + 5); y = stack.top(); stack.pop(); stack.push(x + y); stack.push(y - 2); stack.push(3); x = stack.top(); stack.pop(); cout x=3 y=9 4197174 4197856 124

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

In what ways do organisations possess knowledge?

Answered: 1 week ago

Question

Question What is a secular trust?

Answered: 1 week ago