3

PHOTO EMBED

Tue Apr 27 2021 01:24:35 GMT+0000 (Coordinated Universal Time)

Saved by @ahmedqgqgq #java

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
	/*ofstream outfile("grade.txt", ios::out);
	if (!outfile)
	{
		cerr << "error:output file cannot be opened\n";
		exit(1);
	}
	char id[9], name[16];
	int grade;
	cout << "\t1:";
	int n = 1;
	while (cin>>id>>name>>grade)
	{
		if (n==3)
		{
			break;

		}
		outfile << name << " " << id << " " << grade << endl;
		cout << "\t" << ++n << ":";
	}
	outfile.close();*/
	ifstream infile("grade.txt", ios::in);
	if (!infile)
	{
		cerr << "error:input file cannot be opened.\n";
		exit(1);
	}
	char id[9], name[16];
	int grade, sum = 0, count = 0;
	while (infile>>id>>name>>grade)
	{
		sum += grade;
		++count;
	}
	infile.close();
	cout << "the grade average is:" << float(sum) / count << endl;
}
content_copyCOPY