Function prevent any memory leaks

Assignment Help Basic Computer Science
Reference no: EM132254223

Need help with this homework problem.

Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints, 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 dynamically allocate an array that is twice as long, filled with the values from the original array followed by each of those values times 2. For example, if the array that was passed in was {4, 2, 5}, then it should be replaced by {4, 2, 5, 8, 4, 10}. The address of the new array should be assigned to the pointer that was passed as a parameter.  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:

   int* myArray = new int[3];
   myArray[0] = 4;
   myArray[1] = 2;
   myArray[2] = 5;

   transformArray(myArray, 3);

   for (int i=0; i<6; i++)
      cout << myArray[i] << endl;

   delete []myArray;

The file must be named transformArray.cpp.

Reference no: EM132254223

Questions Cloud

Perform the following calculations assuming : Perform the following calculations assuming that the values are 8-bit decimal integers stored in two's complement format. Be sure to consider the possibility of
Why might management opt for other than the most economic : Using expected value, is it economically better to make or buy the component? Strategically thinking, why might management opt for other than the most economic?
What is the binary representation of the decimal number : 1. What is the binary representation of the decimal number 5.75 assuming the IEE 754 single precision format?
Discuss the weather forecast for the given area : This week's discussion covers topics of weather observations, weather forecasts, and severe weather. Choose any location and discuss the weather forecast.
Function prevent any memory leaks : Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints
Define the practicality of the terror management theory : In the opening of your work, provide an overview of the TMT, noting the critical aspects of the theory, to demonstrate a clear understanding of what the theory.
Create a new string consisting of alternating characters : Given the strings s1 and s2, not necessarily of the same length, create a new string consisting of alternating characters of s1 and s2.
The? punctuated-equilibrium model of group? development : According to the? punctuated-equilibrium model of group? development, the transition sets the revised direction for? ______.
Should the given be viewed as the new normal : Considering the materials for the week, share your thoughts on the effect of media exposure to images from terrorist events. Should these be viewed.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What are some of most important technological innovations

What are some of the most important technological innovations of the past year?

  Write a program that inputs a series of integers

(Even or Odd) Write a program that inputs a series of integers and passes them one at a time to function even, which uses the remainder operator to determine.

  What are the authentication methods

What are the authentication methods that can be used ? Name some methods

  Possible values for each of the random variables

The number of pumps in use at both a six-pump station and a four-pump station will be determined. Give the possible values for each of the following random variables:

  Why information security is not factor for organization

But would not require to give for information security on those systems. Explain that environment and desribe why information security is not factor for that organization.

  Discuss the disadvantages of the designs

A third object keeps a table of Person objects and their place-of-birth Location objects. Discuss the advantages and disadvantages of each of these three design

  Implement a complete traversal of all directories

Using queue, implement a complete traversal of all directories on your hard disk and print them on the console. Implement the algorithm Depth-First-Search (DFS) - you may find some articles in the internet.

  Course major and gpa of any students on athletic scholarship

Using the data from the database you created yesterday for me:Extract the First and Last Name, Student ID, Course Major and GPA of any students on athletic scholarship. Sort by Student ID. Produce a report with the data from Step #1 and Use good head..

  Describe the merge-sort algorithm

Describe the Merge-Sort algorithm. How do you get the recurrence equation for Merge-sort?

  Anomalous behaviour of fifo

Describe Belady's anomaly and provide an example that illustrates anomalous behaviour of FIFO.

  Difference bettween dsum and dcount

What does a spreadsheet consist of

  Create an outline or storyboard for such a world

You could record the narration first, and then make the action in the world match the narration.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd