Modify the class ArrayList given in the lecture by adding to it the methods list
ID: 3536102 • Letter: M
Question
Modify the class ArrayListgiven in the lecture by adding to it the methods listed below for Exercise 2. In each case, the appropriate error message should be generated if an invalid condition occurs. For example, an error message should be generated when trying to insert an item in a given location in the list and the location is out of range. Create a Main class to test your ArrayList class.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
a. ArrayList(int size): create a constructor that sets the size of the array list to the value passed in size(note that the class variable SIZEcannot be finalanymore).
b. int getLength(): create this method to return the number of items in the list (accessor method).
c. int getSize(): create this method to return the size of the list (accessor method).
d. void clear(): create this method to remove all of the items from the list. After this operation, the length of the list is zero.
e. void replace(int location, int item): create this method to replace the item in the list at the position specified by location. The item should be replaced with item.
f. void add(int location, int item): create this method to add an item to the list at the position specified by location.
g. void remove(int item): create this method to remove an item from the list. All occurrences of item in the list should be removed.
h. int get(int location): create a method that returns the element at location.
In the Doc Sharing area labeled “Implementing an ArrayList class" you will find the basic framework of the ArrayList class you need to use to implement your solution.
Using the class ArrayList completed in the previous exercise, write a program to store the first 30 Fibonacci numbers in an ArrayList object.
Create a class Bag (multiset) that uses an array to store the bag items. The class should have the methods listed below. Create a Main class to test your Bagclass. This Main class should fill a bag of integers with 10 random numbers, each in the interval [0, 15], and print how many times each integer in the interval [0, 15] appears in the bag.
a. Bag(): default constructor that sets the size of the bag to 20
b. Bag(int size): non default constructor that sets the size of the bag to the value passed in size.
c. boolean isEmpty(): determines whether the bag is empty
d. void display(): prints the bag elements.
e. int getLength(): returns the number of items in the bag.
f. int getSize(): returns the size of the bag.
g. void clear(): removes all of the items from the bag.
h. void add(int item): adds an item to the bag.
i. void remove(int item): removes an item from the bag. All occurrences of itemin the bag should be removed.
j. int count(int item): counts the number of occurrences of item in the bag.
Explanation / Answer
#include using namespace std; class Arrays { public: int sizeOfArray; void displayMessage() { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.