Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SET-252 C Programming #2 Homework: 5 CResizableArray This is a mean one. Step 1 Create a CResizableArray class with the following private properties and public

SET-252 C Programming #2

Homework: 5 CResizableArray This is a mean one.

Step 1

Create a CResizableArray class with the following private properties and public methods:

m_lngArraySize

m_palngValues

void Initialize( ); // Set array size and array pointer to 0

void SetSize( long lngNewSize ); // Zero value are allowed but not negative values.

long GetSize( );

void SetValueAt( long lngValue, long lngIndex );

long GetValueAt( long lngIndex );

void AddValueToFront( long lngValue );

void AddValueToEnd( long lngValue );

void InsertValueAt( long lngValue, long lngIndex );

void RemoveAt( long lngIndex );

You may need to add more methods to the class but you need at least those specified above.

Make sure you boundary check in ALL method input parameters that change the array. That means you have to check to make sure the indexes are valid. Purposefully test your code with bad index values (e.g. 1). I recommend you clip bad index values to either the front or the end.

When you call the SetSize method you want to preserve any existing values. Default all new array values to 0.

For example: SetSize( 5 )

Before:

2

4

6

8

After:

2

4

6

8

0

Adding a value to the front or end preserves the existing values.

For example: AddValueToFront( 10 )

Before:

2

4

6

8

After:

10

2

4

6

8

(continued on the next page)

Inserting a value to the middle does not overwrite any existing values but makes the array larger by one. Again, preserve any existing values.

For example: InsertValueAt( 5, 2 )

Before:

2

4

6

8

After:

2

4

5

6

8

RemoveAt also preserves existing values.

For example: RemoveAt( 2 )

Before:

2

4

6

8

After:

2

4

8

Make sure you test your code thoroughly. For example, insert a value into a size zero array and remove a value from a size zero array.

(continued on the next page)

Extra Credit

Overload the [] operator which can be used instead of SetValueAt and GetValueAt.

Muchious Extrous Creditous

Use templates.

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

List the five steps in the decision-making model.

Answered: 1 week ago