Hello:
I need help with a project.
I have to read an input file that contains data for 17 students. This is how they are: first ID, then first name, then last name, then 10 test scores.
For this data, I have to read it and process it to send it to a new file that only contains:
the last name, a comma, the first name, the ten scores, and the average for them followed by a letter grade.
However, the names have to be in alphabetical order, and it has to be formatted.
This is the code I have now:
It outputs the last name, a comma, first name, scores, average and letter grade.
However, it doesn't put the names in order neither makes them look formatted.
Any ideas?
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
ifstream infile;
int ID, score[10];
float ave, sum=0;
string firstn, lastn, fullname;
infile.open ("c:\\students.txt");
while (infile>>ID>>firstn>>lastn) // read file
{
fullname= lastn + "," +firstn; // combine last
cout.setf(ios::fixed); // and 1st name
cout.setf(ios::showpoint);
cout<<fullname<<" "; // Outputs fullname
for (int n=0; n<10; n++) // processes scores
{ infile>>score[n];
cout<<score[n]<<" "; // outputs scores
sum+=score[n]; // sums scores
}
ave=sum/10; // Processes average
cout.precision(3);
cout<<ave<<" "; // Outputs average
if (ave>=90)
{cout<<"A"; // Processes letter grades and
} // Outputs it
else
{ if (ave>=80)
{cout<<"B";
}
else
{ if(ave>=70)
{cout<<"C";
}
else
{ if(ave>=60)
{cout<<"D";
}
else
{cout<<"F";
}
}
}
}
cout<<endl;
sum=0; // resets sum to 0 for new student
}
system("PAUSE");
return EXIT_SUCCESS;
}
<< moderator edit: added [code][/code] tags >>