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

Store the following data in a file: 5 96 87 78 93 21 4 92 82 85 87 6 72 69 85 71

ID: 3631211 • Letter: S

Question

Store the following data in a file:

5 96 87 78 93 21 4 92 82 85 87 6 72 69 85 71 81 73

Write a program to calculate and display the average of each group of numbers. The data are arranged in the file so that each group of numbers is preceded by the number of data items in the group.

Use eof() for termination of the file.

Also write the average of each group to an output file.

Prompt the user for input and output file names.




( I tried to solve it but I couldn't ) ..... below is my answer and it is wrong


# include <iostream>
# include <fstream>
using namespace std;
int main ()
{
int num1, num2, num3;
double cn(0), av;
ifstream inputfile ("input.dat", ios:: in);

if (inputfile.fail())
{
cerr<<"no such file ";
exit (1);
}
inputfile>>num1>>num2>>num3;
while (!inputfile.eof())
{
cn++;
av=(num1+num2+num3)/cn;
inputfile>>num1>>num2>>num3;
}
inputfile.close();
cout<<"the average of these groups of numbers is "<<av<<endl;
return 0;

}



thank you all

Explanation / Answer

Dear Friend here is the program u want PLEASE RATE #include #include #include using namespace std; int main() { ifstream myfile; ofstream out; string filename; double num1,nums,sum=0,count=1; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote