Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

image text in transcribed

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago