Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write two C++ functions, printArray that print the int array and smallestInde

ID: 3675935 • Letter: 1

Question

1) Write two C++ functions, printArray that print the int array and smallestIndex that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array.

Grading scheme: printArray function -5 points; smallestIndex function- 5 points; main function - 5 points.

2) Write and test a program that consists of the following functions:

Initialize two one-dimension arrays as global variables

int main( ): in main function print out the two original arrays.

arrayAdd( ): do the addition for two one-dimension arrays and output the result.

arrayMulti( ): do the multiplication for one one-dimension array and one integer and output the result.

3) 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.

Explanation / Answer

#include<iosream.h>

#include<constream.h>

#include<math.h>

class Array1

{

public:

{

array a[5];

array a1[5];

array tot[5];

int n,i;

cout<<" Enter the size of first array";

cin>>n;

cout<<" Enter the element in first array";

cin>>a[i];

cout<<" Enter the size of second array";

cin>>n

cout<<" Enter the element in second array";

cin>>a1[i];

a1[i]={a1[i]*a1[i]};

}

array Add()

{

for(i=0;i<n;i++)

{

tot[i]=a[i]+a1[i];

}

cout<<" The result of adding two arrays are:", tot[i];

}

array Multi()

{

for(i=0;i<n;i++)

{

tot[i]=a[i]*a1[i];

}

cout<<" The result of multiplying two arrays are:", tot[i];

}

int printArray()

{

for(i=0;i<n;i++)

{

cout<<" The first array is:", a[i];

}

for(i=0;i<n;i++)

{

cout<<" The second array is:, a1[i];

}

return 0;

}

int smallestIndex(int a[],int n)

{

for(i=0;i<1;i++)

cout<<" the Index of first occurence of smallest element in array is:", a[i];

}

int main()

{

for(i=0;i<n;i++)

{

cout<<" the first array is:", a[i];

}

for(i=0;i<n;i++)

{

cout<<" The second array is:", a1[i];

}

return 0;

}

};

Array1 p;

{

p.add();

p.multi();

p.printArray();

p.smallestIndex();

p.main();

}