Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAMMING MICROSOFT VISUAL #define _CRT_SECURE_NO_WARNINGS #include #include #include typedef struct { int *array; int effectiveSize; int maximumSize; } DynamicArray; void CreateArray(DynamicArray *pDynamicStruct, int initialSize)

C PROGRAMMING MICROSOFT VISUAL

#define _CRT_SECURE_NO_WARNINGS

#include

#include

#include

typedef struct

{

int *array;

int effectiveSize;

int maximumSize;

} DynamicArray;

void CreateArray(DynamicArray *pDynamicStruct, int initialSize)

{

pDynamicStruct->array = (int *)malloc(sizeof(int) * initialSize);

//Or

//pDynamicStruct->array = (double *) calloc(initialSize,sizeof(double));

pDynamicStruct->effectiveSize = 0;

pDynamicStruct->maximumSize = initialSize;

}

//TODO: Fill in this function

// This function expands the array to maximumSize * 2

void ExpandArray(DynamicArray *pDynamicStruct)

{

//1) Create new memory space by calling malloc or calloc, save the address to a temp pointer

// You want maximumSize * 2 new indices. Don't forget, malloc is number of BYTES, so include sizeof(int)

//2) Copy the data from the old pointer (pDynamicStruct->array) to your new pointer.

// You may use a for loop or if you want an advanced solution, use memcpy

//3) Free the old pointer that is stored in the pDynamicStruct->array variable

//4) Update the pDynamicStruct's array and maximumSize variables with their new values (the temp pointer and new size)

}

//TODO: Fill in this function

// This function adds a new value to the expanding array

void PlaceValue(DynamicArray *pDynamicStruct, int value)

{

//1) Place value in the array to the index effectiveSize is pointing to

//2) Increment effective size

//3) If effective size == maximum size, expand the array

}

void PrintArray(const DynamicArray *pDynamicStruct)

{

int i;

for (i = 0; i < pDynamicStruct->effectiveSize; i++)

{

printf("%d ", pDynamicStruct->array[i]);

}

printf(" ");

}

int main(void)

{

int i;

DynamicArray dynamicArray;

CreateArray(&dynamicArray, 5);

//TODO: Delete from here.....

dynamicArray.array[dynamicArray.effectiveSize++] = 5;

dynamicArray.array[dynamicArray.effectiveSize++] = 10;

dynamicArray.array[dynamicArray.effectiveSize++] = 15;

dynamicArray.array[dynamicArray.effectiveSize++] = 20;

//TODO: ...to here and replace with repeated calls to PlaceValue()

PrintArray(&dynamicArray);

system("pause");

}

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago