Q2 (70 pts). In this question, you will write your own container class named MyList similar...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Q2 (70 pts). In this question, you will write your own container class named MyList similar to vector class in C++. Your class must be a template class which will contain its elements in an array named my Array. Since this class will be a template class, you should include the function definitions at the end of the header file. You can also check the Stack example in Chapter 9. You should keep the size and capacity of your list in two separate attributes named mySize and myCapacity. Therefore, your class will have three data members: one generic dynamic array (you should use pointer representation as given in the Stack example) and two integers. In the list, the elements will always be sorted in decreasing order. As the function members of your class write the following functions: a. (10 pts) Write a constructor that accepts one integer parameter as the capacity of your list, creates a new array with the given capacity, and stores new array in myArray. The constructor should also set myCapacity to the parameter value and mySize to 0. If the parameter is not a positive number, you should set the capacity as 10 and create the array with 10 elements. b. (5 pts) Write getters for size (getSize) and capacity (getCapacity). c. (15 pts) Write add function that accepts an element having generic type and adds this element to the appropriate place in myArray. Note that the elements must always be sorted. For instance, if the list elements are [12, 9, 7, 3] and the parameter of add function is 5, it will be added as the fourth element. The elements will be [12, 9, 7,5, 3] after addition. You should also update the size (mySize) accordingly. The function should return nothing. If the capacity is full, you should double the capacity by creating a new array, copy existing elements into new array, add the element into appropriate place, destroy old array, store the new array in myArray, update myCapacity. d. (5 pts) Write two functions getMin and get Max that returns the minimum element and the maximum element in the list, respectively. If there is no element in the list, throw an exception. e. (10 pts) Write remove function that accepts an element having generic type, searches it in the array and removes all occurrences of that element in the array. You should shift the elements after removal. For instance, if the elements are [12, 9, 7, 5, 5, 3], and the parameter of remove function is 5, the list elements will be [12, 9, 7, 3] after the removal. You should also update the size (mySize) accordingly. The function should return nothing. f. (10 pts) Write remove Max function that does not accept any parameter and removes the first element from the list. You should shift the remaining elements after removal. For instance, if the elements are [12, 9, 7, 5, 5, 3], the list elements will be [9, 7, 5, 5, 3] after calling removeMax function. You should also update the size (mySize) Q2 (70 pts). In this question, you will write your own container class named MyList similar to vector class in C++. Your class must be a template class which will contain its elements in an array named my Array. Since this class will be a template class, you should include the function definitions at the end of the header file. You can also check the Stack example in Chapter 9. You should keep the size and capacity of your list in two separate attributes named mySize and myCapacity. Therefore, your class will have three data members: one generic dynamic array (you should use pointer representation as given in the Stack example) and two integers. In the list, the elements will always be sorted in decreasing order. As the function members of your class write the following functions: a. (10 pts) Write a constructor that accepts one integer parameter as the capacity of your list, creates a new array with the given capacity, and stores new array in myArray. The constructor should also set myCapacity to the parameter value and mySize to 0. If the parameter is not a positive number, you should set the capacity as 10 and create the array with 10 elements. b. (5 pts) Write getters for size (getSize) and capacity (getCapacity). c. (15 pts) Write add function that accepts an element having generic type and adds this element to the appropriate place in myArray. Note that the elements must always be sorted. For instance, if the list elements are [12, 9, 7, 3] and the parameter of add function is 5, it will be added as the fourth element. The elements will be [12, 9, 7,5, 3] after addition. You should also update the size (mySize) accordingly. The function should return nothing. If the capacity is full, you should double the capacity by creating a new array, copy existing elements into new array, add the element into appropriate place, destroy old array, store the new array in myArray, update myCapacity. d. (5 pts) Write two functions getMin and get Max that returns the minimum element and the maximum element in the list, respectively. If there is no element in the list, throw an exception. e. (10 pts) Write remove function that accepts an element having generic type, searches it in the array and removes all occurrences of that element in the array. You should shift the elements after removal. For instance, if the elements are [12, 9, 7, 5, 5, 3], and the parameter of remove function is 5, the list elements will be [12, 9, 7, 3] after the removal. You should also update the size (mySize) accordingly. The function should return nothing. f. (10 pts) Write remove Max function that does not accept any parameter and removes the first element from the list. You should shift the remaining elements after removal. For instance, if the elements are [12, 9, 7, 5, 5, 3], the list elements will be [9, 7, 5, 5, 3] after calling removeMax function. You should also update the size (mySize)
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
A US corporation borrows Swiss francs for 1 year at 8%. For the next year, the Swiss franc is anticipated to fall by 6% against the dollar. What is the loan's effective interest rate?* A US company...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
I need a report with a specific product from a company Assessment 3: Individual Assignment Marking Criteria Report: Structure and Marking Criteria Executive Summary (5 marks) A well written...
-
Consider the Cobb-Douglas production function f(x, y) = 300x0.85, 0.15 When x = 4000 and y = 800, find the following. (Round your answers to two decimal places.) (a) the marginal productivity of...
-
The group D 1h has a C, axis perpendicular to the principal axis and a horizontal mirror plane. Show that the group must therefore have a centre of inversion.
-
Does the current of an enhancement-type MOSFET increase at about the same rate as a depletion-type MOSFET for the conduction region? Carefully review the general format of the equations, and if your...
-
The wings of old airplanes are often strengthened by the use of wires that provided cross-bracing as shown in Fig. P9.106. If the drag coefficient for the wings was 0.020 (based on the planform...
-
There is a parcel of land next to the Playful Paws, Inc. building. Ellen, the owner of this property, approached John to discuss the idea of selling it to him. John is interested. Ellen knows that...
-
Assume that you are the leadership team of a convenience store chain that has more than 300 outlets. The company is facing an inventory shrinkage problem, and store managers report that the main...
-
Amanda Boleyn, an entrepreneur who recently sold her start-up for a multi-million-dollar sum, is looking for alternate investments for her newfound fortune. She is considering an investment in wine,...
-
Base Electronics buys 2,000 shares of Blue Mission Company for $20 per share on January 2 of the current year. Base Electronics does not have the ability to participate in the decisions of Blue...
-
The typical non-critical patient going to the Wexner emergency room (a) checks in with the receptionist, (b) gets vitals checked, (c) receives consultation from a physician, and (d) checks out. There...
-
what are the Current segmentation & Target market of the Aquarius soda brand?
-
Multiply. 864 3 C 3c 15c 2b Simplify your answer as much as possible.
-
For the equation x + y = 26 dy find dt dy x= given that x = 5, y = 1, and dx - dt dt = 1.
-
Find the derivative of the function. y = x49 y's
-
Explain the Features of the Unix in detail.
-
One study found that the elderly who do not have children dissave at about the same rate as the elderly who do have children. What might this finding imply about the reason the elderly do not dissave...
-
Let X be a random variable that is equal to the number of heads in two flips of a fair coin. What is E [X 2 ]? What is E 2 [X]?
-
Suppose that in the rod-cutting problem of Section 15.1, we also had limit l i on the number of pieces of length i that we are allowed to produce, for i = 1, 2, . . . ,n. Show that the...
-
How can the number of strongly connected components of a graph change if a new edge is added?
-
Make a bar chart of \(\mathrm{CO}_{2}\) footprint divided by embodied energy, using data from the data sheets of Appendix A, Table A10, for a. Cement b. Low carbon steel c. Copper d....
-
a. A range of office furniture includes a chunky hardwood table weighing \(18 \mathrm{~kg}\) and a much lighter table with a \(3.0 \mathrm{~kg}\) virgin aluminium frame and a \(3.0 \mathrm{~kg}\)...
-
a. Window frames are made from extruded aluminium. It is argued that making them instead from extruded PVC would give a product with a lower embodied energy and carbon footprint. If the section shape...
Study smarter with the SolutionInn App