Question: The following methods ( below 1 - 8 ) are to be added to ArrayInterface that is implemented in MyArray.h . Part of this assignment

The following methods (below 1-8) are to be added to ArrayInterface that is implemented in MyArray.h. Part of this assignment is building an interface, so they must be included in the interface.
You may not convert the arrays to vectors in the completion of these methods. The driver must also be updated to thoroughly test the newly added methods through the menu shown below. Your output does not need to match exactly the samples shown. MyArray is meant to handle all interactions with the underlying data structure, the array. You will use no other data structures in this assignment aside from the array in MyArray. NO VECTORS and NO DYNAMIC DATA STRUCTURES. You will not use any global variables in this assignment - part of the assignment is the ability to pass an object to functions.
Functional decomposition is to be employed in this assignment. Functional decomposition can be tricky - I would err on the side of too many functions rather than too few. If you find yourself rewriting code, a function is implied (and expected).
Note: Remember that MyArray is a template, not an actual class. MyArray.h should contain the implementation of the methods after the ; (semi-colon) of the specification of the class. The MyArray.cpp file is not used in this assignment since the implementation is in MyArray.h. Remove MyArray.cpp from your project.
Add these methods to the interface, fully define them in your template class and demonstrate them in the driver.
1) int countOccurrenceOf(T): This method will count the occurrences of the T item in the array.
2)void printReverse(): this method displays the original array in reverse order
3)void increaseElementsBy(T): this method will increase all elements by the parameter. In the case of a string, you will concatenate T
for example, the array looks like this:
red
blue
green
increaseElementsBy("two") yields this array:
redtwo
bluetwo
greentwo
4) bool find (T): this method will determine if the parameter exists in the array, return true if found, false if not - for strings this can be case sensitive (although, you may consider writing a function to ignore the case)
5) bool isFull(): this method will return true if there are 25 elements in the array, false if not
6) void add(T): this method will add the parameter to the end of the array if there is space (kind of like push_back() on vectors) Consider using the isFull() method as above. Use this method when loading the data from the data files, increase currentSize by 1 when an element is added.
7) void removeLast(); this method will effectively "remove" the last element of the array by reducing the count of the items by 1. Since the behavior of this is not the same for all data types, reducing the count by 1 will suffice. Make sure to check to see if there is an element to remove before removing it.
8) bool remove(T): this method will remove the first occurrence of T in the array, returns true if the element was found and removed, false otherwise
Removing an element from an array is effectively copying [n+1] to [n] repeatedly until you reach the end.
Other changes/additions to MyArray.h.
Make sure that you have an attribute in the MyArray.h class, int currentSize;
initialize this to 0 in the default constructor. Make sure that you have an attribute for the default array size, like this:
const int DEFAULT_SIZE =25;
then instantiate the array with that size, like this: T items[DEFAULT_SIZE];
In the driver you will instantiate MyArray.h twice, one to store integers and another strings.
The maximum size of the array is 25, you may have more in the data file.
The data for the integers will come from lab3Integers.txt (by line, more than 25 items in the file. limit to 25 items.)
The data for the strings will come from lab3Strings.txt (by line, more than 25 items in the file. limit to 25 items.)
Provide a menu of available functions (this should be a function) to the user as below (run this with both objects of MyArray - you may consider making this another option for your user):
1. display all items
2. find an item
3. display current state (this will display the number of items currently in the data structure and whether it's full or not)
4. display in reverse
5. add an item
6. remove the last item
7. remove an item by value
8. increase elements by
9. quit
Loop around the menu until the user selects the quit option.
ADeliverable files are arrayInterface.h, MyArray.h, main.cpp
ArrayInterface.h--------
#ifndef ARRAYINTERFACE_H
#define ARRAYINTERFACE_H
template
class ArrayInterface {
public:
virtual T maximumElement()=0;
virtual int countOccurrenceOf(T item) const =0;
virtual void printReverse() const =0;
virtual void increaseElementsBy(T item) const =0;
virtual bool find(T item) const =0;
virtual bool isFull() const =0;
};
#endif // ARRAYINTERFACE_H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!