I'm getting an error for Segment fault 11. It will run through the printall()
command but seems to fail at the printInvalidEmail
command.
I can also input the other classes I have created. I have about 6 different classes and header files for the classes. I'm looking for where to start to troubleshoot this error.
/*
* roster.cpp
*
* Created on: Jan 9, 2019
* Author: kaylasiemon
*/
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include "student.h"
#include "securityStudent.h"
#include "networkStudent.h"
#include "softwareStudent.h"
#include "degree.h"
#include "roster.h"
using namespace std;
roster::roster() {
}
roster::~roster() {
}
void roster::add(string studentID, string firstName, string lastName, string emailAddress, int age, int daysInCourse1, int daysInCourse2, int daysInCourse3, degree d){
int courseDays[] = {daysInCourse1, daysInCourse2, daysInCourse3};
if (d == degree::SECURITY)
classRosterArray[iindex++] = new securityStudent(studentID, firstName, lastName, emailAddress, age, courseDays, d);
if (d == degree::SOFTWARE)
classRosterArray[iindex++] = new softwareStudent(studentID, firstName, lastName, emailAddress, age, courseDays, d);
if (d == degree::NETWORK)
classRosterArray[iindex++] = new networkStudent(studentID, firstName, lastName, emailAddress, age, courseDays, d);
}
void roster::remove(string studentID){
bool removeStudent = false;
for(int i = 0; i < 5; i++){
if (classRosterArray[i] != NULL) {
if(studentID == classRosterArray[i] ->getID()){
classRosterArray[i] = nullptr;
removeStudent = true;
}
}
}
if (removeStudent == false)
cout << "Student ID invalid. No one to remove";
}
void roster::printAll(){
cout << "Roster:" << endl;
for (int i = 1; i < 6; i++)
classRosterArray[i] -> print();
}
void roster::printByDegreeProgram(int degreeProgram){
cout << "Displaying Roster by Degree Type:" << endl;
degree deg1;
if (degreeProgram == 0)
deg1 = degree::SECURITY;
if (degreeProgram == 1)
deg1 = degree::NETWORK;
if (degreeProgram == 2)
deg1 = degree::SOFTWARE;
for (int i = 1; i < 6; i++){
if (deg1 == classRosterArray[i]->getDegreeProgram())
classRosterArray[i] -> print();
}
}
void roster::printDaysInCourse(string studentID){
int average;
for (int i = 1; i < 6; i++){
if (classRosterArray[i] ->getID() == studentID){
average = (classRosterArray[i]->getCourseDays()[0] + classRosterArray[i]->getCourseDays()[1] + classRosterArray[i]->getCourseDays()[2]) / 3;
cout << average << endl;
}
}
}
void roster::printInvalidEmails(){
cout << "invalid email addresses:" << endl;
for (int i = 0; i < 5; i++){
bool atSign = false;
bool space = false;
bool period = false;
string email;
email = classRosterArray[i] ->getemail();
for (char &letter:email){
if (letter == '@')
atSign = true;
if (letter == ' ')
space = true;
if (letter == '.')
period = true;
}
if (atSign == false || space == false || period == false)
cout << classRosterArray[i] ->getemail() << endl;
}
}
int main(){
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,Kayla,Siemon,ksiemon@wgu.edu,24,30,33,29,SOFTWARE"};
roster classRoster;
cout << "Scripting and Programming - Applications – C867" << endl << "Kayla Siemon" << endl <<"#000736769" << endl;
degree degreepath;
for (int i = 0; i < 5; i++){
stringstream studentlist(studentData[i]);
vector<string> results;
while(studentlist.good()){
string temp;
getline(studentlist, temp, ',');
results.push_back(temp);
}
if (results[8] == "SECURITY")
degreepath = degree::SECURITY;
if (results[8] == "NETWORK")
degreepath = degree::NETWORK;
if (results[8] == "SOFTWARE")
degreepath = degree::SOFTWARE;
classRoster.add(results[0], results[1], results[2], results[3], stoi(results[4]), stoi(results[5]), stoi(results[6]), stoi(results[7]), degreepath);
}
classRoster.printAll();
classRoster.printInvalidEmails();
classRoster.printDaysInCourse("A1");
classRoster.printByDegreeProgram(SOFTWARE);
classRoster.remove("A3");
classRoster.remove("A3");
return 0;
}