Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a void function called repeatArray that takes two parameters - a reference to a pointer to a dynamically allocated array of doubles, and the

Write a void function called repeatArray that takes two parameters - a reference to a pointer to a dynamically allocatedarray of doubles, and the size of that array. The pointer is passed by reference because you want to change the value of the pointer. The function should replace the array with one that is twice as large, with the values from the original array appearing twice. For example, if array that was passed in was {3.1, 4.2, 5.3}, then it should be replaced by {3.1, 4.2, 5.3, 3.1, 4.2, 5.3}. The function should prevent any memory leaks. Remember to also prevent memory leaks in the main you use for testing.

For example, it could be used like this:

 double* myArray = new double[3]; for (int i=0; i<3; i++) myArray[i] = (i+1)*2; repeatArray(myArray, 3); for (int i=0; i<6; i++) cout << myArray[i] << endl; delete []myArray; 

For the following projects (and all future projects in this course):

Do not include a main method in the files you submit - just the definitions of the assigned functions. I will compile your code with my own main method for testing, and there can only be one main method in a program. You will of course need to have a main method for testing purposes - just make sure you comment it out (or delete it) before submitting your file.

Do not use any global variables. Global variables and their drawbacks are discussed on pages 357-9 of the textbook. If the assignment description doesn't specify a return value for a function, then it should have a return type of void.

The file must be named repeatArray.cpp.

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

Beyond Greed And Fear Understanding Behavioral Finance And The Psychology Of Investing

Authors: Hersh Shefrin

1st Edition

0195161211, 978-0195161212

Students also viewed these Databases questions