#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>

using namespace std;
/* read in a bunch of student records of the form
name(<10characters) quiz1 quiz2 quiz3 quiz4 test1 test2 final
calculate their course average by 20% quizzes, 25% each test
30% final exam. Print out to the screen a summary */

class student
{
private:
  char name[10];
  int q1,q2,q3,q4,t1,t2,final;
  double avg;

public:
  void input(istream &in);
  void output(ostream &out);
  void calc_average();
};

void student::input(istream &in)
{
in >> name >> q1 >> q2 >> q3 >> q4 >> t1 >> t2 >> final;
}

void student::output(ostream &out)
{
out << setw(12) << name <<
       setw(4) << q1 <<
       setw(4) << q2 <<
       setw(4) << q3 <<
       setw(4) << q4 <<
       setw(4) << t1 <<
       setw(4) << t2 <<
       setw(4) << final <<
	   ": average is " << avg << endl;
}

void student::calc_average()
{
avg = .05*(q1+q2+q3+q4)+.25*(t1+t2)+.3*final;
}

int main()
{
char fname[20];

cout << "What filename has grades in it? ";
cin >> fname;

ifstream infile;
infile.open(fname);
// ifstream infile("grades.dat");

if(infile.fail())
	{
	cout << "Error opening file";
	exit(1);
	}

ofstream outfile("output.txt");

student nextstudent;
nextstudent.input(infile);

while (infile)
	{
	nextstudent.calc_average();
	nextstudent.output(outfile);
	nextstudent.input(infile);
	}

return 0;
}