Question

Write in C++ program Larger than n In a program, write a function that accepts three...

Write in C++ program

Larger than n

In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n.

Input from the keyboard: The filename and path of a list of integer numbers.

                                          The number n to test the file numbers.

Output to the console: The numbers in the array that are greater than the input number n. (A title and your name should be on the output.)

Assumptions: The list of numbers input from the file will not contain more than 50 integers.

Sample file: hw7File.txt

4

6

2

7

5

3

8

34

62

9

7

5

3

22

11

Sample console output:

      HOMEWORK #7

Enter the filename with the list of numbers G:hw7File.txt

Enter the integer to test integers greater than: 5

The numbers in the list that are greater than 5 are:

6

7

8

34

62

9

7

22

11

Programmer: insert your name here

Press any key to continue . . .

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

#include<iostream>

#include<fstream>

using namespace std;

void fxn(int arr[], int size, int n)

{

    int i;

   

    // traverse the array

    for( i = 0 ; i < size ; i++ )

    {

        // if the current element is greater than n

        if( arr[i] > n )

            cout<<arr[i]<<endl;

    }

}

int main()

{

    string filename;

    int n;

   

    cout<<"      HOMEWORK #7\n";

    cout<<"Enter the filename with the list of numbers : ";

   

    // get user input

    cin>>filename;

   

    cout<<"Enter the integer to test integers greater than: ";

   

    // get user input

    cin>>n;

   

    // open file in read mode

    ifstream in(filename.c_str());

   

    int arr[100000];

    int size = 0;

   

    // loop untill file is completely traversed

    while( !in.eof() )

    {

        int x;

       

        // read from file

        in>>x;

       

        arr[size++] = x;

    }

   

    cout<<"The numbers in the list that are greater than 5 are:\n";

   

    fxn(arr, size, n);

   

    return 0;

}

----------------hw7File.txt-------------

4
6
2
7
5
3
8
34
62
9
7
5
3
22
11

Sample Output

Add a comment
Know the answer?
Add Answer to:
Write in C++ program Larger than n In a program, write a function that accepts three...
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 a program, write a function that accepts three arguments: an array, the size of the...

    in a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n.

  • (C++ programming) Need help with homework. Write a program that can be used to gather statistical...

    (C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...

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

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

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

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

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

  • PYTHON CODE In a program, write a function that accepts two arguments: a list, and a...

    PYTHON CODE In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all of the numbers in the list that are greater than the number n. Output should look like: Number: 5 List of numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] List of numbers that are larger than 5: [6, 7, 8, 9, 10]

  • Write a program call p1.py. Add a function called make_rand_list(n) to your program that takes an...

    Write a program call p1.py. Add a function called make_rand_list(n) to your program that takes an integer n as input and returns a list of n random integers in the range [1,100]. Add another function called product(list) that takes a list of random numbers as an argument and return the product of all the random numbers of that list. Sample run: make_rand_list(7) returns list = [34, 18, 35, 26, 53, 9, 48] product(list) returns 12751240320

  • python In a program, write a function that accepts two arguments: a list, and a number...

    python In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display the number n, the list of numbers, and a sub list of all the numbers in the list that are greater than the number n. Initialize the list and the number n in the main function of your code and call your function, passing the list and number as arguments. Run your code...

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