Question
Visual Studio c++ Make sure it runs and add a picture of the console screen and comments Objective: Pointers Templates Question 1a: Implement a class
Visual Studio c++
Make sure it runs and add a picture of the console screen and comments
Objective:
- Pointers
- Templates
Question 1a:
Implement a class called myVector that stores integers in it. You have to implement the following members:
- Private data member arrayPtr to integer array
- Private data member capacity of array
- Private data member that specifies the actual elements i.e.current size(elements added to the array by the user (initially it should be set to zero))
- Default constructor (initially it should allocate an array of size 2. You will have to set the other private members too. Initialize the array to zero)
- Constructor with int parameter (the int parameter specifies the capacity of the array). The constructor should initialize the entire array to zero.
- Copy constructor (should make a deep copy)
- Destructor (if the array is allocated then deallocate it)
- Get function for total capacity…(think of other get functions)
- + operator that takes an integer variable as parameter. This method should add one integer to the array and increase the number of current elements. If the allocated size is not sufficient then increase the capacity of the array by double. Copy the old array in the new one (including the new element) and delete the old array.
- – operator that takes no parameters. This method should delete the last added value from the array and change the current size. (note no memory allocation or deallocation will take place here)
- + operator that takes any Vector object as argument. What should be the exact type of that parameter? This operator should return a new array which has all the elements of the current object (lhs) and the array passed as parameter (rhs).
- = operator which should make a deep copy. Make sure if lval is already allocated then it should be deallocated and allocated again with the size of the rval
- [] operator which should set the element at index to the value specified in parameter. If the index is out of bound then return false otherwise return true.
- [] operator which should place the value of an element at index in the parameter. If the index is out of bound then return false otherwise return true.
- >>operator which takes as input the elements of myVector.
- <
Provide a sufficient main program that tests all of the above functions. (including destructors too).
Question b:
Convert the class myVector, which is implemented in Question 1, in a generic template class that can store any data value in it.
Question c:
Design a specialized template class for myVector which is implemented in Question 2, to handle ( char* ) data type.
Step by Step Solution
3.40 Rating (169 Votes )
There are 3 Steps involved in it
Step: 1
Here is the code for myVector class include include using namespace std template ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started