Write a C++ main program that calls each function listed below. Load values into
ID: 652619 • 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
A) Include a function to find the length of a vector stored in an array where the length of an N-dimensional vector L is:
Form of function call: Result = Length(A, Size)
B) Include a function to swap the contents of two equal size arrays named A and B.
Form of function call: Swap(A, B, Size)
C) 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>
#include<algorithm>
#include<iterator>
#include<string>
using namespace std;
template<typenmae T, size_t N>
void Array_swapping(T (&A) [N], T (&B) [N])
{
T tmp[N];
copy(begin (A), END (A),BEGIN (TEMP));
copy(begin (B), END (B),BEGIN (A));
copy(begin (temp), END (tmp),BEGIN (B));
}
template<typename T,size_t N>
void swapping_values (T (&A)[N], T (&B) [N])
{
cout<<"N a BEFORE SWAP:";
for_each(begin (A), end (A),[](T const& t)
{
cout<<" "<<t;
}
}
);
cout<<" B before swap:";
for_each(begin (B) , end (B), [] (t CONST& T)
{
cout<<" "<<T;
}
);
Array_swapping(A,B);
cout<<" A after swap:";
for_each(begin (A) , end (A), [] (t CONST& T)
{
cout<<" "<< t;
}
);
cout<" B after swap:";
for_each(begin(B), end (B), [] (T const& t)
{
cout<<" "<<t;
}
);
}
main()
{
int A[]={11,22,33,44};
int B[]={55,66,77,88};
swapping_values(A,B);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.