Write a C++ program that contains the following functions ReadIn (A Function tha
ID: 3720929 • Letter: W
Question
Write a C++ program that contains the following functions
ReadIn (A Function that request the user to fill up 2 arrays of size 10)
CompareFunc (A function that takes in 2 arrays and compares them, and outputs an appropriate message)
ReverseFunc ( A function that takes in 2 arrays, and copies the content of the the 1st into the 2nd in reverse order)
PrintForward (A function that prints the content of an array in normal order)
PrintBackword (A function that prints the content of an array in reverse order)
PrintBoth (A function that takes two arrays and prints them, one forward, one backwards)
e.g
1 5
2 4
3 3
4 2
5 1
Write a C++ program that contains the following functions
A function that reads in 15 numbers from a file and into an array passed as an input parameter
A function that takes in an integer array, and a particular key (item to be searched) and returns the location of the item in the array
A function that takes in an integer array and a particular key and returns true if the key is contained in the array, and false otherwise
A function that takes in an integer array and a particular key and returns the location of the 3rd occurrence of the key, when this function is used, it should output the location or an appropriate message otherwise.
Explanation / Answer
PLEASE REFER BELOW CODE
#include<iostream>
using namespace std;
void ReadIn(int *arr1, int *arr2)
{
//asking user input for 10 times
for(int i = 0; i < 10; i++)
{
cout<<"Enter elements of array 1 and array 2 : ";
cin>>arr1[i]>>arr2[i];
}
}
bool CompareFunc(int *arr1,int *arr2)
{
//traversing both array and checking if equal
for(int i = 0; i < 10; i++)
{
if(arr1[i] != arr2[i]) //if not equal return false ;else return true
return false;
}
return true;
}
void ReverseFunc(int *arr1, int *arr2)
{
//copying array1 into array2 in reverse order
for(int i = 0; i < 10; i++)
{
arr2[i] = arr1[9-i];
}
}
void PrintForward(int *arr)
{
cout<<"Printing array in Normal order "<<endl;
for(int i = 0; i < 10; i++)
cout<<arr[i]<<endl;
}
void PrintBackword(int *arr)
{
cout<<"Printing array in Reverse order "<<endl;
for(int i = 9; i >= 0; i--)
cout<<arr[i]<<endl;
}
void PrintBoth(int *arr1,int *arr2)
{
cout<<"Printing both array with one forward and one backward order"<<endl;
for(int i = 0; i < 10; i++)
cout<<arr1[i]<<" "<<arr2[9-i]<<endl;
}
int main()
{
int arr1[10],arr2[10]; //declaring two arrays of size 10
//ReadIn (A Function that request the user to fill up 2 arrays of size 10)
ReadIn(arr1,arr2);
//CompareFunc (A function that takes in 2 arrays and compares them, and outputs an appropriate message)
if(CompareFunc(arr1,arr2))
cout<<"Array 1 and Array 2 both are same"<<endl;
else
cout<<"Array 1 and Array 2 are NOT same"<<endl;
//ReverseFunc ( A function that takes in 2 arrays, and copies the content of the the 1st into the 2nd in reverse order)
ReverseFunc(arr1,arr2);
//PrintForward (A function that prints the content of an array in normal order)
PrintForward(arr1);
//PrintBackword (A function that prints the content of an array in reverse order)
PrintBackword(arr1);
//PrintBoth (A function that takes two arrays and prints them, one forward, one backwards)
PrintBoth(arr1,arr2);
return 0;
}
PLEASE REFER BELOW OUTPUT
Enter elements of array 1 and array 2 : 1 8
Enter elements of array 1 and array 2 : 2 2
Enter elements of array 1 and array 2 : 3 3
Enter elements of array 1 and array 2 : 4 5
Enter elements of array 1 and array 2 : 5 5
Enter elements of array 1 and array 2 : 6 6
Enter elements of array 1 and array 2 : 7 7
Enter elements of array 1 and array 2 : 8 8
Enter elements of array 1 and array 2 : 9 9
Enter elements of array 1 and array 2 : 10 10
Array 1 and Array 2 are NOT same
Printing array in Normal order
1
2
3
4
5
6
7
8
9
10
Printing array in Reverse order
10
9
8
7
6
5
4
3
2
1
Printing both array with one forward and one backward order
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
Process returned 0 (0x0) execution time : 23.665 s
Press any key to continue.
PLEASE POST SEPARATE 2ND QUESTION
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.