Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ question. The original language is German. Even though the question is long, the answer is short. It has to be done till Thursday midday.
C++ question. The original language is German. Even though the question is long, the answer is short. It has to be done till Thursday midday. I can give 5 stars and suggest you if you answer well. There is also a given code on the second and third photo.( Simple stack code)
If you don't understand the question please ask.
For this task, download the files task_09_2.cpp and simple_stack hpp from the Exercise website. You already know the ADT stack from Chapter 9 of the lecture. The simple_stack.hpp file contains the declaration of another version of the stack. In memory, this version uses the same layout as the version from the Lecture: The elements lying on the stack are stored in an array data_of size capacity_. The variable size_indicates how many elements are currently available are. The lowest element (i.e. the element that was added first) is in position data_ [O]. The top element (i.e. the element that was added last) is at position data_ [size_- 1). After adding elements 17,5, 13, 29, 14 a stack would with capacity = 8, for example, look like this: 171320 (size - 5) a) Add the implementation of the constructors, des Destructor, and the assignment operator. The constructor without parameters should be empty Create batch with capacity = 1. The copy constructor and the assignment operator should make a deep copy of the submitted batch. Make sure you are in the right places dynamically allocate and release memory with new t] and delete ]. they may assume that calling new [l and delete [] always works without errors (no Exception handling necessary). (7 points) b) Add the implementation of the push functions to the simple_stack.hop file and pop. The push function puts the transferred element on the stack (i.e. writes the element Position data_ [size]) and then increases size_by 1 Check beforehand whether the There is new element space, or whether the size of the stack has already reached its maximum capacity. If there is no space then you should double the capacity. To do this, you need to create a new double-sized array and the existing elements copy from the old array to the new array. Remember you no longer need it To release memory areas again! You can find an example of push on page 3. The pop function removes the top element from the stack. If the stack was hit when the pop is empty, then use the error function to output a corresponding error message You should also prevent the stack from having too few items relative to its own Includes capacity. If only a quarter (or less) of the allocated Storage space is being used, then you should halve the capacity. So since you have both the capacity may have to be adjusted for both push and pop, it is advisable to use the To implement capacity change in the private auxiliary function set capacity (7 points) C) Implement the functions top, bottom and size. The top () function with no parameters returns the top element of the stack. The function top (x), however, gives that (x + 1)-th element back from the top (so that the calls top ) and top (0) are identical). The bottom function without parameters returns the bottom element of the stack. The bottom (x) function, on the other hand, returns the (x + 1) th element from the bottom (so that the calls bottom () and bottom (O) are identical). You can find an example of top and bottom on page 3. In the case of invalid calls, you should use the error function to display appropriate error messages output Simple Stack Code given code) ine EIDP_SIMPLE_STACK #include
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