Your Perfect Assignment is Just a Click Away
We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!

glass
pen
clip
papers
heaphones

Discussion: Vectors

Discussion: Vectors

Q4 (70 pts). In this question, you will write your own container class named MyCon similar to vector class in C++. Your class must be a template class which will contain its elements in an

array named myArray. Since this class will be a template class, you should include the function

definitions at the end of the header file. You can also check the Stack example in Chapter 9. You

should keep the size and capacity of your container in two separate attributes named mySize

and myCapacity. Therefore, your class will have three data members: one generic dynamic

array (you should use pointer representation as given in the Stack example) and two integers.

In this container, the elements will always be sorted in increasing order. As the function

members of your class write the following functions:

a. (10 pts) Write a constructor that accepts one integer parameter as the capacity of your

container, creates a new array with the given capacity, and stores new array in myArray.

The constructor should also set myCapacity to the parameter value and mySize to 0. If

the parameter is not a positive number, you should set the capacity as 10 and create the

array with 10 elements.

b. (5 pts) Write getters for size (getSize) and capacity (getCapacity).

c. (15 pts) Write add function that accepts an element having generic type and adds this

element to the appropriate place in myArray. Note that the elements must always be

sorted. For instance, if the container elements are [3, 7, 9, 12] and the parameter of add

function is 5, it will be added as the second element. The elements will be [3, 5, 7, 9, 12]

after addition. You should also update the size (mySize) accordingly. The function should

return nothing. If the capacity is full, you should

? double the capacity by creating a new array,

? copy existing elements into new array,

? add the element into appropriate place,

? destroy old array,

? store the new array in myArray,

? update myCapacity.

d. (15 pts) Write remove function that accepts an element having generic type, searches it

in the array and removes all occurrences of that element in the array. You should shift

the elements after removal. For instance, if the elements are [3, 5, 5, 7, 9, 12], and the

parameter of remove function is 5, the container elements will be [3, 7, 9, 12] after the

removal. You should also update the size (mySize) accordingly. The function should

return nothing.

e. (5 pts) Write a function named display to print the elements in the container separated

by a space. Note that you should not print all array content, you should print the

elements in the container. For instance, when you create an integer container with

capacity 100, myArray will contain 100 zeros, but you should not display them.

Therefore, you should iterate your loop from 0 to mySize-1. The function should return

nothing.

f. (5 pts) Write a function named sum to return the sum of the elements in the container.

g. (5 pts) Write a function named at that accepts an integer parameter index and returns

the element at the given index.

h. (5 pts) Write a function named search that accepts an element having generic type as a

parameter and searches it in the container. The function should return true or false.

i. (5 pts) Write a function named clear that does not accept any parameter and clears the

container by setting size as 0. The function should return nothing.

An example driver class (MyConDriver.cpp) and its output are given below.

Size of b: 0

Capacity of b: 10

4

2 4

2 4 9

2 4 4 9

2 4 4 8 9

1 2 4 4 8 9

1 2 4 4 8 9 9

a.sum(): 37

a.at(3): 4

1 2 8 9 9

1 2 8 9 9

1: FOUND.

2: FOUND.

3: NOT FOUND.

4: NOT FOUND.

Order Solution Now

Our Service Charter

1. Professional & Expert Writers: Homework Free only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Homework Free are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Homework Free is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Homework Free, we have put in place a team of experts who answer to all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

Homework Free Org

Your one stop solution for all your online studies solutions. Hire some of the world's highly rated writers to handle your writing assignments. And guess what, you don't have to break the bank.

© 2020 Homework Free Org