class Student {
public:
int fetchAge();
int *fetchDaysInCourse();
string fetchEmail();
string fetchFirstName();
string fetchLastName();
string fetchStudentId();
Degree fetchDegreeType();
void mutateAge(int);
void mutateDaysInCourse(int[1]);
void mutateEmail(string);
void mutateFirstName(string);
void mutateLastName(string);
void mutateStudentId(string);
void mutateDegreeType(Degree);
virtual void print();
virtual Degree fetchDegreeProgram();
Student(int age, int daysInCourse[3], string studentId, string email, string firstName, string lastName, Degree degreeType);
~Student();
private:
int Age, DaysInCourse[1];
string Email, FirstName, LastName, StudentId;
Degree DegreeType;
};
using namespace std;
int main() {
cout << "Course Title: Scripting and Programming - Applications - C867 \n";
cout << "Language used: C++ \n";
cout << "Student ID: 467185 \n";
cout << "Written by: Gregory Young \n\n";
Roster classRoster;
const string studentData[] =
{
"A1,John,Smith,John1989@gm ail.com,20,30,35,40,SECURITY",
"A2,Suzan,Erickson,Erickson_1990@gmailcom,19,50,30,40,NETWORK",
"A3,Jack,Napoli,The_lawyer99yahoo.com,19,20,40,33,SOFTWARE",
"A4,Erin,Black,Erin.black@comcast.net,22,50,58,40,SECURITY",
"A5,Gregory,young,gyoun15@wgu.edu,29,30,20,33,40,SOFTWARE"
};
for (int i = 0; i < sizeof(studentData) / sizeof(studentData[i]); i++) {
cout << studentData[i] << endl;
string input = studentData[i];
istringstream ss(input);
string token;
string tempHolder[9];
int x = 0;
while (x < 9 && getline(ss, token, ',')) {
tempHolder[x] = token;
x += 1;
}
Degree studentDegree;
if (tempHolder[8] == "NETWORK") {
studentDegree = NETWORKING;
}
else if (tempHolder[8] == "SECURITY") {
studentDegree = SECURITY;
}
else if (tempHolder[8] == "SOFTWARE") {
studentDegree = SOFTWARE;
}
else {
studentDegree = NODEGREE;
}
classRoster.add(tempHolder[0], tempHolder[1], tempHolder[2], tempHolder[3], std::stoi(tempHolder[4]), std::stoi(tempHolder[5]), std::stoi(tempHolder[6]), std::stoi(tempHolder[7]), studentDegree);
}
classRoster.printAll();
cout << "\n";
classRoster.printInvalidEmails();
cout << "\n";
for (int i = 0; i < sizeof(classRoster.classRosterArray) / sizeof(classRoster.classRosterArray[i]); i++) {
classRoster.printDaysInCourse(classRoster.classRosterArray[i]->fetchStudentId());
}
cout << "\n";
classRoster.printByDegreeProgram(SOFTWARE);
cout << "\n";
classRoster.remove("A3");
classRoster.remove("A3");
return 0;
}
void Roster::add(string studentID, string firstName, string lastName, string email, int age, int daysInCourse1, int daysInCourse2, int daysInCourse3, Degree degreeProgram)
{
int courseDays[3] = { daysInCourse1, daysInCourse2, daysInCourse3 };
for (int i = 0; i < sizeof(classRosterArray) / sizeof(classRosterArray[i]); i++) {
if (classRosterArray[i] == nullptr) {
if (degreeProgram == NETWORKING) {
classRosterArray[i] = new NetworkStudent(age, courseDays, studentID, email, firstName, lastName, degreeProgram);
}
else if (degreeProgram == SECURITY) {
classRosterArray[i] = new SecurityStudent(age, courseDays, studentID, email, firstName, lastName, degreeProgram);
}
else if (degreeProgram == SOFTWARE) {
classRosterArray[i] = new SoftwareStudent(age, courseDays, studentID, email, firstName, lastName, degreeProgram);
}
else {
classRosterArray[i] = new Student(age, courseDays, studentID, email, firstName, lastName, degreeProgram);
}
break; }
}
}
void Roster::printAll()
{
for (int i = 0; i < sizeof(classRosterArray) / sizeof(classRosterArray[i]); i++) {
classRosterArray[i]->print();
}
}
void Roster::printByDegreeProgram(int degreeProgram)
{
for (int i = 0; i < sizeof(classRosterArray) / sizeof(classRosterArray[i]); i++) {
if (classRosterArray[i]->fetchDegreeProgram() == degreeProgram) {
classRosterArray[i]->print();
}
}
}
void Roster::printDaysInCourse(string studentID)
{
float avg = 0;
int max = 3;
for (int i = 0; i < sizeof(classRosterArray) / sizeof(classRosterArray[i]); i++) {
if (classRosterArray[i] != nullptr && classRosterArray[i]->fetchStudentId() == studentID) {
int *daysInCourse = classRosterArray[i]->fetchDaysInCourse();
for (int x = 0; x < max; x++) {
avg += daysInCourse[x];
}
cout << "Student " << classRosterArray[i]->fetchStudentId() << "'s average number of days in each course is." << (avg / max) << "\n";
break;
}
}
}
void Roster::printInvalidEmails()
{
for (int i = 0; i < sizeof(classRosterArray) / sizeof(classRosterArray[i]); i++) {
string email = classRosterArray[i]->fetchEmail();
bool isValid = false;
size_t found = email.find("@");
if (found != string::npos) {
found = email.find(".");
if (found != string::npos) {
found = email.find(" ");
if (found == string::npos) {
isValid = true;
}
}
}
if (!isValid) {
cout << email << " is not a valid email address \n";
}
}
}
void Roster::remove(string studentID)
{
bool studentRemoved = false;
for (int i = 0; i < sizeof(classRosterArray) / sizeof(classRosterArray[i]); i++) {
if (classRosterArray[i] != nullptr && classRosterArray[i]->fetchStudentId() == studentID) {
classRosterArray[i] = nullptr;
studentRemoved = true;
break;
}
}
if (studentRemoved == false) {
cout << "ERROR: Student ID '" << studentID << "' was not found.";
}
}
Roster::~Roster()
{
delete * classRosterArray;
}
string Student::fetchEmail()
{
return Email;
}
#include "Student.h"
int Student::fetchAge()
{
return Age;
}
int * Student::fetchDaysInCourse()
{
return DaysInCourse;
}
void Student::mutateEmail(string email)
{
Email = email;
}
string Student::fetchEmail()
{
return Email;
}
string Student::fetchFirstName()
{
return FirstName;
}
string Student::fetchLastName()
{
return LastName;
}
string Student::fetchStudentId()
{
return StudentId;
}
Degree Student::fetchDegreeType()
{
return Degree();
}
void Student::mutateAge(int age)
{
Age = age;
}
void Student::mutateDaysInCourse(int *daysInCourse)
{
for (int i = 0; i < 3; i++) {
DaysInCourse[i] = daysInCourse[i];
}
}
void Student::mutateFirstName(string firstName)
{
FirstName = firstName;
}
void Student::mutateLastName(string lastName)
{
LastName = lastName;
}
void Student::mutateStudentId(string studentId)
{
StudentId = studentId;
}
void Student::mutateDegreeType(Degree degreeType)
{
DegreeType = degreeType;
}
Student::Student(int age, int daysInCourse[3], string studentId, string Email, string firstName, string lastName, Degree degreeType)
{
mutateAge(age);
mutateStudentId(studentId);
mutateEmail(Email);
mutateFirstName(firstName);
mutateLastName(lastName);
mutateDegreeType(degreeType);
mutateDaysInCourse(daysInCourse);
mutateDegreeType(degreeType);
}
void Student::print()
{
int *daysInCourse = fetchDaysInCourse();
cout << fetchStudentId() << "\t";
cout << "First Name: " << fetchFirstName() << "\t";
cout << "Last Name: " << fetchLastName() << "\t";
cout << "Age: " << fetchAge() << "\t";
cout << "daysInCourse: " << daysInCourse[0] << "8" << daysInCourse[1] << "8" << daysInCourse[2] << "\t";
cout << "Degree Program: ";
switch (fetchDegreeProgram()) {
case 0: cout << "Security";
break;
case 1: cout << "Networking";
break;
case 2: cout << "Software";
break;
case 4: cout << "Unknown or Unspecified";
break;
}
}
Degree Student::fetchDegreeProgram()
{
return NODEGREE;
}
Student::~Student()
{
}
What I have tried:
I am getting a read access violation on the line Return Email; I have included the associated code from Student class as well. I am not really sure why it is running into a read access violation Email is apparently unable to read the characters from the string.