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 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 ; semicolon 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.
int countOccurrenceOfT: This method will count the occurrences of the T item in the array.
void printReverse: this method displays the original array in reverse order
void increaseElementsByT: 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
increaseElementsBytwo yields this array:
redtwo
bluetwo
greentwo
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
bool isFull: this method will return true if there are elements in the array, false if not
void addT: this method will add the parameter to the end of the array if there is space kind of like pushback on vectors Consider using the isFull method as above. Use this method when loading the data from the data files, increase currentSize by when an element is added.
void removeLast; this method will effectively "remove" the last element of the array by reducing the count of the items by Since the behavior of this is not the same for all data types, reducing the count by will suffice. Make sure to check to see if there is an element to remove before removing it
bool removeT: 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 to n repeatedly until you reach the end.
Other changesadditions to MyArray.h
Make sure that you have an attribute in the MyArray.h class, int currentSize;
initialize this to in the default constructor. Make sure that you have an attribute for the default array size, like this:
const int DEFAULTSIZE ;
then instantiate the array with that size, like this: T itemsDEFAULTSIZE;
In the driver you will instantiate MyArray.h twice, one to store integers and another strings.
The maximum size of the array is you may have more in the data file.
The data for the integers will come from labIntegers.txt by line, more than items in the file. limit to items.
The data for the strings will come from labStrings.txt by line, more than items in the file. limit to 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:
display all items
find an item
display current state this will display the number of items currently in the data structure and whether it's full or not
display in reverse
add an item
remove the last item
remove an item by value
increase elements by
quit
Loop around the menu until the user selects the quit option.
ADeliverable files are arrayInterface.h MyArray.h main.cpp
ArrayInterface.h
#ifndef ARRAYINTERFACEH
#define ARRAYINTERFACEH
template
class ArrayInterface
public:
virtual T maximumElement;
virtual int countOccurrenceOfT item const ;
virtual void printReverse const ;
virtual void increaseElementsByT item const ;
virtual bool findT item const ;
virtual bool isFull const ;
;
#endif ARRAYINTERFACEH
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
