Question

Write a C++ program that contains the following functions. Have at least 3 arrays created in...

Write a C++ program that contains the following functions. Have at least 3 arrays created in the main to test your functions using appropriate function calls

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 if they are the same or not)

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 simultaneously)

e.g
1 5
2 4
3 3
4 2
5 1

C++ Language Please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Explanation:

a and b are two arrays defined of size 10.

First values are taken using ReadIn function, then CompareFunc compares them if they are same or not.

Then, first array is copied to second reverse.

Then, they are printed forward using printForward method.

Then, using PrintBoth, they are printed, one forward, one backward simultaneously.

Code:


#include <iostream>

using namespace std;

void ReadIn(int* a, int* b)
{
cout<<"Enter first array: "<<endl;
for(int i=0; i<10; i++)
{
cin>>a[i];
}
  
cout<<"Enter second array: "<<endl;
for(int i=0; i<10; i++)
{
cin>>b[i];
}
}

void CompareFunc(int* a, int* b)
{
int f=0;
for(int i=0; i<10; i++)
{
if(a[i]!=b[i])
f = 1;
}
  
if(f==1)
cout<<"Arrays are not same"<<endl;
else
cout<<"Arrays are same"<<endl;
}


void ReverseFunc(int* a, int* b)
{
for(int i=9; i>=0; i--)
{
b[9-i] = a[i];
}
}

void PrintForward(int* a)
{
for(int i=0; i<10; i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}

void PrintBackward(int* a)
{
for(int i=9; i>=0; i--)
{
cout<<a[i]<<" ";
}
cout<<endl;
}

void PrintBoth(int* a, int* b)
{
for(int i=0; i<10; i++)
{
cout<<a[i]<<" "<<b[9-i]<<endl;
}
}


int main()
{
int a[10], b[10];
  
ReadIn(a, b);
  
CompareFunc(a, b);
  
ReverseFunc(a, b);
  
PrintForward(a);
PrintForward(b);
  
PrintBoth(a, b);
  
return 0;
}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that contains the following functions. Have at least 3 arrays created in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • In C Write a couple of functions to process arrays. Note that from the description of...

    In C Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an int array and size, and...

  • **IN C*** * In this lab, you will write a program with three recursive functions you...

    **IN C*** * In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...

  • use C language please Problem 5. (5 points] Use string functions. Write a program that: 1)...

    use C language please Problem 5. (5 points] Use string functions. Write a program that: 1) Ask the user to write two strings. 2) If both strings are equal, print an appropriate message then print out both strings with their length. 3) If the strings are not equal, print an appropriate message then concatenate both strings and print out the length of the concatenating strings. 4) In the main function prints both arrays.

  • C++ 2) Functions with arrays • Write a function that returns a count of how many...

    C++ 2) Functions with arrays • Write a function that returns a count of how many temperatures are below freezing (32 degrees Fahrenheit). The function takes two parameters: i) temps, an array of temperatures (in Fahrenheit degrees) ii) numTemps, the number of temperatures • Write a main() that initializes an array of temperatures (hard-coding the values is fine) and prints the number of temperatures below freezing. Your main() must call the above function to compute this result for output.

  • Please and thank you 2) (5 pts) Arrays & Vectors: write a program which prompts the...

    Please and thank you 2) (5 pts) Arrays & Vectors: write a program which prompts the user to enter numbers (terminated with a non-numeric), reads them simultaneously into an array of doubles and into a vector of doubles, then prints A) the array elements in the original order B) the vector elements in reverse order C) the average of the vector elements D) the largest of the vector elements Example program output, user input shown underlined Enter a list of...

  • using C programming Compose a program that declares two string arrays that are 81 characters in...

    using C programming Compose a program that declares two string arrays that are 81 characters in size. Prompt the user to enter in a string and store it in array 1. Construct a function that returns a void and takes both arrays as parameters and copies array 1 into array 2 using sizeof() to ensure that the size does not exceed the destination array. Back in the caller print the second array to show that the function worked. NOTE: We...

  • C++ Arrays & Methods

     #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it...

  • Write C++ Program The aim of this is to develop various functions on an array. First,...

    Write C++ Program The aim of this is to develop various functions on an array. First, create an array (A) with 10 integers, which will be randomly selected from the range of 0 to 100. Print the items of the array on screen as one line. Write a function to copy A to B. The function signature should be "void Copy(int A[], int B[], int size)". This function copies content of A into B in the same order. - Write...

  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT