I can\'t do it, but I was told it is very simple and fast to do.. . Please I nee
ID: 3659236 • Letter: I
Question
I can't do it, but I was told it is very simple and fast to do.. . Please I need it done literally within hour Design and implement the class myArray that allows user to store an array of items of certain type. Your class should support arrays of various types, as long as items within the array are the same. It is sufficient to iimplement only one constructor, with only uB argument (for upperBound). Your class should have a method to insert element in certain position in the array (called insertAt) and to retrieve element from certain position (retrieveAt). Method retrieveAt can take two arguments - the position number and the reference to a variable, into which it will write the result (retrieved item from the array) Your app.cpp should look as follows: #include #include "myArray.h" using namespace std; int main() { cout<<"int array:"<<endl; myArray intArr(3); intArr.insertAt(0, 11); intArr.insertAt(1, 12); intArr.insertAt(2, 13); for(int i=0; i<3; i++){ cout<<"intArr["<<i<<"]: "; int item = 0; intArr.retrieveAt(i, item); cout<<item<<endl; } cout<<endl; cout<<"double array:"<<endl; myArray doubleArr(3); doubleArr.insertAt(0, 0.11); doubleArr.insertAt(1, 0.12); doubleArr.insertAt(2, 0.13); for(int i=0; i<3; i++){ cout<<"doubleArr["<<i<<"]: "; double item = 0; doubleArr.retrieveAt(i, item); cout<<item<<endl; } cout<<endl; return 0; } //the above code produces the following output: int array: intArr[0]: 11 intArr[1]: 12 intArr[2]: 13 double array: doubleArr[0]: 0.11 doubleArr[1]: 0.12 doubleArr[2]: 0.13 Press any key to continue . . . To accomplish this, you will need to use templates. Sample header file, as well as app.cpp are uploaded on blackboard with this assignment.Explanation / Answer
This is all what i got as of now...as u said ASAP :: //Header the myArray.h #ifndef H_myArray #define H_myArray #include using namespace std; class myArray { public: // constructors myArray ( int ); myArray ( int, int ); ~myArray(); // subscript operator for non-const objects int &operator[] (int); //subcript operator for const objects returns rvalue int &operator[] (int) const; private: int size; // pointer-based array size int startIndex; //pointer-based array size //pointer to first element of pointer-based array int *ptr; }; //end template class array #endif //implementation file #include #include "myArray.h" using namespace std; //constructor myArray :: myArray ( int si, int s ) { startIndex = -si; size = s; // create space for pointer based array ptr = new int [ size + startIndex ]; // set pointer-based array element for ( int i = 0; i < ( s + startIndex ); i++ ) ptr[i] = 0; } // end function myArray //constructor myArray::myArray (int s) { startIndex = 0; size = s; //crate space for pointer-based array ptr = new int [size]; //set pointer-based array element for (int i = 0; i= size ) { cerrRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.