I'm trying to write a program that will print the data of 10 records from a file and then, sort them descending to ascending by year.
Here are the records:
Name Year Tuition
David 2011 1582.38
Sylvester 2012 728.82
Ben 1992 0
Brandon 1995 500.25
Riley 1997 845.19
Mark 2009 700.05
Roberts 2002 450.87
Butler 2005 920.78
Steve 2000 1000.00
Joe 1994 1200.15
int main ()
{
string line;
ifstream myfile ("bubblesort.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
class Student
{
string name;
unsignedint year;
unsignedfloat tuition;
}
As you read each line, allocate new object and populate the object from each line. Once you have all objects allocated, you can then sort based on year field in each object.
And de-allocate objects before exiting the program.