A Stack Problem =============== Name the source file for this section stack.cpp.
ID: 3713738 • Letter: A
Question
A Stack Problem
===============
Name the source file for this section stack.cpp.
We are going to see what happens when we try to write a function that *returns*
an array, without using the "new" keyword.
Write a function named gimmieArray, that takes an int named size as an
argument, and returns an array of int. The function should declare an int
array with a size equal to the input parameter and then return that array as
the result.
Write a main function that calls gimmieArray to get a new array of size
10000000, then try to loop through that array outputting each elemet to the
console.
This program should exit with some sort of segmentation fault when run.
Your function signature should look like this: int* gimmieArray(int size)
New
===
Name the source file for this section new.cpp.
Let's write a proper function that returns an array. Write a function named
newIntArray that accepts two integers as arguments: the first is the size of
the new array wanted, and the second is the int that every element should be
initialized to.
Write a main function that calls newIntArray to get a new array, and then test
that each element is initialized to the value you specified. You will be
graded on the completeness and correctness of your test code just as much as
your other code.
Concat
======
Name the source file for this section concat.cpp.
Write a function named concat that returns an array of int. concat takes 4
parameters as input:
- int*: The first array.
- int : The size of the first array.
- int*: The second array.
- int : The size of the second array.
concat creates and returns a new array whose contents are the elements of the
first array followed by the elements of the second array. The following
pseudocode shows the desired behavior of concat::
concat([1, 2, 3], 3, [7, 8, 9], 3) == [1, 2, 3, 7, 8, 9]
The above is only pseudocode, it is not valid C++. Write a main function tests
that concat works properly. You will be graded on the completeness and
correctness of your test code just as much as your other code.
Feel free to copy your newIntArray function into this source code to make your
test code a bit easier.
Explanation / Answer
Hi Dear,
Please find my implementation of Q1.
As per the chegg policy, please repost others in separate post.
#include <iostream>
#include <cstdlib>
using namespace std;
int* gimmieArray(int size);
int main() {
int *arr = gimmieArray(10000000);
for(int i=0; i<10000000; i++)
cout<<arr[i]<<" ";
cout<<endl;
delete [] arr;
return 0;
}
int* gimmieArray(int size) {
int* arr = new int[size];
return arr;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.