Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SET-252 C Programming #2 Homework: 7 CResizableArray Part 2. Step 1 Continued with your code from homework 5. I recommend you make a copy of

SET-252 C Programming #2

Homework: 7 CResizableArray Part 2.

Step 1

Continued with your code from homework 5. I recommend you make a copy of the folder/project and keep your homework 5 separate.

Add the following constructors.

Make the Initialize method protected and add two parameters: initial size and default value. Call Initialize from all the the constructors.

Add a destructor and a protected clean up method. Call clean up from the destructor. Delete any allocated memory. Either delete any allocated memory and set all properties to zero or call SetSize( 0 ). Either way make sure you dispose of memory correctly.

Make get size a constant method.

Make get value at a constant method.

Make print a constant method. Make the caption parameter a const char*.

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. WARNING: do not procedurize any code in main. You may exceed the 1-page limit for main for this assignment.

(continued on the next page)

Step 2 A Mystery

Using your CResizableArray class, create the following main and test subroutines. Run your code. Make sure the application terminates normally. Do NOT click the X on the command window.

// --------------------------------------------------------------------------------

// Prototypes

// --------------------------------------------------------------------------------

void Test1( CResizableArray &clsValues ); // By Reference

void Test2( CResizableArray clsValues ); // By Value

// --------------------------------------------------------------------------------

// Name: main

// Abstract: This is where the program starts.

// --------------------------------------------------------------------------------

void main()

{

CResizableArray clsValues;

// Create the array

clsValues.SetSize(4);

// Populate Array (value, index)

clsValues.SetValueAt( 2, 0 );

clsValues.SetValueAt( 4, 1 );

clsValues.SetValueAt( 6, 2 );

clsValues.SetValueAt( 8, 3 );

// Test 1

Test1( clsValues );

printf( "After Test 1 ------------------------------ " );

clsValues.Print( );

// Test 2

Test2( clsValues );

printf( "After Test 2 ------------------------------ " );

clsValues.Print( );

}

// --------------------------------------------------------------------------------

// Name: Test1

// Abstract: Pass by reference

// --------------------------------------------------------------------------------

void Test1( CResizableArray &clsValues )

{

printf( "Test 1 ------------------------------ " );

clsValues.Print( );

}

// --------------------------------------------------------------------------------

// Name: Test2

// Abstract: Pass by value

// --------------------------------------------------------------------------------

void Test2( CResizableArray clsValues )

{

printf( "Test 2 ------------------------------ " );

clsValues.Print( );

}

(continued on the next page)

Step 3 What is happen?

Explain in comments, at the top of your program, what is happening. Your answer is worth 31% of the grade for this assignment.

Propose one or more possible solutions. Making variables global is a hack not a solution. Always passing by reference is a hack not a solution.

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions