In C++, create a templated class with the name “Student” that will act as a cont
ID: 3777378 • Letter: I
Question
In C++, create a templated class with the name “Student” that will act as a container adapter.
The class will have the following properties:
1. Student name: as std::string. (private)
2. Student ID number: as std::string. (private)
3. Student grades: as std::vector of the type T (the student class template type name) (private)
4. An iterator to traverse the student grades. (public)
The class will also have the following methods (None should be inline, but all methods should be declared inside the header file):
1. A set of constructors
2. A constructor that accepts a file path, reads the first line of the path and convert and parse it. Use the sample file data.txt from the assignment folder, it’s a comma separated string where the first value is the name, the second is the id, and the rest are grades. (This constructor will have a specialized version for int so that you can use stoi method, for generic types just read name and id).
3. begin(): returns an iterator that points to the first grade in the student grades.
4. end(): returns an iterator that points to the last grade in the student grades.
5. get_student_name(): a getter for student name data member.
6. set_student_name(): a setter for the student name data member.
7. get_student_id(): a getter for student id data member.
8. set_student_id(): a setter for the student id data member.
9. get_gpa(): this method will compute the average of the student grades and return a value of the type T (so it should be templated).
10. Specialized get_gpa() method for the type string: if the grade is string (“A”, “A-“, “B+”, “B“, “B-“, “C+”, “C”, “C-“, “D”), then a different calculation is required, so this method is required.
11. push_back(T): it accepts a value of the type T and insert it at the end of the student grades.
12. size(): to get the number of grades in the student grades.
13. Overload the operator [] to get a grade at a specific location.
14. Any other method that is required to make the class work with Source.cpp.
Use the file Source.cpp as your main source file. Don’t change anything in that file, your Student.h file is supposed to work with Source.cpp. Use only standard data structures and objects, no third-party libraries (Don’t use Boost or any similar libraries).
Below is Source.cpp:
data.txt:
Harry,999999,95,94,96
#include Kiostream> #include "Student. h #include Kvector using namespace std; template void display student (Student & const st) coutExplanation / Answer
#include "Student.h"
#include <iostream>
using namespace std;
Student :: Student()
{
ID = 0;
name = "";
GPA = 0;
gender = ' ';
}
Student :: Student(int ID, string name, double GPA, char gender)
{
this -> ID = ID;
this -> name = name;
this -> GPA = GPA;
this -> gender = gender;
}
void Student :: setStudent(int ID, string name, double GPA, char gender)
{
this -> ID = ID;
this -> name = name;
this -> GPA = GPA;
this -> gender = gender;
}
int Student :: getID()
{
return ID;
}
string Student :: getName()
{
return name;
}
double Student :: getGPA()
{
return GPA;
}
char Student :: getGender()
{
return gender;
}
void Student :: print()
{
cout << "ID : " << ID << endl;
cout << "Name : " << name << endl;
cout << "GPA : " << GPA << endl;
cout << "Gender : " << gender << endl;
}