return variable

why i get an fatal error with it on my read 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void readRecord( ifstream &inFile , int sizeCourse , int sizeOfStudent ){

	Course theCourse;

	string SubjectCode;
	string SubjectName;
	string StudentName;
	int theCredit;
	string filename;

	if ( inFile.is_open() ){
		inFile.ignore();
		for( int i = 0 ; i < sizeCourse ; i++ ){
			getline( inFile , SubjectCode );
			theCourse.setCourseCode( SubjectCode );

			getline( inFile , SubjectName );
			theCourse.setCourseName( SubjectName );

			inFile >> theCredit;
			theCourse.setCredit( theCredit);

			inFile >> sizeOfStudent;
			theCourse.setNumOfStudent( sizeOfStudent );
			inFile.ignore();

			for ( int z = 0 ; z < sizeOfStudent ; z++ ){
				getline( inFile , theCourse.theStudent[z].studentName);
				inFile >> theCourse.theStudent[z].studentMarks;
				inFile.ignore();
			}
		}
	}
	cout << sizeCourse  << endl;
	for( int i = 0 ; i < sizeCourse ; i++ ){
		cout << theCourse.getCourseCode() << endl
			 << theCourse.getCourseName() << endl
			 << theCourse.getCredit() << endl
			 << theCourse.getNumOfStudent() << endl;
			 for( int z = 0 ; z < theCourse.getNumOfStudent() ; z++ ){
				 cout << theCourse.theStudent[z].studentName << endl
					  << theCourse.theStudent[z].studentMarks<< endl;
			 }
	}
}


my main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main(){
	
	string filename;
	Course *theCourse;
	int numOfCourse = 0;
	int numOfStudent = 0;
	int choice = 0;
	ifstream inFile;

	cout << "Enter filename to read : ";
	getline( cin , filename );
	cout << endl;

	inFile.open( filename.c_str() );
	
	if( inFile.fail() )
		cout << "Unable to open file !" << endl;
	inFile >> numOfCourse;

	theCourse = new Course[numOfCourse];//dynamic array created

	for( int i = 0 ; i < numOfCourse ; i++ ){
		theCourse[i].readRecord( inFile, numOfCourse , numOfStudent ); 
	}


my class
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
#include <iostream>
#include <string>
#include <conio.h>
#include <fstream>

using namespace std;

class Course{
private:
	string courseCode;
	string courseName;
	int credit;
	int numOfStudent;
public:

	struct Student{
		string studentID;
		string studentName;
		double studentMarks;
	}theStudent[30];

	Course();
	

	void setCourseCode( string );
	string getCourseCode();

	void setCourseName( string );
	string getCourseName();

	void setCredit( int );
	int getCredit();

	void setNumOfStudent( int );
	int getNumOfStudent();

	void setStudentID( string );
	string getStudentID();

	void setStudentMarks( double );
	double getStudentMarks();

	void readRecord( ifstream & , int  , int );
};
Last edited on
Topic archived. No new replies allowed.