Click here to Skip to main content
15,912,082 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
bool InsertResult(char *filename, List<Student> *list)
{
	Student stu;
	Exam exam;

	bool read=true;
	char stuid[10];

	ifstream in; 
	in.open(filename);

	if(!in){
		cout << "The file cannot open." << endl;
		read = false; //set the read to false when the file not found
	}
	
	while(!in.eof())
	{	
		int check=1;
		in >> stuid;

		for(int i=1; i<=list->size(); i++)
		{
			list->get(i,stu);
			if(strcmp(stu.id,stuid) == 0)
			{	
				check = 0;
				break;
			}
		}

		in >> exam.trimester;
		in >> exam.year;
		in >> exam.numOfSubjects;

		for(int i=0;i<exam.numofsubjects;i++)>
		{
			in>>exam.sub[i].subject_code;
			in>>exam.sub[i].subject_name;
			in>>exam.sub[i].credit_hours;
			in>>exam.sub[i].marks;
		}

//////////////////////////////////Problem in here /////////////////////////////////
		if (check==0)
		{
			if(list->find(stu)->item.exam->empty())
			{
			list->find(stu)->item.exam = new List<exam>;
				list->find(stu)->item.exam->insert(exam);
			}	
			else
				list->find(stu)->item.exam->insert(exam);						
		}
	
////////////////////////////////////////////////////////////////////////////////
		for(int i=1; i<=list->size(); i++)
		{
			list->get(i,stu);
			if(strcmp(stu.id,stuid) == 0)
			{	
				exam.calculateGPA();
				stu.calculateCurrentCGPA();
				list->set(i,stu); 
				cout << stu;
			} 
				//cout << exam;

		}
	}
	in.close();
	cout << "\n\t Student results are successfully inserted.\n";
	return true;

}
Posted
Updated 5-Aug-15 6:59am
v4

Try
C++
list->find(atoi(stuid))

instead of
C++
list->find(stu)
 
Share this answer
 
Quote:
bool InsertResult(char *filename, List<student> *list)

That should be
C++
bool InsertResult(char *filename, List<Student> *list)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Aug-15 12:57pm    
Good catch, a 5.
—SA
CPallini 5-Aug-15 14:33pm    
Thank you.
Member 10452585 5-Aug-15 13:02pm    
Still Same
Error:
left of '->item' must point to class/struct/union/generic type
left of '->insert' must point to class/struct/union/generic type
left of '.exam' must have class/struct/union
'List<t>::find' : cannot convert parameter 1 from 'Student' to 'int'
CPallini 5-Aug-15 14:34pm    
You should, at least:
post the Student definition.
indicate the offending line (the compiler tells you that).
[no name] 5-Aug-15 16:09pm    
It means just what it says. stu is not an integer, it's a Student and you have a find function defined somewhere that takes an int not a Student.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900