Class Templates, Linked Lists, Print Functions, Need Help?

I am using Class templates and Linked lists to read and write to a .txt file. I have the code down to where it will compile but i'm not sure what to do within the Linked list print function but it should call print functions from a class called Student.

Here is the code in the Main file.cpp:

1
2
3
4
void PrintGradeReports(ofstream &outFile, linkedList<Person*> personList, int numStudentsReg, int tuitionRate)
{
		personList.Print(outFile, personList,numStudentsReg, tuitionRate);
}


Here is the code for the Template class Print function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
template <class Type>
void linkedList<Type>::Print(ofstream &outFile, linkedList<Person*> personList, int numStudentsReg,
	int tuitionRate) const
{	
	/*Student *temp;
   
    temp = first;
   
    while (temp != NULL)
    {
         outFile << temp->title << ": ";
	 for (i = 0; i < temp->nAuthors; i++)
	 {
	    cout << temp->author[i];
	    if (i < temp->nAuthors - 1)
	    {
	       cout << ", ";
	    }
	 }
	 cout << endl;
         temp = temp->link;
   }*/

}


Here is the code for the Student class print function:

1
2
3
4
5
6
7
8
9
10
11
12
void Student::Print(ofstream &outFile, int tuitionRate)
{
	outFile << "Student Name: " << GetFirstName() << " " << GetLastName() << endl;
	outFile << "Student ID: " << mID << endl;
	outFile << "Number of courses enrolled: " << mNumCourses << endl << endl;

	mCoursesEnrolled[mNumCourses]->CoursePrint(outFile, mCoursesEnrolled, mIsTuitionPaid, mNumCourses);

	outFile << endl;
	outFile << "Total number of credit hours: " << GetHoursEnrolled() << endl;
	outFile << GetGPA(tuitionRate, outFile) << endl << endl;
}
In this code,
void PrintGradeReports(ofstream &outFile, linkedList<Person*> personList, int numStudentsReg, int tuitionRate)

why do you use linkedList<Person*> personList instead of linkedList<Person*>& personList ? Is this a typo or do you really want to pass linkedList<Person*> personList by copy constructor?

Also, what are you trying to achieve with this code (can you explain with plain words what is the task you are solving?)
Last edited on
Topic archived. No new replies allowed.