Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting input file data

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
how would i get an average of the test scores in a text file
formatted like this:


socialsec# lastname firstname grade1 grade2 grade3

etc....
 
You could use a struct:
Code:
struct StudentType
{
   string socSec;    // in the form 123-45-6789
   string lastName;
   string firstName;
   float grade1;
   float grade2;
   float grade3;
};  
StudentType student;
// open file and check for open file etc.

// read data from file, (declare these variables to hold data)
inFile >> ss >> lastN >> firstN >> grd1 >> grd2 >> grd3;
while(inFile)
{
    student.socSec = ss;
    student.lastName = lastN;
    student.firstName = firstN;
    student.grade1 = grd1;
    student.grade2 = grd2;
    student.grade3 = grd3;
    inFile >> ss >> lastN >> firstN >> grd1 >> grd2 >> grd3;
}
[\code]
Besure to check for over flow of the list of students in the while loop
if you are using a static container.
such as an array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top