3 unresolved externals?

I know what it means, but I'm having trouble finding the darn things. Can someone help me find them?

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

using namespace std;

struct studentType {
	string studentFname;
	string studentLname;
	int testScore;
	char grade;
};

const int numstudents = 20;

void getData(ifstream&,studentType, int);

void calculateGrade(studentType, const int);

void printResult(ofstream&, const studentType, const int);

int main() {

	ifstream infile;
	infile.open("names.txt");

	studentType sList[20];


	if (infile.fail())
	{
		cout << "Error: Cannot open input file. Exiting...";
		system("pause");
	}

	ofstream outfile;
	outfile.open("grades.txt");

	getData(infile, sList[numstudents], numstudents);
	calculateGrade(sList[numstudents], numstudents);
	printResult(outfile, sList[numstudents], numstudents);

	infile.close();
	outfile.close();

	system("pause");
	return 0;
}

void getData(ifstream& infile, studentType sList[], int &listCount)
{
	while (!infile.eof())
	{
		for (int i = 0; i < listCount; i++)
			infile >> sList[i].studentFname >> sList[i].studentLname
			>> sList[i].testScore;
	}
}


void calculateGrade(studentType sList[], const int listSize)
{

	int score = 0;

	for (int i = 0; i < listSize; i++){
		if (score >= 90)
			sList[i].testScore = 'A';
		else if (score >= 80)
			sList[i].testScore = 'B';
		else if (score >= 70)
			sList[i].testScore = 'C';
		else if (score >= 60)
			sList[i].testScore = 'D';
		else
			sList[i].testScore = 'F';
	}
}

void printResult(ofstream& outfile, const studentType sList[], const int listSize)
{
	int i;
		outfile << setw(15) << "Student Name " << setw(10) << "Test Score" << setw(7) << "Grade" << endl;
		
		for (i = 1; i < listSize; i++)
			outfile << left << setw(25)
		 << sList[i].studentLname + ", " + sList[i].studentFname
		 << right << " " << setw(5) << sList[i].testScore
		 << setw(6) << " " << sList[i].grade << endl;
}
closed account (SECMoG1T)
1
2
3
getData(infile, sList[numstudents], numstudents); 
calculateGrade(sList[numstudents], numstudents); 	
printResult(outfile, sList[numstudents], numstudents); 


That's not how you pass an array argument.
These are your prototypes:
1
2
3
void getData(ifstream&,studentType, int);
void calculateGrade(studentType, const int);
void printResult(ofstream&, const studentType, const int);


These are your function you're actually trying to implement:
1
2
3
void getData(ifstream& infile, studentType sList[], int &listCount)
void calculateGrade(studentType sList[], const int listSize)
void printResult(ofstream& outfile, const studentType sList[], const int listSize)


studentType sList[] is not the same type as studentType.
One is an array (or rather a pointer to an array), the other is a single object of type studentType.

lines 40, 41, 42:
I assume you want to just be passing in sList, not sList[numStudents], sList[20] is out of bounds anyway.
Last edited on
Oh, okay, how do I just pass sList then? I tried sList and sList[] and both just give me another error.
You want to pass it like
1
2
3
	getData(infile, sList, numstudents);
	calculateGrade(sList, numstudents);
	printResult(outfile, sList, numstudents);

But you're still going to get errors because your function prototypes do not match your function definitions.

Change them to this
1
2
3
4
5
void getData(ifstream&,studentType[], int);

void calculateGrade(studentType[], const int);

void printResult(ofstream&, const studentType[], const int);
closed account (SECMoG1T)
Also the logic in this function calculateGrade is wrong, what is score? What is the type of member testscore?
"score" is supposed to be the number that is taken from the infile in the getData function as testScore. But the problem there is that I can't call getData to get testScore into calculateGrade without having to call an ifstream& and studentType as well.
closed account (SECMoG1T)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 void calculateGrae(studentType sList[], const int listSize)
 { 	
	for (int i = 0; i < listSize; i++)
         { 		
                 if (sList [i].testScore>= 90) 			
                           sList[i].grade= 'A'; 		
                 else if ( sList [i].testScore>= 80) 			
                           sList[i].grade = 'B'; 		
                 else if (sList [i].testScore>= 70) 			
                           sList[i].grade= 'C'; 		
                 else if ( sList [i].testScore>= 60) 			
                           sList[i].grade= 'D'; 		
                 else 			
                            sList[i].grade = 'F'; 	
           } 
}

I mean shouldn't it be like that, correct me if am wrong


Last edited on
Thanks! But I'm still getting the 3 unresolved external errors.

EDIT: It's actually only one.

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

using namespace std;

struct studentType {
	string studentFname;
	string studentLname;
	int testScore;
	char grade;
};

const int numstudents = 20;

void getData(ifstream&,studentType[], int);

void calculateGrade(studentType[], const int);

void printResult(ofstream&, const studentType[], const int);

int main() {

	ifstream infile;
	infile.open("names.txt");

	studentType sList[20];


	if (infile.fail())
	{
		cout << "Error: Cannot open input file. Exiting...";
		system("pause");
	}

	ofstream outfile;
	outfile.open("grades.txt");

	getData(infile, sList, numstudents);
	calculateGrade(sList, numstudents);
	printResult(outfile, sList, numstudents);

	infile.close();
	outfile.close();

	system("pause");
	return 0;
}

void getData(ifstream& infile, studentType sList[], int &listCount)
{
	while (!infile.eof())
	{
		for (int i = 0; i < listCount; i++)
			infile >> sList[i].studentFname >> sList[i].studentLname
			>> sList[i].testScore;
	}
}


void calculateGrade(studentType sList[], const int listSize)
{

	for (int i = 0; i < listSize; i++){
		if (sList[i].testScore >= 90)
			sList[i].testScore = 'A';
		else if (sList[i].testScore >= 80)
			sList[i].testScore = 'B';
		else if (sList[i].testScore >= 70)
			sList[i].testScore = 'C';
		else if (sList[i].testScore >= 60)
			sList[i].testScore = 'D';
		else
			sList[i].testScore = 'F';
	}
}

void printResult(ofstream& outfile, const studentType sList[], const int listSize)
{
	int i;
		outfile << setw(15) << "Student Name " << setw(10) << "Test Score" << setw(7) << "Grade" << endl;
		
		for (i = 1; i < listSize; i++)
			outfile << left << setw(25)
		 << sList[i].studentLname + ", " + sList[i].studentFname
		 << right << " " << setw(5) << sList[i].testScore
		 << setw(6) << " " << sList[i].grade << endl;
}
Last edited on
closed account (SECMoG1T)
1
2
void getData(ifstream&,studentType[], int);///doesn't take an int reference
void getData (ifstream& infile, studentType sList [], int& listCount);///takes an int reference 



Look at your function declaration/definition the differ slightly and that might cause the error.
1
2
void getData(ifstream&,studentType[], const int);
void getData(ifstream& infile, studentType sList[], const int listSize)


Yeah, it's running now. Appreciate the help!
Topic archived. No new replies allowed.