CSC136 – Program 3, Array Assignment: Update the provided Array template class to handle partial usage. Supplied: Array template class: Array.h Initial test program: itest.cpp Working executable...

CSC136 – Program 3, Array


Assignment: Update the provided Array template class to handle partial usage. Supplied: Array template class: Array.h Initial test program: itest.cpp Working executable examples: isoln, fsoln Location: /export/home/public/carelli/csc136/Projects/Project3 Deliverable: Updated Array.h and completed itest.cpp program Additional test program ftest.cpp Do not compile the header file! Do not turn in executables or any compiled files!!! Due: The programs MUST be turned in by the assigned date and time using the turnin script. Late submissions will, in fact, be rejected by the script, resulting in a grade of zero. Overview: The task in this assignment is to update the provided Array class to manage the situation where the internal array can be partially filled. Up to this point, the examples we have worked with have assumed that the entire array was filled with useful data. This assignment will address a situation wherein the array has been allocated with a specific capacity, but only a subset of the elements are being used. To facilitate this, instead of having just one class variable to store the size of the array (previously called size, or items), there will be two variables. The first, called capacity, will store the actual allocated size of the array. The second, called numUsed, will store the number of elements in the array that are actually being used. It is assumed that the used elements are stored in locations zero through numUsed‐1. Obviously, numUsed must be class definition has been updated to reflect this change, with both capacity and numUsed defined. In addition, the “get” methods for capacity and numUsed have been defined and implemented as has the default constructor. Beyond that, a number of methods have been defined. They are written with minimal functionality. Generally, just enough is written to allow the test program to compile. numUsed is left unset. You will need to go through each method and update it, rewriting and replacing code as needed to implement both the desired overall functionality and partial array usage. Use the provided test program, itest.cpp, to ensure that your changes work correctly. Compare your results to those obtained from the compiled example, isoln. They should match.


Look at the Array examples provided in class. There are many relevant methods defined there!


Implementation details: The first problem to address is the constructors. There are three of them. It will be necessary to set not only the capacity, as the internal arrays are allocated, but the number of elements in use, as follows: Default constructor: This one is already implemented for you – nothing to do here. The number of elements in use is set to zero. The default capacity is 3. The capacity can, optionally, be set to a different value with an argument. Constructor from dataType array: both the Array capacity and the number of elements to load from the given dataType array will be given as arguments. Note that the number to use (numUsed) must be <= to="" allocated="" array="" size="" (capacity)!="">


Assignment operator (=): Like the copy constructor (watch out for self‐assignment) Plus equals(+=): A special case. If the number of elements in use is less than the capacity, just add the new element in the next available unused array location. If the array is full (number of elements equals capacity), then you will need to expand the size of the array, as was done in existing examples. Subscript operators ([]): You need to write these – two possibilities. 1. For the const version, an error should occur if a user attempts to access an unused location. 2. For the non‐const version, any location index within the array’s capacity is valid – but!... if the requested location is a previously unused location (i.e. > numUsed), then numUsed must be updated to that location. In other words, the used portion of the array expands when a previously unused value is accessed, but only if it is with the array’s capacity. Accessing any location outside of the capacity would still be an error. Pre‐increment(++): For this one, add an element with a default value to the end of the array. Be sure to properly update the capacity and numUsed. Be sure to initialize the new element to a valid default value. Post‐increment(++): Behaves the same as the pre‐increment in that it adds a default value to the end of the array. Be sure to make both operators work correctly when used in statements (as in the test program)! Dereference (*): Simply return the value of the first element in the stored array. Output stream (<): this="" one="" is="" already="" completed="" for="" you.="">>): Write this operator. It should add elements to the end of an existing Array object.


Test Programs (Drivers): The itest.cpp program includes a working function, called printArray(), for outputting Array’s including the values for capacity and numUsed. There is also a working executable that illustrates how the completed class should work. itest.cpp will compile and print out brief messages for each test to be implemented. The tests are written. You will need to complete the test program called ftest.cpp that will take a user‐supplied input from the terminal and load it into an Array object that stores floats. You must define and use an overloaded >> operator to load the item directly into the Array object. Don’t read it into a float variable and then load them. Set the program up to read and store the value into default (empty) Array object. An example executable called fsoln is provided to illustrate how it should work. Final Notes: Complete the updates one at a time and test after each change using itest.cpp. You don’t need a makefile, just compile the program with your updated Array.h. Compare your results against the provided isoln executable. You should get the same thing. Do them in the order they are tested in itest.cpp. Don’t forget to document the methods. There are some comments in Array.h – you have to add the departmental standard documentation there. Turn, in ONLY itest.cpp, ftest.cpp, and Array.h. Grading Considerations: 1. Program must compile and be turned in on time. Turn in only itest.cpp, ftest.cpp and Array.h 2. The methods must be well commented/documented. a. Using the departmental standard for documentation. 3. Update the constructors to properly account for the number of elements in use 4. Update the assignment operation to properly account for the number of elements in use. 5. Properly implement the partially filled and at‐capacity cases for operator+= 6. Properly implement both the const and non‐const versions of the subscript operator as described above. 7. Properly implement the pre‐ and post‐increment (++) operator2. 8. Test using itest.cpp. 9. Complete the input stream operator and write the test program (ftest.cpp). Templates for adhering to the departmental documentation guidelines can be found in CodeDocTemplate.txt under the Documents link on the course webpage.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here