mutator or accessor

hi . I'm new to here ! wanna to ask a question

i try to read this in my file using class with accessor and mutator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
CSCI124
Applied Programming
6
2
Alice
56
Bob
75
CSCI114
Procedural Programming
6
3
Nancy
89
Paul
67
Lisa
58


and this is my readFunction()
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
void readRecord( Course *theCourse , int &sizeCourse , int &sizeStudent ){

	string filename;
	ifstream inFile;

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

	inFile.open( filename.c_str());

	if( inFile.fail() ){
		cout << "Unable to open file ! Re-check !" << endl;
		getch();
		exit(1);
	}

	if ( inFile.is_open() ){
		inFile >> sizeCourse;
		inFile.ignore();
		for( int i = 0 ; i < sizeCourse ; i++ ){
			getline( inFile , theCourse[i].setCourseCode() );
			getline( inFile , theCourse[i].getCourseName() );
			inFile >> theCourse[i].getCredit();
			inFile >> sizeStudent;
			for ( int z = 0 ; z < sizeStudent ; z++ ){
				getline( inFile , theCourse[z].getStudentName());
				inFile >> theCourse[z].getStudentMarks();
			}
		}
	}
}


i'm not really sure when i read the file name is using accessor or mutator.
can someone give an advise and teach me? and
sizeStudent problem , should i using theCourse[i].sizeStudent or just pass by ampersand?
someone help please?
Your question is not very clear. Since readRecord is not a member of a class it's neither a mutator nor an accessor. If it were a member of a class it would be a mutator.

But, somehow I suspect that's not what you wanted to know.

All of those theCourse[i].get..() functions look suspicious in a 'read from file' operation.


Should i using theCourse[i].sizeStudent or just pass by ampersand?

It's "pass by reference" not "pass by ampersand." You would only pass it in by reference if you needed to modify it in the function and have the change reflected in the calling code. Honestly, it looks like it should be a local variable in this code.
Last edited on
Topic archived. No new replies allowed.