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
string result = "{";
for (Student s : v) {
result += toString(s) + ",";
}
result += "}";
return result;
}
static string toString(vector
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
static double minStudentGPA(vector
static double averageGPA(vector
static vector
static void removeByID(vector
static void updateStudent(vector
static vector
static vector
};
/********************************************************************************************************************************************************************************************************/
//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
{
//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
{
//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
//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
vector
//YOUR CODE HERE
return result;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
