Question: C++ Loops exercise (please answer as fast as possible) //Student.h #include #include #include using namespace std; enum Gender{ MALE, FEMALE }; class Student{ private: long

C++ Loops exercise (please answer as fast as possible)

//Student.h

#include

#include

#include

using namespace std;

enum Gender{

MALE,

FEMALE

};

class Student{

private:

long id; // Unique ID

string name; // Name of student

Gender gender; // Gender of student

string courseCode; // Course code (CIIC or ICOM)

double gpa; // GPA of student

public:

Student(long id, const string &name, Gender gender, double gpa){

this->id = id;

this->name = name;

this->gender = gender;

this->courseCode = "";

this->gpa = gpa;

}

Student(long id, const string &name, Gender gender, string courseCode, double gpa){

this->id = id;

this->name = name;

this->gender = gender;

this->courseCode = courseCode;

this->gpa = gpa;

}

Student(){}

static string toString(Student& s){

string genderLetter = (s.gender == MALE ? "M" : "F");

return string("{" + to_string(s.id) + "," + s.name + "," + genderLetter + "," + to_string(s.gpa) + "}");

}

static string toString(vector& v){

string result = "{";

for (Student s : v) {

result += toString(s) + ",";

}

result += "}";

return result;

}

static string toString(vector& v){

string result = "{";

for (long id : v) {

result += to_string(id) + ",";

}

result += "}";

return result;

}

// Getters

long getID(){return id;}

string getName(){return name;}

Gender getGender(){return gender;}

double getGPA(){return gpa;}

string getCourseCode(){return courseCode;}

//Setters

void setName(string name){this->name = name;}

void setGender(Gender gender){this->gender = gender;}

void setGPA(double gpa){this->gpa = gpa;}

void setCourseCode(string code){this->courseCode = code;}

// EXERCISES

static double maxStudentGPA(vector& v);

static double minStudentGPA(vector& v);

static double averageGPA(vector &v, int N);

static vector countStudents(vector& v, string code);

static void removeByID(vector &v, long ID);

static void updateStudent(vector &v, Student s);

static vector findStudents(vector& v, float gpa);

static vector repeatedStudentNames(vector& v); //BONUS

};

/********************************************************************************************************************************************************************************************************/

//Student.cpp

#include "Student.h"

using namespace std;

/*

* EXERCISE: #2A

*

* IMPLEMENT USING AN ENHANCED FOR LOOP (ForEach).

*

* Returns the value of the Student's GPA

* that has the maximum GPA on the list

*

*/

double Student::maxStudentGPA(vector& v)

{

//YOUR CODE HERE

return -99.9; //DUMMY RETURN

}

/*

* EXERCISE: #2B

*

* IMPLEMENT USING A REGULAR FOR LOOP.

*

* Returns the value of the Student's GPA

* that has the minimum GPA of the list

*

*/

double Student::minStudentGPA(vector& v)

{

//YOUR CODE HERE

return -99.9; //DUMMY RETURN

}

/*

* Exercise #2C

*

* IMPLEMENT USING A WHILE LOOP

*

* For the first N students, calculate the average gpa

*

* Formula: average = sum / N

* Assume N is greater than 0

*/

double Student::averageGPA(vector &v, int N){

//YOUR CODE HERE

return -99.9; //DUMMY RETURN

}

/*

* EXERCISE #3

*

* IMPLEMENT IT USING AN ENHANCED FOR LOOP (ForEach)

*

* Given the course code (CIIC or ICOM), you must return a vector

* that contains ONLY the unique ID of the Students that have on record

* a that course code.

*/

vector Student::countStudents(vector& v, string code){

vector result;

//YOUR CODE HERE

return result;

}

/*

* EXERCISE #4

*

* IMPLEMENT USING A DO...WHILE LOOP

*

* Return a vector that contains all the Students that have a GPA greater

* or equal to the GPA passed as the parameter

*

* Assume the list contains at least one element

*/

vector Student::findStudents(vector& v, float gpa){

//YOU CODE HERE

return v;

}

/*

* EXERCISE: #5

*

* IMPLEMENT WITH ANY LOOP

*

* Removes the first occurrence of the specified Student ID,

* if it is present. If not present, then list is unchanged.

*

* HINT: Verify the methods erase() and begin() of the vector

*/

void Student::removeByID(vector &v, long ID){

//YOUR CODE HERE

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!