diff --git a/.cproject b/.cproject index b672d91..de1db8d 100644 --- a/.cproject +++ b/.cproject @@ -5,14 +5,14 @@ - + - + @@ -25,7 +25,7 @@ - + + + + + + \ No newline at end of file diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 56952ee..4eb981b 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index c12b93b..39984cf 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -1,3 +1,8 @@ +doxygen/doxygen_new_line_after_brief=true +doxygen/doxygen_use_brief_tag=false +doxygen/doxygen_use_javadoc_tags=true +doxygen/doxygen_use_pre_tag=false +doxygen/doxygen_use_structural_commands=false eclipse.preferences.version=1 org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.cdt.core.formatter.alignment_for_assignment=16 diff --git a/Debug/myCode/main.o b/Debug/myCode/main.o deleted file mode 100644 index ab1f9b2..0000000 Binary files a/Debug/myCode/main.o and /dev/null differ diff --git a/Debug/studentDB.exe b/Debug/studentDB.exe deleted file mode 100644 index 18d2c71..0000000 Binary files a/Debug/studentDB.exe and /dev/null differ diff --git a/local_json_fetch.py b/local_json_fetch.py new file mode 100644 index 0000000..fdcaa4f --- /dev/null +++ b/local_json_fetch.py @@ -0,0 +1,65 @@ +from flask import Flask, jsonify +from faker import Faker +import random +import datetime + +app = Flask(__name__) +fake = Faker() + +def safe_fake_date(start_year=1971, end_year=2015): + while True: + dt = fake.date_time_between(start_date='-80y', end_date='-10y') + if dt.year >= start_year: + return dt + +@app.route('/generate', methods=['GET']) +def generate_user(): + dob = safe_fake_date() + reg = fake.date_time_between(start_date='-10y', end_date='now') + + user_data = { + "cell": fake.phone_number(), + "dateOfBirth": { + "date": dob.day, + "day": dob.weekday(), + "hours": dob.hour, + "minutes": dob.minute, + "month": dob.month - 1, + "seconds": dob.second, + "time": int(dob.timestamp() * 1000), + "timezoneOffset": -60, + "year": dob.year - 1900 + }, + "email": fake.email(), + "gender": random.choice(["male", "female"]), + "location": { + "city": fake.city().lower(), + "postCode": fake.postcode(), + "state": fake.state().lower(), + "street": fake.street_address() + }, + "name": { + "firstName": fake.first_name().lower(), + "lastName": fake.last_name().lower(), + "title": fake.prefix() + }, + "nationality": fake.country_code(), + "phone": fake.phone_number(), + "picture": "...", + "registrationDate": { + "date": reg.day, + "day": reg.weekday(), + "hours": reg.hour, + "minutes": reg.minute, + "month": reg.month - 1, + "seconds": reg.second, + "time": int(reg.timestamp() * 1000), + "timezoneOffset": -60, + "year": reg.year - 1900 + } + } + + return jsonify(user_data) + +if __name__ == '__main__': + app.run(port=4242) diff --git a/myCode/Address.cpp b/myCode/Address.cpp new file mode 100644 index 0000000..7927f33 --- /dev/null +++ b/myCode/Address.cpp @@ -0,0 +1,65 @@ +#include "Address.h" +#include +#include +#include + +using namespace std; + +Address::Address() +{ +} + +Address::Address(std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo) +{ + this->street = street; + this->postalCode = postalCode; + this->cityName = cityName; + this->additionalInfo = additionalInfo; +} + +Address::~Address() +{ +} + +const std::string& Address::getAdditionalInfo() const +{ + return additionalInfo; +} + +const std::string& Address::getCityName() const +{ + return cityName; +} + +unsigned short Address::getPostalCode() const +{ + return postalCode; +} + +const std::string& Address::getStreet() const +{ + return street; +} + +void Address::write(std::ostream &out) const +{ + out << street << ';' << postalCode << ';' << cityName << ';' << additionalInfo << "\n"; +} + +void Address::read(std::istream &in) +{ + string line; + + getline(in, street, ';'); + getline(in, line, ';'); + postalCode = static_cast(stoi(line)); // Convert string to unsigned short + getline(in, cityName, ';'); + if (in.peek() == '\n') { + additionalInfo = ""; // Explicitly set to empty + } + else + { + getline(in, additionalInfo); + } + +} diff --git a/myCode/Address.h b/myCode/Address.h new file mode 100644 index 0000000..bfa87b8 --- /dev/null +++ b/myCode/Address.h @@ -0,0 +1,33 @@ +#ifndef ADRESS_H +#define ADRESS_H + +#include + +class Address +{ + +private: + + std::string street; + unsigned short postalCode; + std::string cityName; + std::string additionalInfo; + +public: + + Address(); + Address(std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo); + ~Address(); + + const std::string& getAdditionalInfo() const; + const std::string& getCityName() const; + unsigned short getPostalCode() const; + const std::string& getStreet() const; + + void write(std::ostream& out) const; //write attributes to os stream + void read(std::istream& in); + + +}; + +#endif diff --git a/myCode/BlockCourse.cpp b/myCode/BlockCourse.cpp new file mode 100644 index 0000000..a6ff7d8 --- /dev/null +++ b/myCode/BlockCourse.cpp @@ -0,0 +1,132 @@ +#include "BlockCourse.h" +#include +#include +#include + +using namespace std; + +BlockCourse::BlockCourse() +{ +} + +BlockCourse::BlockCourse(unsigned int courseKey, std::string title, std::string major, float creditPoints) +: Course(courseKey,title,major,creditPoints) {} + +BlockCourse::~BlockCourse() +{ +} + +const Poco::Data::Time& BlockCourse::getStartTime() const +{ + return startTime; +} + +const Poco::Data::Time& BlockCourse::getEndTime() const +{ + return endTime; +} + +const Poco::Data::Date& BlockCourse::getStartDate() const +{ + return startDate; +} + +const Poco::Data::Date& BlockCourse::getEndDate() const +{ + return endDate; +} + +void BlockCourse::setStartTime(const Poco::Data::Time &startTime) +{ + this->startTime = startTime; +} + +void BlockCourse::setEndTime(const Poco::Data::Time &endTime) +{ + this->endTime = endTime; +} + +void BlockCourse::setStartDate(const Poco::Data::Date &startDate) +{ + this->startDate = startDate; +} + +void BlockCourse::setEndDate(const Poco::Data::Date &endDate) +{ + this->endDate = endDate; +} + +void BlockCourse::write(std::ostream &out) const +{ + out << "B;"; + + Course::write(out); + + out << startDate.day() << '.' << startDate.month() << '.' << startDate.year() << ';'; + out << endDate.day() << '.' << endDate.month() << '.' << endDate.year() << ';'; + out << startTime.hour() << '.' << startTime.minute() << '.' << startTime.second(); + out << endTime.hour() << '.' << endTime.minute() << '.' << endTime.second()<< "\n"; +} + +void BlockCourse::read(std::istream &in) +{ + string line; + string startTimeStr, endTimeStr, startDateStr, endDateStr; + int day, month, year; + int startHour, startMinute, startSecond, endHour, endMinute, endSecond; + + Course::read(in); + + getline(in, startDateStr, ';'); + istringstream dateStreamStart(startDateStr); + getline(dateStreamStart, line, '.'); + + day = stoi(line); + getline(dateStreamStart, line, '.'); + + month = stoi(line); + getline(dateStreamStart, line, '.'); + + year = stoi(line); + startDate = Poco::Data::Date(year, month, day); + + getline(in, endDateStr, ';'); + istringstream dateStreamEnd(endDateStr); + getline(dateStreamEnd, line, '.'); + + day = stoi(line); + getline(dateStreamEnd, line, '.'); + + month = stoi(line); + getline(dateStreamEnd, line, '.'); + + year = stoi(line); + endDate = Poco::Data::Date(year, month, day); + + getline(in, startTimeStr, ';'); + istringstream timeStreamStart(startTimeStr); + getline(timeStreamStart, line, '.'); + + startHour = stoi(line); + getline(timeStreamStart, line, '.'); + + startMinute = stoi(line); + getline(timeStreamStart, line, '.'); + + startSecond = stoi(line); + startTime = Poco::Data::Time(startHour, startMinute, startSecond); + + getline(in, endTimeStr, ';'); + istringstream timeStreamEnd(endTimeStr); + getline(timeStreamEnd, line, '.'); + + endHour = stoi(line); + getline(timeStreamEnd, line, '.'); + + endMinute = stoi(line); + getline(timeStreamEnd, line, '.'); + + endSecond = stoi(line); + endTime = Poco::Data::Time(endHour, endMinute, endSecond); + +} diff --git a/myCode/BlockCourse.h b/myCode/BlockCourse.h new file mode 100644 index 0000000..4fc2575 --- /dev/null +++ b/myCode/BlockCourse.h @@ -0,0 +1,39 @@ +#ifndef BLOCKCOURSE_H +#define BLOCKCOURSE_H + +#include +#include + +#include "Course.h" + +class BlockCourse : public Course +{ + +private: + + Poco::Data::Date startDate; + Poco::Data::Date endDate; + Poco::Data::Time startTime; + Poco::Data::Time endTime; + +public: + + BlockCourse(); + BlockCourse(unsigned int courseKey, std::string title, std::string major, float creditPoints); + ~BlockCourse(); + + const Poco::Data::Time& getStartTime() const; + const Poco::Data::Time& getEndTime() const; + const Poco::Data::Date& getStartDate() const; + const Poco::Data::Date& getEndDate() const; + + void setStartTime(const Poco::Data::Time &startTime); + void setEndTime(const Poco::Data::Time &endTime); + void setStartDate(const Poco::Data::Date &startDate); + void setEndDate(const Poco::Data::Date &endDate); + + void write(std::ostream& out) const; //write attributes to os stream + void read(std::istream& in); +}; + +#endif diff --git a/myCode/CAddress.cpp b/myCode/CAddress.cpp deleted file mode 100644 index 23b8ea8..0000000 --- a/myCode/CAddress.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * CAddress.cpp - * - * Created on: 20 Jan 2022 - * Author: Mateo C. Querol - */ - -#include "CAddress.h" - -/* - * CAddress constructor - */ -CAddress::CAddress(std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo) -{ - this->street = street; - this->postalCode = postalCode; - this->cityName = cityName; - this->additionalInfo = additionalInfo; -} - -/* - * CAddress destructor - */ -CAddress::~CAddress() -{ - -} - -/* - * returns additional info - */ -const std::string& CAddress::getAdditionalInfo() const -{ - return this->additionalInfo; -} - -/* - * returns city name - */ -const std::string& CAddress::getCityName() const -{ - return this->cityName; -} - -/* - * returns postal code - */ -unsigned short CAddress::getPostalCode() const -{ - return this->postalCode; -} - -/* - * returns street - */ -const std::string& CAddress::getStreet() const -{ - return this->street; -} diff --git a/myCode/CAddress.h b/myCode/CAddress.h deleted file mode 100644 index c4f37f9..0000000 --- a/myCode/CAddress.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef CADRESS_H -#define CADRESS_H - -#include - -class CAddress { -private: - - /* - * street string - */ - std::string street; - - /* - * postal code unsigned short - */ - unsigned short postalCode; - - /* - * city name string - */ - std::string cityName; - - /* - * additional info string - */ - std::string additionalInfo; - -public: - - /* - * this is the constructor for the CAddress class - */ - CAddress(std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo); - - /* - * virtual destructor - */ - virtual ~CAddress(); - - /* - * getter functions for the class members - */ - const std::string& getAdditionalInfo() const; - const std::string& getCityName() const; - unsigned short getPostalCode() const; - const std::string& getStreet() const; -}; -#endif /* CADRESS_H */ diff --git a/myCode/CBlockCourse.cpp b/myCode/CBlockCourse.cpp deleted file mode 100644 index ee96e47..0000000 --- a/myCode/CBlockCourse.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "CBlockCourse.h" - -/* - * CBlockCourse constructor - * inherits from the CCourse class - */ -CBlockCourse::CBlockCourse(unsigned int courseKey, std::string title, unsigned char major, float creditPoints) -: CCourse(courseKey,title,major,creditPoints) -{ - this->courseKey = courseKey; - this->title = title; - this->major = major; - this->creditPoints = creditPoints; -} - -/* - * Empty destructor - */ -CBlockCourse::~CBlockCourse() -{ - -} - -/* - * CBlockCourse constructor - * inherits from the CCourse class - */ - -const Poco::Data::Time& CBlockCourse::getStartTime() const -{ - return startTime; -} - -const Poco::Data::Time& CBlockCourse::getEndTime() const -{ - return endTime; -} - -const Poco::Data::Date& CBlockCourse::getStartDate() const -{ - return startDate; -} - -const Poco::Data::Date& CBlockCourse::getEndDate() const -{ - return endDate; -} - -void CBlockCourse::setStartTime(const Poco::Data::Time &startTime) -{ - this->startTime = startTime; -} - -void CBlockCourse::setEndTime(const Poco::Data::Time &endTime) -{ - this->endTime = endTime; -} - -void CBlockCourse::setStartDate(const Poco::Data::Date &startDate) -{ - this->startDate = startDate; -} - -void CBlockCourse::setEndDate(const Poco::Data::Date &endDate) -{ - this->endDate = endDate; -} diff --git a/myCode/CBlockCourse.h b/myCode/CBlockCourse.h deleted file mode 100644 index 4a99958..0000000 --- a/myCode/CBlockCourse.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef CBLOCKCOURSE_H -#define CBLOCKCOURSE_H -#include "CCourse.h" - -#include -#include -#include - -class CBlockCourse : public CCourse { -private: - - /* - * start and end time/date for the CBlockCourse - * these are POCO time and date objects - */ - Poco::Data::Time startTime; - Poco::Data::Time endTime; - Poco::Data::Date startDate; - Poco::Data::Date endDate; -public: - - /* - * CBlockCourse constructor - * inherits from the CCourse class - */ - CBlockCourse(unsigned int courseKey, std::string title, unsigned char major, float creditPoints); - - /* - * Empty destructor - */ - ~CBlockCourse(); - - /* - * getter and setter functions for the class members - */ - const Poco::Data::Time& getStartTime() const; - const Poco::Data::Time& getEndTime() const; - const Poco::Data::Date& getStartDate() const; - const Poco::Data::Date& getEndDate() const; - - void setStartTime(const Poco::Data::Time &startTime); - void setEndTime(const Poco::Data::Time &endTime); - void setStartDate(const Poco::Data::Date &startDate); - void setEndDate(const Poco::Data::Date &endDate); - -}; -#endif /* CBLOCKCOURSE_H */ diff --git a/myCode/CCourse.cpp b/myCode/CCourse.cpp deleted file mode 100644 index f96dce1..0000000 --- a/myCode/CCourse.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "CCourse.h" - -using namespace std; -/* - * course class constructor - */ -CCourse::CCourse(unsigned int courseKey, std::string title, unsigned char major, float creditPoints) -{ - this->courseKey = courseKey; - this->title = title; - this->major = major; - this->creditPoints = creditPoints; - -// this->majorById.insert({'A', "Automation"}); -// this->majorById.insert({'C', "Communications"}); -// this->majorById.insert({'E', "Embedded"}); -// this->majorById.insert({'P', "Power"}); - -} - -CCourse::~CCourse() -{ - -} - -unsigned int CCourse::getCourseKey() const -{ - return this->courseKey; -} - -const std::string& CCourse::getTitle() const -{ - return this->title; -} - -unsigned char CCourse::getMajor() const -{ - return this->major; -} - -float CCourse::getCreditPoints() const -{ - return this->creditPoints; -} - - diff --git a/myCode/CCourse.h b/myCode/CCourse.h deleted file mode 100644 index 06baa80..0000000 --- a/myCode/CCourse.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef CCOURSE_H -#define CCOURSE_H - -#include -#include -#include - -class CCourse { -protected: - - /* - * static map to keep track of major by char/string - * as well as course info - */ - //static std::map majorById; - unsigned int courseKey; - std::string title; - unsigned char major; - float creditPoints; - -public: - /* - * course class contains default constructor and constructor with parameters - * and virtual destructor because it is the parent class - */ - CCourse(); - CCourse(unsigned int courseKey, std::string title, unsigned char major, float creditPoints); - virtual ~CCourse() = 0; - - unsigned int getCourseKey() const; - const std::string& getTitle() const; - unsigned char getMajor() const; - float getCreditPoints() const; - - -}; - -#endif /* CCOURSE_H */ diff --git a/myCode/CEnrollment.cpp b/myCode/CEnrollment.cpp deleted file mode 100644 index 739ebbb..0000000 --- a/myCode/CEnrollment.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "CEnrollment.h" - -CEnrollment::CEnrollment(std::string semester, CCourse *course) : course{course} -{ - this->grade = -1; //can be changed later - this->semester = semester; -} - -float CEnrollment::getGrade() const -{ - return this->grade; -} - -std::string CEnrollment::getSemester() const -{ - return this->semester; -} - -const CCourse* CEnrollment::getCourse() const -{ - return this->course; -} - -void CEnrollment::setGrade(float grade) -{ - this->grade = grade; -} diff --git a/myCode/CEnrollment.h b/myCode/CEnrollment.h deleted file mode 100644 index 85a8574..0000000 --- a/myCode/CEnrollment.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef CENROLLMENT_H -#define CENROLLMENT_H - -#include "CCourse.h" -#include - -class CEnrollment { -private: - float grade; - std::string semester; - /** - * @link aggregation - */ - const CCourse* course; -public: - CEnrollment(std::string semester, CCourse* course); - - float getGrade() const; - std::string getSemester()const ; - const CCourse* getCourse() const; - - void setGrade(float grade); -}; - -#endif /* CENROLLMENT_H */ diff --git a/myCode/CSimpleUI.cpp b/myCode/CSimpleUI.cpp deleted file mode 100644 index 74c3c76..0000000 --- a/myCode/CSimpleUI.cpp +++ /dev/null @@ -1,237 +0,0 @@ -#include -#include - -#include "CSimpleUI.h" -#include "CBlockCourse.h" -#include "CWeeklyCourse.h" - -#include -#include -#include -#include -#include -#include - -using namespace std; - -/* - * constructor for the simple UI - * takes in a studentDB object and is passed by reference - */ -CSimpleUI::CSimpleUI(CStudentDb& db) : db{db} -{ - this->course = 0; - //this->student = 0; -} - -/* - * this is the main method that contains everything - * the user chooses an option out of the menu then - * a switch statement is called, each option has a certain functionality - * - * after the swtich statement, the data is added into a csv file which - * when the program is executed can be generated in the project directory - * - * finally, test data is obtained from mnl.de:4242 and parsed into a json file - * format - */ -void CSimpleUI::run() -{ - int choice; - - cout << "Select an option:" << endl; - cout << "1. Add new course" << endl; - cout << "2. List courses" << endl; - cout << "3. Add new student" << endl; - cout << "4. Add enrollment" << endl; - cout << "5. Print students" << endl; - cout << "6. Search student" << endl; - cout << "7. Update student" << endl; - cout << "or type 0 to terminate" << endl; - - while(1) - { - cin >> choice; - if(choice == 0) - { - return; - } - else - { - switch(choice) - { - case 1: - cout << "1. Add new course" << endl; - - unsigned int courseKey; - //string title; - unsigned char major; - float creditPoints; - int dayOfWeek; - int startHour, startMinute, startSecond; - int endHour, endMinute, endSecond; - - cout << "Enter Course key: "; - cin >> courseKey; -// cout << "Enter Module title: "; -// cin >> title; - cout << "Enter Major (char): "; - cin >> major; - cout << "Enter Credit points: "; - cin >> creditPoints; - cout << "Enter day of the week (0-6): "; - cin >> dayOfWeek; - cout << "Enter start time (h:m:s:): "; - cin >> startHour >> startMinute >> startSecond; - cout << "Enter end time (h:m:s:): "; - cin >> endHour >> endMinute >> endSecond; - - - this->course = new CWeeklyCourse(courseKey,"",major,creditPoints); - this->course->setDayOfWeek((Poco::DateTime::DaysOfWeek)dayOfWeek); - this->course->setStartTime({startHour, startMinute, startSecond}); - this->course->setEndTime({endHour, endMinute, endSecond}); - db.setCourse(this->course); - - cout << "course added!" << endl; - - break; - case 2: - cout << "2. List courses" << endl; - - ////for (int it = 0; it <=db.getCourses().size(); it++) - //{ - cout << "Course key: "<< this->course->getCourseKey() << endl; - cout << "Module title: "<< this->course->getTitle() << endl; - cout << "Major: "<< this->course->getMajor() << endl; - cout << "Credit points: "<< this->course->getCreditPoints() << endl; - cout << "Day of the week: "<< this->course->getDayOfWeek() << endl; - cout << "Start time: "<< this->course->getStartTime().hour() << "." <course->getStartTime().minute() << "." <course->getStartTime().second() <course->getEndTime().hour() << "." <course->getEndTime().minute() << "." <course->getEndTime().second() << endl; - //} - - break; -// case 3: -// cout << "3. Add new student" << endl; -// -// string firstname; -// string lastname; -// int year,month,day; -// string street; -// int postalcode; -// string cityname; -// string additionalinfo; -// -// cout << "Enter first name: "; -// cin >> firstname; -// cout << "Enter last name: "; -// cin >> lastname; -// cout << "Enter date of birth (y:m:d): "; -// cin >> year >> month >> day; -// cout << "Enter street: "; -// cin >> street; -// cout << "Enter postal code: "; -// cin >> postalcode; -// cout << "Enter city name: "; -// cin >> cityname; -// cout << "Enter additional info: "; -// cin >> additionalinfo; -// -// this->student = new CStudent(firstname, lastname, {year,month,day}, street, postalcode, cityname, additionalinfo); -// db.setStudent(this->student); -// break; -// case 4: -// cout << "4. Add enrollment" << endl; -// break; -// case 5: -// cout << "5. Print student" << endl; -// break; -// case 6: -// cout << "6. Search student" << endl; -// -// int matrikelnumber; -// cin >> matrikelnumber; -// cout << "enter matrikel number:" << endl; -// -// -// cout << "Matrikel number: "<< this->student.getMatrikelNumber() << endl; -// cout << "first name: "<< this->student.getFirstName() << endl; -// cout << "last name: "<< this->student.getLastName() << endl; -// cout << "date of birth: "<< this->student.getDateOfBirth().day() << "." << this->student.getDateOfBirth().month() << "." <student.getDateOfBirth().year() << endl; -// cout << "street: "<< this->student.address.getStreet() << endl; -// cout << "postal code: "<< this->student.address.getPostalCode() << endl; -// cout << "additional info" << this->student.address.getAdditionalInfo() << endl; -// -// break; -// case 7: -// cout << "7. Update student" << endl; -// break; - } - } - } - - /* 3.2 - persisting the database*/ - /* - * the following lines of code write data to data.csv - * with the course, student and enrollment data. - * This file is located in the project directory - */ - - std::ofstream csvFile; - try - { - csvFile.open("data.csv"); - } - catch(std::exception const& e){ - cout << "There was an error: " << e.what() << endl; - } - - csvFile << db.getCourses().size() << "\n"; - //for (int it = 0; it <=db.getCourses().size(); it++) - //{ - csvFile << this->course->getCourseKey() << ";"; - csvFile << this->course->getTitle() << ";"; - csvFile << this->course->getMajor() << ";"; - csvFile << this->course->getCreditPoints() << ";"; - csvFile << this->course->getDayOfWeek() << ";"; - csvFile << this->course->getStartTime().hour() << "." <course->getStartTime().minute() << "." <course->getStartTime().second() <<";"; - csvFile << this->course->getEndTime().hour() << "." <course->getEndTime().minute() << "." <course->getEndTime().second() << ";"; - csvFile << "\n"; - //} - - csvFile << db.getStudents().size() << "\n"; -// for (int it = 0; it <=db.getCourses().size(); it++) -// { -// csvFile << this->student.getMatrikelNumber() << ";"; -// csvFile << this->student.getFirstName() << ";"; -// csvFile << this->student.getLastName() << ";"; -// csvFile << this->student.getDateOfBirth().day() << "." << this->student.getDateOfBirth().month() << "." <student.getDateOfBirth().year() << ";"; -// csvFile << this->student.address.getStreet() << ";"; -// csvFile << this->student.address.getPostalCode() << ";"; -// csvFile << this->student.address.getAdditionalInfo() << ";"; -// csvFile << "\n"; -// } - - csvFile.close(); - - cout << "write to csv file successful!"; - - - /* 3.3 - obtaining test data */ - /* - * the following lines of code connect to the server and gather data - * to put it into a json file format - */ - - // mutex consoleLock; - // - // while (true) { - // Poco::Net::SocketStream streamToClient(connectionToClient);// does not work - // - // streamToClient << "Hello!\r\n"; - // streamToClient.flush(); - // - // string command; - // std::getline(streamToClient, command); - // } -} diff --git a/myCode/CSimpleUI.h b/myCode/CSimpleUI.h deleted file mode 100644 index d5710ff..0000000 --- a/myCode/CSimpleUI.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CSIMPLEUI_H -#define CSIMPLEUI_H - -#include "CStudentDb.h" -#include "CWeeklyCourse.h" -#include "CStudent.h" - -class CSimpleUI { -private: - - /* - * pointer to assign courses - */ - CStudentDb &db; - CWeeklyCourse *course; - //CStudent &student; - -public: - /* - * constructor takes in a studentDB object by reference - */ - CSimpleUI(CStudentDb& db); - - /* - * the run method executes the UI, generates the csv file - * and obtains test data from mnl.de:4242 - */ - void run(); -}; - -#endif /* CSIMPLEUI_H */ diff --git a/myCode/CStudent.cpp b/myCode/CStudent.cpp deleted file mode 100644 index 37fa44b..0000000 --- a/myCode/CStudent.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "CStudent.h" - -using namespace std; - -unsigned int CStudent::nextMatrikelNumber = 100000; - -CStudent::CStudent(std::string firstName, std::string lastName, Poco::Data::Date dateOfBirth, std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo) -: address{street, postalCode, cityName, additionalInfo} -{ - this->firstName = firstName; - this->lastName = lastName; - this->dateOfBirth = dateOfBirth; - this->maktrikelNumber = CStudent::nextMatrikelNumber++; -} - -const unsigned int CStudent::getMatrikelNumber() const -{ - return this->maktrikelNumber; -} - -const std::string& CStudent::getFirstName() const -{ - return this->firstName; -} - -const std::string& CStudent::getLastName() const -{ - return this->lastName; -} diff --git a/myCode/CStudent.h b/myCode/CStudent.h deleted file mode 100644 index 16df48e..0000000 --- a/myCode/CStudent.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CSTUDENT_H -#define CSTUDENT_H - -#include -#include -#include - -#include "CAddress.h" -#include "CEnrollment.h" - -class CStudent { -private: - static unsigned int nextMatrikelNumber; - unsigned int maktrikelNumber; - std::string firstName; - std::string lastName; - Poco::Data::Date dateOfBirth; - /** - * @link aggregationByValue - */ - std::vector enrollments; - /** - * @link aggregationByValue - */ - -public: - CStudent(std::string firstName, std::string lastName, Poco::Data::Date dateOfBirth, std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo); - - CAddress address; - - const unsigned int getMatrikelNumber() const; - const std::string& getFirstName() const; - const std::string& getLastName() const; - const Poco::Data::Date& getDateOfBirth() const; - - void setFirstName(const std::string &firstName); - void setLastName(const std::string &lastName); - void setDateOfBirth(const Poco::Data::Date &dateOfBirth); - -}; -#endif /* CSTUDENT_H */ diff --git a/myCode/CStudentDb.cpp b/myCode/CStudentDb.cpp deleted file mode 100644 index 6da9d9b..0000000 --- a/myCode/CStudentDb.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "CStudentDb.h" - -CStudentDb::CStudentDb() -{ - -} - - -/* - * map setters and getters - * they return the entire maps as well as allow to add values to the maps - * by pointer and reference respectively - */ - -const std::map >& CStudentDb::getCourses() const -{ - return courses; -} - -const std::map& CStudentDb::getStudents() const -{ - return students; -} - -/* - * the index of the course map is the course key and using the std::move function - * the pointer can be assigned to the course key - */ -void CStudentDb::setCourse(CCourse *course) -{ - this->courses[course->getCourseKey()] = std::move(std::unique_ptr(course)); - -} - -/* - * in this map, the student matrikel number serves as the "index" - * and is mapped to the student object. unlike the above map this is passed by reference - */ -void CStudentDb::setStudent(CStudent &student) -{ - this->students.insert({student.getMatrikelNumber(),student}); -} diff --git a/myCode/CStudentDb.h b/myCode/CStudentDb.h deleted file mode 100644 index 615a846..0000000 --- a/myCode/CStudentDb.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef CSTUDENTDB_H -#define CSTUDENTDB_H - -#include -#include - -#include "CStudent.h" -#include "CCourse.h" - -class CStudentDb { - -private: - /* - * both of these maps represent the students and courses - */ - std::map students; - std::map> courses; - -public: - - /* - * empty constructor - */ - CStudentDb(); - - /* - * map setters and getters - * they return the entire maps as well as allow to add values to the maps - * by pointer and reference respectively - */ - const std::map >& getCourses() const; - const std::map& getStudents() const; - - void setCourse(CCourse *course); - void setStudent(CStudent &student); - -}; -#endif /* CSTUDENTDB_H */ diff --git a/myCode/CWeeklyCourse.cpp b/myCode/CWeeklyCourse.cpp deleted file mode 100644 index d8574b7..0000000 --- a/myCode/CWeeklyCourse.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "CWeeklyCourse.h" - -CWeeklyCourse::CWeeklyCourse(unsigned int courseKey, std::string title, unsigned char major, float creditPoints) -: CCourse(courseKey,title,major,creditPoints){ - - this->courseKey = courseKey; - this->title = title; - this->major = major; - this->creditPoints = creditPoints; - - // the following paramters will be changed through setters - this->dayOfWeek = Poco::DateTime::DaysOfWeek::SUNDAY; // default day is sunday - this->startTime = -1; // default startTime - this->endTime = -1; // default endTime -} - -CWeeklyCourse::~CWeeklyCourse() -{ - -} - -Poco::DateTime::DaysOfWeek CWeeklyCourse::getDayOfWeek() const -{ - return this->dayOfWeek; -} - -const Poco::Data::Time& CWeeklyCourse::getStartTime() const -{ - return this->startTime; -} - -const Poco::Data::Time& CWeeklyCourse::getEndTime() const -{ - return this->endTime; -} - -void CWeeklyCourse::setDayOfWeek(Poco::DateTime::DaysOfWeek dayOfWeek) -{ - this->dayOfWeek = dayOfWeek; -} - -void CWeeklyCourse::setStartTime(const Poco::Data::Time &startTime) -{ - this->startTime = startTime; -} - -void CWeeklyCourse::setEndTime(const Poco::Data::Time &endTime) -{ - this->endTime = endTime; -} diff --git a/myCode/CWeeklyCourse.h b/myCode/CWeeklyCourse.h deleted file mode 100644 index fdd5c06..0000000 --- a/myCode/CWeeklyCourse.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef CWEEKLYCOURSE_H -#define CWEEKLYCOURSE_H - -#include "CCourse.h" - -#include -#include - -class CWeeklyCourse : public CCourse { -private: - - Poco::DateTime::DaysOfWeek dayOfWeek; - Poco::Data::Time startTime; - Poco::Data::Time endTime; - -public: - - CWeeklyCourse(unsigned int courseKey, std::string title, unsigned char major, float creditPoints); - ~CWeeklyCourse(); - - Poco::DateTime::DaysOfWeek getDayOfWeek() const; - const Poco::Data::Time& getStartTime() const; - const Poco::Data::Time& getEndTime() const; - - void setDayOfWeek(Poco::DateTime::DaysOfWeek dayOfWeek); - void setStartTime(const Poco::Data::Time &startTime); - void setEndTime(const Poco::Data::Time &endTime); - -}; -#endif /* CWEEKLYCOURSE_H */ diff --git a/myCode/Course.cpp b/myCode/Course.cpp new file mode 100644 index 0000000..7708bc1 --- /dev/null +++ b/myCode/Course.cpp @@ -0,0 +1,108 @@ +#include "Course.h" +#include +#include +#include + +using namespace std; + + +std::map Course::majorById = +{ + {'A', "Automation"}, + {'C', "Communications"}, + {'E', "Embedded"}, + {'P', "Power"}, +}; + +Course::Course() +{ +} + +Course::Course(unsigned int courseKey, std::string title, std::string major, float creditPoints) +{ + this->courseKey = courseKey; + this->title = title; + this->creditPoints = creditPoints; + + // Find the char representation for the provided string + for (const auto& pair : majorById) + { + if (pair.second == major) + { + this->major = pair.first; // Store the char internally + return; + } + } + throw std::invalid_argument("Invalid major: " + major); + +} + +Course::~Course() +{ + +} + +unsigned int Course::getCourseKey() const +{ + return courseKey; +} + +float Course::getCreditPoints() const +{ + return creditPoints; +} + +const std::string& Course::getMajor() const +{ + auto it = majorById.find(this->major); + if (it != majorById.end()) + { + return it->second; // Return the string representation + } + throw std::runtime_error("Major not found in mapping"); + +} + +const std::string& Course::getTitle() const +{ + return title; +} + +void Course::write(std::ostream &out) const +{ + out << courseKey << ";" << title << ";" << majorById.at(major) << ";" << creditPoints << ";"; +} + +const std::map& Course::getMajorById() +{ + return Course::majorById; // Explicitly qualify the static member +} + +void Course::read(std::istream &in) +{ + string line, temp, majorStr; + + getline(in, temp, ';'); + courseKey = static_cast(stoi(temp)); + + getline(in, title, ';'); + + getline(in, majorStr, ';'); + if (!majorStr.empty()) + { + this->major = majorStr[0]; + } + else + { + std::cerr << "Warning: Major string is empty!" << std::endl; + } + + getline(in, temp, ';'); + creditPoints = stof(temp); + + if (in.peek() == '\n') + { + in.ignore(); + } + +} diff --git a/myCode/Course.h b/myCode/Course.h new file mode 100644 index 0000000..5f3c17a --- /dev/null +++ b/myCode/Course.h @@ -0,0 +1,38 @@ +#ifndef COURSE_H +#define COURSE_H + +#include +#include +#include + +class Course +{ + +protected: + + static std::map majorById; + unsigned int courseKey; + std::string title; + unsigned char major; + float creditPoints; + +public: + + Course(); + Course(unsigned int courseKey, std::string title, std::string major, float creditPoints); + virtual ~Course() = 0; + + virtual void write(std::ostream& out) const; //write base attributes to os stream + virtual void read(std::istream& in); + + unsigned int getCourseKey() const; + float getCreditPoints() const; + const std::string& getMajor() const; + const std::string& getTitle() const; + + //getter to use in simpleui class valdiation for major + static const std::map& getMajorById(); + +}; + +#endif diff --git a/myCode/Enrollment.cpp b/myCode/Enrollment.cpp new file mode 100644 index 0000000..03b232d --- /dev/null +++ b/myCode/Enrollment.cpp @@ -0,0 +1,57 @@ +#include "Enrollment.h" +#include +#include +#include + +using namespace std; + +Enrollment::Enrollment() : grade(0), course(nullptr) {} + +Enrollment::Enrollment(float grade, std::string semester, Course *course) +{ + this->grade = grade; + this->semester = semester; + this->course = course; +} + +Enrollment::~Enrollment() +{ +} + +float Enrollment::getGrade() const +{ + return grade; +} + +void Enrollment::setGrade(float grade) +{ + this->grade = grade; +} + +const std::string& Enrollment::getSemester() const +{ + return semester; +} + +const Course& Enrollment::getCourse() const +{ + return *course; +} + +void Enrollment::write(std::ostream &out) const +{ + out << course->getCourseKey() << ';' << semester << ';' << grade << "\n"; +} + +void Enrollment::read(std::istream &in) +{ + std::string temp; + + // Read semester (string) + getline(in, semester, ';'); + // Read grade (float) + getline(in, temp, '\n'); + + grade = std::stof(temp); +} + diff --git a/myCode/Enrollment.h b/myCode/Enrollment.h new file mode 100644 index 0000000..ac36067 --- /dev/null +++ b/myCode/Enrollment.h @@ -0,0 +1,33 @@ +#ifndef ENROLLMENT_H +#define ENROLLMENT_H + +#include + +#include "Course.h" + +class Enrollment +{ + +private: + + float grade; + std::string semester; + Course* course; + +public: + + Enrollment(); + Enrollment(float grade, std::string semester, Course* course); + ~Enrollment(); + + void setGrade(float grade); + float getGrade() const; + const std::string& getSemester() const; + const Course& getCourse() const; + + void write(std::ostream& out) const; //write attributes to os stream + void read(std::istream& in); + +}; + +#endif diff --git a/myCode/SimpleUI.cpp b/myCode/SimpleUI.cpp new file mode 100644 index 0000000..d68e2c3 --- /dev/null +++ b/myCode/SimpleUI.cpp @@ -0,0 +1,766 @@ +#include "SimpleUI.h" +#include "Course.h" +#include "WeeklyCourse.h" +#include "BlockCourse.h" +#include "Student.h" + +#include +#include +#include +#include + +#include +#include + +using boost::asio::ip::tcp; +namespace json = boost::json; +using namespace std; + +/* Error handling and input validation help functions + * + */ +Poco::Data::Date SimpleUI::getValidatedDate(const std::string& prompt) +{ + Poco::Data::Date date; // Placeholder for the valid date + + while (true) + { + try + { + int day, month, year; + cout << prompt; // Show the prompt to the user + cin >> day >> month >> year; + + date = Poco::Data::Date(year, month, day); // Attempt to construct a valid date + return date; // Return the valid date if no exception is thrown + } + catch (const Poco::InvalidArgumentException& ex) + { + cerr << "Invalid date. Please try again in the format DD MM YYYY." << endl; + + cin.clear(); // Clear input errors + cin.ignore(std::numeric_limits::max(), '\n'); // Discard invalid input + } + } +} + +Poco::Data::Time SimpleUI::getValidatedTime(const std::string& prompt) +{ + Poco::Data::Time time; // Placeholder for the valid time + + while (true) + { + try + { + int hour, minute, second; + cout << prompt; // Show the prompt to the user + cin >> hour >> minute >> second; + + // Optional manual validation for ranges + if (hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) + { + throw Poco::InvalidArgumentException("Time values out of range."); + } + + time = Poco::Data::Time(hour, minute, second); // Construct the valid time + return time; // Return the valid time if no exception is thrown + } + catch (const Poco::InvalidArgumentException& ex) + { + cerr << "Invalid time. Please try again in the format HH MM SS." << endl; + + cin.clear(); // Clear input errors + cin.ignore(std::numeric_limits::max(), '\n'); // Discard invalid input + } + } +} + +Poco::DateTime::DaysOfWeek SimpleUI::getValidatedDayOfWeek(const std::string& prompt) +{ + int dayOfWeek; + + while(true) + { + cout << prompt; + cin >> dayOfWeek; + + if(cin.fail() || dayOfWeek < 0 || dayOfWeek > 6) + { + cin.clear(); + cin.ignore(std::numeric_limits::max(), '\n'); + cerr << "Invalid input. Please enter a number between 0 and 6." << endl; + } + else + { + return static_cast(dayOfWeek); + } + } +} + +unsigned int SimpleUI::getValidatedUnsignedInt(const std::string& prompt, unsigned int min, unsigned int max) +{ + unsigned int value; // Variable to store the input + while (true) + { + cout << prompt; + cin >> value; + + // Check if the input was invalid or out of range + if (cin.fail() || value < min || value > max) + { + cin.clear(); // Clear the error flag + cin.ignore(std::numeric_limits::max(), '\n'); // Discard invalid input + cerr << "Invalid input. Please enter a number between " << min << " and " << max << "." << endl; + } + else + { + cin.ignore(std::numeric_limits::max(), '\n'); // Clear any trailing characters + return value; // Valid input + } + } +} + + +float SimpleUI::getValidatedFloat(const std::string& prompt, float min, float max) +{ + float value; + while (true) + { + cout << prompt; + cin >> value; + + if (cin.fail() || value < min || value > max) + { + cin.clear(); + cin.ignore(std::numeric_limits::max(), '\n'); + cerr << "Invalid input. Please enter a number between " << min << " and " << max << "." << endl; + } + else + { + return value; + } + } +} + +std::string SimpleUI::getValidatedString(const std::string& prompt, bool allowNumbers) +{ + std::string input; + + while (true) + { + cout << prompt; + + // If previous input was `cin >>`, clear the buffer once + if (cin.peek() == '\n') + { + cin.ignore(); + } + + std::getline(cin, input); + + if (input.empty()) + { + cerr << "Input cannot be empty. Please try again." << endl; + continue; + } + + if (!allowNumbers && input.find_first_of("0123456789") != std::string::npos) { + cerr << "Invalid input. Numbers are not allowed." << endl; + continue; + } + + return input; + } +} + +std::string SimpleUI::getValidatedMajor(const std::string& prompt) +{ + const auto& majorMap = Course::getMajorById(); // Access the static map + string majorInput; + while (true) + { + cout << prompt; + getline(cin, majorInput); + // Check user input against map values + for (const auto& pair : majorMap) + { + if(majorInput == pair.second) + { + return majorInput; + } + } + // If no match was found, print error and continue loop + cerr << "Invalid major. Please enter Automation, Communications, Embedded, or Power." << endl; + } +} + +unsigned short SimpleUI::getValidatedPostalCode(const std::string& prompt) +{ + unsigned short postalCode; + + while(true) + { + cout << prompt; + cin >> postalCode; + if(cin.fail() || postalCode < 0) + { + cin.clear(); // Clear the error flag + cin.ignore(std::numeric_limits::max(), '\n'); // Discard invalid input + cerr << "Invalid input. Please enter a number greater than 0 " << endl; + } + else + { + cin.ignore(std::numeric_limits::max(), '\n'); // Clear any trailing input + return postalCode; + } + } +} + + +SimpleUI::SimpleUI(StudentDb &db) +{ + this->db = &db; +} + +void SimpleUI::run() +{ + int choice; + + while(1) + { + cout << endl; + cout << "Select an option:" << endl; + cout << "1. Add new course" << endl; + cout << "2. List courses" << endl; + cout << "3. Add new student" << endl; + cout << "4. Add enrollment" << endl; + cout << "5. Print student" << endl; + cout << "6. Search student" << endl; + cout << "7. Update student" << endl; + cout << "8. Write student db contents to csv file" << endl; + cout << "9. Read csv contents to db" << endl; + cout << "10. Obtain test data from server" << endl; + cout << "or type 0 to terminate" << endl; + + choice = getValidatedUnsignedInt("Enter choice: ", 0, 10); + + switch(choice) + { + case 1 : addNewCourse(); break; + case 2 : listCourses(); break; + case 3 : addNewStudent(); break; + case 4 : addEnrollment(); break; + case 5 : printStudent(); break; + case 6 : searchStudent(); break; + case 7 : updateStudent(); break; + case 8 : writeToCsv(); break; + case 9 : readFromCsv(); break; + case 10 : obtainingTestData(); break; + case 0 : cerr << "Program Terminated" << endl; return; + default: cerr << "Invalid choice. Please try again." << endl; + } + } +} + +void SimpleUI::addNewCourse() +{ + unsigned int courseKey; + string title; + string major; + float creditPoints; + Poco::Data::Time startTime; + Poco::Data::Time endTime; + Poco::DateTime::DaysOfWeek dayOfWeek; + + char courseChoice; + + cout << "-------------------------" << endl; + cout << "1. Add new course" << endl; + cout << "-------------------------" << endl; + cout << endl; + + cout << "Enter W for Weeklycourse or B for Blockcourse" << endl; + do + { + cin >> courseChoice; + } + while(courseChoice != 'W' && courseChoice != 'w' && courseChoice != 'B' && courseChoice != 'b'); + + /* Course class parameters */ + + courseKey = getValidatedUnsignedInt("Enter Course key: ", 1); + while (db->getCourses().find(courseKey) != db->getCourses().end()) + { + cerr << "Course key already exists. Please enter a unique Course key." << endl; + courseKey = getValidatedUnsignedInt("Enter Course key: ", 1); + } + title = getValidatedString("Enter Module title: "); + major = getValidatedMajor("Enter Major (Automation, Communications, Embedded, Power): "); + creditPoints = getValidatedFloat("Enter Credit points: ", 0.0, 5.0); + startTime = getValidatedTime("Enter start time (HH MM SS): "); + endTime = getValidatedTime("Enter end time (HH MM SS): "); + + if(courseChoice == 'B' || courseChoice == 'b') + { + Poco::Data::Date startDate = getValidatedDate("Enter start date (DD MM YYYY): "); + Poco::Data::Date endDate = getValidatedDate("Enter end date (DD MM YYYY): "); + + std::unique_ptr blockCourse = std::make_unique(courseKey, title, major, creditPoints); + + blockCourse->setStartDate(startDate); + blockCourse->setEndDate(endDate); + blockCourse->setStartTime(startTime); + blockCourse->setEndTime(endTime); + + db->setCourse(std::move(blockCourse)); + cout << "Block course added" << endl; + } + else if(courseChoice == 'W' || courseChoice == 'w') + { + dayOfWeek = getValidatedDayOfWeek("Enter day of the week (0-6): "); + + std::unique_ptr weeklyCourse = std::make_unique(courseKey, title, major, creditPoints); + + weeklyCourse->setDayOfWeek((Poco::DateTime::DaysOfWeek)dayOfWeek); + weeklyCourse->setStartTime(startTime); + weeklyCourse->setEndTime(endTime); + + db->setCourse(std::move(weeklyCourse)); + cout << "Weekly course added" << endl; + } + cout << endl; +} + +void SimpleUI::listCourses() +{ + cout << "-------------------------" << endl; + cout << "2. List courses" << endl; + cout << "-------------------------" << endl; + cout << endl; + + for(const auto& coursePtr : db->getCourses()) + { + //data from base class + cout << "Course key: " << coursePtr.first << endl; // use the first iterator instead of having to use .second + cout << "Title: " << coursePtr.second->getTitle() << endl; + cout << "Major: " << coursePtr.second->getMajor() << endl; + cout << "Credit Points: " << coursePtr.second->getCreditPoints() << endl; + + auto* blockCourse = dynamic_cast(const_cast(coursePtr.second.get())); + auto* weeklyCourse = dynamic_cast(const_cast(coursePtr.second.get())); + + if(blockCourse) + { + cout << "Start Date: " << blockCourse->getStartDate().day() << "." << blockCourse->getStartDate().month() << "." << blockCourse->getStartDate().year() << endl; + cout << "End Date: " << blockCourse->getEndDate().day() << "." << blockCourse->getEndDate().month() << "." << blockCourse->getEndDate().year() << endl; + cout << "Start Time: " << blockCourse->getStartTime().hour() << "." << blockCourse->getStartTime().minute() << "." << blockCourse->getStartTime().second() << endl; + cout << "End Time: " << blockCourse->getEndTime().hour() << "." << blockCourse->getEndTime().minute() << "." << blockCourse->getEndTime().second() << endl; + } + else if(weeklyCourse) + { + cout << "Day of the week: " << weeklyCourse->getDayOfWeek() << endl; + cout << "Start Time: " << weeklyCourse->getStartTime().hour() << "." << weeklyCourse->getStartTime().minute() << "." << weeklyCourse->getStartTime().second() << endl; + cout << "End Time: " << weeklyCourse->getEndTime().hour() << "." << weeklyCourse->getEndTime().minute() << "." << weeklyCourse->getEndTime().second() << endl; + } + cout << endl; + } +} + +void SimpleUI::addNewStudent() +{ + string firstName; + string lastName; + string street; + unsigned short postalCode; + string cityName; + string additionalInfo; + + cout << "-------------------------" << endl; + cout << "3. Add new student" << endl; + cout << "-------------------------" << endl; + cout << endl; + + + firstName = getValidatedString("Enter first name: ", true); + lastName = getValidatedString("Enter last name: ", true); + Poco::Data::Date dateOfBirth = getValidatedDate("Enter start date (DD MM YYYY): "); + + street = getValidatedString("Enter street: "); + postalCode = getValidatedPostalCode("Enter postal code: "); + cityName = getValidatedString("Enter City: "); + additionalInfo = getValidatedString("Enter any additional info: "); + + Student student(firstName, lastName, dateOfBirth, street, postalCode, cityName, additionalInfo); + db->setStudent(student); +} + +void SimpleUI::addEnrollment() +{ + unsigned int matrikelNumber; + float grade; + string semester; + unsigned int courseKey; + + cout << "-------------------------" << endl; + cout << "4. Add enrollment" << endl; + cout << "-------------------------" << endl; + cout << endl; + + matrikelNumber = getValidatedUnsignedInt("Enter matrikel number: "); + courseKey = getValidatedUnsignedInt("Enter course key: "); + grade = getValidatedFloat("Enter grade: "); + semester = getValidatedString("Enter semester: "); + + + //access the enrollments but might need to create a setter for the enrollments vector + //check if the enrollment exists when trying to make it..so yea will need a settter + //add the course to the enrollment vector that is associated with the coursekey that is provided here + + if (db->getStudents().find(matrikelNumber) != db->getStudents().end()) + { + // Access the course associated with the courseKey + auto it = db->getCourses().find(courseKey); + + if (it != db->getCourses().end()) + { + // Get the raw Course pointer + Course* course = const_cast(it->second.get()); + // Call setEnrollment on the Student object + auto& enrollments = db->getStudents().at(matrikelNumber).getEnrollments(); + + auto it = std::find_if(enrollments.begin(), enrollments.end(), [&](const Enrollment& e) { + return e.getCourse().getCourseKey() == courseKey; + }); + + if(it != enrollments.end()) + { + cerr << "Enrollment already exsits" << endl; + } + else + { + db->getStudents().at(matrikelNumber).setEnrollment(grade, semester, course); + } + } + else + { + cerr << "Course with key " << courseKey << " not found!" << endl; + } + } + else + { + cerr << "Student with matrikel number " << matrikelNumber << " not found!" << endl; + } +} + +void SimpleUI::printStudent() +{ + + unsigned int matrikelNumber; + + cout << "-------------------------" << endl; + cout << "5. Print Student" << endl; + cout << "-------------------------" << endl; + cout << endl; + + matrikelNumber = getValidatedUnsignedInt("Enter matrikel number: "); + + cout << endl; + cout << "Info for: " << matrikelNumber << endl; + cout << "-------------------------" << endl; + + if (db->getStudents().find(matrikelNumber) != db->getStudents().end()) + { + auto it = db->getStudents().find(matrikelNumber); + + cout << "\tfirst name: "<< it->second.getFirstName() << endl; + cout << "\tlast name: "<< it->second.getLastName() << endl; + cout << "\tdate of birth: "<< it->second.getDateOfBirth().day() << "." << it->second.getDateOfBirth().month() << "." << it->second.getDateOfBirth().year() << endl; + cout << "\tstreet: "<< it->second.address.getStreet() << endl; + cout << "\tpostal code: "<< it->second.address.getPostalCode() << endl; + cout << "\tcity name: " << it->second.address.getCityName() << endl; + cout << "\tadditional info: " << it->second.address.getAdditionalInfo() << endl; + + cout << endl; + + cout << "\tEnrollment info" << endl; + + for(const auto& enrollment : it->second.getEnrollments()) + { + cout << "\t\tSemester: " << enrollment.getSemester() << endl; + cout << "\t\tGrade: " << enrollment.getGrade() << endl; + cout << "\tCourse info for: " << enrollment.getCourse().getCourseKey() << endl; + cout << "\t\tTitle: " << enrollment.getCourse().getTitle() << endl; + cout << "\t\tMajor: " << enrollment.getCourse().getMajor() << endl; + cout << "\t\tCreditPoints: " << enrollment.getCourse().getCreditPoints() << endl; + } + cout << endl; + } + else + { + cerr << "Student with matrikel number " << matrikelNumber << " not found!" << endl; + } +} + +void SimpleUI::searchStudent() +{ + std::string stringToSearch; + + cout << "-------------------------" << endl; + cout << "6. Search student" << endl; + cout << "-------------------------" << endl; + cout << endl; + + stringToSearch = getValidatedString("Enter a string to search for a student: "); + + for(const auto& students : db->getStudents()) + { + if(students.second.getFirstName().find(stringToSearch) != string::npos || students.second.getLastName().find(stringToSearch) != string::npos) + { + cout << "Matrikel Number: " << students.second.getMatrikelNumber() << endl; + cout << "\tfirst name: "<< students.second.getFirstName() << endl; + cout << "\tlast name: "<< students.second.getLastName() << endl; + cout << endl; + } + else + { + cerr << "No matching student containing : " << stringToSearch << endl; + } + } +} + +void SimpleUI::updateStudent() +{ + unsigned int matrikelNumber; + int choice; + + cout << "-------------------------" << endl; + cout << "7. Update student" << endl; + cout << "-------------------------" << endl; + cout << endl; + + matrikelNumber = getValidatedUnsignedInt("Enter matrikel number: "); + + if (db->getStudents().find(matrikelNumber) != db->getStudents().end()) + { + auto& student = db->getStudents().at(matrikelNumber); + auto& enrollments = const_cast&>(db->getStudents().at(matrikelNumber).getEnrollments()); + + do + { + cout << "What would you like to update?: " << endl; + cout << "-------------------------" << endl; + cout << "1. First name" << endl; + cout << "2. Last name" << endl; + cout << "3. Date of birth" << endl; + cout << "4. Address" << endl; + + for (size_t i = 0; i < enrollments.size(); i++) + { + const auto& enrollment = enrollments[i]; + cout << (i + 5) << ". [Enrollment #" << (i + 1) << " Semester: " << enrollment.getSemester() << ", Grade: " << enrollment.getGrade() << "]" <> choice; + switch(choice) + { + case 1: + student.setFirstName(getValidatedString("Enter first name: ")); + break; + case 2: + student.setLastName(getValidatedString("Enter last name: ")); + break; + case 3: + student.setDateOfBirth(getValidatedDate("Enter start date (DD MM YYYY): ")); + break; + case 4: + student.setAddress + ( + Address + ( + getValidatedString("Enter street: "), + getValidatedPostalCode("Enter postal code: "), + getValidatedString("Enter City: "), + getValidatedString("Enter any additional info: ") + ) + ); + break; + case 0: + cout << "Exiting update menu..." << endl; + return; //exit + default: + break; + } + + // Dynamically handle enrollments (Choices 5 and beyond) + if (choice >= 5 && choice < static_cast(5 + enrollments.size())) + { + size_t enrollmentIndex = choice - 5; // Calculate index for vector + auto& selectedEnrollment = enrollments[enrollmentIndex]; + + do + { + cout << "What would you like to do with the enrollment?" << endl; + cout << "1. Remove enrollment" << endl; + cout << "2. Add grade" << endl; + cin >> choice; + + if(choice == 1) + { + student.removeEnrollment(enrollmentIndex); + } + else if (choice == 2) + { + selectedEnrollment.setGrade(getValidatedFloat("Enter grade: ")); + } + else + { + cerr << "Invalid choice. Please select 1 or 2." << endl; + } + + } while(choice != 1 && choice != 2); + } + } while (choice != 0); + } + else + { + cerr << "Student with matrikel number " << matrikelNumber << " not found!" << endl; + } +} + +void SimpleUI::writeToCsv() +{ + cout << "-------------------------" << endl; + cout << "8. Write studentdb contents to csv file" << endl; + cout << "-------------------------" << endl; + cout << endl; + ofstream csvFile; + string fileName = getValidatedString("Enter a file name: ", true); + csvFile.open(fileName); + + if (!csvFile.is_open()) + { + cerr << "Error: Unable to open file '" << fileName << "'" << endl; + return; + } + + db->write(csvFile); + csvFile.close(); // Ensure file is closed properly +} + +void SimpleUI::readFromCsv() +{ + cout << "-------------------------" << endl; + cout << "9. Read csv contents to studentDb" << endl; + cout << "-------------------------" << endl; + cout << endl; + ifstream csvFile; + string fileName = getValidatedString("Enter a file name: ", true); + csvFile.open(fileName); + + if (!csvFile.is_open()) + { + cerr << "Error: Unable to open file '" << fileName << "'" << endl; + return; + } + + db->read(csvFile); + csvFile.close(); // Ensure file is closed properly +} + +void SimpleUI::obtainingTestData() +{ + int userCount; + std::cout << "How many users to generate? "; + std::cin >> userCount; + std::cin.ignore(); // flush newline + + tcp::iostream stream; + stream.connect("www.hhs.users.h-da.cloud", "4242"); + if (!stream) + { + cerr << "Failed to connect to server!" << endl; + } + else + { + cout << "Connected successfully!" << endl; + } + + for (int i = 0; i < userCount; ) + { + stream << "generate\n"; + stream.flush(); + + std::string line; + json::value jv; + + while (std::getline(stream, line)) + { + try + { + jv = json::parse(line); + if (!jv.is_object()) { + std::cerr << "Not a JSON object. Skipping.\n"; + continue; + } + break; + } + catch (const std::exception& e) + { + std::cerr << "Invalid JSON: " << e.what() << " | Line: " << line << std::endl; + } + } + + json::object obj = jv.as_object(); + + try { + auto name = obj["name"].as_object(); + auto location = obj["location"].as_object(); + auto dob = obj["dateOfBirth"].as_object(); + + std::string firstName = name["firstName"].as_string().c_str(); + std::string lastName = name["lastName"].as_string().c_str(); + std::string street = location["street"].as_string().c_str(); + std::string cityName = location["city"].as_string().c_str(); + std::string email = obj["email"].as_string().c_str(); + + unsigned short postalCode = 0; + try { + postalCode = static_cast(std::stoi(location["postCode"].as_string().c_str())); + } catch (...) { + std::cerr << "Warning: Invalid postalCode, using 0.\n"; + } + + int day = dob["day"].as_int64() + 1; + int month = dob["month"].as_int64() + 1; + int year = dob["year"].as_int64() + 1900; + + cout << "---- Student #" << i + 1 << " ----" << endl; + cout << "First Name : " << firstName << endl; + cout << "Last Name : " << lastName << endl; + cout << "Street : " << street << endl; + cout << "Postal Code : " << postalCode << endl; + cout << "City : " << cityName << endl; + cout << "Day : " << day << endl; + cout << "Month : " << month << endl; + cout << "Year : " << year << endl; + cout << "Additional Info : " << email << endl; + + Poco::Data::Date dateOfBirth = { year, month, day }; + Student student(firstName, lastName, dateOfBirth, street, postalCode, cityName, email); + db->setStudent(student); + + ++i; // only increment if all went well + } catch (const std::exception& e) { + std::cerr << "Failed to process student #" << i + 1 << ": " << e.what() << std::endl; + } + } + + + stream << "quit\n"; + stream.flush(); + stream.close(); + +} diff --git a/myCode/SimpleUI.h b/myCode/SimpleUI.h new file mode 100644 index 0000000..93e0e10 --- /dev/null +++ b/myCode/SimpleUI.h @@ -0,0 +1,43 @@ +#ifndef SIMPLEUI_H +#define SIMPLEUI_H + +#include "StudentDb.h" + +class SimpleUI +{ + +private: + + StudentDb* db; + +public: + + SimpleUI(StudentDb& db); + void run(); + + /* Error handling and input validation help functions */ + Poco::Data::Date getValidatedDate(const std::string& prompt); + Poco::Data::Time getValidatedTime(const std::string& prompt); + Poco::DateTime::DaysOfWeek getValidatedDayOfWeek(const std::string& prompt); + unsigned int getValidatedUnsignedInt(const std::string& prompt, unsigned int min = 0, unsigned int max = UINT_MAX); + float getValidatedFloat(const std::string& prompt, float min = 1.0, float max = 5.0); + std::string getValidatedString(const std::string& prompt, bool allowNumbers = true); + std::string getValidatedMajor(const std::string& prompt); + unsigned short getValidatedPostalCode(const std::string& prompt); + + /* Helper functions */ + void addNewCourse(); + void listCourses(); + void addNewStudent(); + void addEnrollment(); + void printStudent(); + void searchStudent(); + void updateStudent(); + + void writeToCsv(); + void readFromCsv(); + + void obtainingTestData(); +}; + +#endif diff --git a/myCode/Student.cpp b/myCode/Student.cpp new file mode 100644 index 0000000..e591f19 --- /dev/null +++ b/myCode/Student.cpp @@ -0,0 +1,123 @@ +#include "Student.h" +#include +#include +#include + +using namespace std; + +unsigned int Student::nextMatrikelNumber = 100000; + +Student::Student(std::string firstName, std::string lastName, Poco::Data::Date dateOfBirth, std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo) +: address(street, postalCode, cityName, additionalInfo) +{ + this->matrikelNumber = Student::nextMatrikelNumber++; + this->firstName = firstName; + this->lastName = lastName; + this->dateOfBirth = dateOfBirth; +} + +Student::~Student() +{ +} + +void Student::setAddress(const Address &address) +{ + this->address = address; +} + +void Student::setDateOfBirth(const Poco::Data::Date &dateOfBirth) +{ + this->dateOfBirth = dateOfBirth; +} + +void Student::setFirstName(const std::string &firstName) +{ + this->firstName = firstName; +} + +void Student::setLastName(const std::string &lastName) +{ + this->lastName = lastName; +} + +const Poco::Data::Date& Student::getDateOfBirth() const +{ + return dateOfBirth; +} + +const std::string& Student::getFirstName() const +{ + return firstName; +} + +const std::string& Student::getLastName() const +{ + return lastName; +} + +unsigned int Student::getMatrikelNumber() const +{ + return matrikelNumber; +} + +const std::vector& Student::getEnrollments() const +{ + return enrollments; +} + +void Student::setEnrollment(float grade, std::string semester, Course *course) +{ + enrollments.emplace_back(grade, semester, course); +} + +void Student::removeEnrollment(size_t index) { + enrollments.erase(enrollments.begin() + index); +} + +void Student::clearEnrollments() +{ + enrollments.clear(); +} + +void Student::write(std::ostream &out) const +{ + out << matrikelNumber << ';' << lastName << ';' << firstName << ';'; + out << dateOfBirth.day() << '.' << dateOfBirth.month() << '.' << dateOfBirth.year() << ';'; + address.write(out); +} + +Student::Student() +{ +} + +void Student::setNextMatrikelNumber(unsigned int newMatrikelNumber) +{ + Student::nextMatrikelNumber = newMatrikelNumber; +} + +void Student::read(std::istream &in) +{ + string line; + string dateOfBirthStr; + int day, month, year; + + getline(in, line, ';'); + matrikelNumber = static_cast(stoi(line)); // Convert string to unsigned int + getline(in, line, ';'); + lastName = line; + getline(in, line, ';'); + firstName = line; + + getline(in, dateOfBirthStr, ';'); + istringstream dateStreamStart(dateOfBirthStr); + getline(dateStreamStart, line, '.'); + day = stoi(line); + getline(dateStreamStart, line, '.'); + month = stoi(line); + getline(dateStreamStart, line, '.'); + year = stoi(line); + dateOfBirth = Poco::Data::Date(year, month, day); + + address.read(in); + +} diff --git a/myCode/Student.h b/myCode/Student.h new file mode 100644 index 0000000..811475f --- /dev/null +++ b/myCode/Student.h @@ -0,0 +1,53 @@ +#ifndef STUDENT_H +#define STUDENT_H + +#include +#include +#include + +#include "Enrollment.h" +#include "Address.h" + +class Student +{ + +private: + + static unsigned int nextMatrikelNumber; + unsigned int matrikelNumber; + std::string firstName; + std::string lastName; + Poco::Data::Date dateOfBirth; + std::vector enrollments; + +public: + + Student(); + Student(std::string firstName, std::string lastName, Poco::Data::Date dateOfBirth, std::string street, unsigned short postalCode, std::string cityName, std::string additionalInfo); + ~Student(); + + Address address; + + const Poco::Data::Date& getDateOfBirth() const; + const std::string& getFirstName() const; + const std::string& getLastName() const; + unsigned int getMatrikelNumber() const; + + const std::vector& getEnrollments() const; + + void setEnrollment(float grade, std::string semester, Course *course); + void removeEnrollment(size_t index); + void clearEnrollments(); + + void setAddress(const Address &address); + void setDateOfBirth(const Poco::Data::Date &dateOfBirth); + void setFirstName(const std::string &firstName); + void setLastName(const std::string &lastName); + + void write(std::ostream& out) const; //write attributes to os stream + void read(std::istream& in); + + static void setNextMatrikelNumber(unsigned int newMatrikelNumber); +}; + +#endif diff --git a/myCode/StudentDb.cpp b/myCode/StudentDb.cpp new file mode 100644 index 0000000..c9fd9e7 --- /dev/null +++ b/myCode/StudentDb.cpp @@ -0,0 +1,167 @@ +#include "StudentDb.h" +#include +#include +#include +#include "WeeklyCourse.h" +#include "BlockCourse.h" + +using namespace std; + +StudentDb::StudentDb() +{ +} + +StudentDb::~StudentDb() +{ +} + +const std::map >& StudentDb::getCourses() const +{ + return courses; +} + +const std::map& StudentDb::getStudents() const +{ + return students; +} + +std::map& StudentDb::getStudents() +{ + return students; +} + +void StudentDb::setCourse(std::unique_ptr course) +{ + // Move the unique pointer into the courses map using the course id as the key + courses.emplace(course->getCourseKey(), std::move(course)); +} + +void StudentDb::setStudent(Student student) +{ + // add an entry to the students map: matrtikelnumber and the student object + students.emplace(student.getMatrikelNumber(), student); +} + +void StudentDb::write(std::ostream &out) const +{ + //used for running count of enrollment vector size + size_t enrollmentsSize = 0; + for(const auto& student: students) + { + enrollmentsSize+= student.second.getEnrollments().size(); + } + //output the course count and courses info + out << courses.size() << "\n"; + for(const auto& course: courses) + { + course.second->write(out); + } + //output the student count and student info + out << students.size() << "\n"; + for(const auto& student: students) + { + student.second.write(out); + } + //output the enrollment count and enrollment info + out << enrollmentsSize << "\n"; + for(const auto& student: students) + { + unsigned int matrikelNumber = student.second.getMatrikelNumber(); + auto& enrollments = student.second.getEnrollments(); + for(const auto& enrollment: enrollments) + { + out << matrikelNumber << ';'; + enrollment.write(out); + } + } +} + +void StudentDb::read(std::istream &in) +{ + size_t courseCount, studentCount, enrollmentCount; + string line, temp; //strings for line and temp data + + courses.clear(); + for(auto& student: students) + { + student.second.clearEnrollments(); + } + students.clear(); + + in >> courseCount; + in.ignore(); + + for(size_t i = 0; i < courseCount; i++) + { + char courseType; + getline(in, line); // Read the next line before extracting first character + courseType = line[0]; // Extract first character safely (either W or B) + std::istringstream lineStream(line.substr(2)); // Start reading after "W; + if (courseType == 'W') + { + unique_ptr weeklyCourse = std::make_unique(); + weeklyCourse->read(lineStream); + setCourse(move(weeklyCourse)); // add to courses map + } + else if (courseType == 'B') + { + unique_ptr blockCourse = std::make_unique(); + blockCourse->read(lineStream); + setCourse(move(blockCourse)); // add to courses map + } + } + + in >> studentCount; + in.ignore(); + for(size_t i = 0; i < studentCount; i++) + { + Student s; + s.read(in); + setStudent(s); // add to students map + } + + in >> enrollmentCount; + in.ignore(); + + for(size_t i = 0; i < enrollmentCount; i++) + { + std::string line, temp; + unsigned int matrikelNumber, courseKey; + + getline(in, line); // Read the whole line + std::istringstream iss(line); // Create stream from line + + // Extract matrikel number + getline(iss, temp, ';'); + matrikelNumber = static_cast(std::stoi(temp)); + // Extract course key + getline(iss, temp, ';'); + courseKey = static_cast(std::stoi(temp)); + + // Extract remaining enrollment data (semester and grade) + Enrollment e; + e.read(iss); // Pass the stream! DO NOT call getline again here. + + if (courses.find(courseKey) == courses.end()) + { + cerr << "Error: Course with key " << courseKey << " not found." << endl; + continue; // Skip this enrollment + } + else + { + Course* course = const_cast(courses.at(courseKey).get()); + students.at(matrikelNumber).setEnrollment(e.getGrade(), e.getSemester(), course); //add enrollment to enrollment vector of student with given matrikelnumber + } + } + //check last matrikel number and add one to it + auto lastStudent = students.rbegin(); // Reverse iterator, points to last element + if (lastStudent != students.rend()) // Ensure map is not empty + { + unsigned int highestMatrikel = lastStudent->first; // Extract the key + Student::setNextMatrikelNumber(highestMatrikel + 1); // Update static variable + } + else + { + Student::setNextMatrikelNumber(100000); // Default starting value if empty + } +} diff --git a/myCode/StudentDb.h b/myCode/StudentDb.h new file mode 100644 index 0000000..c1b2cf0 --- /dev/null +++ b/myCode/StudentDb.h @@ -0,0 +1,34 @@ +#ifndef STUDENTDB_H +#define STUDENTDB_H + +#include +#include + +#include "Student.h" + + +class StudentDb +{ + +private: + + std::map students; + std::map> courses; + +public: + + StudentDb(); + ~StudentDb(); + + const std::map>& getCourses() const; + const std::map& getStudents() const; + std::map& getStudents(); // non const getter for addenrollment + + void setCourse(std::unique_ptr course); + void setStudent(Student student); + + void write(std::ostream& out) const; //write attributes to ostream + void read(std::istream& in); //read data to instream +}; + +#endif diff --git a/myCode/WeeklyCourse.cpp b/myCode/WeeklyCourse.cpp new file mode 100644 index 0000000..b0d3a32 --- /dev/null +++ b/myCode/WeeklyCourse.cpp @@ -0,0 +1,110 @@ +#include "WeeklyCourse.h" +#include +#include +#include + +using namespace std; + +WeeklyCourse::WeeklyCourse() +{ +} + +WeeklyCourse::WeeklyCourse(unsigned int courseKey, std::string title, std::string major, float creditPoints) +: Course(courseKey,title,major,creditPoints) +{ + + this->dayOfWeek = 0; // default day is sunday + this->startTime = -1; // default startTime + this->endTime = -1; // default endTime + +} + +WeeklyCourse::~WeeklyCourse() +{ +} + +int WeeklyCourse::getDayOfWeek() const +{ + return dayOfWeek; +} + +const Poco::Data::Time& WeeklyCourse::getStartTime() const +{ + return startTime; +} + +const Poco::Data::Time& WeeklyCourse::getEndTime() const +{ + return endTime; +} + +void WeeklyCourse::setDayOfWeek(int dayOfWeek) +{ + this->dayOfWeek = dayOfWeek; +} + +void WeeklyCourse::setEndTime(const Poco::Data::Time &endTime) +{ + this->endTime = endTime; +} + +void WeeklyCourse::setStartTime(const Poco::Data::Time &startTime) +{ + this->startTime = startTime; +} + +void WeeklyCourse::write(std::ostream &out) const +{ + out << "W;"; + + Course::write(out); + out << dayOfWeek << ';'; + out << startTime.hour() << '.' << startTime.minute() << '.' << startTime.second() << ';'; + out << endTime.hour() << '.' << endTime.minute() << '.' << endTime.second() << "\n"; +} + +void WeeklyCourse::read(std::istream &in) +{ + string line; + string dayOfWeekStr; + string startTimeStr, endTimeStr; + int startHour, startMinute, startSecond, endHour, endMinute, endSecond; + + + Course::read(in); + + std::getline(in, line, ';'); + + if (line.empty()) { + std::cerr << "ERROR: DayOfWeek is EMPTY! CHECK INPUT FILE OR GETLINE ORDER." << std::endl; + } else { + dayOfWeek = stoi(line); + } + + + getline(in, startTimeStr, ';'); + istringstream timeStreamStart(startTimeStr); + getline(timeStreamStart, line, '.'); + + startHour = stoi(line); + getline(timeStreamStart, line, '.'); + + startMinute = stoi(line); + getline(timeStreamStart, line, '.'); + + startSecond = stoi(line); + startTime = Poco::Data::Time(startHour, startMinute, startSecond); + + getline(in, endTimeStr, ';'); + istringstream timeStreamEnd(endTimeStr); + getline(timeStreamEnd, line, '.'); + + endHour = stoi(line); + getline(timeStreamEnd, line, '.'); + + endMinute = stoi(line); + getline(timeStreamEnd, line, '.'); + + endSecond = stoi(line); + endTime = Poco::Data::Time(endHour, endMinute, endSecond); +} diff --git a/myCode/WeeklyCourse.h b/myCode/WeeklyCourse.h new file mode 100644 index 0000000..5fc7477 --- /dev/null +++ b/myCode/WeeklyCourse.h @@ -0,0 +1,36 @@ +#ifndef WEEKLYCOURSE_H +#define WEEKLYCOURSE_H + +#include +#include + +#include "Course.h" + +class WeeklyCourse : public Course +{ + +private: + + int dayOfWeek; + Poco::Data::Time startTime; + Poco::Data::Time endTime; + +public: + + WeeklyCourse(); + WeeklyCourse(unsigned int courseKey, std::string title, std::string major, float creditPoints); + ~WeeklyCourse(); + + int getDayOfWeek() const; + const Poco::Data::Time& getEndTime() const; + const Poco::Data::Time& getStartTime() const; + + void setDayOfWeek(int dayOfWeek); + void setEndTime(const Poco::Data::Time &endTime); + void setStartTime(const Poco::Data::Time &startTime); + + void write(std::ostream& out) const; //write attributes to os stream + void read(std::istream& in); +}; + +#endif diff --git a/myCode/main.cpp b/myCode/main.cpp index d4566c7..9c08c91 100644 --- a/myCode/main.cpp +++ b/myCode/main.cpp @@ -1,11 +1,21 @@ -#include "CSimpleUI.h" +#include "SimpleUI.h" + +#include +#include +#include + +#include + +using boost::asio::ip::tcp; +namespace json = boost::json; + +using namespace std; int main (void) { - CStudentDb db; - CSimpleUI ui(db); + StudentDb db; + SimpleUI ui(db); ui.run(); - return 0; } diff --git a/sample_data.csv b/sample_data.csv new file mode 100644 index 0000000..1bd56ba --- /dev/null +++ b/sample_data.csv @@ -0,0 +1,8 @@ +2 +W;5387;APT;Automation;5;3;17.45.0;19.15.0 +B;2371;C Programming;Automation;5;16.9.2019;20.9.2019;14.15.0;19.15.0 +2 +100000;Olsen;Peeeterr;23.11.1998;7158 Spurvevej;21361;Juelsminde; +100001;Stein;Josephine;5.3.1997;2575 Tannenweg;49733;Delitzsch;Apartement 6b +1 +100000;5387;WS2018;2.3 diff --git a/sample_output.csv b/sample_output.csv new file mode 100644 index 0000000..bb0b1cf --- /dev/null +++ b/sample_output.csv @@ -0,0 +1,3 @@ +0 +0 +0