Create a templated class with the name Student that will act

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.

Solution

#ifndef STUDENT_H
#define STUDENT_H
#include <string>
#include <vector>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

class Student{
//declare private class members
private:
int ID;
std::string name;
std::vector<int> grades;

//define the public methods
public:
std::string getName()const{return name;}
int getID()const {return ID;}
void setName(std::string);
void setID(int);
void display();
void displayGrades();
int get_gpa();
~Student();
Student();
Student(int, double, std::string, std::string, Student*);
Student(int, double, std::string, std::string);
};

#endif // STUDENT_H

-----------------------------------------------------------------------------------------------------

#include \"Student.h\"
#include <string>
#include <vector>
#include <iostream>
#include <time.h>

using namespace std;

Student::Student() : grades(10)
{
ID = 0;
name = \"John Doe\";

for(int i=0; i<10; i++)
{
grades[i] = (rand()%100)+1;
}
}

Student::Student(int id, string Name, Student *nextStudent) : grades(10)
{
ID = id;
name = Name;

for(int i=0; i<10; i++)
{
grades[i] = (rand()%100)+1;
}
}

Student::Student(int id, string Name) : grades(10)
{
ID = id;
name = Name;
  
for(int i=0; i<10; i++)
{
grades[i] = (rand()%100)+1;
}
}

//set the Student Name
void Student::setName(string Name)
{
name = Name;
}

//set the Student Id
void Student::setID(int id)
{
ID = id;
}

//Display student Details
void Student::display()
{
cout<<\"ID: \"<<ID<<endl<<\"Name: \"<<name<<endl;
}

//calculate the Average GPA
int Student::get_gpa()
{
int total = 0;
for(int i = 0; i < 10; i++)
{
total += grades[i];
}
return total/10;
}

//Print the Grades
void Student::displayGrades()
{
for(int i = 0; i < 10; i++)
{
cout<<grades[i]<<endl;
}
}

Student::~Student()
{

}

--------------------------------------------------------------------------------------------------------

#include \"Student.h\"
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <time.h>
#include <algorithm>

using namespace std;

int main()
{
srand (time(NULL)); //Instantiate
   //input file stream object
ifstream studentData;
int idInput;
  
string nameInput;

vector<Student> studentVector;

   //Open the file students.txt which in the same directory of the program
studentData.open(\"students.txt\");
  
   //Incase there is no data
if(!studentData)
   {
       cout << \"Problem reading file.\";
       return 0;
   }
  
   //Read the students
for (int i = 0; i < 20; i++)
{
studentData >> idInput;
       getline(studentData, nameInput);
       studentVector.push_back(Student(idInput, nameInput);
}
cout<<\"This is the list of students:\"<<endl;
vector<Student>::iterator i;
cout<<\"Test\";
/*for(i=studentVector.begin(); i != studentVector.end(); ++i)
{
(*i).display();
cout<<\"Test Scores: \"<<endl;
(*i).displayGrades();
cout<<endl;
cout<<endl;
}*/
  
//print the students
vector<Student>::iterator j;
for(j=studentVector.begin(); j != studentVector.end(); ++j)
{
(*j).display();
cout<<\"Test Scores: \"<<endl;
//(*j).displayGrades();
cout<<endl;
cout<<endl;
}
studentData.close();
return 0;
}

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::st
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::st
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::st
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::st

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site