Question

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

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

Code -

#include <iostream>

using namespace std;

int countLarger(int [],int,int);

int main()
{
const int SIZE = 25;
int array[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
int enteredVal,numLarger;
cout<<"This program contains an array holding 25 integer between 1 and 100. \n"
<<"If you enter an integer in this range, the program will tell how \n"
<<"many of the numbers are larger than your value \n";
cout<<"\nEnter value between 1 and 100: ";
cin>>enteredVal;

numLarger = countLarger(array,SIZE,enteredVal);
cout<<numLarger<<" of 25 array value are larger than "<<enteredVal<<" .\n";
return 0;
}
//function defination
int countLarger(int array[],int size,int val){
//variable declared
int i,count=0;
//iterate through array
for(i=0;i<size;i++){
//check for array[i] > val user enter value and increment count
if(array[i]>val)
count++;
}
//return count
return count;
}

Screenshots -

This program contains an array holding 25 integer between 1 and 100. If you enter an integer in this range, the program will

Add a comment
Know the answer?
Add Answer to:
1. The following program calls the function countLarger that accepts three arguments: an integer array, an...
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
  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

  • C++ ProgrammingWrite a function that takes an integer array, the array size and a number....

    C++ ProgrammingWrite a function that takes an integer array, the array size and a number. And it determines how many times that number appears in the array. Just copy the following code and paste it to your answer. And fill the corresponding part. #include < iostream >using namespace atd; int howmany (int array lint , int number){ //Your code comes here} int main() {const int N =10; int array[N] = [11,3,2,1,3,4,6,9,1.3); int count = howlany(array,N,3);cout << 3 < "appesa" << cout << "times!"; return 0;

  • /* Array expander: Write a function that accepts an int array as argument. The function should...

    /* Array expander: Write a function that accepts an int array as argument. The function should create a new array that is n times the size of the argument array, where n is a user input. 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 */ #include <iostream> using namespace std; const int NUM_ELEM...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • /* * Program5 for Arrays * * This program illustrates how to use a sequential search...

    /* * Program5 for Arrays * * This program illustrates how to use a sequential search to * find the position of the first apparance of a number in an array * * TODO#6: change the name to your name and date to the current date * * Created by Li Ma, April 17 2019 */ #include <iostream> using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() {...

  • (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...

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • 61. The following program is accepted by the compiler:         int sum( int x, int y...

    61. The following program is accepted by the compiler:         int sum( int x, int y )         {             int result;             result = x + y;            }                            T__   F__ 62. The following implementation is accepted by the compiler:         void product()         {             int a; int b; int c; int result;             cout << "Enter three integers: ";             cin >> a >> b >> c;             result = a * b * c;            ...

  • * This program illustrates how to use a sequential search to find the position of the...

    * This program illustrates how to use a sequential search to find the position of the first apparance of a number in an array TODO#6: change the name to your name and date to the current date * * Created by John Doe, April 17 2019 */ #include using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() { //TODO#1: declare an integer array named intList with size of...

  • // Program takes 5 numbers from a user (from console), stores them into an // array,...

    // Program takes 5 numbers from a user (from console), stores them into an // array, and then prints them to the screen (on the same line). // Add code to complete this program. You only need to add code where indicated // by "ADD HERE". #include <iostream> using namespace std; int main() { const int SIZE = 5; // size of array // ADD HERE - create an array of integers that will hold 5 integers. cout << "please...

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
ADVERTISEMENT