Question: Write a class named MyVector using the following UML diagram and class attribute descriptions. MyVector will use a partially filled array to store a collection
Write a class named MyVector using the following UML diagram and class attribute descriptions. MyVector will use a partially filled array to store a collection of integers. The array will be created using dynamic memory allocation. UML Diagram: Class Attributes: Variables: list - an integer pointer. Holds the memory address for an integer array. max_size - an integer that holds the capacity of the array. list_size - an integer that stores the number of valid values currently stored in the array. The valid values in the array start at element 0 and go through list_size - 1. Methods: constructor - dynamically allocates the array of integers, storing it's memory address in pointer list. Initializes max_size to 10 and list_size to 0. destructor - deletes the array. push_back - If the array isn't full, assigns it's argument to list[list_size] and then increments list_size. The array is full if list_size == max_size. pop_back - if the array isn't empty (list_size == 0), decrements size. at - uses it's argument as a subscript for the array. Returns that element. It's return type is an integer reference (int&). clear - sets list_size to 0. That's it. This effectively "empties" the array. Note, nothing about the array itself changes. size - returns the list_size variable. None of the above methods interacts with the user in any way. Demonstrate your class in a program that does the following: Uses push_back method to add ten random numbers to a MyVector object. Uses the size method to display the number values in the object. Calls the at method ten times to display the contents of the object. Uses the at method to change the 3rd value in the object to 99. Uses the pop_back method to remove the last value in the object. Calls the at method nine times to display the changed contents of the object. A 10-Point Sample Run: Hints: Review Chapter 7: "Partially filled arrays" and Vectors. Create the array dynamically by having the following statement in the constructor: list = new int[max_size]; Submission Instructions: Submit your solution using three files: pc13.cpp, MyVector.h and MyVector.cpp. MyVector.h will contain the class declaration. MyVector.cpp will contain the method definitions. pc13.cpp will #include "MyVector.h" and contain the logic of the program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
