Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this code is in C++. the first picture is the assignment question, the next 3 pictures are the stack.h and the last 2 pictures is
this code is in C++. the first picture is the assignment question, the next 3 pictures are the stack.h and the last 2 pictures is the stack.cpp
write a code that uses stack. You dont need to do the word part.
Student Name Student ID Assignment II Please use Stack to change the following numbers {18, 17, 21, 107, 171} from base 10 to base 2 and output the results. Stack.h and Stack.cpp are attached. Please write your program in another source file named hw2.cpp and copy the executable codes from hw2.cpp to this word document (35) Answer: Back Stack.h /* -- Stack. This header file defines a Stack data type. Basic operations: constructor: Constructs an empty stack empty: Checks if a stack is empty push: Modifies a stack by adding a value at the top top: Retrieves the top stack value; leaves stack unchanged pop: Modifies stack by removing the value at the top display: Displays all the stack elements Class Invariant: 1. The stack elements (if any) are stored in positions 0, 1,..., myTop of myArray. 2. -1 #ifndef STACK #define STACK const int STACK_CAPACITY = 128; typedef int Stackelement; class Stack { public: /***** Function Members *****/ /***** Constructor *****/ Stack(); Construct a Stack object. Precondition: None. Postcondition: An empty Stack object has been constructed (my Top is initialized to -1 and myArray is an array with STACK_CAPACITY elements of type StackElement). -----*/ bool empty() const; using namespace std; #include "Stack.h" //--- Definition of Stack constructor Stack::Stack() : myTop(-1) O} 1/--- Definition of empty() bool Stack::empty() const { return (myTop == -1); } //--- Definition of push() void Stack::push(const StackElement & value) { if (myTop //--- Definition of display() void Stack::display(ostream & out) const { for (int i = myTop; i >= 0; i--) out myArray[i] 1/--- Definition of display ( ) void Stack::display(ostream & out) const { for (int i = mytop; i >= 0; i--) out myArray[i] 1/--- Definition of pop() void Stack::pop() if (!empty()) myTop--; else cerr Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started