1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
int main ()
{ int p,c, m, sumP =0, sumC = 0, sumM = 0, M=0;
char name[80], str [80], ch;
ofstream fileout ("marks.txt", ios::out);
for (int i=1; i<4; i++)
{ cout << "\nEnter name of student " << i << ": "; fflush (stdin); gets (name);
fileout << name<<"\n";
cout << "Enter marks for Physics, Chemistry, Maths :";
cin >> p >> c >> m;
fileout << "Physics: " << p << "\nChemistry: " << c << "\nMaths: " << m <<"\n";
}
fileout.close ();
ifstream filein ("marks.txt", ios::in);
while (filein)
{filein >> p >> c >> m;
sumP += p; sumC+=c; sumM+=m;
if (m>M) {M=m; filein.getline (str, 80 ,'\n');}
}
filein.close ();
cout << "Average = " << sumP/3 << " " << sumC/3 << " " << sumM/3;
cout << "Maximum marks" << M << "received by "; puts (str);
getch ();
return 0;
}
|