Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. Pointers
  2. Templates

Question 1a:

Implement a class called myVector that stores integers in it. You have to implement the following members:

  1. Private data member arrayPtr to integer array
  2. Private data member capacity of array
  3. 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))
  4. 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)
  5. Constructor with int parameter (the int parameter specifies the capacity of the array). The constructor should initialize the entire array to zero.
  6. Copy constructor (should make a deep copy)
  7. Destructor (if the array is allocated then deallocate it)
  8. Get function for total capacity…(think of other get functions)
  9. + 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.
  10. – 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)
  11. + 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).
  12. = 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
  13. [] 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.
  14. [] 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.
  15. >>operator which takes as input the elements of myVector.
  16. <

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals of Advanced Accounting

Authors: Joe Ben Hoyle, Thomas Schaefer, Timothy Doupnik

6th edition

0-07-786223-6, 101259095592, 13: 978-0-07-7, 13978125909559, 978-0077862237

More Books

Students also viewed these General Management questions