Question: #include #include using namespace std; void readData(istream& is, int* &a, int size); void printData(ostream& os, int *a, int size, string& name, double ave); double findAverage(int

 #include #include using namespace std; void readData(istream& is, int* &a, int

size); void printData(ostream& os, int *a, int size, string& name, double ave);

#include

#include

using namespace std;

void readData(istream& is, int* &a, int size);

void printData(ostream& os, int *a, int size, string& name, double ave);

double findAverage(int *a, int size);

int main()

{

ifstream fin;

ofstream fout;

string fileNameI, fileNameO;

cout

cin >> fileNameI >> fileNameO;

fin.open(fileNameI.c_str());

fout.open(fileNameO.c_str());

int size;

fin >> size;

int *a = new int[size];

readData(fin, a, size);

double ave = findAverage(a, size);

printData(cout, a, size, fileNameI, ave);

printData(fout, a, size, fileNameI, ave);

fin.close();

fout.close();

}

void readData(istream& is, int* &a, int size)

{

//ToDo

fin.open("in.txt");

fout.open("out.txt");

fout

cout

}

double findAverage(int *a, int size)

{

double ave = 0;

double total = 0;

double number = 0;

//ToDo

if (fin.is_open())

{

while (fin.goof())

{

do(!fin.eof())

{

fin >> n;

total = total + n;

number++;

}

ave = total / number;

}

}

return ave;

}

void printData(ostream& os, int *a, int size, string& name, double ave)

{

cout

cin.get();

return cout;

}

Suppose you have a group of N integer numbers in some file. You would like to read all numbers, figure out average of these numbers, and output all these numbers and their average to another file. Write a program to solve this problem Detailed Algorithm 1. Create readData) function that read from input file the following data o value of N o and N integer numbers into a dynamic array Create findAverage() function that finds the average of all elements in your dynamic array. Note - the calculated average, in general, will not be an integer. Use double type to store it. 2. 3. Create printData) function that prints to the output file your array and the average of the numbers Use the provided stub source code while writing your program (replace//ToDo comments with an actual code)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!