Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please help with Resize code for vectorADT, It suppose to follow this unit test. vectorADT::resize() to a smaller size. calling resize() to shorten

Can someone please help with Resize code for vectorADT, It suppose to follow this unit test.

vectorADT::resize() to a smaller size.

calling resize() to shorten your container from 15 to 2 ...

Sorry, your resize() fails the test due to either or both of the following causes:

1. it doesn't change the size to 2

2. it changes the capacity of the container when it should remain the same

Test vectorADT::resize() to a size that's larger than the current capacity

calling resize() to expand your container from 17 to 31 ...

Sorry, your resize() fails the test due to either or both of the following causes:

1. it doesn't change the size to 31

2. it doesn't increase the capacity of the container to 62

(I think my code is only changing the capacity and not the size)This is my code:

void VectorADT::resize(int newSize) { double * temp; if (newSize > capacity) { capacity = newSize * 2; } temp = new double[capacity]; if (newSize < size) { for (int i = 0; i < capacity; i++) { if (i < newSize) temp[i] = array[i]; else temp[i] = 0.0; } } else if(newSize > size) { for (int i = 0; i < newSize; i++) { if(i temp[i] = array[i]; else temp[i] = 0.0; } } delete[] array; array = temp; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

Effort (person-hours) to perform the evaluation, Weval.

Answered: 1 week ago