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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
struct Class
{
int term;
string subject;
string catalog;
string letGrade;
double numGrade;
Class* next;
};
typedef Class* ClassList;
struct Student
{
string ID;
ClassList ClassesTaken;// a linked list of Class objects
...
void loadData (ifstream& IN, vector<Student>& sVec)
{
IN.open("file.tsv");
if (IN.fail())
{
cout << "file has failed to open." << endl;
}
getID (IN, sVec);
}
void getID (ifstream& IN, vector<Student>& sVec)
{
vector<string> nameVec;
int term_num;
string sub, cata, grade_let;
double grade_num;
while (IN >> s.ID >> term_num >> sub >> cata >> grade_let >> grade_num)
{
insertName (s.ID, nameVec);
createList (IN, term_num, sub, cata, grade_let, grade_num);
}
}
void insertName (string id, vector<string>& nameVec)
{
nameVec.push_back (s.ID);
}
void createList (ifstream& IN, int term_num, string sub, string cata, string grade_let, double grade_num)
{
Class *top = new Class;
top -> term = term_num;
top -> subject = sub;
top -> catalog = cata;
top -> letGrade = grade_let;
top -> numGrade = grade_num;
top -> next = storage;
storage = top;
}
|