Question: CS2250 PROGRAMMING PROJECT 2: In this project you will be working with arrays and pointers in order to become more comfortable dealing with them together.

CS2250 PROGRAMMING PROJECT 2: In this project you will be working with arrays and pointers in order to become more comfortable dealing with them together. This project is divided up into parts, with some dependency between them (certainly with the first part), so work on it incrementally.

Note: In this project all arrays need to be created INSIDE functions and then passed to the outside through the return statement or through reference pointers. I want no arrays created without dynamic allocation. I will give you function prototypes that I expect you to use, note that you can re-use functions from previous parts.

Task 1: Your program should call a function that prompts the user for a number (1-10) and then dynamically allocates an array of that size. It should then take from the user integers to fill up that array. It should check to see if the original number is in the range of 1-10 and it should make sure that the following numbers are in the range [1-100] (1 and 100 are allowed). This function should then return that array through the return statement to the main body and the size of the array through a reference parameter. In the main body, the array should be displayed on the screen.

To do this, you should create a function to display that array. When displayArray is called, it should display the array on one line, by itself, with a space following each number, surrounded by square brackets: [1 5 13 3 7 ]

Prototypes for task 1: int * generateAndFillArray(int & size); void displayArray(const int *arr, int size);

Task 2: Your program should call a function to create a copy of the array generated in part one. This function would take in an array and then inside dynamically allocate an array equal in size to it and then copy over all the elements. It should then return that array through the return statement.

Once this is done, output both arrays to the screen using displayArray (yes, even the array you passed to it to get a copy, in order to verify that it was not changed accidentally).

Prototypes for task 2: int * copyArray(const int *arr, int size);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!