accordingly. The function should return the removed element (12 in the previous example). If the list...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
accordingly. The function should return the removed element (12 in the previous example). If the list is empty, throw an exception. g. (5 pts) Write removeMin function that does not accept any parameter and removes the last element from the list. For instance, if the elements are [12, 9, 7, 5, 5, 3], the list elements will be [12, 9, 7, 5, 5] after calling removeMin function. You should only decrease the size (mySize) by one in this function. The function should return the removed element (3 in the previous example). If the list is empty, throw an exception. h. (5 pts) Write a function named display to print the elements in the list separated by a comma. E.g., [13,11,8,9,12]. Note that you should not print all array content, you should print the elements in the list. For instance, when you create an integer list with capacity 100, myArray will contain 100 zeros, but you should not display them. Therefore, you should iterate your loop from 0 to mySize-1. The function should return nothing. i. (5 pts) Write a function named at that accepts an integer parameter index and returns the element at the given index. If there is no element at that index, throw an exception. An example driver class (MyListDriver.cpp) and its output are given below. #include #include "MyList.h" using namespace std; int main() { } MyList a(3); MyList b(-10); cout < < "Size of a: < < a.getSize() < < endl; 11 cout < < "Capacity of a: < < a.getCapacity() < < endl; cout < < "Size of b: " < < b.getSize() < < endl; cout < < "Capacity of b: " < < b.getCapacity () < < endl; a.add(9); a.display(); a.add (2); a.display(); a.add(4); a.display(); a.add (3); a.display(); a.add(5); a.display(); a.add (1); a.display(); a.add(4); a.display(); a.add(10); a.display(); W 11 cout < < "a.getMin(): < < a.getMin() < < endl; cout < < "a.getMax(): < < a.getMax() < < < endl; cout < < "a.at(1): < < a.at(1) < < endl; cout < < "a.removeMin(): < < a.removeMin() < accordingly. The function should return the removed element (12 in the previous example). If the list is empty, throw an exception. g. (5 pts) Write removeMin function that does not accept any parameter and removes the last element from the list. For instance, if the elements are [12, 9, 7, 5, 5, 3], the list elements will be [12, 9, 7, 5, 5] after calling removeMin function. You should only decrease the size (mySize) by one in this function. The function should return the removed element (3 in the previous example). If the list is empty, throw an exception. h. (5 pts) Write a function named display to print the elements in the list separated by a comma. E.g., [13,11,8,9,12]. Note that you should not print all array content, you should print the elements in the list. For instance, when you create an integer list with capacity 100, myArray will contain 100 zeros, but you should not display them. Therefore, you should iterate your loop from 0 to mySize-1. The function should return nothing. i. (5 pts) Write a function named at that accepts an integer parameter index and returns the element at the given index. If there is no element at that index, throw an exception. An example driver class (MyListDriver.cpp) and its output are given below. #include #include "MyList.h" using namespace std; int main() { } MyList a(3); MyList b(-10); cout < < "Size of a: < < a.getSize() < < endl; 11 cout < < "Capacity of a: < < a.getCapacity() < < endl; cout < < "Size of b: " < < b.getSize() < < endl; cout < < "Capacity of b: " < < b.getCapacity () < < endl; a.add(9); a.display(); a.add (2); a.display(); a.add(4); a.display(); a.add (3); a.display(); a.add(5); a.display(); a.add (1); a.display(); a.add(4); a.display(); a.add(10); a.display(); W 11 cout < < "a.getMin(): < < a.getMin() < < endl; cout < < "a.getMax(): < < a.getMax() < < < endl; cout < < "a.at(1): < < a.at(1) < < endl; cout < < "a.removeMin(): < < a.removeMin() <
Expert Answer:
Answer rating: 100% (QA)
template typename T T MyList T removeMin if mySize 0 throw stdruntimeerrorList is empt... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Fitzpatrick Novelties, an edgy producer of sportswear, has been experiencing a period of tremendous growth.Fitzpatrick does not currently pay any dividends, preferring instead to reinvest all...
-
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...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
.How dependent do you think the success of zero-based budgeting would be on the types of attribution models used? How might you increase the odds of success in this budgeting approach? .Advertising,...
-
It is not correct to say that matter can neither be created nor destroyed, what must we say instead?
-
Calculate the expected rate of return for a stock which has the following probability distribution of returns: Scenario Probability Return Recession .3 -5% Normal Economy .5 15% Boom .3 25%
-
How do we use the requirement of design to define messages and methods?
-
Wanda is a 20 percent owner of Video Associates, which is treated as a pass through entity for federal income tax purposes. This year, Wanda was allocated $45,000 of ordinary income from Video...
-
Married taxpayers Otto and Ruth are both self-employed. Otto earns $419,600 of self-employment income and Ruth has a self-employment loss of $25,500. How much 0.9 percent Medicare tax for high-income...
-
This comprehensive review problem requires you to complete the accounting cycle for Sherman Realty twice. This practice set allows you to review Chapters 1-5 while reinforcing the relationships...
-
What is the range in which you can be 95% confident that the true mass percent of Na2C2O4 lies? Answer using a complete sentence and show a calculation for finding the size of the range.
-
When using \(N=50\) observations to estimate the model \(y_{i}=\beta_{1}+\beta_{2} x_{i}+\beta_{3} z_{i}+e_{i}\), you obtain \(S S E=2132.65\) and \(s_{y}=9.8355\). a. Find \(R^{2}\). b. Find the...
-
Describe the "errors-in-variables" problem in econometrics and its consequences for the least squares estimator.
-
Describe how instrumental variables estimation is carried out in the case of surplus instruments.
-
Describe a test for the existence of contemporaneous correlation between the error term and the contemporaneous explanatory variables in a model, explaining the null and alternative hypotheses, and...
-
State the approximate large-sample distribution of the instrumental variables estimator for the simple linear regression model, and how it can be used for the construction of interval estimates and...
-
The volume of world trade in merchandise is growing faster than world GDP. This implies that Select one: O a. the global economy is headed for a large downward correction. O b. the economies of the...
-
Element compound homogeneous mixture (heterogeneous mixture) 4) A piece of gold has a mass of 49.75 g. What should the volume be if it is pure gold? Gold has a density of 19.3 g/cm (3 points) D=m/v...
-
Design and write a complete test program to test if the MyLinkedList class in Listing 24.6 meets all requirements. Listing 1 public class MyLinkedList extends MyAbstractlist { private Node head,...
-
Write a method with the following header to format the integer with the specified width. public static String format(int number, int width) The method returns a string for the number with one or more...
-
Write a program that displays the following table: a 1 2 3 4 aA2 1 16 aA3 1 8 27 64
-
The pendulum on a grandfather clock has a period of 2.00 s. If the clock is not wound, the pendulums amplitude begins to decay at a rate of 0.53% each pendulum period. a. What is the time constant of...
-
The motion of a nightingales wingtips can be modeled as simple harmonic motion. In one study, the tips of a birds wings were found to move up and down with an amplitude of 8.8 cm and a period of 0.82...
-
A block with a mass of 0.28 kg is attached to a horizontal spring. The block is pulled back from its equilibrium position until the spring exerts a force of 1.0 N on the block. When the block is...
Study smarter with the SolutionInn App