Question

In C++ cout<<"" << NO std:cout Write a function that accepts two integer arrays of the...

In C++ cout<<"" << NO std:cout

Write a function that accepts two integer arrays of the same size. The first array will have numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater than or equal to the average and fill out the second array with these numbers. You need to design the function.Comments as well please because i am super confused. Thank you!

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

#include<iostream>
using namespace std;

void fillArray(int arr1[],int arr2[],int arr_size)
{
int cnt=0;
double avg,sum;
for(int i=0;i<arr_size;i++)
{
sum+=arr1[i];
}

avg=sum/arr_size;
//assigning the second array
for(int i=0;i<arr_size;i++)
{
if(arr1[i]>=avg)//condition to check average
{
arr2[cnt]=arr1[i]; //assigning value to array 2
cnt++;
}
}

//printing seond array
cout<<"Second array is: ";

for(int i=0;i<cnt;i++)
{
cout<<arr2[i]<<" ";
}

}

int main()
{
int arr_size;
cout<<"Enter the size of array: ";
cin>>arr_size;
int arr1[arr_size],arr2[arr_size];
cout<<"Enter the element:\n";
for(int i=0;i<arr_size;i++)
{
cin>>arr1[i];
}
fillArray(arr1,arr2,arr_size);


}

Add a comment
Know the answer?
Add Answer to:
In C++ cout<<"" << NO std:cout Write a function that accepts two integer arrays of the...
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
  • In C++ Write a function that accepts two int arrays of the same size. The first...

    In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...

  • c++ write a boolean function that accepts two integer arrays of size 10 as input parameters,...

    c++ write a boolean function that accepts two integer arrays of size 10 as input parameters, the function should return true if there are any similar values between the two arrays and shall return false if not, if there are similar values, print out on screen

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • In C write a function called find_unique (). This function accepts a pointe integers, which consists...

    In C write a function called find_unique (). This function accepts a pointe integers, which consists of numbers that are greater than or equal to 0. The function searches the array for the unique integer. Not all arrays will have a unique integer, but if they do, then there will only be one unique number. A unique number is defined as the integer in the array that does not have at least one other matching value. If a unique number...

  • 1. The following program calls the function countLarger that accepts three arguments: an integer array, an...

    1. The following program calls the function countLarger that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n. The function countLarger should return the number of integers in the array that are greater than the value of the argument n. Update the program to include the definition of the function countLarger. #include <iostream> using namespace std; int countLarger(int[], int, int); // Function prototype int main() const int...

  • C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and...

    C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and the size of the array.as parameters. The function should then create a new array that is the same size as the original array. The function should copy the elements from the first array into the second array in reverse order. So if the initial array is {'a' , 'b', 'c'} then the new array will be {'c', 'b', 'a'} Then in your main(), create...

  • c++ please no global varaible write a value returning function input data to dynamically allocate a...

    c++ please no global varaible write a value returning function input data to dynamically allocate a short array of size elements and store the input data entered from the disk file into array.Return the base address of the array allocated.Read the data from the text file Hello.txt and store the data in reverse order in the array.the size of the data set will be in the file size 10 and the data was 1 2 3 4 5 6 7...

  • Write a C++ console application that adds the corresponding elements of two integer arrays of size...

    Write a C++ console application that adds the corresponding elements of two integer arrays of size five. Prompt the user for the ten values and store the first five in the first array and the second five in the second array. Then create and call function matrixAdd that adds the two arrays and prints the five sums. Here is the function prototype: void matrixAdd(int firstArr[], int secondArr[]); [your program code here]*

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

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