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.

Revisions

  1. Kijimu7 revised this gist Apr 26, 2020. 2 changed files with 80 additions and 41 deletions.
    17 changes: 16 additions & 1 deletion main.cpp
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@
    #include <sstream>



    using std::cout;
    using std::endl;
    using std::string;
    @@ -14,9 +15,23 @@ 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++)
    @@ -41,7 +56,7 @@ int main()

    rep->printAverageDaysInCourse("A3");

    rep->printInvailidDaysEntires();
    rep->printInvailidDaysEntries();

    rep->printByDegreeProgram(SECURITY);
    rep->printByDegreeProgram(NETWORK);
    104 changes: 64 additions & 40 deletions roster.cpp
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #include "roster.h"
    #include "degree.h"
    #include<string>

    using std::string;


    @@ -28,74 +29,97 @@ void Roster::parseAdd(string row)

    if (lastIndex < capacity) {
    lastIndex++;
    double darray[Student::daysArray];
    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);

    }
    /* }
    if (row[0] == 'A') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SECURITY);
    }
    else if (row[0] == 'A1') {
    else if (row[0] == 'A2') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(NETWORK);
    }
    else if (row[0] == 'A2') {
    else if (row[0] == 'A3') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SOFTWARE);
    }
    else if (row[0] == 'A3') {
    else if (row[0] == 'A4') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SECURITY);
    }
    else if (row[0] == 'A4') {
    else if (row[0] == 'A5') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SOFTWARE);
    }
    else {
    cerr << "invaild degree type! exiting now! \n";
    exit(-1);
    }
    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));
    ////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 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 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 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 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);
    darray[0] = stod(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);
    darray[1] = stod(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);
    darray[2] = stod(studentData[lastIndex].substr(lhs, rhs - lhs));
    //lhs = rhs + 1;
    //rhs = studentData[lastIndex].find(",", lhs);
    //studentData[lastIndex].substr(lhs, rhs - lhs));

    //set the days
    classRosterArray[lastIndex]->setDays(darray);
    // //set the days
    //this->days = new double[daysArray];
    // classRosterArray[lastIndex]->setDays(daysArray);

    }

    @@ -168,7 +192,7 @@ void Roster::printAverageDaysInCourse(string studentID)
    }
    }

    void Roster::printInvailidDaysEntires()
    void Roster::printInvailidDaysEntries()
    {
    cout << "Displaying invaild days entries:\n";
    for (int i = 0; i <= lastIndex; i++)
  2. Kijimu7 revised this gist Apr 25, 2020. 4 changed files with 246 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions degree.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #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" };
    45 changes: 45 additions & 0 deletions roster.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #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();

    };

    132 changes: 132 additions & 0 deletions student.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,132 @@
    #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;
    }
    }
    56 changes: 56 additions & 0 deletions student.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #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();

    };
  3. Kijimu7 revised this gist Apr 25, 2020. 1 changed file with 52 additions and 0 deletions.
    52 changes: 52 additions & 0 deletions main.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #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";

    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->printInvailidDaysEntires();

    rep->printByDegreeProgram(SECURITY);
    rep->printByDegreeProgram(NETWORK);
    rep->printByDegreeProgram(SOFTWARE);

    system("pause");
    return 0;
    }
  4. Kijimu7 created this gist Apr 25, 2020.
    224 changes: 224 additions & 0 deletions roster.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,224 @@
    #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++;
    double darray[Student::daysArray];

    if (row[0] == 'A') {

    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SECURITY);
    }
    else if (row[0] == 'A1') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(NETWORK);
    }
    else if (row[0] == 'A2') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SOFTWARE);
    }
    else if (row[0] == 'A3') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SECURITY);

    }
    else if (row[0] == 'A4') {
    this->classRosterArray[lastIndex] = new Student();
    classRosterArray[lastIndex]->setDegreeProgram(SOFTWARE);
    }
    else {
    cerr << "invaild degree type! exiting now! \n";
    exit(-1);
    }

    //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);
    darray[0] = stod(studentData[lastIndex].substr(lhs, rhs - lhs));

    lhs = rhs + 1;
    rhs = studentData[lastIndex].find(",", lhs);
    darray[1] = stod(studentData[lastIndex].substr(lhs, rhs - lhs));

    lhs = rhs + 1;
    rhs = studentData[lastIndex].find(",", lhs);
    darray[2] = stod(studentData[lastIndex].substr(lhs, rhs - lhs));

    //set the days
    classRosterArray[lastIndex]->setDays(darray);

    }

    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::printInvailidDaysEntires()
    {
    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();

    }


    }