# Project2Q1 - Student calculateGrade(Student a/takes an...

This preview shows pages 1–2. Sign up to view the full content.

#include<iostream> #include<string> #include<fstream> using namespace std; u class Student { private: int Id; //the identification # of the student int FinalGrade; //the overall grade of the student [0,100] float Grade[4]; //four different test grades, each of which ranges from 0.0 to 25.0 public: void setId(int x) //takes an integer paramter, returns nothing { Id = x; }; void setGrade(float x[4]) //takes a floating array parameter and assigns four elements { //of the input array to Grade[4], and returns nothing for(int count=0;count<4;count++) Grade[count] = x[count]; }; bool operator==(Student x) const //'==' operator overloading of class Student, which { //compares if the FinalGrade of the current student is if (FinalGrade == x.FinalGrade) //equal to the FinalGrade of another student. If yes, return true; //true is returned. Otherwise, false is returned. else return false; } friend class Teacher; //makes class Teacher a friend of class Student }; } class Teacher { private: int Id; //the identification # of the student float Salary; //annual salary public:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Student calculateGrade(Student a) //takes an input parameter of class Student and sets the { //grade of this student with the given formula a.FinalGrade = a.Grade[0] + a.Grade[1] + a.Grade[2] + a.Grade[3]; return a; }; }; } int main( ) { float g1 = {10.0, 20.0, 25.0, 25.0}; //initializes the 1st set of grades float g2 = {25.0, 20.0, 10.0, 25.0}; //initializes the 2nd set of grades / Student x, y; //creates two instances of class Student / x.setGrade(g1); //sets the grades for Student x y.setGrade(g2); //sets the grades for Student y / Teacher z; //creates an instance of class Teacher / x = z.calculateGrade(x); //calculates FinalGrade for Student x y = z.calculateGrade(y); //calculates FinalGrade for Student y / if(x==y) //compares whether or not x and y are equal, outputting appropriately cout << " Students x and y have the same grade !" << endl; else cout << " Students x and y don't have the same grade !" << endl; c system("pause"); return 0; r }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Project2Q1 - Student calculateGrade(Student a/takes an...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online