Skip to content

Commit

Permalink
Fixed major bugs and added support for courses.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchismanKarmakar authored Feb 17, 2024
1 parent 0c11795 commit bf11e4b
Show file tree
Hide file tree
Showing 8 changed files with 510 additions and 44 deletions.
49 changes: 49 additions & 0 deletions include/course.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef COURSE
#define COURSE

#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <set>
#include <map>
#include <cstring>
#include <queue>
#include <stack>
#include <chrono>
#include <random>
#include <functional>
#include <limits>
#include <fstream>
#include <sstream>
#include <filesystem>

using namespace std;

class Course
{
public:
// Course(string course, string details);

void print();
void addCourse();
void takeInput();
void strToAdd(string str);
string addToStr(string str);
void getDetails(int rec=0);
void saveMap();
void getDetailsFromHistory();
void removeCourse();

protected:
int courseId;
string courseName;
string courseDetails;

private:
friend class Routine;
};

#endif
4 changes: 2 additions & 2 deletions include/employee.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Employee : public Person
{
private:
string type;
int appointmentsBooked;
// friend class appointment;
int classesScheduled;
friend class Routine;

public:
Employee();
Expand Down
27 changes: 27 additions & 0 deletions include/routine.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef ROUTINE
#define ROUTINE
using namespace std;

#include "./course.hh"
#include "./employee.hh"
// #include "./person.hh"

class Routine
{
private:
int id;
Employee D;
Course P;
int hh; // hh -> start hour in 24 hour format;

public:
Routine();
~Routine();
void fillMap();
void saveMap();
void printDetails();
void book();
void fillDetails();
void getDetails();
};
#endif // !ROUTINE
18 changes: 11 additions & 7 deletions include/table_manage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include <filesystem>

#include "./employee.hh"
// #include "./patient.hh"
#include "./course.hh"
// #include "./nurse.hh"
// #include "./driver.hh"
// #include "./ambulance.hh"
// #include "./appointment.hh"
#include "./routine.hh"

#define ull unsigned long long

Expand Down Expand Up @@ -53,34 +53,38 @@ bool classStandardChk(std::string classStandard_fname);
class table_manage
{
private:
//map<id, object>
// map<id, object>
static map<int, Employee> employeeList;
// static map<int, patient> patientsList;
static map<int, Course> courseList;
// static map<int, nurse> nursesList;
// static map<int, driver> driversList;
// static map<int, ambulance> ambulancesList;
// static map<int, appointment> appointmentsList;
static map<int, Routine> appointmentsList;

static const int employeeLimit;
// static const int nursesLimit;
// static const int driversLimit;
// static const int ambulancesLimit;
// static const int appointmentsLimit;
static const int appointmentsLimit;

friend class Employee;
friend class Course;
friend class Routine;
// friend class patient;
// friend class nurse;
// friend class driver;
// friend class ambulance;
// friend class appointment;
friend class appointment;

public:
static void printEmployees();
// static void printPatients();
static void printCourses();
// static void printNurses();
// static void printDrivers();
// static void printAmbulances();
// static void printAppointments();
static void printAppointments();
};

#endif
198 changes: 198 additions & 0 deletions src/course.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <set>
#include <map>
#include <cstring>
#include <queue>
#include <stack>
#include <chrono>
#include <random>
#include <functional>
#include <limits>
#include <fstream>
#include <sstream>
#include <filesystem>

#include "./../include/course.hh"
#include "./../include/table_manage.hh"

using namespace std;

// Course::Course(string courseId, string coursedetails)
// {
// this->courseId = courseId;
// this->courseDetails = coursedetails;
// }

void Course::print()
{
cout << "Course ID: " << courseId << "\n";
cout << "Course Details: " << courseDetails << "\n";
return;
}

void Course::takeInput()
{
cout << "Enter Course ID: ";
// getline(cin >> ws, courseId);
cin >> courseId;
cout << "Enter Course Details: ";
getline(cin >> ws, courseDetails);
return;
}

string Course::addToStr(string str)
{
stringstream s;
s << courseId << "`" << courseDetails;
string addable;
getline(s, addable);
for (auto &i : addable)
if (i == ',')
i = '^';
return addable;
}

void Course::strToAdd(string str)
{
stringstream s(str);
// getline(s, courseId, '`');
// // getline(s, courseDetails);
// for (auto &i : courseId)
// if (i == '^')
// i = ',';
// return;
cin >> courseId;
getline(s, courseDetails, '`');
}

void Course::saveMap()
{
fstream f;
f.open("./data/temp.csv", ios::out);
// `le first line conataining column headers:
f << "courseId,courseName,courseDetails\n";
for (auto i : table_manage::courseList)
f << i.second.courseId << "," << i.second.courseName << "," << i.second.courseDetails << endl;
f.close();
remove("./data/courses.csv");
rename("./data/temp.csv", "./data/courses.csv");
return;
}

void Course::addCourse()
{
cout << "\nEnter the course name:\n";
getline(cin >> ws, courseName);
cout << "\nEnter the course details:\n";
getline(cin >> ws, courseDetails);
fstream f;
f.open("./data/coursesHistory.csv", ios::app);
f << courseId << "," << courseName << "," << courseDetails << "\n";
f.close();

cout << "\n"
<< courseId << " " << courseName << " has been successfully!\n";
cout << "Their ID is: " << courseId << "\n";

return;
}

void Course::getDetails(int rec)
{
int opt = 0;
cout << "\nOPTIONS:\n[1]: Filter by ID\n[2]: Filter by Name\n\n";
cin >> opt;
while (opt != 1 && opt != 2)
cout << "option 1 or 2?\n", cin >> opt;
// 1: Filter by ID;
if (opt == 1)
{
int reqId;
cout << "\nEnter ID:\n";
cin >> reqId;
if (table_manage::courseList.find(reqId) != table_manage::courseList.end())
*this = table_manage::courseList[reqId];
else
cout << "\nNo matching record found!\n";
}
// 2: Filter by name;
else if (opt == 2)
{
string reqFName, reqLName;
cout << "Name:\n";
getline(cin >> ws, reqFName);
vector<Course> matchingRecords;
for (auto i : table_manage::courseList)
{
if (i.second.courseName == reqFName)
matchingRecords.push_back(i.second);
}
cout << "\n";
cout << matchingRecords.size() << " matching record(s) found!\n";
for (auto i : matchingRecords)
i.print();
char tt = 'N';
if (matchingRecords.size() > rec)
{
do
{
int reqId;
cout << "\nEnter the ID of the required course: ";
cin >> reqId;
if (table_manage::courseList.find(reqId) != table_manage::courseList.end())
*this = table_manage::courseList[reqId];
else
{
cout << "\nInvalid ID!\nTry again? (Y = Yes || N = No)\n";
cin >> tt;
while (tt != 'Y' || tt != 'N')
cout << "Y or N?\n", cin >> tt;
}
} while (tt == 'Y');
}
}
return;
}

void Course::removeCourse()
{
cout << "\nSearch for the patient you want to discharge.\n";
getDetails();
if (courseId == -1)
return;
// if (!hospitalized)
// {
// cout << "\nPatient wasn't hospitalized, can't be discharged!\n\n";
// return;
// }
// hospital::patientsList.erase(id);
string s, temp;
stringstream str;
fstream f, fout;
str << courseId << courseName << "," << courseDetails << "\n";
getline(str, s);
f.open("./data/coursesHistory.csv", ios::in);
fout.open("./data/temp.csv", ios::out);
while (getline(f, temp))
{
if (temp == s)
{
fout << courseId << courseName << "," << courseDetails << "\n";
}
else
fout << temp << "\n";
}
f.close();
fout.close();
s.erase();
temp.erase();
remove("./data/coursesHistory.csv");
rename("./data/temp.csv", "./data/coursesHistory.csv");
cout << courseId << " " << courseName << " " << courseDetails << " deleted!\n";
return;
}
Loading

0 comments on commit bf11e4b

Please sign in to comment.