Find the percentage of male and female students with classes, pointers, and a vector

  c++

I’ve introduced a student class with the data members of string name, char gender, and double gpa.
The class looks like this:

class Student {
public:
    Student();
    Student(string name, char gender, double gpa);
    void setName(string name);
    void setGender(char gender);
    void setGpa(double gpa);
    string getName();
    char getGender();
    double getGpa();
private:
    string name;
    char gender;
    double gpa;
};

I have another class Department

class Department {
public:
    Department();
    Department(string department_name);
    void setDepartment(string department_name);
    string getDepartment();
    void claimMajor(Student*);
    void demography_by_gender();
private:
    vector<Student*> majors;
    string department_name;
};

This is my int main

int main(int argc, const char* argv[]) {
Student* mike = new Student("Mike", 'M', 1.9);
Student* alexa = new Student("Alexa", 'F', 2.2);
Student* brook = new Student("Brook", 'F', 3.9);
Student* sam = new Student("Sam", 'F', 2.1);
Student* kevin = new Student("Kevin", 'M', 0.7);
Student* john = new Student("John", 'M', 2.5);
Student* jen = new Student("Jen", 'F', 1.8);
Department* csci = new Department("CSCI");
csci->claimMajor(mike);
csci->claimMajor(alexa);
csci->claimMajor(brook);
csci->claimMajor(sam);
csci->claimMajor(kevin);
csci->claimMajor(john);
csci->claimMajor(jen);
csci->demography_by_gender();

return 0;
}

The vector stores all the Student pointers, but I’m having trouble figuring out how to compute the percentage of male and female students using demography_by_gender(), then printing out the results.

Source: Windows Questions C++

LEAVE A COMMENT