Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROJECT: OOP dynamic array based class Part 1: Build a class dynListType based on dynamic array. Its declaration is provided below: // no more MAX

PROJECT: OOP dynamic array based class

Part 1: Build a class dynListType based on dynamic array. Its declaration is provided below:

// no more MAX

class dynListType

{

public:

private:

int* dataPtr;

int size;

int maxSize;

};

Follow example in W12 Thur (ch12-ch13 Classes with pointer data members), add:

a (default) constructor with a int param (default value 5) and

a destructor.

Add those 10 functions from HW8 into dynListType. Be sure to change each occurrence of dataArr (HW8) into dataPtr. Make additional necessary changes.

getSize()

getMaxSize()

isEmpty()

search()

at()

two inserts

remove()

operator +

operator << (output insertion operator)

At this point your program should be able to compile, but may crash during execution. Thats because copy constructor and overloaded assignment are required to handle dynamic data members.

Now add:

Copy constructor

Overloaded assignment operator =

Your program should work perfectly now. dynListType provides the same functionality listType (HW8) does, except that dynListType doesnt have any capacity cap (i.e. there is no MAX for maxSize).

Test your class thoroughly before proceeding to Part 2.

Part 2: modify your dynListType program from Part 1.

Overload == operator (comparison operator, as in if (obj1 == obj2) ): return true if two list objects contain the same data items in same order. Values of maxSize dont matter. For example, given obj1 {maxSize 10, <10, 20, 30>} and obj2 {maxSize 5, <10, 20, 30>}, the comparison should return true.

Modify the two insert functions so a list will never be full, like how the STL vector class works. Whenever an insertion reaches the maxSize cap, double maxSize, and reallocate storage space.

If size before insertion is equal to maxSize // current maxSize reached

maxSize <- 2 * maxSize

allocate a new dynamic array with maxSize slots

copy data pointed by dataPtr over

delete the dynamic array currently pointed by dataPtr

let dataPtr point to the newly allocated dynamic array

End if

Insert as normal

Modify your driver accordingly to test the new/modified functions.

Part 1 and Part 2: additional requirements:

Organize your program into header file (interface), implementation file, and driver file. Use #include guard with the header file.

Pre- and Post- condition comments for each new/updated function. Pre- condition may be skipped if its just xx is initialized.

Comment your program appropriately. Pay attention to the standard stuff like coding style, indention, heading, and curly braces.

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

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago