Question: Header #include #include #include using namespace std; enum Gender { MALE, FEMALE }; class Student{ private: long id; // Unique ID string name; // Name
Header
#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() const {return id;}
string getName() const {return name;}
Gender getGender() const {return gender;}
double getGPA() const {return gpa;}
string getCourseCode() const {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
};
Cpp file
#include "Student.h"
using namespace std;
/*
* EXERCISE: #1A
*
* IMPLEMENT USING AN ENHANCED FOR LOOP (ForEach).
*
* Returns the highest GPA value possessed by any Student in the given list.
*
*/
double Student::maxStudentGPA(vector
{
//YOUR CODE HERE
return -99.9; //DUMMY RETURN
}
/*
* EXERCISE: #1B
*
* IMPLEMENT USING A REGULAR FOR LOOP.
*
* Returns the lowest GPA value possessed by any Student in the given list.
*
*/
double Student::minStudentGPA(vector
{
//YOUR CODE HERE
return -99.9; //DUMMY RETURN
}
/*
* Exercise #1C
*
* 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 #2
*
* IMPLEMENT IT USING AN ENHANCED FOR LOOP (ForEach)
*
* Given a course code, you must return a vector that contains
* only the unique ID of the Students that have that particular course code.
*/
vector
vector
//YOUR CODE HERE
return result;
}
/*
* EXERCISE #3
*
* 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
//YOU CODE HERE
return v;
}
/*
* EXERCISE: #4
*
* 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
//YOUR CODE HERE
}
/*
* EXERCISE #5
*
* DO NOT USE WHILE LOOPS
*
* Find the Student record that matches the given Student
* and update its data. If the Student is not present, add it to the list.
*
* Remember that each Student has an unique identifier
*/
void Student::updateStudent(vector
//YOUR CODE HERE
}
/*
* BONUS
*
* IMPLEMENT WITH NESTED LOOPS USING ANY LOOP.
*
* Returns a vector cointaining two Students that has the same name.
* If there is no repeated names, the vector stays empty.
*
* HINT: Use the compare method of the string library
*/
vector
//YOUR CODE HERE
return v;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
