Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a C++ program that will: Declare an array of integers that can store up t

ID: 3764192 • Letter: D

Question

Design a C++ program that will:

Declare an array of integers that can store up to 25 values.

Interactively prompt the user for the name of an input file. Read the file name and open it.

Modify the get_data function to read a set of integers from the data file, counting them as they are read. After all values are read, the input file must be closed.

Create a value-returning function that when given the array and its size will return the average of the numbers in the array. Call it from main and print the average with 3 digits to the right of the decimal.

Create a void function that when passed the array and its size will find and print the largest value in the array and its location (subscript). Assume there is a unique largest value. Call this function from main.

Here's part of my code:

#include <Iostream>
#include <iomanip>
using namespace std;

(void read (int list [25] , int& count)

{
count = 0;
cin >> list [count];
while (cin)
{
   count++;
   cin >> list [count];
}

int main()
{
int numbers [25];
int n;
read (numbers, n);
}

My code is a bit impartial and may not be correct on it's own. Also filestream may be used (but I'm not sure) so that'll replace cin with the file input.

Explanation / Answer

Declare an array of integers that can store up to 25 values.

    #include <iostream>
   #include <fstream>
  
   using namespace std;

   const int MAX = 25;
   typedef char File_array[MAX];
  
   int main()
   {
       char character;
       File_array file;
       int count;
       ifstream in_stream;
  
       in_stream.open("file1.cpp");
       in_stream.get(character);
       for (count = 0 ; ! in_stream.eof() && count < MAX ; count++)
       {
           file[count] = character;
           in_stream.get(character);
       }
       in_stream.close();
  
       while (count > 0)
           cout << file[--count];

       return 0;
   }