subject

Check if your stack is empty Implement: bool Stack_Int::is_empty() const; It should return true if the stack (_data vector) is empty and false otherwise. Just return the value of the vector::empty() method. It's a one-liner. Hopefully the first of countless one-liners you will write in your programming life. Your second miniquest- Check your stack's size Implement: size_t Stack_Int::size() const; It should return the size of the _data vector. Another one-liner! Just return the value of the vector::size() method.
Your third miniquest- Push Implement: void push(int val); It should insert the given value into your stack. Choose which end of the stack you're going to treat as the top of your stack. This will become important as your stack grows in size (Why? Discuss it in the forums.)
Your fourth miniquest- Top Implement: int top(bool& success) const; Note the unusual signature I've chosen for this method. What do you think is the reason for this? What problem am I trying to solve? What are the pros and cons of doing it this way as opposed to some other way? When called on a Stack_Int object it must return the value currently occupying the top of the stack, without changing the stack data in any way (hence the const qualifier in the method signature). If the stack is empty, you should return 0 and set the boolean parameter to false. Note that it's passed by reference. Otherwise, it should return the top element and set the parameterto true.
Your fifth miniquest- One kind of pop Implement: bool pop(); This method simply removes the top element off the data vector and return true. You can do this using a one-line std::vector method. If the vector is empty, you would not do that and return false.
Your sixth miniquest- Another kind of pop Implement: bool pop(int& val); This kind of pop() is virtually identical to your top() method, except that it has the side-effect ofremoving the element that is returned if the stack is not empty.
Your seventh miniquest- Stringify Implement: string to_string() const; This method must return a string representation of the stack of integers in the following exact format. As usual, I've colored in the spaces. Each gray rectangle stands for exactly one space. Stack ( elements): Elements, if listed above, are in increasing order of age. The parts in red above (also in angle brackets) must be replaced by you with the appropriate values. There is no newline afterthe last line that ends with "age." You would print a maximum of 10 elements this way. If the stack has more than 10 elements, you must print the top (most recent) 10 and then print a single line of ellipses (...) in place of all other elements.
Your eighth and final miniquest- Stack o' Strings You get to implement a whole other class: Stack_String. Copy the code for your Stack_Int class and adapt it to work with strings instead. This is an exercise in porting code which requires a level of understanding about what the code does. Your Stack_String should do everything your Stack_Int does… except, with strings.
Starter Code (using C++):
#ifndef Stacks_h #define Stacks_h #include #include class Stack_Int { private: std::vector _data; public: // No explicit constructor or destructor size_t size() const { // TODO - Your code here } bool is_empty() const { // TODO - Your code here } void push(int val) { // TODO - Your code here } int top(bool& success) const { // TODO - Your code here } bool pop() { // TODO - Your code here } bool pop(int& val) { // TODO - Your code here } std::string to_string() const { // TODO - Your code here } // Don't remove the following line friend class Tests; }; class Stack_String { // TODO - Your code here. Ask in the forums if you're stuck. }; #endif /* Stacks_h */
(to_string -> converts a bitset object to a string

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 01:50
Free points just awnser this. what should i watch on netflix
Answers: 2
question
Computers and Technology, 24.06.2019 10:00
In which view can you see speaker notes?
Answers: 1
question
Computers and Technology, 24.06.2019 16:00
To fill (copy) a cell across or down, point to the of the cell and drag. top left corner top right corner bottom left corner bottom right corner
Answers: 3
question
Computers and Technology, 25.06.2019 02:30
What are the charges for invasion of privacy on computers
Answers: 1
You know the right answer?
Check if your stack is empty Implement: bool Stack_Int::is_empty() const; It should return true if t...
Questions
question
Mathematics, 29.07.2019 18:00
question
English, 29.07.2019 18:00
question
Mathematics, 29.07.2019 18:00
question
Mathematics, 29.07.2019 18:00
question
Mathematics, 29.07.2019 18:00
Questions on the website: 13722360