Use Stackadt Class Stacktype Classes Given Ch 18 Code Supplied Complete Assignment Include Q43903976
Use the stackADT class and stackType classes given to you in Ch.18 and code supplied here to complete this assignment.
#include <iostream>
#include “myStack.h”
using namespace std;
int main()
{
stackType<int> stack1(50);
stackType<int> stack2(50);
stack1.initializeStack();
stack1.push(23);
stack1.push(45);
stack1.push(38);
stack2 = stack1;
if (stack1 == stack2)
cout << “stack1 and stack2 are identical” <<endl;
else
cout << “stack1 and stack2 are not identical” <<endl;
stack2.pop();
stack2.push(32);
cout << “**** After pop and push operations on stack2****” << endl;
if (stack1 == stack2)
cout << “stack1 and stack2 are identical” <<endl;
else
cout << “stack1 and stack2 are not identical” <<endl;
stack2.push(11);
cout << “**** After another push operation on stack2 ****”<< endl;
if (stack1 == stack2)
cout << “stack1 and stack2 are identical” <<endl;
else
cout << “stack1 and stack2 are not identical” <<endl;
return 0;
}
Modify the stack implementation such that it uses a vectors asthe container instead of an array.
Overload the pure virtual function push such that it takes avector as an argument which pushes multiple values onto thestack.
Throw exceptions when:
·An attempt is made to pop from anempty stack (display message)
·An attempt is made to push onto afull stack (display message)
·top() is called on an empty stack(display message).
·A negative or zero value for stacksize is passed to the constructor (In this case, when handling theerror, automatically recall the constructor with a value of100).
Using the STL queue container, add multiple stackType classes toa queue. Demonstrate an ability to use STL queuemethods such as front() and pop().
Useful notes:
Leverage the functions which are already given to you.
Submission requirements:
Submit all files required to make this program run asrequired. Your solution can be a singlefile.
Submit source code, a screenshot with a time stamp of codeexecution, and a text file of the code. All code should includecomments.
Grading Criteria Assignments
Maximum Points
Program accomplishes requested operations per instructions
40
The code works and meets all assignment specifications
30
The code is organized and easy to follow and output is clear andclean
20
Uses software tools correctly and efficiently
10
Total
100
VPN 14:55 1 100% .. Boost x = 1 Aa a a a The following abstract class stackADT defines these operations as an ADT: template colass Type> class stackADT publie: virtual void initializestack() =0; // Method to initialize the stack to an empty state. //Postconditions Stack is empty. virtual bool isimptystack() const .0 //Function to determine whether the stack is empty. //Postcondition. Return true if the stack is empty otherwise return false virtual bool Tarullstack() const -0 //Function to determine whether the stack is full //Postcondition: Returns true if the stack a full otherwise return false. virtual void push(const Types newItem) = 0 //Function to add newItem to the stack. //Precondition. The stack exiate and is not full. //Postcondition. The stack is changed and new Item is added to the top of the stack. Virtual Type top() const = 0; //Function to return the top element of the stack. //Precondition. The stack exiate and is not empty. //Postcondition. It the stack is empty, the program terminates otherwise, the top olement of the stack is returned virtual void pop() = 0; //Function to remove the top element of the stack. //Precondition. The stack exists and is not espty. //Postcondition. The stack is changed and the top elecent is removed from the stack. Figure 18-4 shows the UML class dia- gram of the class stackADT. 88 minutes. 194 pages left VPN 14:55 100% … Boost x = 1 Aa a a a element is removed from the stack. Figure 18-4 shows the UML class dia- gram of the class stackADT. Figure 18-4. stackADT<Type> +initializeStack(): void +isEmptyStack(): boolean +isFullstack(): boolean +push (Type): void +top(): Type +pop(): void UML class diagram of the class stackADT We now consider the implementation of our abstract stack data structure. Be- 87 minutes. 193 pages left VPN 14:56 100% … Boost x = Аа аа template celas Type> class stacktyper public stackADT<Type> publier const stackType Type>& operators (const stacktype Type>&) //Overload the assignment operator. void initializestack(); //Function to initialize the stack to an empty state. //Postcondition stackTop = 0 bool Lamptystack() consti //Function to determine whether the stack is empty. //Postcondition: Returns true if the stack is empty. otherwise returns talse. bool is Pullstack() const; //Function to determine whether the stack is full. //Postcondition Returns true if the stack is full, otherwise returns talse. void push(const Typek newItem); //Function to add newItem to the stack. //recondition. The stack exists and is not full //Postcondition. The stack a changed and bevite // is added to the top of the stack. Type top() consts //Function to return the top element of the stack. //Precondition. The atack exiate and is not empty. //Postcondition. It the stack is empty. the program terminates otherwise, the top element of the stack is returned. void pop(); //Function to remove the top element of the stack //Precondition. The stack exists and is not empty. //Postcondition. The stack is changed and the top element is removed from the stack stackType(int stackSize = 100) //constructor //Create an array of the size atacksize to hold //the stack elements. The default stack size is 100. //Postcondition. The variable liat contains the base address of the array otacktop=0 and maxstack size-stacksize. stacktype (const stacktypeType>k otherStack); // Copy constructor -stackType(); //Destructor //Remove all the elements from the stack. //Postcondition: The array (list) holding the stack elements is deleted. private: int maxStackSize; //variable to store the maximum stack size Ant stalo teto bont to the to the te 86 minutes. 205 pages left VPN 14:56 100% … Boost x 5 private int maxStackSize; //variable to store the maximum stack size int stackTop //variable to point to the top of the stack Type list, //pointer to the array that holds the //stack elements void copystack (const stackTypes Type> otherStack) //Punction to make a copy of otherStack. //Postcondition. A copy of otherstack is created and assigned to the stack. Figure 18-5 shows the UML class dia- gram of the class stackType. Figure 18-5. stackType<Type> -maxStackSize: int -stack Top: int – list: Type +operator= (const stackType<Type>&) : const stack Type Type> +initializeStack(): void +isEmptyStack() const: bool +isFullstack() const: bool +push(const Type) : void +top() const: Type +pop(): void -copyStack (const stackType<Type>): void +stack Type (int = 100) +stackType (const stackType<Type>) +-stackType() UML class diagram of the class stackType 86 minutes. 189 pages left Show transcribed image text VPN 14:55 1 100% .. Boost x = 1 Aa a a a The following abstract class stackADT defines these operations as an ADT: template colass Type> class stackADT publie: virtual void initializestack() =0; // Method to initialize the stack to an empty state. //Postconditions Stack is empty. virtual bool isimptystack() const .0 //Function to determine whether the stack is empty. //Postcondition. Return true if the stack is empty otherwise return false virtual bool Tarullstack() const -0 //Function to determine whether the stack is full //Postcondition: Returns true if the stack a full otherwise return false. virtual void push(const Types newItem) = 0 //Function to add newItem to the stack. //Precondition. The stack exiate and is not full. //Postcondition. The stack is changed and new Item is added to the top of the stack. Virtual Type top() const = 0; //Function to return the top element of the stack. //Precondition. The stack exiate and is not empty. //Postcondition. It the stack is empty, the program terminates otherwise, the top olement of the stack is returned virtual void pop() = 0; //Function to remove the top element of the stack. //Precondition. The stack exists and is not espty. //Postcondition. The stack is changed and the top elecent is removed from the stack. Figure 18-4 shows the UML class dia- gram of the class stackADT. 88 minutes. 194 pages left
VPN 14:55 100% … Boost x = 1 Aa a a a element is removed from the stack. Figure 18-4 shows the UML class dia- gram of the class stackADT. Figure 18-4. stackADT +initializeStack(): void +isEmptyStack(): boolean +isFullstack(): boolean +push (Type): void +top(): Type +pop(): void UML class diagram of the class stackADT We now consider the implementation of our abstract stack data structure. Be- 87 minutes. 193 pages left
VPN 14:56 100% … Boost x = Аа аа template celas Type> class stacktyper public stackADT publier const stackType Type>& operators (const stacktype Type>&) //Overload the assignment operator. void initializestack(); //Function to initialize the stack to an empty state. //Postcondition stackTop = 0 bool Lamptystack() consti //Function to determine whether the stack is empty. //Postcondition: Returns true if the stack is empty. otherwise returns talse. bool is Pullstack() const; //Function to determine whether the stack is full. //Postcondition Returns true if the stack is full, otherwise returns talse. void push(const Typek newItem); //Function to add newItem to the stack. //recondition. The stack exists and is not full //Postcondition. The stack a changed and bevite // is added to the top of the stack. Type top() consts //Function to return the top element of the stack. //Precondition. The atack exiate and is not empty. //Postcondition. It the stack is empty. the program terminates otherwise, the top element of the stack is returned. void pop(); //Function to remove the top element of the stack //Precondition. The stack exists and is not empty. //Postcondition. The stack is changed and the top element is removed from the stack stackType(int stackSize = 100) //constructor //Create an array of the size atacksize to hold //the stack elements. The default stack size is 100. //Postcondition. The variable liat contains the base address of the array otacktop=0 and maxstack size-stacksize. stacktype (const stacktypeType>k otherStack); // Copy constructor -stackType(); //Destructor //Remove all the elements from the stack. //Postcondition: The array (list) holding the stack elements is deleted. private: int maxStackSize; //variable to store the maximum stack size Ant stalo teto bont to the to the te 86 minutes. 205 pages left
VPN 14:56 100% … Boost x 5 private int maxStackSize; //variable to store the maximum stack size int stackTop //variable to point to the top of the stack Type list, //pointer to the array that holds the //stack elements void copystack (const stackTypes Type> otherStack) //Punction to make a copy of otherStack. //Postcondition. A copy of otherstack is created and assigned to the stack. Figure 18-5 shows the UML class dia- gram of the class stackType. Figure 18-5. stackType -maxStackSize: int -stack Top: int – list: Type +operator= (const stackType&) : const stack Type Type> +initializeStack(): void +isEmptyStack() const: bool +isFullstack() const: bool +push(const Type) : void +top() const: Type +pop(): void -copyStack (const stackType): void +stack Type (int = 100) +stackType (const stackType) +-stackType() UML class diagram of the class stackType 86 minutes. 189 pages left
Expert Answer
Answer to Use the stackADT class and stackType classes given to you in Ch. 18 and code supplied here to complete this assignment….
OR