Initialize an array by two functions. The first function should initialize the a
ID: 3676017 • Letter: I
Question
Initialize an array by two functions. The first function should initialize the array with same value. The second function should initialize the array in which each value is the square of the index. For example. array[i]=i*i; You must define the two functions with the same function name and the parameter in the two functions must be different. In other words, you are required to do the function overloading. You are also required to write a output function for the array. Grading scheme: the first initialize function -5 points; the second initialize function -5 points: the output function - 5 points; main function - 5 points.Explanation / Answer
InitilizeArrays.cpp
// Function overload example
#include <iostream>
#include <cmath>
using namespace std;
int foo [] = {16, 2, 77, 40, 12071};
int n,k, result=0;
int main ()
{
int n,k,l;
int x=2,y=4;
cout << "Enter a number:";
cin >> a;
cout << "Enter how many times you want me to store the same number in an array :";
cin >> tot;
int arr[]=new int[tot];
int arr1[]=new int[tot];
initialize(x);
initialize(x,y);
print();
return 0;
}
void initialize(int x)
{
for ( n=0 ; n<tot ; ++n )
{
arr[n]=a;
}
}
void initialize(int x,int y)
{
for ( k=0 ; k<tot ; ++k )
{
arr1[k]=pow(arr[k],k*k);
}
}
void print()
{
cout << "The Numbers in the Array 1:";
for(l=0;l<tot;++l)
{
cout << arr[l];
}
cout << "The Numbers in the Array 2:";
for(l=0;l<tot;++l)
{
cout << arr1[l];
}
}
-------------------------------------------------------------------------------------------------------------------