Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can't figure out how to fix this error. Thanks for anyone's help


C#
#include <iostream>
using namespace std;

class Student

{
    public: Student();
            Student (int, int, int, int);
            double quizAverage();
            double finalGrade();
            void displayGrade()const;

    private: int id;
             int quiz1;
             int quiz2;
             int finalExam;

};

Student::Student()
{
    id= 0;
    quiz1= 40;
    quiz2= 40;
    finalExam= 40;

}

Student::Student(int ID ,int QUIZ1 ,int QUIZ2,int FINAL)
{
    id= ID;
    quiz1= QUIZ1;
    quiz2= QUIZ2;
    finalExam= FINAL;
}

double Student::quizAverage()
{
    double average;
    average = (quiz1 + quiz2)/2;
    return average;

}

double Student::finalGrade()
{
    double finalgr;
    finalgr = (quizAverage() + finalExam)/2;
    return finalgr;

}

void Student::displayGrade()const
{
    cout<<"The student's ID is:\t"<<id<<endl;
    cout<<"The final grade is:\t"<<finalGrade()<<endl;

}
Posted
Updated 27-Jun-10 6:21am
v2

You already have an answer to this question from emilio, and this is just a tip for you.

If you have your code in a .h and .cpp file, which is impossible to see here, don\'t put a using statement in your header file. Remember that the statement will be included in all files including your header, and that can be annoying.

Also, a good idea is to keep the names of the formal parameters in the declaration (your second constructor) since this is the part of your class that is exposed to others. Users should not have to read the implementation to understand how to use a method.
 
Share this answer
 
<code>dispalyGrade is const, but finalGrade is not.
A const function cannot invoke non-const functions.

Since all the function in the sinppet are "accessor" (they don't need to modify the class members) let all be const.
 
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