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

  What is the country gdp for the year

Given the following data for a hypothetical economy in a given year:

  Create variables and call modules

Create variables and call modules.

  Would this help the attacker

Suppose that furthermore the attacker could reset the clock on the server host, perhaps using the Network Time Protocol. Show how an attacker could now authenticate itself to the server without knowing CHK (although it could not decrypt SK).

  Research on failover clustering for hyper

Do some research on failover clustering for Hyper-V. Create a table showing how clustering can help with both storage and network failure.

  A table contains the following fields

You have a table contains the following fields: MemberLastName,MemberFirstName, Street, City, State, PostCode, and MembershipFee. What indexes would you create for the table, and why would you create these indexes?

  Determine the torque m required to overcome friction

The collar bearing uniformly supports an axial force of P = 800 lb If the coefficient of static friction is µs = 0.3 determine the torque M required to overcome friction.

  Massively multiplayer online role-playing games

In a virtual world (VW) of massively multiplayer online role-playing games (MMORPGs), collaboration and communication are provided through the Internet between MMORPG-ready devices such as the Microsoft Xbox, and Sony PlayStation, and by using the..

  Find an algorithm that minimizes the total unhappiness

Each guest ' s unhappiness at the party can be calculated as the absolute value of the differences between its actual distance from a guest and the desired distance. Find an algorithm that minimizes the total unhappiness at the party.

  Developing an application that can accept payments

You work for a healthcare company that processes insurance payments. Your company is developing an application that can accept payments over the internet.

  Derive logging and auditing requirements

Prove or disprove that state-based logging and transition-based logging are equivalent if and only if the state of the system at the first transition is recorded.

  Which were put into inventories the end of the year

Companies were left with $100,000 worth of goods and services, which were put into inventories the end of the year. Is it part of GDP?

  Write a commented c++ program to re-format dates

Write a commented C++ program to re-format dates. Prompt the user to input a date in the form: Sunday, January 2, 2010. Display the date in each of the following formats: January 2 was a Sunday in 2010 Sun, Jan 2 '10 2010-01-02

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