Click here to Skip to main content
15,749,288 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
I am new to this community and new to the programming also. I have been tasked with the program and my problem is that I don't know the operator overloading. So, anyone can help me ?

Develop a Student class that has the following header file:
#ifndef STUDENT_H
#define STUDENT_H
using namespace std;
class Student{
Student(string name,string surname,int a1, int a2, int test, int exam);
string getName()const;
string getSurname()const;
int getAssignment1Mark()const;
int getAssignment2Mark()const;
int getLabTestMark()const;
int getExamMark()const;
void setAssignment1Mark(int);
void setAssignment2Mark(int);
void setLabTestMark(int);
void setExamMark(int);
bool passed()const;
string getGrade()const;
friend ostream& operator<<(ostream& stream, const Student &);
bool operator<(const Student &)const;
string name;
string surname;
int assignment1Mark;
int assignment2Mark;
int labTestMark;
int examMark;

implement the class, i.e. to develop the implementation file “Student.cpp” that conforms to the following specifications:
(1) The data fields have self explanatory identifiers, and their meaning should be clear from the Introduction.
(2) The “set” functions allow the user to set the assessment task marks within the specified margins, e.g. setExamMark ensures that the examMark is in the appropriate range – from 0 to 50.
(3) The function getGrade() returns the student’s grade, calculated as specified in the Introduction. The rest of the “get” functions simply return the values of the corresponding fields.
(4) The function passed() returns true if this student , has passed the course, and returns false otherwise (see the Introduction).
(5) friend ostream& operator<<(ostream& stream, const Student &) – the function overloads << operator, which allows a Student object information to be output in the following format:
Underwood Scott:
Assignment 1 8
Assignment 2 16
Lab Test 0
Exam 34
Grade P

(6) bool operator<(const Student &student)const – the function overloads < operator, which allows to compare student’s full names lexicographically.

Collapse | Copy Code
The following describes how to calculate the marks and grade:
Lab Test Mark – is an integer from 0 to 10;
Assignment1 Mark – is an integer from 0 to 20;
Assignment2 Mark – is an integer from 0 to 20;
Final exam Mark – is an integer from 0 to 50;

A student passes the course if and only if
(Assignment1 Mark + Assignment2 Mark) >= 20 and (Lab Test Mark + Final Exam Mark) >= 30

Collapse | Copy Code
There are 5 grades, which are calculated according to the following rules:
F – if the Total Mark is less then 40;
MF – if (40 <= Total Mark < 50) or (Total Mark >= 50 but student didn’t pass);
P – if (50 <= Total Mark < 60) and student passed;
C – if (60 <= Total Mark < 70) and student passed;
D – if (70 <= Total Mark < 80) and student passed;
HD – if Total Mark >= 80;
H.Brydon 31-May-13 1:33am    
Ummm... homework - we don't do that here.
[no name] 31-May-13 2:02am    
Why did you choose programming as a subject?
SumitLamba 31-May-13 2:31am    
Because I want to learn C++ programming. I am struggling with this code from a week that's why I posted it here.
AlphaDeltaTheta 31-May-13 2:05am    
Hmmm... I don't have time to do your homework code!
SumitLamba 31-May-13 2:32am    
Thank you very much for your reply. I will try to implement your logic.

1 solution

I don't like doing other's homework but still... Since I had such problems while I was learning C++ back in school days so...

Implement the operator as you do to a simple method
bool operator<(const Student &student)
    bool ret = false;
    //do check whether greater or less and store it in ret
    return ret;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900