Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab #1 Dynamic Memory Allocation Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. You can view the

Lab #1 Dynamic Memory Allocation

Read the instructions carefully. At least 10% will be deducted if the instructions are not followed.

You can view the General Lab Requirements page for details on the general lab requirements.

Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input.

Use an IDE to create the program Lab1c.cpp as follows.

(Lab1c.cpp) Write Lab1c.cpp in the following order.

Write A Function Prototype

Write a function prototype for the function named allocIntArray. The function receives an integer parameter for the number of integer values the allocated memory can contain. The function returns a pointer to the first integer value in the allocated memory.

Write The Main Function

Define and initialize a pointer named ptr1 for pointing to an int value.

Define and initialize a pointer named ptr2 for pointing to an int value.

Allocate an array that can contain 100 int values by calling allocIntArray and assign the returned pointer to ptr1.

Store odd numbers starting from 1 into the array.

Allocate an array that can contain 1000 int values by calling allocIntArray and assign the returned pointer to ptr2.

Store even numbers starting from 2 into the array.

Print partial contents of the first array on the screen.

Print partial contents of the second array on the screen.

Delete the memory allocated for the first array.

Delete the memory allocated for the second array.

Write the function definition for allocIntArray

Write the block comment that describes the function name, what the function does, the parameter and the return value.

In the function body,

Use the new operator to allocate an array of integers using the parameter as the size of the array.

Return the pointer that is returned by the new operator.

Test the program

The output should look exactly as follows.

1 3 5 ... 195 197 199

2 4 6 ... 1996 1998 2000


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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Describe the nature of negative messages.

Answered: 1 week ago