C++ (increase array size) Once an array is created, it's size is fixed. Sometimes, you need to
Fantastic news! We've Found the answer you've been seeking!
Question:
C++ (increase array size)
Once an array is created, it's size is fixed. Sometimes, you need to add more values to an array than it is able to hold; in this case, you may create a new larger array to replace the existing array.
Transcribed Image Text:
Once an array is created, its size is fixed. Sometimes, you need to add more values to an array than it is able to hold; in this case, you may create a new larger array to replace the existing array. Write a function that returns a pointer to a new int array that is double the size of the array passed in the parameters to this function. Use the following header: int double capacity (const int *list, int size) Write a test program that prompts the user to enter the number of elements of an array, and then enter the elements (type int). After that the program will use your double capacity() function to double the capacity of the array and prompt the user for more values. Finally, the program will display all the elements of the array. Note: make sure to delete the old array, since it isn't likely to be used after the function creates and returns the new, bigger array. SAMPLE RUN #1: ./double_capacity Interactive Session Show Invisibles Enter the number of elements for the array:5 Enter 5 int values:0 1 2 3 4 Enter 5 more int values: 5 6 7 8 9 The elements of the array are: 0 1 2 3 4 5 6 7 8 9 Highlight: None Once an array is created, its size is fixed. Sometimes, you need to add more values to an array than it is able to hold; in this case, you may create a new larger array to replace the existing array. Write a function that returns a pointer to a new int array that is double the size of the array passed in the parameters to this function. Use the following header: int double capacity (const int *list, int size) Write a test program that prompts the user to enter the number of elements of an array, and then enter the elements (type int). After that the program will use your double capacity() function to double the capacity of the array and prompt the user for more values. Finally, the program will display all the elements of the array. Note: make sure to delete the old array, since it isn't likely to be used after the function creates and returns the new, bigger array. SAMPLE RUN #1: ./double_capacity Interactive Session Show Invisibles Enter the number of elements for the array:5 Enter 5 int values:0 1 2 3 4 Enter 5 more int values: 5 6 7 8 9 The elements of the array are: 0 1 2 3 4 5 6 7 8 9 Highlight: None
Expert Answer:
Related Book For
Artificial Intelligence A Modern Approach
ISBN: 978-0136042594
3rd edition
Authors: Stuart Russell, Peter Norvig
Posted Date:
Students also viewed these electrical engineering questions
-
How many terms of the series would you need to add to find its sum to within 0.01? 2-2 1/[n(ln n)*] n=2
-
Sometimes taxpayers may not be able to file their tax returns by the normal due date. Are extensions available? How long are the extensions? How long are the extensions? Do extensions enable...
-
In deciding whether to replace an existing machine with a newer, more cost effective machine, the original cost of the existing machine should be compared to the cost of the new machine. Do you...
-
Air flows with negligible friction through a 4-indiameter duct at a rate of = lbm/s. The temperature and pressure at the inlet are T1 = 800 R and P1 = 30 psia, and the Mach number at the exit is Ma2...
-
A recent balance sheet for Porsche AG shows beginning raw materials inventory of 83 million and ending raw materials inventory of 85 million. Assume the company purchased raw materials (on account)...
-
1. Why is Avon so committed to diversity? 2. Select another retailer that also values diversity. How does this commitment affect its financial results? 3. What values have helped Avon be a successful...
-
White Brothers manufactures conveyor belts. Early in May 2011, White Brothers constructed its own building at a materials, labor, and overhead cost of $970,000. White Brothers also paid for architect...
-
A solar collector consists of a parallel plate channel that is connected to a water storage plenum at the bottom and to a heat sink at the top. The channel is inclined 0 = 30 from the vertical and...
-
6. You have been asked to analyze the investment (-$792, $1,780, -$1,000). Compute the internal rate of return for this investment
-
Whats the difference between a real resource and a virtual resource?
-
There are a number of theories of the term structure of interest rates including the unbiased expectations hypothesis, preferred habitat hypothesis, and market segmentation hypothesis. Discuss the...
-
Present your findings to me. Your assignment will be to a summary report on your findings. Imagine that you are an attorney who was recently hired by a company to analyze this contract and you are...
-
Your CEO has asked you to write a memo on telemedicine's pertinent legal and regulatory environment. Without going into detail on the exact laws and regulations, explain how you would draft this memo...
-
No, we should not pay federal employees or contractors a percentage of any amounts they help recover. Doing so may introduce a conflict of interest in that federal employees would be incentivized to...
-
The customer help center in your company receives calls from customers who need help with some of the customized software solutions your company provides. Your company claims that the average waiting...
-
Igor decided to incorporate Sweet Buns Ltd. The three shareholders are Olga, Alexandrra and Joseph in exhange for 1000 shares each. If Sweet Buns Ltd could not repay it's bank loan of $50,000 how...
-
A water pump system connected in parallel. If you know that the electrical power of the first and second pump is 22 watts and 25 watts, respectively, and the pressure reading on one of them is 0.7...
-
Rowland Textile Inc. manufactures two products: sweatshirts and T-shirts. The manufacturing process involves two activities: cutting and sewing. Expected overhead costs and cost drivers are as...
-
Which of the following are correct? a. False True. b. True False. c. (A B) (A B). d. A B A B. e. A B A B. f. (A B) C (A C) (B C). g. (C (A B)) ((A C) (B C)). h. (A B) (C D ...
-
Up to now we have assumed that the plans we create always make sure that an actions preconditions are satisfied. Let us now investigate what propositional successor-state axioms such as HaveArrow t+1...
-
Construct levels 0, 1, and 2 of the planning graph for the problem in Figure 10.1. Figure 10.1 Init(At (1, SFO) At(>, JFK) At(P, SFO) At(>, JFK) go (C) argo(C>) ^ Plane (P.) Plane(P:) Aiport...
-
Examine the financial data of Black Corporation. Show how to compute Black's current ratio from 2018 to 2020. Is the company's ability to pay its current liabilities improving or deteriorating? 1 23...
-
Vision Software Limited reported the following amounts on its balance sheets at December 31, 2020, 2019, and 2018: Sales and profits are high. Nevertheless, Vision is experiencing a cash shortage....
-
Use the Allstott, Inc., balance sheet data below. 1. Compute Allstott, Inc.'s quick (acid-test) ratio at December 31, 2020 and 2019. 2. Use the comparative information from the table on page 597 for...
Study smarter with the SolutionInn App