c++ class program having trouble

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
#include <iostream>
using namespace std;
int main()
{
    class Student {

      private:
	int Id;
	int FinalGrade;
	float Grade[4];


      public:
	 Student(const &Student x)	// Takes a parameter of Student, returns the current object (Copy Constructor)
	{
	} void setId(int x)	// Takes an integer parameter, returns nothing
	{
	    Id = x;
	}
	void setGrade(float y[])	// Takes a floating array parameter, assignment four elements of the input array to Grade[4], and returns nothing. 
	{
	    float y[] = grade[4];
	}

	operator ==()		// ‘==’ operator overloading of class Student, which compares if the FinalGrade of the current student is equal to the FinalGrade of another student. If yes, return true; otherwise, return false. 
    friend Teacher};
    class Teacher {
      private:
	int id;
	float salary;

      public:
	 calculateGrade(int FinalGrade)	// Takes an input parameter of class Student, set the grade of this student by the following formula: FinalGrade=Grade[0]+Grade[1]+Grade[2]+Grade[3]
	{
    FinalGrade = Grade[0] + Grade[1] + Grade[2] + Grade[3]}};

    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);

	Student w(x);
	Student v;
	v = y;

	Teacher z;
	z.calculateGrade(x);
	z.calculateGrade(y);

	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;

	system("pause");
	return 0;
    }

You should use friend to let class Teacher access private data members of class Student. In the main( ) routine, you should test both operator overloading and friend.


I need help trying to get my program to run. The main is correctly formatted but I am having trouble with my two classes, Teacher and Student. In particular I am having trouble with the copy constructor for Student and the operator overloading of class Student. Can anyone help me fix this program. The comments to the side of the each of the functions will tell you how they are supposed to be implemented. If you notice any other errors please tell me. Thanks
Topic archived. No new replies allowed.