Errors for passed parameters for functions in struct/class

The confusion I'm having is the Main function calls, I added the prototypes to put it all in context...

No matter what I do, the compile keeps finding issues with these function calls...saying that the parameters being passed are undeclared identifiers.

1
2
3
Calc_GPA(Examgrade, Labgrade, CompStud);
LetterGrade(GPA, CompStud);
Display_File(Out_Data, CompStud);


Student is the struct tag creating a "type" (just like int or float) and CompStud[size] means there are 20 compsci students who have the members (listed in the struct def) of "type" Student...this is how I understand it...let me know if that's wrong??

I have moved them around and tried different things with both the functions and objects w/accessors but still getting errors.

I have also tried moving the Student CompStud[size]; around and put it both in and out of Main.

I'm not concerned about errors related to my pointer right now as priority is just to get the function calls so they'll work.

Thanks.

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

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

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

struct Student//declares struct type Student
	//default public members
{
	string Firstname, Middlename, Lastname;
	float GPA;//each student has 1 GPA
	char Lettergrade;
	//int Examgrade1, Examgrade2, Examgrade3;
	int Examgrade[3];
	//int Labgrade1, Labgrade2, Labgrade3, Labgrade4;
	int Labgrade[4];

};//<----YES I PUT SEMICOLON

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

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

//function declarations
void Initialize(Student s[]);
//function initializes all the elements to 0

void Read_Data(ifstream& In_Data, Student s[]);
//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 s[]);
//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 s[]);
//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(int Examgrade[], int Labgrade[], Student s[]);
//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 s[]);
//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 s[]);
//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

ifstream In_Data;
ofstream Out_Data;
float ClassAverage;

int main()
{
	CompStud *ptr;//declare pointer to student's GPA (s[i].GPA)

	//function calls begin
	Initialize(CompStud);
	Read_Data(In_Data, CompStud);
	Calc_GPA(Examgrade, Labgrade, CompStud);
	LetterGrade(GPA, CompStud);
	calc_ClassAverage(Examgrade, Labgrade, CompStud);
	Display_File(Out_Data, CompStud);
	Display_Screen(CompStud);
}
Last edited on
So CompStud is an array of 20 students, each having their own data members/grade arrays etc?

Leave off the struct on line 27. (Also check spelling Compstud vs. CompStud.)

Line 70 - not sure why you need a separate pointer? You can use the name of the CompStud array to pass into functions.

Lines 74 - 77 : Examgrade, Labgrade etc are members of the individual struct. You can't access them separately with just Examgrade, etc. The compiler doesn't know what they are outside the context of the struct. Each student in the array is going to have their own Examgrade array, e.g. CompStud[0].Examgrade[2], etc.

I'd send the functions the CompStud array and access the 20 students through that.
Thank you, as for this
"Lines 74 - 77 : Examgrade, Labgrade etc are members of the individual struct. You can't access them separately with just Examgrade, etc. The compiler doesn't know what they are outside the context of the struct. Each student in the array is going to have their own Examgrade array, e.g. CompStud[0].Examgrade[2], etc. "....... I got that concept but I changed s to Compstud to make it more obvious but I am still getting the function call errors like before, they seem to be referencing to this function -- the one that's supposed to calc each student's GPA...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
float 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);
	} return StudGPA;//student (element's) calculated GPA
}
float 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);
//tried to use Compstud[i].GPA = ((.60 * sum1) + (.40 * sum2) / 2); but it created errors
} return StudGPA;//student (element's) calculated GPA
}
Topic archived. No new replies allowed.