Having some trouble with converting my driver input from one class to the friend class and then summing the array. My setGrade function is reading the input correctly (I think, the numbers match up) but I need to pass the class to the friend in order to add up the values. Herein lies the aggravation. The errors I've been getting are that Grade is an undeclared identifier, or that I can't make the conversion from the setGrade variable to something I can work with in the other class. I'll also need to use the '==' operator eventually but I'd rather get to that after I deal with the previous mess. That said however, I'd appreciate any advice anyone could give me. Thanks in advance. Here's the code:
[LIST=1]
[*]#include<iostream>
[*]using namespace std;
[*]const int MAX_GRADES = 4;
[*]class Student;
[*]class Student
[*]{
[*] private:
[*] int Id;
[*] float FinalGrade;
[*] float Grade[MAX_GRADES];
[*] public:
[*] void setId(int i){Id = i;};
[*] void setGrade(float G[])
[*] {
[*] for (int i=0;i<MAX_GRADES;i++)
[*] cout << G[i]<< endl;
[*] };
[*] // bool operator == (Student x,y){if x.FinalGrade == y.FinalGrade return true; else return false;};
[*] friend class Teacher;
[*]};
[*]class Teacher
[*]{
[*]private:
[*] int Id;
[*] float Salary;
[*]public:
[*] float calculateGrade(Student G[])
[*] {
[*] float FinalGrade = 0;
[*] Grade[0] = G[0];
[*] Grade[1] = G[1];
[*] Grade[2] = G[2];
[*] Grade[3] = G[3];
[*]
[*] FinalGrade = Grade[0] + Grade[1] + Grade[2] + Grade[3];
[*] return FinalGrade;
[*] };
[*]
[*]
[*]};
[*]int main()
[*]{
[*]float g1[] = {10.0, 20.0, 25.0, 25.0};
[*]float g2[] = {25.0, 20.0, 10.0, 25.0};
[*]Student x, y;
[*]x.setGrade(g1);
[*]y.setGrade(g2);
[*]Teacher z;
[*]cout << z.calculateGrade(x) << endl;
[*]//cout << z.calculateGrade(y) << endl;
[*]//if(x==y)
[*]//cout << " Students x and y have the same grade !" << endl;
[*]//else
[*]//cout << " Students x and y don’t have the same grade !" << endl;
[*]return 0;
[*]}
[/LIST]