Class program won't run (identifier undefined and deleted function errors)

Hello, would someone mind taking a look at this as this program will not run. The input file is filled vertically with words/data. I have taken initiative to move things around, redefine them, but this stage of the program is the best I have gotten it to.

I am getting these errors:
1 IntelliSense: identifier "Total_Examgrade" is undefined

2 IntelliSense: identifier "Total_Labgrade" is undefined

3 IntelliSense: identifier "Final_grade" is undefined

4 IntelliSense: identifier "Average_Examgrade" is undefined

5 IntelliSense: identifier "Average_Labgrade" is undefined

6 IntelliSense: function "std::basic_ofstream<_Elem, _Traits>::basic_ofstream(const std::basic_ofstream<_Elem, _Traits>::_Myt &) [with _Elem=char, _Traits=std::char_traits<char>]" (declared at line 1016 of "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\fstream") cannot be referenced -- it is a deleted 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

const int size = 20;//change here to change array size

class Student//declares class type Student

{
public:
	string Firstname, Middlename, Lastname;
	float GPA;//each student has 1 GPA
	char Lettergrade;	
	int Examgrade[3];
	//holds Examgrade1, Examgrade2, Examgrade3;
	int Labgrade[4];
	//holds Labgrade1, Labgrade2, Labgrade3, Labgrade4;

	//function declarations
	void Initialize(Student Compstud[]);
	//function initializes all the elements
	void Read_Data(ifstream& In_Data, Student Compstud[]);
	//function read values from a file, these values will be used for calculations
	//postcondition: replaces 0 initialization with those values
	float Calc_GPA(int Examgrade[], int Labgrade[], Student Compstud[]);
	//function calculates the GPA of each of the students
	//Postcondition: Able to use the return values of this function to assign letter grade
	char LetterGrade(float GPA, Student Compstud[]);
	//Precondition: Student has a GPA calculated
	//function outputs a letter grade according to the student's calculated GPA
	//Grading scale: 100-90: A , 90-80: B, 80-70: C, 70-0: D: Failure
	float calc_ClassAverage(float GPA, Student Compstud[]);
	//Precondition: Each student has a GPA calculated
	//function uses all student's GPA to calculates average grade of the class
	//use pointer to point to each student's GPA and sum them up
	void Display_File(ofstream Out_Data, Student Compstud[]);
	//Postconditions: 
	//Outputs each of the 20 students' full name, 3 exam grades,
	//each of the 4 lab grades, and final grade to an output file
	//Outputs the average GPA of whole class
	void Display_Screen(Student Compstud[]);
	//Postconditions: 
	//Outputs each of the 20 students' full name, 3 exam grades,
	//each of the 4 lab grades, and final grade to the screen
	//Outputs the average GPA of whole class
};

//to "access" any student's ID number: Student.IDnumber
//to "access" a student's 1st exam grade: Student.Examgrade[0]

Student Compstud[size];
//initializes an array within type Student to hold 'size' Compsci students

ifstream In_Data;
ofstream Out_Data;
float ClassAverage;

int main()
{
	//function calls begin, Still getting the "identifier" is UNDEFINED
	Compstud[size].Read_Data(In_Data, Compstud);
	Compstud[size].Calc_GPA(Examgrade, Labgrade, Compstud);
	Compstud[size].LetterGrade(GPA, Compstud);
	Compstud[size].calc_ClassAverage(GPA, Compstud);
	Compstud[size].Display_File(Out_Data, Compstud);
	Compstud[size].Display_Screen(Compstud);
}

void Student:: Read_Data(ifstream& In_Data, Student Compstud[])
{
	In_Data.open("inputlab10.txt");
	if (!In_Data.is_open())
		exit(1);

	for (int i = 0; i < size; i++)//loop through each student in array
	{
		In_Data >> Compstud[i].Firstname >> Compstud[i].Middlename >> Compstud[i].Lastname;

		for (int j = 0; j < 3; j++)//loop and read in exam grades
		{
			In_Data >> Compstud[i].Examgrade[j];
		}
		for (int k = 0; k < 4; k++)//loop and read in lab grades
		{
			In_Data >> Compstud[i].Labgrade[k];
		}
	}
	In_Data.close();
	return;
}

float Student:: Calc_GPA(int Examgrade[], int Labgrade[], Student Compstud[])
{
	int sum1, sum2;//holds value of sums	
	float StudGPA;

	for (int i = 0; i < size; i++)//loop through each student in array
	{
		for (int j = 0; j < size; j++)
		{
			sum1 += Compstud[i].Examgrade[j];//loop and add up student's exam grades
		}
		for (int k = 0; k < size; k++)
		{
			sum2 += Compstud[i].Labgrade[k];//loop and add up student's lab grades
		}
		StudGPA = ((.60 * sum1) + (.40 * sum2) / 2);
		Compstud[i].GPA = ((.60 * sum1) + (.40 * sum2) / 2);
	} return StudGPA;//student (element's) calculated GPA
}

char Student:: LetterGrade(float GPA, Student Compstud[])
{
	for (int i = 0; i < size; i++)//loop through each student in array
	{
		char letter = 0;//variable to hold the letter
		if (Compstud[i].GPA > 90)
			letter = 'A';
		else if (Compstud[i].GPA > 80)
			letter = 'B';
		else if (Compstud[i].GPA > 70)
			letter = 'C';
		else if (Compstud[i].GPA > 60)
			letter = 'D';
		else
			letter = 'F';
		char Lettergrade = letter;//assign the Lettergrade value of letter.
		return Lettergrade;
	}
}

float Student:: calc_ClassAverage(float GPA, Student Compstud[])
{
	float GPAsum;//hold all student's GPA

	for (int i = 0; i < size; i++)//loop through each student in array
	{
		//sum all student's GPAs and store value in GPAsum
		GPAsum += Compstud[i].GPA;

		ClassAverage = (GPAsum / size);
		return ClassAverage;
	}
}

void Student:: Display_File(ofstream Out_Data, Student Compstud[])
{
	for (int i = 0; i < size; i++)//loop through each student in array
	{
		Out_Data.open("outputlab10.txt");
		if (!Out_Data.is_open())
			exit(1);
		//write each student's record to file
		Out_Data <<
			Compstud[i].Firstname << "   " << Compstud[i].Middlename << "   " << Compstud[i].Lastname << "   "
			<< Compstud[i].GPA << "   " << Compstud[i].Lettergrade << "    ";
		for (int j = 0; j < 3; i++)//loop and output exam grades
		{
			Out_Data << Compstud[i].Examgrade[j];
		}
		for (int k = 0; k < 4; i++)//loop and output lab grades
		{
			Out_Data << Compstud[i].Labgrade[k];
		}
		Out_Data.close();
		return;
	}
}

void Student::Display_Screen(Student Compstud[])
{
	const int width = 6;
	for (int i = 0; i < size; i++)//loop through each student in array
	{
		cout << "Name:      " << Compstud[i].Firstname << setw(width) << Compstud[i].Middlename << setw(width)
			<< Compstud[i].Lastname << endl;
		cout << "Exam Grades:      " << Compstud[i].Examgrade[3] << setw(width) << endl;
		cout << "Lab Grades:      " << Compstud[i].Labgrade[4] << setw(width) << endl;
		cout << "GPA:      " << Compstud[i].GPA << endl;
		cout << "Grade:      " << Compstud[i].Lettergrade << endl;

		cout << "The class grade average was" << ClassAverage << endl;
		return;
	}

	for (int i = 0; i < size; i++)//loop through each student in array
	{
		Out_Data.open("outputlab10.txt");
		if (!Out_Data.is_open())
			exit(1);
		//write each student's record to file
		Out_Data <<
			Compstud[i].Firstname << "   " << Compstud[i].Middlename << "   " << Compstud[i].Lastname << "   "
			<< Compstud[i].GPA << "   " << Compstud[i].Lettergrade << "    ";
		for (int j = 0; j < 3; i++)//loop and output exam grades
		{
			Out_Data << Compstud[i].Examgrade[j];
		}
		for (int k = 0; k < 4; i++)//loop and output lab grades
		{
			Out_Data << Compstud[i].Labgrade[k];
		}
		Out_Data.close();
		return;
	}

}
Your problem comes from the arguments you're attempting to pass into your function calls. Here's a simplistic version of what you're trying to do:
1
2
3
4
5
6
7
8
9
10
11
12
class Classy
{
public:
    int hello;
    void stay_classy(int h);
}

int main (void)
{
    Classy hey;
    hey.stay_classy(hello);
}


The problem here is that hello exists within the Classy class. It does not exist as a global or local variable in main, and subsequently CANNOT be referenced in main unless you reference form the class. So this would be legal:

 
hey.stay_classy( hey.hello );


However, this code is redundant. stay_classy and hello are members of the same class. There's no need to pass hello as a parameter into stay_classy because you can directly modify the data inside of stay_class because both members are of the same class.

Your problem, in short, is that you are treating class member variables as global variable.s That is syntactically illegal. You should address the problem a different way, remove function parameters that you are attempting to pass class variables into, and use the power of classes to not have to add those unnecessary parameters and modify the class variables directly.
Thank you!

I made edits to the program and now I get the following 2 errors:

Error 5 error LNK2019: unresolved external symbol "public: __thiscall Student::Student(void)" (??0Student@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'Compstud''(void)" (??__ECompstud@@YAXXZ)

Error 6 error LNK1120: 1 unresolved externals

New 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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

ifstream In_Data;
ofstream Out_Data;

const int size = 20;//change here to change array size

class Student//declares class type Student

{
public:
	string Firstname, Middlename, Lastname;
	float GPA;//each student has 1 GPA
	char Lettergrade;
	int Examgrade[3];
	//holds Examgrade1, Examgrade2, Examgrade3;
	int Labgrade[4];
	//holds Labgrade1, Labgrade2, Labgrade3, Labgrade4;

	//member function declarations
	Student();//empty constructor
	void Initialize();
	//function initializes all the elements
	void Read_Data(ifstream& In_Data);
	//function read values from a file, these values will be used for calculations
	//postcondition: replaces 0 initialization with those values
	float Calc_GPA();
	//function calculates the GPA of each of the students
	//Postcondition: Able to use the return values of this function to assign letter grade
	char LetterGrade();
	//Precondition: Student has a GPA calculated
	//function outputs a letter grade according to the student's calculated GPA
	//Grading scale: 100-90: A , 90-80: B, 80-70: C, 70-0: D: Failure
	float calc_ClassAverage();
	//Precondition: Each student has a GPA calculated
	//function uses all student's GPA to calculates average grade of the class
	//use pointer to point to each student's GPA and sum them up
	void Display_File(ofstream& Out_Data);
	//Postconditions: 
	//Outputs each of the 20 students' full name, 3 exam grades,
	//each of the 4 lab grades, and final grade to an output file
	//Outputs the average GPA of whole class
	void Display_Screen();
	//Postconditions: 
	//Outputs each of the 20 students' full name, 3 exam grades,
	//each of the 4 lab grades, and final grade to the screen
	//Outputs the average GPA of whole class
};

//to "access" any student's ID number: Student.IDnumber
//to "access" a student's 1st exam grade: Student.Examgrade[0]

Student Compstud[size];
//initializes an array within type Student to hold 'size' Compsci students

float ClassAverage;

int main()
{
	//function calls begin
	Compstud[size].Read_Data(In_Data);
	Compstud[size].Calc_GPA();
	Compstud[size].LetterGrade();
	Compstud[size].calc_ClassAverage();
	Compstud[size].Display_File(Out_Data);
	Compstud[size].Display_Screen();
}

void Student::Read_Data(ifstream& In_Data)
{
	In_Data.open("inputlab10.txt");
	if (!In_Data.is_open())
		exit(1);

	for (int i = 0; i < size; i++)//loop through each student in array
	{
		In_Data >> Compstud[i].Firstname >> Compstud[i].Middlename >> Compstud[i].Lastname;

		for (int j = 0; j < 3; j++)//loop and read in exam grades
		{
			In_Data >> Compstud[i].Examgrade[j];
		}
		for (int k = 0; k < 4; k++)//loop and read in lab grades
		{
			In_Data >> Compstud[i].Labgrade[k];
		}
	}
	In_Data.close();
}

float Student::Calc_GPA()
{
	int sum1 = 0, sum2 = 0;//holds value of sums	
	float StudGPA;

	for (int i = 0; i < size; i++)//loop through each student in array
	{
		for (int j = 0; j < 3; j++)
		{
			sum1 += Compstud[i].Examgrade[j];//loop and add up student's exam grades
		}
		for (int k = 0; k < 4; k++)
		{
			sum2 += Compstud[i].Labgrade[k];//loop and add up student's lab grades
		}
		StudGPA = ((.60 * sum1) + (.40 * sum2) / 2);
		Compstud[i].GPA = ((.60 * sum1) + (.40 * sum2) / 2);
	} return StudGPA;//student (element's) calculated GPA
}

char Student::LetterGrade()
{
	for (int i = 0; i < size; i++)//loop through each student in array
	{
		char letter = 0;//variable to hold the letter
		if (Compstud[i].GPA > 90)
			letter = 'A';
		else if (Compstud[i].GPA > 80)
			letter = 'B';
		else if (Compstud[i].GPA > 70)
			letter = 'C';
		else if (Compstud[i].GPA > 60)
			letter = 'D';
		else
			letter = 'F';
		char Lettergrade = letter;//assign the Lettergrade value of letter.
		return Lettergrade;
	}
}

float Student::calc_ClassAverage()
{
	float GPAsum = 0;//hold all student's GPA

	for (int i = 0; i < size; i++)//loop through each student in array
	{
		//sum all student's GPAs and store value in GPAsum
		GPAsum += Compstud[i].GPA;

		ClassAverage = (GPAsum / size);
		return ClassAverage;
	}
}

void Student::Display_File(ofstream& Out_Data)
{
	for (int i = 0; i < size; i++)//loop through each student in array
	{
		Out_Data.open("outputlab10.txt");
		if (!Out_Data.is_open())
			exit(1);
		//write each student's record to file
		Out_Data <<
			Compstud[i].Firstname << "   " << Compstud[i].Middlename << "   " << Compstud[i].Lastname << "   "
			<< Compstud[i].GPA << "   " << Compstud[i].Lettergrade << "    ";
		for (int j = 0; j < 3; i++)//loop and output exam grades
		{
			Out_Data << Compstud[i].Examgrade[j];
		}
		for (int k = 0; k < 4; i++)//loop and output lab grades
		{
			Out_Data << Compstud[i].Labgrade[k];
		}
		Out_Data.close();
		}
}

void Student::Display_Screen()
{
	const int width = 6;
	for (int i = 0; i < size; i++)//loop through each student in array
	{
		cout << "Name:      " << Compstud[i].Firstname << setw(width) << Compstud[i].Middlename << setw(width)
			<< Compstud[i].Lastname << endl;
		for (int j = 0; j < 3; i++)//loop and output exam grades
		{
			cout << Compstud[i].Examgrade[j];
		}
		for (int k = 0; k < 4; i++)//loop and output lab grades
		{
			cout << Compstud[i].Labgrade[k];
		}
		cout << "GPA:      " << Compstud[i].GPA << endl;
		cout << "Grade:      " << Compstud[i].Lettergrade << endl;
	}
		cout << "The class grade average was" << ClassAverage << endl;
}
closed account (SECMoG1T)
Line 58 - Student Compstud[size];, I guess your problem is here, you allocated size student elements that are default initialized, how will your default constructor work bearing in mind that your class have no private members it can reference to, If what you have is your desired class design then I suggest you should explicitly state what your default constructor should do to intialize your public class members, am not very certain of these coz in struct your routine works for the default constructor although all their members are implicitly public ofc, try define your default constructor, define how your class members should be initialized , might be that will help.
Last edited on
Student();//empty constructor
No it is not. It is a declaration of constructor (promise that it will be defined later).

To decalre an empty constructor you should do: Student() {}, or (preferably in C++11) Student() = default;
Topic archived. No new replies allowed.