Function should prevent any memory leaks

Assignment Help Basic Computer Science
Reference no: EM132250133

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

Questions Cloud

Artisan tiles is launching new laminate flooring product : Artisan Tiles is launching a new laminate flooring product which is distributed in boxes of 12 units each.
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?
Cycles of stopwatch study : A worker-machine operation was found to involve 3.7 minutes of machine time per cycle in the course of 40 cycles of stopwatch study.
Research a popular subculture or counterculture : For this assignment you will research a popular subculture or counterculture. In a two-page paper, tell me about the subculture or counterculture you researched
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.
Difficulty in executing the strategic change initially : If the merger seems to make strategic sense (synergies), why is there such difficulty in executing the strategic change initially?
Where does each device reside within the osi model : Explain the differences between the following network devices: hub, bridge, switch, router, firewall. Where would you utilize each device and why?
Prevent a user from having access : In linux how could you automatically prevent a user from having access to any files or directories that you create?
Accept the number of points that each team : The winning team is that one that wins the most matches. Note: It is not necessarily the team that scores the most number of points

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