SkinnyFatBoy
SkinnyFatBoy

Reputation: 1

Multiple data used in some functions

I have a problem with a function, i want to generate the average admission to a facultacy. I don't know how to create the function average(), i think that i can do it like this:

int display(int note1_ex1, int note2_ex1, ...., int note_bac)
{
sum_ex1 = note1_ex1 + note2_ex1 + note3_ex1;
sum_ex2 = note1_ex2 + note2_ex2 + note_ex2;
avg1 = sum_ex1/sum_ex1.size();
avg2 = sum_ex2/sum_ex2.size();

average = note_bac + ((avg1 + avg2)*0.75)/3;
return average;

}

Each exam is examined by 3 teachers, each teacher gives a grade, and the average of these three grades is the final grade for that exam.

My question is how can i create that average function on the last lane of my code ? Average must be made like this: grade_bac*0.25 (that's the high school final exam baccalaureate grade) and the averege of the two exams. My code is this:

class Student {
private:
    std::string name;
    int birth_day;
    int birth_month;
    int birth_year;
    int note_bac;
    int note1_ex1;
    int note2_ex1;
    int note3_ex1;
    int note1_ex2;
    int note2_ex2;
    int note3_ex2;
    int average;

public:
    Student(std::string name, int birth_day, int birth_month, int birth_year, int note_bac, int note1_ex1,int note2_ex1,
            int note3_ex1, int note1_ex2, int note2_ex2, int note3_ex2, int average);
    Student(const Student &source);
    ~Student();

    void set_name(std::string name)
    {
        this->name = name;
    }

    std::string get_name() const
    {
        return name;
    }

    void set_birth_day(int birth_day)
    {
        this->birth_day = birth_day;
    }

    int get_birth_day() const
    {
        return birth_day;
    }

    void set_birth_month(int birth_month)
    {
        this->birth_month = birth_month;
    }

    int get_birth_month() const
    {
        return birth_month;
    }

    void set_birth_year(int birth_year)
    {
        this->birth_year = birth_year;
    }

    int get_birth_year() const
    {
        return birth_year;
    }

    void set_note_bac(int note_bac)
    {
        this->note_bac = note_bac;
    }

    int get_note_bac() const
    {
        return note_bac;
    }

    void set_note1_ex1(int note1_ex1)
    {
        this->note1_ex1 = note1_ex1;
    }

    int get_note1_ex1() const
    {
        return note1_ex1;
    }

    void set_note2_ex1(int note2_ex1)
    {
        this->note2_ex1 = note2_ex1;
    }

    int get_note2_ex1() const
    {
        return note2_ex1;
    }

    void set_note3_ex1(int note3_ex1)
    {
        this->note3_ex1 = note3_ex1;
    }

    int get_note3_ex1() const
    {
        return note3_ex1;
    }

    void set_note1_ex2(int note1_ex2)
    {
        this->note1_ex2 = note1_ex2;
    }

    int get_note1_ex2() const
    {
        return note1_ex2;
    }

    void set_note2_ex2(int note2_ex2)
    {
        this->note2_ex2 = note2_ex2;
    }

    int get_note2_ex2() const
    {
        return note2_ex2;
    }

    void set_note3_ex2(int note3_ex2)
    {
        this->note3_ex2 = note3_ex2;
    }

    int get_note3_ex2() const
    {
        return note3_ex2;
    }

    int average


};

Upvotes: 0

Views: 51

Answers (1)

Austin Jiang
Austin Jiang

Reputation: 31

Add this function to the last line of your code. which is the place you haven't finish,

int average

int average()
{
    int sum_ex1 = note1_ex1 + note2_ex1 + note3_ex1;
    int sum_ex2 = note1_ex2 + note2_ex2 + note3_ex2;
    double avg1 = sum_ex1/3.0;
    double avg2 = sum_ex2/3.0;

    double average = 0.25*note_bac + ((avg1 + avg2)/2)*0.75;
    return (int)average;
}

Upvotes: 1

Related Questions