Function should prevent any memory leaks

Assignment Help Basic Computer Science
Reference no: EM132243825

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: EM132243825

Questions Cloud

Compare global business competitiveness : Explain how their global business competitiveness (examples may include: institutions, infrastructure, macroeconomic environment, health and primary education.
Pizza king and noble greek are competitive pizza chains : Pizza King (PK) and Noble Greek (NG) are competitive pizza chains. To maximize its expected profit, what price should PK charge for a pizza?
Identify at least three reasons why continuing business : Identify at least three reasons why continuing business growth has been a challenge for eBay database management
Advantages and some disadvantages of sole proprietorship : What are some advantages and some disadvantages of a sole proprietorship?
Function should prevent any memory leaks : The function should prevent any memory leaks. Remember to also prevent memory leaks in the main you use for testing.
Stock brokerages and large corporate entertainment : Suppose a denial-of-service attack shuts down two dozen major websites, including retailers, stock brokerages and large corporate entertainment and information
Did you learn about genocide in school : Did you learn about genocide in school? Should subjects such as the Holocaust be taught, and if so how (see Hirsch & Kacandes, 2004)?
Did administrator turn it into a platform to foster growth : Did the administrator turn it into a platform to foster growth? How could you have improved the situation had you been in the "driver's seat?"
Minimal and equivalent nondeterministic finite automata : Give an example of two different (i.e. non-isomorphic), minimal and equivalent Nondeterministic Finite Automata that both have two states only.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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