C++ stack related. given .cpp file and main file along with the pdf

 In this assignment, you will be using the Stack abstract data type we developed this week and discussed in our weeks lectures, to implement 4 functions that use a stack data type to accomplish their algorithms. The functions range from relatively simple, straight forward use of a stack, to a bit more complex. But in all 4 cases, you should only need to use the abstract stack interface functions push(), pop(), top(), and isEmpty() in order to successfully use our Stack type for this assignment and the function you are asked to write. For this assignment you need to perform the following tasks.

1. In the first task, we will write a function that will check if a string of parenthesis is matching. Strings will be given to the function of the format “(()((())))”, using only opening “(” and closing “)”. Your function should be named doParenthesisMatch(). It takes a single 1 string as input, and it returns a boolean result of true if the parenthesis match, and false otherwise. The algorithm to check for matching parenthesis using a stack is fairly simple. A pseudo-code description migth be for each charcter c in expression do if c is an open paren ‘(‘ push it on stack if c is a close paren ‘)’: do if stack is empty answer is false, because we can’t match the current ‘)’ else pop stack, because we just matched an open ‘(‘ with a close ‘)’ done done Your function will be given a C++ string class as input. It is relatively simple to parse each character of a C++ string. Here is an example for loop to do this: s = “(())”; for (size_t index = 0; index < s.length(); index++) { char c = s[index]; // handle char c of the string expression s here }

2. In the next task, we will also write a function that decodes a string expression. Given a sequence consisting of ‘I’ and ‘D’ characters, where ‘I’ denotes increasing and ‘D’ denotes decreasing, decode the given sequence to construct a “minimum number” without repeated digits. An example of some inputs and outputs will make it clear what is meant by a “minimal number”. 2 sequence output IIII -> 12345 DDDD -> 54321 ID -> 132 IDIDII -> 1325467 IIDDIDID -> 125437698 If you are given 4 characters in the input sequence, the result will be a number with 5 characters, and further only the digits ‘12345’ would be in the “minimal number” output. Each ‘I’ and ‘D’ in the input denotes that the next digit in the output should go up (increase) or go down (decrease) respectively. As you can see for the input sequence “IDI” you have to accommodate the sequence, thus the output goes from 1 to 3 for the initial increase, becase in order to then decrease, and also only have the digits ‘123’, we need 3 for the second digit so the third can decrease to 2. Take a moment to think how you might write an algorithm to solve this problem? It may be dicult to think of any solution involving a simple iterative loop (though a recursive function is not too dicult). However, the algorithm is relatively simple if we use a stack. Here is the pseudo-code: for each character c in input sequence do push character index+1 onto stack (given 0 based index in C) if we have processed all characters or c == ‘I’ (an increase) do pop each index from stack and append it to the end of result done done Your function should be named decodeIDSequence(). It will take a string of input sequence, like “IDI” as input, and it will return a string type, the resulting minimal number. Notice we will be constructing a string to return here, so simply start with an empty string ~string result = “”` and append the digits to the end when you pop them from the stack as described. 3

3. In the third task, you will write two functions that will be able to sort a stack. First of all, you should write a simpler method that, given an already sorted stack as input, and an item of the same type as the stack type, the item should be inserted into the correct position on the sorted stack to keep it sorted. For example, the stacks will be sorted in ascending order, where the item at the bottom of the stack is the smallest value, and the item at the top is the largest, like this: top: 8 7 5 3 1 :bottom If we call the function to insert a 4 into this sorted stack, the result should be: top: 8 7 5 4 3 1 Your function should be called insertItemOnSortedStack(). This function takes an item as its rst parameter, and a reference to a Stack as its second parameter. You should create and use another temporary stack in your function in order to accmplish the task. The pseudo-code to accomplish this insertion is relatively simple: given inputStack and create temporaryStack for this algorithm while top of inputStack > item we want to insert do pop topItem from inputStack push topItem onto the temporaryStack done at this point, items on inputStack are <= to the item we want to insert so push item onto inputStack now put items back from temporaryStack to original inputStack while temporaryStack is not empty do pop topItem from temporaryStack push topItem onto the inputStack done 4 The tests given for the insert function use an AStack (a stack of integers) for the tests. You can originally create your function to use a Stack & as its second input parameter. It is important that the stack be a reference parameter here. Also notice that instead of specifying an AStack &, we specify the abstract base class Stack &. This is to demonstrate the power of using virtual classes and class abstractions. If you specify the base class, you can pass an AStack or an LStack or any class that is derived from the base Stack class, as long as that class implements all of the virtual functions of the abstract Stack interface. Once you have your function working for Stack &, templatize your function. We practiced creating function templates in a previous assignment. Here it should be relatively simple, you simply need to add the template  before the function, and change the  to  to templatize. Once you do this, you function should still work and pass the tests using an  type. Once you have your insertItemOnSortedStack() template function working, it is even easier to use this function to create a sortStack() function. We could implement this function again using a temporary stack, but for this fourth and nal function I want you instead to create a recursive function. A recursive function in this case is going to work in essentially the same way, but we will be using the OS/system function call stack implicitly to perform the algorithm, rather than explicitly creating and using our own temporary stack. Create a function called sortStack(). This function should take a Stack & (a reference to a Stack of  types) as its only parameters. You will later templatize this function as well, but all of the tests of sortStack() use stacks of strings, so get it working rst for strings, then try and templatize the function. This is a void funciton, it doesn’t return a result, but it implicitly causes the stack it is given to become sorted. The function, as the name implies, will take an unsorted stack, and will sort them in the same order we used previously, e.g. in ascending order with the smallest item at the bottom of the stack, and the largest at the top. The pseudo-code to accomplish this using a recursize algorithm is as follows: 5 given inputStack as an input parameter # the base case if inputStack is empty, do nothing (return) # the general case take top item from inputStack and save it in a local variable call sortStack(inputStack) recursively on this now smaller stack # on return, the stack should be sorted, so insertItemOnSortedStack(my item I popped, inputStack) Once you have it working for  type stacks, also templatize your sortStack() function, so that it will actually work to sort a Stack of any type. In this assignment you will only be given 2 les, an assg-10-tests.cpp le with a main function and unit tests of the functions you are to write. You will also use the Stack.hpp header le that was developed and shown in the videos for class this week. You should not have to add or change any code in Stack.hpp. You just need to use the Stack class to implement your code/functions for this assignment. As usual, the tests have been commented out. I strongly suggest you implement the functions one at a time, in the order described above, and uncomment each test 1 at a time to test your work incrementally. 

Order a unique copy of this paper
(550 words)

Approximate price: $22

Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees


We value our customers, and so ensure that our papers are 100 percent original. Our Team of professionals does not miss the mark; they ensure that step by step each paper is written uniquely. We never duplicate or work as we compare papers rest assured. We deliver our work a day before time to ensure that you don’t miss your deadlines. It is not only doing the work but delivering it at the right time. We capture the consequences of late remittances. .

Money-back guarantee

We value customer satisfaction here at popularessaywriters.com and make sure that you get the best value for your Money. It happens that sometimes you can pay twice for your order or may want to cancel it, or you feel that it doesn’t meet your requirements; our money back guarantee will give you the opportunity to get back your money. We will also refund 100% of money paid double. In case your paper does not satisfy your requirements , we request that you notify us via writing within 2 days otherwise on the third day we will assume that you have been satisfied. Do all your correspondences through our email address popularessaywriters@gmail.com.

Read more

Zero-plagiarism guarantee

At popularessaywriters.com, our professional writers know the consequence plagiarism does for our clients. We have updated software’s such as article checker and copyscape to check for originality of the custom papers before submission of the final paper to the you. Our guarantee to the customer is that we will write 100% original papers for them that are quality, timely and of low cost. We have experienced professional and competent PhD writers who will write quality custom papers for you..

Read more

Free-revision policy

. At popularessaywriters.com, we are proud to provide top-quality Essay writing service to our esteemed customers. We are ready to take up that challenging academic assignment that is giving you sleepless nights and simplify it for you according to your desired requirements. We are willing to revise your paper if it does not meet your requirements. At popularessaywriters.com, we do not compromise with quality; thus, we offer unlimited free revisions until the customer is satisfied with their custom paper. Our unlimited free revision services are provided under the following terms:.. .

Read more

Privacy policy

Popularessawriters.com knows that client’s information is an essential tool for our company. It means that whatever the client requests from our service is kept strictly confidential. It means that whoever writes for this company understands the terms and conditions hence you should not be worried because you will never see your work somewhere else...

Read more

Fair-cooperation guarantee

Rest assured that we will always be attentive to your needs and requirements. We belief in the phrase treat your neighbour as you would want them to treat you. We leave nothing to chance and always look forward to a good interaction with each other.. .

Read more

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency