/* Array expander: Write a function that accepts an int array as
argument. The function should create a new array that is n times
the size of the argument array, where n is a user input.
The function should copy the contents of the argument array to the
new array, and initialize the unused elements of the second array
with 0. The function should return a pointer
to the new array */
#include <iostream>
using namespace std;
const int NUM_ELEM = 5;
int* expandArray(int *a, int expFactor);
int main()
{
int origArr[NUM_ELEM], n;
for (int i = 0; i < NUM_ELEM; ++i)
origArr[i] = i;
cout << "Original array" <<
endl;
for (int i = 0; i < NUM_ELEM; ++i)
cout << origArr[i]
<< " ";
cout << endl;
cout << "By how many times should the new array grow" << endl;
cin >> n;
int *newArr = expandArray(origArr, n);
for (int i = 0; i < n*NUM_ELEM; ++i)
cout << newArr[i]
<< " ";
cout << endl;
delete [] newArr;
return 0;
}
int* expandArray(int *a, int expFactor)
{
// Your code goes
here
}
Dear Student,
below i have completed the given C++ program as per the requirement.
Please note that the below program is tested on ubuntu 14.04 sytem and compiled in g++ compiler. This program will also work on other IDE's
================================================================
Program:
================================================================
#include <iostream>
using namespace std;
const int NUM_ELEM = 5;
int* expandArray(int *a, int expFactor);
int main()
{
int origArr[NUM_ELEM], n;
for (int i = 0; i < NUM_ELEM; ++i)
origArr[i] = i;
cout << "Original array" << endl;
for (int i = 0; i < NUM_ELEM; ++i)
cout << origArr[i] << " ";
cout << endl;
cout << "By how many times should the new array grow" << endl;
cin >> n;
int *newArr = expandArray(origArr, n);
for (int i = 0; i < n*NUM_ELEM; i++)
cout << *(newArr+i) << " ";
cout << endl;
//delete [] newArr;
return 0;
}
//complete defintion
int* expandArray(int *a, int expFactor)
{
// Your code goes
here
int *copy_array = new int[NUM_ELEM * expFactor];
for(int i = 0 ; i< NUM_ELEM; i++)
{
*(copy_array+i) = *(a+i);
}
return copy_array;
}
================================================================
Output:

================================================================
Kindly Check and Verify Thanks...!!!
/* Array expander: Write a function that accepts an int array as argument. The function should...
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....
(C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...
Who could write the array.cpp file ? //main.cpp #include "array.hpp" #include <iostream> int main() { int n; std::cin >> n; array a(n); for (int i = 0; i < n; i++) { std::cin >> a.data()[i]; } std::cout << "array size:" << a.max_size() << std::endl; std::cout << "array front:" << a.front() << std::endl; std::cout << "array back:" << a.back() << std::endl; int* data = a.data(); std::cout << "array elements using data:" << std::endl; for (int i = 0; i < n;...
One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << ; cout << endl; return 0; }
C++ Array Expander and Element Shifter Thank you so much to anybody that can help! Here are our two homework prompts: PART A: Array Expander Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0....
#include <iostream> using namespace std; int main(void) { int SIZE; cout<<"Enter the size of the array"<<endl; cin>>SIZE; int *numlist = new int[SIZE]; // Read SIZE integers from the keyboard for (int i = 0; i<SIZE; i++ ) { cout << "Enter value #" << i+1 << ": "; cin >> numlist[i]; } // Display the numbers in a reverse order for (int i = SIZE; i > 0; i--...
1. The following program calls the function countLarger that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n. The function countLarger should return the number of integers in the array that are greater than the value of the argument n. Update the program to include the definition of the function countLarger. #include <iostream> using namespace std; int countLarger(int[], int, int); // Function prototype int main() const int...
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...
When running the program at the destructor an exception is being thrown. Can someone help me out? vararray.h: #ifndef VARARRAY_H_ #define VARARRAY_H_ class varArray { public: varArray(); // void constructor int arraySize() const { return size; } // returns the size of the array int check(double number); // returns index of element containg "number" or -1 if none void addNumber(double); // adds number to the array void removeNumber(double); // deletes the number from the array ...
Write a int function that accepts as parameter the name of a candidate and return the number of votes received by the candidate. So, if the user enters Duck, the output will be 6000. Of course, if the given name does not exist, display an appropriate message. Need help with the above here is what i have so far: #include <iostream> #include <iomanip> #include <string> #include <vector> #include <map> using namespace std; // Get the details from the user for...