Question: 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

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)

Stack.h

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

stack.cpp

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

/*-- Stack.h 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, ..., my Top of myArray. 2. -1 #ifndef STACK #define STACK const int STACK_CAPACITY = 128; typedef int StackElement; -class Stack { public: /***** Function Members ***** 7 /***** 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; /*---- Check if stack is empty. Precondition: None Postcondition: Returns true if stack is empty and false otherwise. -*/ void push(const StackElement & value); * - /*-- Add a value to a stack. Precondition: value is to be added to this stack Postcondition: value is added at top of stack provided there is space; otherwise, a stack-full message is displayed and execution is terminated. 7 void display(ostream& out) const; /*-- Display values stored in the stack. Precondition: ostream out is open. Postcondition: Stack's contents, from top down, have been output to out. -*/ StackElement top() const; /*----- Retrieve value at top of stack (if any). Precondition: Stack is nonempty Postcondition: Value at top of stack is returned, unless the stack is empty; in that case, an error message is displayed and a "garbage value" is returned. */ void pop(); /*--- Remove value at top of stack (if any). Precondition: Stack is nonempty. Postcondition: Value at top of stack has been removed, unless the stack is empty; in that case, an error message is displayed and execution allowed to proceed. */ private: /***** Data Members *****/ StackElement myArray[STACK_CAPACITY]; int my Top; 1}; // end of class declaration #endif /*-- Stack.cpp-- This file implements Stack member functions. */ == #include using namespace std; #include "Stack.h" //--- Definition of Stack constructor Stack::Stack() : myTop(-1) {} //-- Definition of empty() bool Stack::empty() const { return (my Top -1); } //--- Definition of push() Ovoid Stack::push(const StackElement & value) { if (my Top = 0; i--) out

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 Databases Questions!