(almost solved) Constructors/Destructors Student enroling Program

Pages: 12
Hi, I've nearly finished the program but there are some errors saying there are missing semi colons. However when I put them in I get so many errors :(
Here is the code. I know that just because it says there are missing ; does not ALWAYS mean they should be there. Any help? Much appreciated :)

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
using namespace std;

    class student
       {
       	protected:
	   	string surname;
	   	int enNo;
                float nMark;
	public:
		student();
		~student();
		string getSurname();
		int getEnNo();
                float tMark;
                float getNMark();
		float getTMark();
       };

    class course
        {
        protected:
                string student;
                int enNo;
                float tMark;
                string cName;
                int *CoursePtr;
                bool enrollYN;
        public:
                course();
                ~course();
                string nStudent();
                string lStudent();
                string getCourse();
                bool getEnrollYN();
                string getStudent();
                float getNMark();
                float getTMark();
        };

course::course()
{
        cout << "A new course has been created. Please enter the title of the course: ";
	getline(cin, cName);;
}

course::~course()
{
        cout << "The course ";
        cout << cName;
        cout << " has been deleted.";
        if (enrollYN == 1)
        {
        cout << "The student ";
        cout << student;
        cout << " with the enrolment number ";
        cout << enNo;
        cout << " is still enrolled with a total mark of ";
        cout << tMark;
}

course::nStudent()
{
        student();
        enrollYN = 1;
}

course::lStudent()
{
        cout << "The student ";
        cout << surname;
        cout << "is leaving and their total mark was: ";
        cout << getTMark();
        getchar();
        enrollYN = 0;
}

course::getCourse()
{
        return(cName);
}

course::getEnrollYN()
{
        if (enrollYN = 0)
        {
        return(0)
        else if (enrollYN = 1)
        return (1)
        }
}

student::student()
{
        cout << "A new student is enrolling. Please enter the new student's surname: ";
	getline(cin, surname);
	cout << "Please enter their enrolment number: ";
	cin >> enNo;
	tMark = 0;
}


student::~student()
{
        cout << "The student ";
		cout << surname;
        cout << "is leaving and their total mark was: ";
		cout << student::getTMark();
        getchar();
}
string student::getSurname()
{
	return(surname);
}
int student::getEnNo()
{
	return (enNo);
}
float student::getTMark()
{
	return (tMark);
}

float student::getNMark()
{
	cin >> nMark;
	tMark += nMark;
	return (tMark);
}



void main(void)
{

	  clrscr();
          student studScore;
	  cout << studScore.student::getSurname() << " has enrolled and their enroll number is ";
          cout << studScore.student::getEnNo();

char again;

do
{
          cout << ". Please enter their mark from their latest test: ";
          cout << studScore.student::getNMark();
          cout << "Their total score is now ";
          cout << studScore.student::getTMark();
          cout << ". Do you want to enter another mark? (Type 'Y' or 'N')";
          cin >> again;
} while (again != 'N' && again != 'n');

cin.get();
}
}
Last edited on
There are a lot of errors in your program. I would suggest you start small, with just constructor and destructor, see if it compiles. Then add functions one at a time. Here are some examples of what is wrong:

1. In the destructor you did not have a closing }
2. need to include <string>
3. The definition of nStudent is string nStudent();, but the implementation is course::nStudent(). If your definition is correct, the implementation should be string course::nStudent()
4. In the same function, you need to return something.
5. In the same function, student in the string student or the class student?
6. Try to explain what is the meaning of student(); statement.

There might be more, but that's how far I checked. Like I mentioned, start with the minimal implementation and see if you have any errors.
Thanks for the reply :)

I made a program without courses before hand which all seems to work fine:

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <iostream>
using namespace std;

    class student
       {
       	protected:
	   	string surname;
	   	int enNo;
                float nMark;
	public:
		student();
		~student();
		string getSurname();
		int getEnNo();
                float tMark;
                float getNMark();
		float getTMark();
       };

student::student()
{
        cout << "A new student is enrolling. Please enter the new student's surname: ";
	getline(cin, surname);
	cout << "Please enter their enrolment number: ";
	cin >> enNo;
	tMark = 0;
}


student::~student()
{
        cout << "The student ";
		cout << surname;
        cout << "is leaving and their total mark was: ";
		cout << tMark;
        getchar();
}
string student::getSurname()
{
	return(surname);
}
int student::getEnNo()
{
	return (enNo);
}
float student::getTMark()
{
	return (tMark);
}

float student::getNMark()
{
	cin >> nMark;
	tMark += nMark;
	return (tMark);
}



int main()
{

	  system("cls");
          student studScore;
	  cout << studScore.student::getSurname() << " has enrolled and their enroll number is ";
          cout << studScore.student::getEnNo();

char again;

do
{
          cout << ". Please enter their mark from their latest test: ";
          cout << studScore.student::getNMark();
          cout << "Their total score is now ";
          cout << studScore.student::getTMark();
          cout << ". Do you want to enter another mark? (Type 'Y' or 'N')";
          cin >> again;
} while (again != 'N' && again != 'n');

cin.get();
}


But I'm having trouble modifying it so I can allow a student to enrol on the course one at a time. I want to record the course name, use a flag to say if a student is enrolled or not, and the course constructor asks for the course name. The destructor is supposed to show the course name etc. as well as a student is enrolled/shows their enroll number.

And I think like with student the main part should have an auto object of class course with a name.

I think I need a do loop as well to be able to let the user say when a student is recruited, left or finished a test. Only one student enrols at a time. And no test can be taken if no student is enrolled.

I'm not sure what you mean with the closing brace for the destructor. They all seem there to me. Which line is it missing?

I've corrected 2 and 3. Have I returned correctly? And have I also done 4 and 5 corrections correctly? I've removed student(); also.

Here are the changes:

1
2
3
4
5
6
#include <iostream>
#include <string>

string course::nStudent()

        return(nStudent)


When putting in string before course it says a function definition is not allowed before the { ?
Last edited on
Any ideas?
all of these:
1
2
3
#include <stdio.h>
#include <conio.h>
#include <string.h> 


are old. I don't even know why you've included stdio.h and conio.h?

you need to include:
 
#include <string> 


edit: one more comment: I wouldn't do any coding (as such) in class constructors or destructing (with the exception of your trace statements I guess. Ctor's and dtor's are there so you can initialise and clear up the object correctly.
i'd move this:
1
2
3
4
	cout << "A new student is enrolling. Please enter the new student's surname: ";
	getline(cin, surname);
	cout << "Please enter their enrolment number: ";
	cin >> enNo;

into a method called getStudentDetails, or something like that, and i'd move all of the code currently in your destructor into another method, especially your call to getchar(). this is very bad in a destructor.
Last edited on
They are from the working program without the course. I am talking about the initial code.
Right I have changed a few bits but don't know if I've done anything wrong because I am stuck with the semicolon missing thing and can't see if any more errors are found.
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <iostream> // declaring header files so I can use the code
#include <string>
using namespace std;

    class student //declaring class student
       {
       	protected: //this means these variables are used in the functions
	   	string surname; //variables where data is entered and stored
	   	int enNo;
        float nMark;
	public: //alowed to use these functions in main program
		student(); //constructor
		~student(); //destructor
		string getSurname();
		int getEnNo();
        float tMark;
        float getNMark();
		float getTMark();
       };

    class course //declaring class course. Similar contents to class student
        {
        protected:
                string student;
                int enNo;
                float tMark;
                string cName;
                int *CoursePtr;
                bool enrollYN;
        public:
                course();
                ~course();
                string nStudent();
                string lStudent();
                string getCourse();
                bool getEnrollYN();
                string getStudent();
                float getNMark();
                float getTMark();
        };

course::course() //course constructor, in which course name is entered.
{
        cout << "A new course has been created. Please enter the title of the course: ";
	getline(cin, cName);;
}

course::~course() //destructor when the program ends.
{
        cout << "The course ";
        cout << cName;
        cout << " has been deleted.";
        if (enrollYN == 1)
        {
        cout << "The student ";
        cout << student;
        cout << " with the enrolment number ";
        cout << enNo;
        cout << " is still enrolled with a total mark of ";
        cout << tMark;
}

course::nStudent()
{
        enrollYN = 1;
        return(student)
}

course::lStudent()
{
        cout << "The student ";
        cout << surname;
        cout << "is leaving and their total mark was: ";
        cout << getTMark();
        getchar();
        enrollYN = 0;
}

course::getCourse()
{
        return(cName);
}

course::getEnrollYN()
{
        if (enrollYN = 0)
        {
        return(0)
        else if (enrollYN = 1)
        return (1)
        }
}

student::student()
{
        cout << "A new student is enrolling. Please enter the new student's surname: ";
	getline(cin, surname);
	cout << "Please enter their enrolment number: ";
	cin >> enNo;
	tMark = 0;
}


student::~student()
{
        cout << "The student ";
		cout << surname;
        cout << "is leaving and their total mark was: ";
		cout << student::getTMark();
        getchar();
}
string student::getSurname()
{
	return(surname);
}
int student::getEnNo()
{
	return (enNo);
}
float student::getTMark()
{
	return (tMark);
}

float student::getNMark()
{
	cin >> nMark;
	tMark += nMark;
	return (tMark);
}



void main(void)
{

	  clrscr();
          student studScore;
          course studCourse;
	  cout << studScore.student::getSurname() << " has enrolled and their enroll number is ";
          cout << studScore.student::getEnNo(); 
          cout << ". "
    	cout << studCourse.course()::getCourse() << " is the title of the course they are enrolling on.";

	
char again, rlc;
		
do
{
		cout << "Type 'r' to recruit a new student, 'l' if a student has left and 'c' if a student has completed a test. "
		cin >> rlc;
} while (rlc != 'n' && rlc != 'l' && rlc != 'c')

	if (rlc == 'r')
	{
		if (enrollYN == 1)
		{
		cout << "There is already a student enrolled. Please type 'l' if they have left.";
		}
		cout << "Please enter the new student: ";
		cin << student.course::nStudent();
		else if (rlc == 'l')
		{
		cout << student.course::lStudent();
		else if (rlc == 'c')
		{
		do
{
		  if (enrollYN == 0);
		  {
		  	"There is no student enrolled. Please type 'r' to recruit a student";
		  }
		  cout << ". Please enter their mark from their latest test: ";
          cout << studScore.student::getNMark();
          cout << "Their total score is now ";
          cout << studScore.student::getTMark();
          cout << ". Do you want to enter another mark? (Type 'Y' or 'N')";
          cin >> again;
} while (again != 'N' && again != 'n');	
		}
		}
	}

if (enrollYN == 1);
{
	course::~course()
}
cin.get();
}
}
}}


Also don't know how many } there should be.
Last edited on
They are from the working program without the course.

well it didnt work for me because my compiler (quite rightly) didn't like
#include<string.h>
and wanted
#include<string>

how old are you course notes?

i can see you don't want to listen to my advice about having code in your constructor and destructor... Fair enough.

and there's now a load of syntax errors. what IDE/compiler are you using? Are they telling you line numbers of where the errors are? one example, when i try and compile your code, one error is:

Error	3	error C2143: syntax error : missing ';' before '}'	

i click on this error and it takes me to here:

1
2
3
4
5
	course::nStudent()
	{
		enrollYN = 1;
		return(student)  // <-- compiler told me you are missing a semi-colon here
	}


most of your errors are similar to that.

one major thing: you seem to be trying to define methods inside your destructor.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
course::~course()
{
        cout << "The course ";
        cout << cName;
        cout << " has been deleted.";
        if (enrollYN == 1)
        {
        cout << "The student ";
        cout << student;
        cout << " with the enrolment number ";
        cout << enNo;
        cout << " is still enrolled with a total mark of ";
        cout << tMark;
}  // <- this is the closing brace for you 'if', not your destructor.

Last edited on
Thanks for replying. I'm using Dev C++ and tells me the line numbers. I transitioned from Borland code. Perhaps I didn't understand what I needed to do for cons/destructors?

I've added ; after all return statements and added extra } after the if.

How do I avoid " trying to define methods inside your destructor."?

I get LOADS of errors after changing the code :( is this mostly due to the above?

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <iostream> // declaring header files so I can use the code
#include <string>
using namespace std;

    class student //declaring class student
       {
       	protected: //this means these variables are used in the functions
	   	string surname; //variables where data is entered and stored
	   	int enNo;
        float nMark;
	public: //alowed to use these functions in main program
		student(); //constructor
		~student(); //destructor
		string getSurname();
		int getEnNo();
        float tMark;
        float getNMark();
		float getTMark();
       };

    class course //declaring class course. Similar contents to class student
        {
        protected:
                string student;
                int enNo;
                float tMark;
                string cName;
                int *CoursePtr;
                bool enrollYN;
        public:
                course();
                ~course();
                string nStudent();
                string lStudent();
                string getCourse();
                bool getEnrollYN();
                string getStudent();
                float getNMark();
                float getTMark();
        };

course::course() //course constructor, in which course name is entered.
{
        cout << "A new course has been created. Please enter the title of the course: ";
	getline(cin, cName);;
}

course::~course() //destructor when the program ends.
{
        cout << "The course ";
        cout << cName;
        cout << " has been deleted.";
        if (enrollYN == 1) //if a student is enrolled
        {
        cout << "The student ";
        cout << student;
        cout << " with the enrolment number ";
        cout << enNo;
        cout << " is still enrolled with a total mark of ";
        cout << tMark;
    	}
}

course::nStudent() //function for if student is enrolled
{
        enrollYN = 1;
        return(student); //return student surname
}

course::lStudent() //student leaving function
{
        cout << "The student ";
        cout << surname;
        cout << "is leaving and their total mark was: ";
        cout << getTMark();
        getchar();
        enrollYN = 0; //now left there is no student enrolled
}

course::getCourse() //get course name function
{
        return(cName);
}

course::getEnrollYN() //function for if student is enrolled or not
{
        if (enrollYN = 0) //if not
        {
        return(0); //0 means they are not enrolled.
        else if (enrollYN = 1) //else they are
        return (1); //1 means they are enrolled
        }
}

student::student()//student constructor
{
        cout << "A new student is enrolling. Please enter the new student's surname: ";
	getline(cin, surname);
	cout << "Please enter their enrolment number: ";
	cin >> enNo;
	tMark = 0; //starts with no mark
}


student::~student() //destructor when program ends
{
        cout << "The student ";
		cout << surname;
        cout << "is leaving and their total mark was: ";
		cout << student::getTMark();
        getchar();
}
string student::getSurname() //return surname function
{
	return(surname);
}
int student::getEnNo() //return their enrol number function
{
	return (enNo);
}
float student::getTMark() //total mark function
{
	return (tMark);
}

float student::getNMark() //new mark function
{
	cin >> nMark;
	tMark += nMark; //short way of putting tMark = tMark + nMark;
	return (tMark);
}

void main(void) //main program
{

	  clrscr();
          student studScore; //total mark for student
          course studCourse; //course name
	  cout << studScore.student::getSurname() << " has enrolled and their enroll number is ";
          cout << studScore.student::getEnNo(); 
          cout << ". "
    	cout << studCourse.course()::getCourse() << " is the title of the course they are enrolling on.";

	
char again, rlc; //again for when entering another mark, rlc for when a student is recruited, left or completed test
		
do
{
		cout << "Type 'r' to recruit a new student, 'l' if a student has left and 'c' if a student has completed a test. "
		cin >> rlc;
} while (rlc != 'n' && rlc != 'l' && rlc != 'c') //happens if any above is desired

	if (rlc == 'r') //if recruit a new student
	{
		if (enrollYN == 1) //error if statement if already enrolled
		{
		cout << "There is already a student enrolled. Please type 'l' if they have left.";
		}
		cout << "Please enter the new student: ";
		cin << student.course::nStudent();
		else if (rlc == 'l') //to leave a student
		{
		cout << student.course::lStudent();
		else if (rlc == 'c') //announce test completion
		{
		do
{
		  if (enrollYN == 0);
		  {
		  	"There is no student enrolled. Please type 'r' to recruit a student";
		  }
		  cout << ". Please enter their mark from their latest test: ";
          cout << studScore.student::getNMark();
          cout << "Their total score is now ";
          cout << studScore.student::getTMark();
          cout << ". Do you want to enter another mark? (Type 'Y' or 'N')";
          cin >> again;
} while (again != 'N' && again != 'n');	//when answer is 'n' the program ends
		}
		}
	}

if (enrollYN == 1);
{
	course::~course()
}
cin.get();
}
}
}}


Posting errors in a sec.
Jesus man just read a book, its so bad...

I recommend for you to just copy and pasting an example off of google, because this is a really common homework...
The program now runs (compiles) but the only two things problem wise I have is:

The course constructor runs twice at the beginning but not like the student constructor which correctly runs once,
When the if statements for entering l and c (r works fine) at the end are 'completed', the program activates the course destructor twice as well. How do I change when the destructor activates? Or is the loop wrong?

Also, the student destructor doesn't seem to happen.

Here is the modified code:

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <iostream> // declaring header files so I can use the code
#include <string>
using namespace std;

    class student //declaring class student
       {
		public: //alowed to use these functions in main program
		int enNo;
        float nMark;
		string surname;
		student(); //constructor
		~student(); //destructor
		string getSurname();
		int getEnNo();
        float tMark;
        float getNMark();
		float getTMark();
       };

    class course //declaring class course. Similar contents to class student
        {
        	public:
                string student;
                int enNo;
                float tMark;
                string cName;
                int *CoursePtr;
                bool enrollYN;
                course();
                ~course();
                string nStudent();
                string lStudent();
                string getCourse();
                bool getEnrollYN();
                string getStudent();
                float getNMark();
                float getTMark();
        };

course::course() //course constructor, in which course name is entered.
{
        cout << "A new course has been created. Please enter the title of the course: ";
		cin >> cName;
}

course::~course() //destructor when the program ends.
{
        cout << "The course ";
        cout << cName;
        cout << " has been deleted.";
        if (enrollYN == 1) //if a student is enrolled
        {
        cout << " The student ";
        cout << student;
        cout << " with the enrolment number ";
        cout << enNo;
        cout << " is still enrolled with a total mark of ";
        cout << tMark;
        cout << ".";
    	}
}

string course::nStudent() //function for if student is enrolled
{
        enrollYN = 1; //return student surname
}

string course::lStudent() //student leaving function
{
        cout << "The student ";
        cout << student;
        cout << "is leaving and their total mark was: ";
        cout << tMark;
        getchar();
        enrollYN = 0; //now left there is no student enrolled
}

string course::getCourse() //get course name function
{
        return(cName);
}

bool course::getEnrollYN() //function for if student is enrolled or not
{
        if (enrollYN = 0) //if not
        {
        return(0); //0 means they are not enrolled.
    	}
        else if (enrollYN = 1)
		{ //else they are
        return (1); //1 means they are enrolled
        }
}

student::student()//student constructor
{
        cout << "A new student is enrolling. Please enter the new student's surname: ";
	getline(cin, surname);
	cout << "Please enter their enrolment number: ";
	cin >> enNo;
	tMark = 0; //starts with no mark
}

student::~student() //destructor when program ends
{
        cout << "The student ";
		cout << surname;
        cout << " is leaving and their total mark was ";
		cout << student::getTMark();
        getchar();
}

string student::getSurname() //return surname function
{
	return(surname);
}
int student::getEnNo() //return their enrol number function
{
	return (enNo);
}
float student::getTMark() //total mark function
{
	return (tMark);
}

float student::getNMark() //new mark function
{
	cin >> nMark;
	tMark += nMark; //short way of putting tMark = tMark + nMark;
	return (tMark);
}

int main(void) //main program
{
        student studScore; //total mark for student
        course studCourse; //course name
		course enNo;
		string sur;
		int enr;
		sur = studScore.student::getSurname();
		enr = studScore.student::getEnNo();
	  	cout << studScore.student::getSurname() << " has enrolled and their enroll number is ";
        cout << studScore.student::getEnNo(); 
        cout << ". ";
    	cout << studCourse.course::getCourse() << " is the title of the course they are enrolling on.";

	
char again;
char rlc; //again for when entering another mark, rlc for when a student is recruited, left or completed test
		
	do
	{
		cout << " Type 'r' to recruit a new student, 'l' if a student has left and 'c' if a student has completed a test. Press any other key to quit the program.";
		cin >> rlc;
		if (rlc == 'r') //if recruit a new student
		{
			if (studCourse.course::getEnrollYN() == 1)
			{	
				cout << "There is already a student enrolled.";
			}
			else
			{
				cout << "Please enter the surname of the new student: ";
				cin >> sur;
				cout << ". Please enter their enrollment number: ";
				cin >> enr;
			}
		}
		else if (rlc == 'l') //to leave a student
		{
			studCourse.course::getEnrollYN() == 0;
			cout << "The student is no longer enrolled.";
		}
		else if (rlc == 'c') //announce test completion
		{
			do
			{
		 	 if (studScore.student::getEnNo() == 0)
		 	 {
		 	 	"There is no student enrolled. Please type 'r' to recruit a student";
		 	 }
		 	 cout << ". Please enter their mark from their latest test: ";
          	cout << studScore.student::getNMark();
          	cout << "Their total score is now ";
          	cout << studScore.student::getTMark();
          	cout << ". Do you want to enter another mark? (Type 'Y' or 'N')";
          	cin >> again;
			}	while (again != 'N' && again != 'n');	//when answer is 'n' the program ends
		}
	}
 while (rlc != 'n' && rlc != 'l' && rlc != 'c'); //happens if any above is desired

}


Thanks for the help everyone has offered so far :)
Last edited on
It seems as though there are two different instances of the course con/destructor. The second destructor for course does not have a value for what is supposed to be in cName.
Here's an annotated print screen of the program running too:

http://i.imgur.com/XKSSWNl.png
i'll say it again:


edit: one more comment: I wouldn't do any coding (as such) in class constructors or destructing (with the exception of your trace statements I guess. Ctor's and dtor's are there so you can initialise and clear up the object correctly.
i'd move this:

cout << "A new student is enrolling. Please enter the new student's surname: ";
getline(cin, surname);
cout << "Please enter their enrolment number: ";
cin >> enNo;

into a method called getStudentDetails, or something like that, and i'd move all of the code currently in your destructor into another method, especially your call to getchar(). this is very bad in a destructor.



also, what are you trying to do in these kind of situations:
 
cout << studScore.student::getNMark();


calling convention is:
object.method()

why do you have a scope resolution operator in there?

I would not class a project as "nearly solved" just because it compiles.


edit: one more thing (but not the last..):

1
2
3
4
string course::nStudent() //function for if student is enrolled
{
        enrollYN = 1; //return student surname
}


This does not compile for me. You even say "return student surname" but you don't return anything from this.

I seriously recommend reading up on both functions and classes and objects.
Last edited on
I've tried to move the code as you said but they still repeat. I've also removed the getchar in the destructor.

That line is supposed to print to the screen the value of getNMark. I've changed it to studScore.getNMark() but it worked before anyway.

I thought I needed the scope resolution operator to get the program to write the code.
Last edited on
I can compile it with Dev C++ and will change the above comment.
nah you just need to do something like:

cout << studScore.getNMark()
Yes, I've changed that :)
Hotchoc26 wrote:
It seems as though there are two different instances of the course con/destructor.
Yes, you have two instances of course: line 136 and 137. For both the constructor and the destructor will be called. Line 137 seems to be useless.

And read carefully what mutexe told you.
Pages: 12