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

Write a C++ main program that calls each function listed below. Load values into

ID: 3679739 • Letter: W

Question


Write a C++ main program that calls each function listed below. Load values into each array using a list to test each function. Print out results to show original array contents and contents after using the functions. All printing should be done in the main programs - do not print from the functions. Turn in copies of the program and all results. Output: The output should clearly show original array contents, new array contents (if modified), and the result. For example, the output for part B might look as follows: Contents of array A before swap: 1 2 3 4 5 6 7 Contents of array B before swap: 8 9 10 11 12 13 14 Contents of array A after swap: 8 9 10 11 12 13 14 Contents of array B after swap: 1 2 3 4 5 6 7 Include a function to find the length of a vector stored in an array where the length of an N-dimensionalvector L is: Length =squareroot (L_0)^2+(L_1)^2+(L_2)^2+.....+(L_N-1)^2 Form of function call: Result = Length(A, Size) Include a function to swap the contents of two equal size arrays named A and B. Form of function call: Swap(A, B, Size) Include a function to reverse the contents of an array. For example, an array that originally contained the elements 1,2,3,4 would contain 4,3,2,1 after the function call. Form of function call: Reverse(A, Size)

Explanation / Answer

#include <iostream>

using namespace std;

void swap(int array1[],int array2[], int size)

{

        int temp;

cout<<”Contents of array1 before swap”;

for(int i=0;i<size;i++)

cout<<array1[i];

cout<<”Contents of array2 before swap”;

for(int i=0;i<size;i++)

cout<<array2[i];

for(int i=0;i<=size;i++)

{

    temp = array1[i];

    array1[i] = array2[i];

    array2[i] = temp;

   

}

cout<<”Contents of array1 after swap”;

for(int i=0;i<size;i++)

cout<<array1[i];

cout<<”Contents of array2 before swap”;

for(int i=0;i<size;i++)

cout<<array2[i];

}

void reverse(int array1[],int size)

{

int i,j,temp;

for(i=0,j=size-1;i<size/2;i++,j--)

      {

            temp=array1[i];

            array1[i]=array1[j];

            array1[j]=temp;

      }

      cout<<" Reverse array"<<endl;

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

            cout<<array1[i]<<" ";

}

long length(int array1[],int size)

{

long sum=0;

for(int i=0;i<size;i++)

sum = sum + array1[i]*array1[i];

return(sqrt(sum));

}

int main()

{

    int array1[];

    int array2[];

    int size;

cout<<”Please enter the size of array:”;

cin>>size;

array1 = new int[size];

array2 = new int[size];

cout<<"please Enter Element of The first array"<<endl;

for(int i=0;i<size;i++)

cin>>array1[i];

cout<<"please Enter Element of The Second array"<<endl;

for(int i=0;i<size;i++)

cin>>array2[i];

swap (array1,array2,size);

reverse(array1,size);

long result = length(array1,size);

cout<<”Length of array vector:”<<result;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote