Create an application that can add/remove/display students, degree programs, courses in C++ using Visual Studio.
/*Michael Bean
Source file: main.cpp
Description:F.Demonstrate the program�s required functionality by adding a main() function in main.cpp,
which will contain the required function calls to achieve the following results.
Updated 3.27.2023*/
#include <iostream>
#include "student.h"
#include "roster.h"
#include "degree.h"
#include <string>
#include <array>
using namespace std;
int main()
{
/*My Student Information - Michael Bean*/
cout << "Course: C867 Scripting and Programming" << endl;
cout << "Programming Language Used: C++" << endl;
cout << "Name: Michael R. Bean" << endl;
cout << "SID: #001003284" << endl << endl;
/*Student Data*/
const string studentInfo[] =
{
"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,Michael,Bean,mbean19@wgu.edu,33,35,30,45,SOFTWARE"
};
/*Creating Class Roster*/
Roster* classRoster = new Roster(5);
/*Adding each index of student data to a new Student class obj*/
for (int i = 0; i < 5; ++i)
{
classRoster->add(studentInfo[i]);
};
/*Print Class Roster*/
classRoster->printAll();
/*Print Invalid Emails*/
classRoster->printInvalidEmails();
for (int i = 0; i < 5; ++i)
{
classRoster->printAverageDaysInCourse(classRoster->GetStudentID(i));
}
cout << endl;
/*Print students on Roster in the Software Program*/
classRoster->printByDegreeProgram(SOFTWARE);
cout << endl;
/*Remove student with Student ID = A3*/
classRoster->remove("A3");
cout << endl;
/*Print class roster*/
classRoster->printAll();
cout << endl;
/*Student ID does not exist error*/
classRoster->remove("A3");
cout << endl;
/*Destructor*/
classRoster->~Roster();
delete classRoster;
}
/*Michael Bean
Source file: roster.cpp
Description: E. Create a Roster class (roster.cpp)
Updated 3.15.2023*/
#include <iostream>
#include <string>
#include "degree.h"
#include "student.h"
#include "roster.h"
#include <array>
#include <string>
using namespace std;
/*Constructor*/
Roster::Roster(int classSize)
{
this->classSize = classSize;
this->index = 0;
for (int i = 0; i < classSize; ++i)
{
this->classRosterArray[i] = new Student;
}
return;
}
/*Get SID*/
string Roster::GetStudentID(int index)
{
string id = classRosterArray[index]->GetID();
return id;
}
/*Create new student*/
void Roster::add(string stdntInfo)
{
string id, fName, lName, emailAdd;
int yAge, courseDaysComplete1, courseDaysComplete2, courseDaysComplete3;
if (index < classSize)
{
classRosterArray[index] = new Student();
int i = stdntInfo.find(",");
id = stdntInfo.substr(0, i);
classRosterArray[index]->SetID(id);
int t = i + 1;
i = stdntInfo.find(",", t);
fName = stdntInfo.substr(t, i - t);
classRosterArray[index]->SetFirstName(fName);
t = i + 1;
i = stdntInfo.find(",", t);
lName = stdntInfo.substr(t, i - t);
classRosterArray[index]->SetLastName(lName);
t = i + 1;
i = stdntInfo.find(",", t);
emailAdd = stdntInfo.substr(t, i - t);
classRosterArray[index]->SetEmailAddr(emailAdd);
t = i + 1;
i = stdntInfo.find(",", t);
yAge = stoi(stdntInfo.substr(t, i - t));
classRosterArray[index]->SetAge(yAge);
t = i + 1;
i = stdntInfo.find(",", t);
courseDaysComplete1 = stoi(stdntInfo.substr(t, i - t));
t = i + 1;
i = stdntInfo.find(",", t);
courseDaysComplete2 = stoi(stdntInfo.substr(t, i - t));
t = i + 1;
i = stdntInfo.find(",", t);
courseDaysComplete3 = stoi(stdntInfo.substr(t, i - t));
classRosterArray[index]->SetDaysToComp(courseDaysComplete1, courseDaysComplete2, courseDaysComplete3);
/*Program type to string*/
t = i + 1;
i = stdntInfo.find(",", t);
string type = stdntInfo.substr(t, i - t);
if (type == "SECURITY")
{
classRosterArray[index]->SetDegreeProg(SECURITY);
}
else if (type == "NETWORK")
{
classRosterArray[index]->SetDegreeProg(NETWORK);
}
else if (type == "SOFTWARE")
{
classRosterArray[index]->SetDegreeProg(SOFTWARE);
}
else
{
cout << "UNDECIDED" << endl;
}
++index;
}
return;
}
/*Remove student*/
void Roster::remove(string id)
{
bool studentExists = false;
for (int i = 0; i < classSize; ++i)
{
if (classRosterArray[i] == nullptr)
{
continue;
}
else if (id == classRosterArray[i]->GetID())
{
classRosterArray[i] = nullptr;
studentExists = true;
break;
}
}
if (studentExists == false)
{
cout << "Student " << id << " Not Found. Please check your spelling or search another SID." << endl;
}
else if (studentExists == true)
{
cout << "Student " << id << " has been removed from the roster." << endl;
}
return;
}
/*Print roster*/
void Roster::printAll()
{
cout << "Student Rosters: " << endl;
for (int i = 0; i < classSize; ++i)
{
if (classRosterArray[i] == nullptr)
{
continue;
}
else
{
classRosterArray[i]->PrintAllStudentInfo();
}
}
cout << endl;
return;
}
/*Print average number of days for all 3 courses*/
void Roster::printAverageDaysInCourse(string id)
{
for (int i = 0; i < classSize; ++i)
{
if (id == classRosterArray[i]->GetID())
{
int localArray[3] = { classRosterArray[i]->GetDaysToComp1(), classRosterArray[i]->GetDaysToComp2(), classRosterArray[i]->GetDaysToComp3() };
double avgDays = (static_cast<double>(localArray[0]) + static_cast<double>(localArray[1]) + static_cast<double>(localArray[2])) / 3.0;
cout << id << " students AVG days In the courses: " << avgDays << endl;;
}
}
return;
}
/*Print invalid emails*/
void Roster::printInvalidEmails()
{
for (int i = 0; i < classSize; ++i)
{
string emailAdd = classRosterArray[i]->GetEmailAddr();
if ((emailAdd.find(' ') != string::npos) || (emailAdd.find('.') == string::npos) || (emailAdd.find('@') == string::npos))
{
cout << classRosterArray[i]->GetID() << " students email address " << emailAdd << " is either mispelled or invalid." << endl;
}
}
cout << endl;
return;
}
/*Print students enrolled in a specific program*/
void Roster::printByDegreeProgram(DegreeProgram degProg)
{
string degreeString;
if (degProg == SECURITY)
{
degreeString = "SECURITY";
}
else if (degProg == NETWORK)
{
degreeString = "NETWORK";
}
else if (degProg == SOFTWARE)
{
degreeString = "SOFTWARE";
}
else
{
degreeString = "!ERROR!";
}
cout << "Students in the program: " << degreeString << endl;
int numStudents = 0;
for (int i = 0; i < classSize; ++i)
{
if (classRosterArray[i]->GetDegreeProg() == degProg)
{
classRosterArray[i]->PrintAllStudentInfo();
++numStudents;
}
}
if (numStudents == 0)
{
cout << "No students currently enrolled in this program." << endl;
}
return;
}
/*Destructor*/
Roster::~Roster()
{
return;
}
/*Michael Bean
Source file: student.cpp
Description: E. Create a Roster class (roster.cpp)
Updated 3.15.2023*/
#include <iostream>
#include <string>
#include "degree.h"
using namespace std;
#include "student.h"
/*Constructor*/
Student::Student()
{
this->studentID = "";
this->firstName = "";
this->lastName = "";
this->emailAddress = "";
this->age = 0;
this->daysToComp[0] = 0;
this->daysToComp[1] = 0;
this->daysToComp[2] = 0;
this->degrProg;
}
/*Setters*/
void Student::SetID(string id)
{
this->studentID = id;
return;
}
void Student::SetFirstName(string fName)
{
this->firstName = fName;
return;
}
void Student::SetLastName(string lName)
{
this->lastName = lName;
return;
}
void Student::SetEmailAddr(string emailAdd)
{
this->emailAddress = emailAdd;
return;
}
void Student::SetAge(int yAge)
{
this->age = yAge;
return;
}
void Student::SetDaysToComp(int daysComplete1, int daysComplete2, int daysComplete3)
{
this->daysToComp[0] = daysComplete1;
this->daysToComp[1] = daysComplete2;
this->daysToComp[2] = daysComplete3;
return;
}
void Student::SetDegreeProg(DegreeProgram degProg)
{
this->degrProg = degProg;
return;
}
/*Getters*/
string Student::GetID()
{
return studentID;
}
string Student::GetFirstName()
{
return firstName;
}
string Student::GetLastName()
{
return lastName;
}
string Student::GetEmailAddr()
{
return emailAddress;
}
int Student::GetAge()
{
return age;
}
int Student::GetDaysToComp1()
{
return daysToComp[0];
}
int Student::GetDaysToComp2()
{
return daysToComp[1];
}
int Student::GetDaysToComp3()
{
return daysToComp[2];
}
DegreeProgram Student::GetDegreeProg()
{
return degrProg;
}
/*Print SID*/
void Student::PrintID()
{
cout << studentID;
return;
}
/*Print first name*/
void Student::PrintFirstName()
{
cout << firstName << endl;
return;
}
/*Print last name*/
void Student::PrintLastName()
{
cout << lastName << endl;
return;
}
/*Print email*/
void Student::PrintEmailAddr()
{
cout << emailAddress << endl;
return;
}
/*Print age*/
void Student::PrintAge()
{
cout << age << endl;
return;
}
/*Print days to complete each course*/
void Student::PrintDaysToComp()
{
cout << daysToComp[0] << ", " << daysToComp[1] << ", " << daysToComp[2] << endl;
return;
}
/*Print degree program*/
void Student::PrintDegreeProg()
{
string degreeString;
if (degrProg == SECURITY)
{
degreeString = "SECURITY";
}
else if (degrProg == NETWORK)
{
degreeString = "NETWORK";
}
else if (degrProg == SOFTWARE)
{
degreeString = "SOFTWARE";
}
else
{
degreeString = "!ERROR!";
}
cout << degreeString << endl;
return;
}
/*Print all student personal information*/
void Student::PrintAllStudentInfo()
{
string degreeString;
if (degrProg == SECURITY)
{
degreeString = "SECURITY";
}
else if (degrProg == NETWORK)
{
degreeString = "NETWORK";
}
else if (degrProg == SOFTWARE)
{
degreeString = "SOFTWARE";
}
else
{
degreeString = "!ERROR!";
}
cout << studentID << " First Name: " << firstName << " Last Name: " << lastName << " Age: " << age << " Days in Courses, Course 1: " << daysToComp[0] << ", Course 2: " << daysToComp[1]
<< ", Course 3: " << daysToComp[2] << " Degree Program: " << degreeString << "." << endl;
return;
}
/*Michael Bean
Header File: degree.h
Description: Define an enumerated data type DegreeProgram for the degree programs containing the data type values SECURITY, NETWORK, and SOFTWARE.
Updated 3.15.2023*/
#include <iostream>
#ifndef DEGREE_H
#define DEGREE_H
using namespace std;
/*create a new variable called DegreeProgram*/
enum DegreeProgram { SECURITY, NETWORK, SOFTWARE };
#endif
/*Michael Bean
Header File: roster.h
Updated 3.14.2023*/
#ifndef ROSTER_H
#define ROSTER_H
#include <iostream>
#include <string>
#include "degree.h"
#include <array>
using namespace std;
/*Roster class*/
class Roster
{
public:
Roster(int classSize);
string GetStudentID(int index);
void add(string studentInfo);
void remove(string sID);
void printAll();
void printAverageDaysInCourse(string sID);
void printInvalidEmails();
void printByDegreeProgram(DegreeProgram degProg);
~Roster();
int classSize;
int index;
private:
Student* classRosterArray[5];
};
#endif
/*Michael Bean
Header File: student.h
Updated 3.15.2023*/
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>
#include "degree.h"
using namespace std;
/*Student class*/
class Student
{
public:
Student();
/*setters*/
void SetID(string id);
void SetFirstName(string fName);
void SetLastName(string lName);
void SetEmailAddr(string emailAdd);
void SetAge(int yAge);
void SetDaysToComp(int daysComplete1, int daysComplete2, int daysComplete3);
void SetDegreeProg(DegreeProgram degProg);
/*getters*/
string GetID();
string GetFirstName();
string GetLastName();
string GetEmailAddr();
int GetAge();
int GetDaysToComp1();
int GetDaysToComp2();
int GetDaysToComp3();
DegreeProgram GetDegreeProg();
/*prints*/
void PrintID();
void PrintFirstName();
void PrintLastName();
void PrintEmailAddr();
void PrintAge();
void PrintDaysToComp();
void PrintDegreeProg();
void PrintAllStudentInfo();
private:
string studentID;
string firstName;
string lastName;
string emailAddress;
int age;
int daysToComp[3];
DegreeProgram degrProg;
};
#endif