Skip to content

Instantly share code, notes, and snippets.

@Kijimu7
Last active April 26, 2020 00:40
Show Gist options
  • Select an option

  • Save Kijimu7/e12778157e7ebca60f66f263abe6370e to your computer and use it in GitHub Desktop.

Select an option

Save Kijimu7/e12778157e7ebca60f66f263abe6370e to your computer and use it in GitHub Desktop.
#pragma once
#include<iostream>
#include<iomanip>
#include<string>
using std::string;
//enumurated data type data type values
enum DegreeProgram {UNDECIDED, SECURITY, NETWORK, SOFTWARE};
static const std::string degreeProgramString[] = {"UNDECIDED", "SECURITY", "NETWORK", "SOFTWARE" };
#include <iostream>
#include <string>
#include "roster.h"
#include <sstream>
using std::cout;
using std::endl;
using std::string;
using namespace std;
int main()
{
cout << "SCRIPTING AND PROGRAMMING APPLICATION C867\n";
cout << "C++\n";
const int numStudents = 6;
static string studentData[numStudents] =
{
"A1,John,Smith,[email protected],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,[email protected],22,50,58,40,SECURITY",
"A5,D,S,[email protected],31,25,34,31,SOFTWARE"
};
Roster* rep = new Roster(numStudents);
cout << "Parsing data and adding students:\t";
for (int i= 0; i < numStudents; i++)
{
rep->parseAdd(studentData[i]);
}
cout << "DONE.\n";
cout << "Displaying all students:\n";
rep->print_All();
cout << "Removing A1:\n";
if (rep->remove("A1")) rep->print_All();
else cout << "Book not found!\n";
cout << "Removing A1:\n";
if (rep->remove("A1")) rep->print_All();
else cout << "Book not found!\n";
rep->printAverageDaysInCourse("A3");
rep->printInvailidDaysEntries();
rep->printByDegreeProgram(SECURITY);
rep->printByDegreeProgram(NETWORK);
rep->printByDegreeProgram(SOFTWARE);
system("pause");
return 0;
}
#include "roster.h"
#include "degree.h"
#include<string>
using std::string;
//empty constructor
Roster::Roster()
{
this->capacity = 0;
this->lastIndex = -1;//Empty
this->classRosterArray = nullptr;
}
Roster::Roster(int capacity)
{
this->capacity = capacity;
this->lastIndex = -1;
this->classRosterArray = new Student * [capacity];
}
void Roster::parseAdd(string row)
{
if (lastIndex < capacity) {
lastIndex++;
DegreeProgram degree;
if (row[0] == '1') degree = SECURITY;
else if (row[0] == '2')degree = NETWORK;
else if (row[0] == '3')degree = SOFTWARE;
else if (row[0] == '4')degree = SECURITY;
else if (row[0] == '5')degree = SOFTWARE;
else {
cerr << "invalid";
exit(-1);
}
/* }
this->classRosterArray[lastIndex] = new Student();
classRosterArray[lastIndex]->setDegreeProgram(SECURITY);
}
else if (row[0] == 'A2') {
this->classRosterArray[lastIndex] = new Student();
classRosterArray[lastIndex]->setDegreeProgram(NETWORK);
}
else if (row[0] == 'A3') {
this->classRosterArray[lastIndex] = new Student();
classRosterArray[lastIndex]->setDegreeProgram(SOFTWARE);
}
else if (row[0] == 'A4') {
this->classRosterArray[lastIndex] = new Student();
classRosterArray[lastIndex]->setDegreeProgram(SECURITY);
}
else if (row[0] == 'A5') {
this->classRosterArray[lastIndex] = new Student();
classRosterArray[lastIndex]->setDegreeProgram(SOFTWARE);
}
else {
cerr << "invaild degree type! exiting now! \n";
exit(-1);*/
int rhs = row.find(",");
string studentID = row.substr(0, rhs);
int lhs = rhs + 1;
rhs = row.find(",", lhs);
string firstName = row.substr(lhs, rhs - lhs);
////ID
//int rhs = studentData[lastIndex].find(",");
//classRosterArray[lastIndex]->setID(studentData[lastIndex].substr(0, rhs));
////read firstname
//int lhs = rhs + 1;
//rhs = studentData[lastIndex].find(",", lhs);
//classRosterArray[lastIndex]->setFirstname(studentData[lastIndex].substr(lhs, rhs - lhs));
////read lastname
//lhs = rhs + 1;
//rhs = studentData[lastIndex].find(",", lhs);
//classRosterArray[lastIndex]->setLastname(studentData[lastIndex].substr(lhs, rhs - lhs));
////read Email
//lhs = rhs + 1;
//rhs = studentData[lastIndex].find(",", lhs);
//classRosterArray[lastIndex]->setEmail(studentData[lastIndex].substr(lhs, rhs - lhs));
////read Age
//lhs = rhs + 1;
//rhs = studentData[lastIndex].find(",", lhs);
//classRosterArray[lastIndex]->setAge(studentData[lastIndex].substr(lhs, rhs - lhs));
////read days in course
//lhs = rhs + 1;
//rhs = studentData[lastIndex].find(",", lhs);
//studentData[lastIndex].substr(lhs, rhs - lhs));
//lhs = rhs + 1;
//rhs = studentData[lastIndex].find(",", lhs);
//studentData[lastIndex].substr(lhs, rhs - lhs));
//lhs = rhs + 1;
//rhs = studentData[lastIndex].find(",", lhs);
//studentData[lastIndex].substr(lhs, rhs - lhs));
// //set the days
//this->days = new double[daysArray];
// classRosterArray[lastIndex]->setDays(daysArray);
}
else{
cerr << "Error! List has exceeded maximum capacity! \n exiting now!";
exit(-1);
}
}
void Roster::add(string studentID, string firstName, string lastName, string emailAddress, int age,
int daysInCourse1, int daysInCourse2, int daysInCourse3, DegreeProgram degreeprogram)
{
double daysOfArray[Student::daysArray];
daysOfArray[0] = daysInCourse1;
daysOfArray[1] = daysInCourse2;
daysOfArray[2] = daysInCourse3;
if (degreeprogram == SECURITY)
classRosterArray[lastIndex] = new Student(studentID, firstName, lastName, emailAddress, age, daysOfArray, degreeprogram);
else if (degreeprogram == NETWORK)
classRosterArray[lastIndex] = new Student(studentID, firstName, lastName, emailAddress, age, daysOfArray, degreeprogram);
else classRosterArray[lastIndex] = new Student(studentID, firstName, lastName, emailAddress, age, daysOfArray, degreeprogram);
}
void Roster::print_All()
{
for (
int i = 0; i <= this->lastIndex; i++)(this->classRosterArray)[i]->print();
}
bool Roster::remove(string ID)
{
bool found = false;
for (int i = 0; i <= lastIndex; i++)
{
if (this->classRosterArray[i]->getID() == ID)
{
found = true;
delete this->classRosterArray[i];
this->classRosterArray[i] = this->classRosterArray[lastIndex];
lastIndex--;
}
}
return found;
}
void Roster::printAverageDaysInCourse(string studentID)
{
bool found = false;
for (int i = 0; i <= lastIndex; i++)
{
if (this->classRosterArray[i]->getID() == studentID)
{
found = true;
double* p = classRosterArray[i]->getDays();
cout << "Average days in course " << classRosterArray << "is" << (p[0] + p[1] + p[2]) / 3;
}
if (!found)cout << "Book not found!\n";
}
}
void Roster::printInvailidDaysEntries()
{
cout << "Displaying invaild days entries:\n";
for (int i = 0; i <= lastIndex; i++)
{
cout << "Student ID: " << classRosterArray[i]->getID() << ":";
bool any = false;
double* p = classRosterArray[i]->getDays();
for (int j = 0; j < Student::daysArray; j++)
{
if (p[j] < 0)
{
any = true;
cout << p[j] << " ";
}
}
if (!any) cout << "NONE";
cout << "\n";
}
}
void Roster::printByDegreeProgram( DegreeProgram d)
{
cout << "Printing degree of type" << degreeProgramString[d] << '\n';
for (int i = 0; i <= lastIndex; i++) {
if (this->classRosterArray[i]->getDegreeProgram() == d) this->classRosterArray[i]->print();
}
}
#pragma once
#include<string>
#include<iostream>
#include "student.h"
using namespace std;
// creat student table
const int numStudents = 6;
static string studentData[numStudents] =
{
"A1,John,Smith,[email protected],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,[email protected],22,50,58,40,SECURITY",
"A5,D,S,[email protected],31,25,34,31,SOFTWARE"
};
//E. Create a Roster class
class Roster {
public:
//E.3 Add void add fucntion
void add(string studentID, string firstName, string lastName, string emailAddress, int age,
int daysInCourse1, int daysInCourse2, int daysInCourse3, DegreeProgram degreeprogram);
int lastIndex;
int capacity;
Student** classRosterArray;
void parseAdd(string row);
void print_All();
bool remove(string studentID);
void printAverageDaysInCourse(string studentID);
void printByDegreeProgram(DegreeProgram d);
void printInvailidDaysEntires();
Roster();
Roster(int capacity);
~Roster();
};
#include <iostream>
#include<iomanip>
#include"student.h"
#include "degree.h"
using std::string;
using std::cout;
using std::left;
using std::setw;
using std::cerr;
using namespace std;
Student::Student() //Empty constructor
{
this->studentID = "";
this->firstName = "";
this->lastName = "";
this->Email = "";
this->age = "";
this->days = new double[daysArray];
for (int i = 0; i < daysArray; i++) this->days[i] = 0;
this->dtype = DegreeProgram::UNDECIDED;
}
//full constructor
Student::Student(string ID, string firstName, string lastName, string email, int Age, double days[], DegreeProgram type)
{
this->studentID = ID;
this->firstName = firstName;
this->lastName = lastName;
this->Email = email;
this->age = Age;
this->days = new double[daysArray];
for (int i = 0; i < 3; i++) this->days[i] = days[i];
this->dtype = type;
}
//getters
string Student::getID()
{
return studentID;
}
string Student::getFirstname()
{
return firstName;
}
string Student::getLastname()
{
return lastName;
}
string Student::getEmail()
{
return Email;
}
string Student::getAge()
{
return age;
}
double* Student::getDays()
{
return days;
}
DegreeProgram Student::getDegreeProgram()
{
return dtype;
}
//Setters
void Student::setID(string ID)
{
studentID = ID;
}
void Student::setFirstname(string firstname)
{
this->firstName = firstName;
}
void Student::setLastname(string lastname)
{
this->lastName = lastName;
}
void Student::setEmail(string email)
{
this->Email = Email;
}
void Student::setAge(string age)
{
this->age = age;
}
void Student::setDays(double days[])
{
for (int i = 0; i < 3; i++) this->days[i] = days[i];
}
void Student::setDegreeProgram(DegreeProgram d)
{
this->dtype = d;
}
void Student::print()
{
cout << left << setw(10) << studentID;
cout << left << setw(10) << firstName;
cout << left << setw(10) << lastName;
cout << left << setw(30) << Email;
cout << left << setw(5) << age;
cout << left << setw(10) << days[0];
cout << left << setw(10) << days[1];
cout << left << setw(10) << days[2];
cout << left << setw(10) << degreeProgramString[getDegreeProgram()];
}
Student::~Student()
{
if (days != nullptr) {
delete[] days;
days = nullptr;
}
}
#pragma once
#include <string>
#include<iostream>
#include "degree.h"
using std::string;
class Student
{
//D1. create variables
private:
string studentID;
string firstName;
string lastName;
string Email;
string age;
double* days;
DegreeProgram dtype;
public:
const static int daysArray = 3;
Student(); // empty constructor
Student(string ID, string firstName, string lastName, string email, int Age, double days[], DegreeProgram type);
//full constractor
Student(string ID, string firstName, string lastName, string email, string age, double days[], DegreeProgram type);
//create function getter
string getID();
string getFirstname();
string getLastname();
string getEmail();
string getAge();
double* getDays();
DegreeProgram getDegreeProgram();
//create setter
void setID(string StudentID);
void setFirstname(string firstname);
void setLastname(string lastname);
void setEmail(string email);
void setAge(string age);
void setDays(double days[]);
void setDegreeProgram(DegreeProgram d);
void print();
// destructor
~Student();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment