diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c6e68f8 --- /dev/null +++ b/main.cpp @@ -0,0 +1,396 @@ +#include +#include +#include +#include +#include /*libraries*/ +#include "insert_db.h" +#include "create_db.h" +#include "select_db.h" +#include "insert1_db.h" +#include "create1_db.h" +#include "select1_db.h" +#include +#include +#include +using namespace std; + +//https://github.com/haarcuba/cpp-text-table +//https://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm +class student_data{ + protected: //variables + string modules,classes, lecturers, room; + int studentID; + string name, surname, username, email, password; + string log1, pass1, startTiming, endTiming; + + public: + string get_modules(){ + return modules; + } + void change_modules(string _modules){ + modules=_modules; + } + int get_studentID(){ + return studentID; + } + void change_studentID(int _studentID){ + studentID=_studentID; + } + string get_classes(){ + return classes; + } + + void change_classes(string _classes){ + classes=_classes; + } + + string get_lecturers(){ + return lecturers; + } + void change_lecturers(string _lecturers){ + lecturers=_lecturers; + } + string get_room(){ + return room; + } + void change_room(string _room){ + room=_room; + } + + string get_surname(){ + return surname; + } + void change_surname(string _surname){ + surname=_surname; + } + string get_username(){ + return username; + } + void change_username(string _username){ + username=_username; + } + string get_email(){ + return email; + } + void change_email(string _email){ + email=_email; + } + string get_log1(){ + return log1; + } + void change_log1(string _log1){ + log1=_log1; + } + string get_pass1(){ + return pass1; + } + void change_pass1(string _pass1){ + pass1=_pass1; + } + string get_password(){ + return password; + } + void change_password(string _password){ + password=_password; + } + string get_name(){ + return name; + } + void change_name(string _name){ + name=_name; + } + string get_startTiming(){ + return startTiming; + } + void change_startTiming(string _startTiming){ + startTiming=_startTiming; + } + string get_endTiming(){ + return endTiming; + } + void change_endTiming(string _endTiming){ + endTiming=_endTiming; + } +}; + + + + + + +int dayNumber(int day, int month, int year) +{ +static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; +year -= month < 3; +return ( year + year/4 - year/100 + year/400 + t[month-1] + day) % 7; +} + +string getMonthName(int monthNumber) +{ +string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" +}; +return (months[monthNumber]); +} + +int numberOfDays (int monthNumber, int year) +{ + // January + if (monthNumber == 0) + return (31); + + // February + if (monthNumber == 1) + { + // If the year is leap then February has + // 29 days + if (year % 400 == 0 || + (year % 4 == 0 && year % 100 != 0)) + return (29); + else + return (28); + } + + // March + if (monthNumber == 2) + return (31); + + // April + if (monthNumber == 3) + return (30); + + // May + if (monthNumber == 4) + return (31); + + // June + if (monthNumber == 5) + return (30); + + // July + if (monthNumber == 6) + return (31); + + // August + if (monthNumber == 7) + return (31); + + // September + if (monthNumber == 8) + return (30); + + // October + if (monthNumber == 9) + return (31); + + // November + if (monthNumber == 10) + return (30); + + // December + if (monthNumber == 11) + return (31); +} +int showingthetimetable(){ + string Sdates; + select1_db db; + cout << "When does your term start? dd/mm/yyyy"; cin >> Sdates; + int days; + Sdates.erase(remove(Sdates.begin(), Sdates.end(), '/'), Sdates.end()); + string monthdate = Sdates.substr(2,2); + int month = stoi(monthdate); + string yeardate = Sdates.substr(4,4); + int year = stoi(yeardate); + printf (" Calendar - %d\n\n", year); + + // Index of the day from 0 to 6 + int current = dayNumber (1, month, year); + string arrayofdays[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; + cout << arrayofdays[current]; + + days = numberOfDays (month, year); + // Print the current month name + printf("\n ----------------------------------------------------%s---------------------------------------------------\n", + getMonthName (month).c_str()); + + // Print the columns + printf(" Sun Mon Tue Wed Thu Fri Sat\n"); + + // Print appropriate spaces + int k; + for (k = 0; k < current; k++) + printf(" "); + + for (int j = 1; j <= days; j++) + { + printf("%15d", j); + + if (++k > 6) + { + k = 0; + printf("\n"); + } + } + + if (k) + printf("\n"); + + current = k; + + //cout << db.printingeverything();this part doesn’t work so my lessons don’t come and i remove it do it doesn't stop the program + return 0; +}; + + + +int Timetablesforstudent(){ + student_data s; + string stringtemp; + int inttemp; + int term; + int option; + cout << "Which term are you entering lessons for? :"; cin >> term; + cout << "Welcome to term" << term << "please enter all your lessons for this term" <> inttemp; + s.change_studentID(inttemp); + cout << "What is the code of your class. :"; cin >> stringtemp; + s.change_modules(stringtemp); + cout << "The date of your class. In dd/mm/yyyy format. :"; cin >> stringtemp; + s.change_classes(stringtemp); + cout << "Who is your lecturer for this class :"; cin >> stringtemp; + s.change_lecturers(stringtemp); + cout << "What is the room number of your class:"; cin >> stringtemp; + s.change_room(stringtemp); + cout << "When is the start of your lecture. Using the 24 hours clock :"; cin >> inttemp; + s.change_startTiming(stringtemp); + cout << "When is the end of your lecture. Using the 24 hours clock :"; cin >> inttemp; + s.change_endTiming(stringtemp); + insert1_db(s.get_studentID(), s.get_modules(), s.get_classes(), s.get_lecturers(), s.get_room(), s.get_startTiming(), s.get_endTiming()); + + cout << "Do you eant another lesson enter 1 for yes or 0 for no? :"; cin >> option; + if(option == 1){ + another = true; + } + else{ + another = false; + } + showingthetimetable(); + + } + return 0; // need to return something afterwards. +} + + + +int optionafterverifying(){ + int option; + menu: + cout << "[1] Enter all of your lessons" <> option; + create1_db(); + switch(option){ + case 1: + Timetablesforstudent(); + break; + + case 2: + showingthetimetable(); + break; + }; +return 0; +} + +int login(){ + select_db db; + string log1, pass1; + cout << "Please enter your student details to Login :" <> log1; + cout << "Password :"; cin >> pass1; + + + string returnedvalue = db.matchingusername(log1); + string returnedvalue1 = db.matchingpassword(pass1); + + + if(returnedvalue == "Not In Database" && returnedvalue1 == "Not In Database"){ + cout << "Account not in the database." << endl; + login(); + }else if(returnedvalue == log1 && returnedvalue1 != pass1){ + cout << "Invalid password" << endl; + login(); + }else if(returnedvalue != log1 && pass1 == returnedvalue1 ){ + cout << "Invalid username" << endl; + login(); + }else if(returnedvalue == log1 && pass1 == returnedvalue1){ + cout << "Correct credentials. Welcome." << endl; + optionafterverifying(); + } + + +}; + + +int signup(){ + student_data s; + string stringtemp; + int inttemp; + string username, password, retry; + + cout << "Student ID :"; cin >> inttemp; + s.change_studentID(inttemp); + cout << "Name :"; cin >> stringtemp; + s.change_name(stringtemp); + cout << "Surname :"; cin >> stringtemp; + s.change_surname(stringtemp); + username = s.get_surname() + s.get_name()[0]; + s.change_username(username); + cout << "You user name is : " << username << endl; + cout << "Enter your school email :"; cin >> stringtemp; + s.change_email(stringtemp); + cout << "Password :"; cin >> password; + stringtemp = password; + s.change_password(stringtemp); + cout << "Enter Password again :"; cin >> retry; + + insert_db(s.get_studentID(), s.get_name(), s.get_surname(), s.get_username(), s.get_email(), s.get_password()); + + if (password == retry){ + cout << "Password match" << endl; + login(); + return 0; + } + else{ + cout << "Try again, password doesnt match."; + signup(); + } +}; + + +int signuporlogin(){ + int option; + + menu: + cout << "[1] Sign Up" <> option; + + switch(option){ + case 1: + signup(); + break; + + case 2: + login(); + break; + + }; + return 0; +} + +int main() { + create_db(); + signuporlogin(); + return 0; +} diff --git a/select1_db.h b/select1_db.h new file mode 100644 index 0000000..b2770cc --- /dev/null +++ b/select1_db.h @@ -0,0 +1,105 @@ +#ifndef SELECT1_DB_H +#define SELECT1_DB_H +#include +#include +#include +#include +#include +#include "libsqlite.hpp" +#include "insert1_db.h" +using namespace std; + +class select1_db +{ +protected: + std::vector modules, classes, lecturers, rooms; + std::vector studentID; + std::vector name, surname, username, email, password, startTiming, endTiming; +public: + select1_db(){ + try + { + sqlite::sqlite db("Timetable.db"); + + auto cur = db.get_statement(); + cur->set_sql("SELECT * FROM WORK"); + cur->prepare(); + + + while (cur->step()){ + modules.push_back(cur->get_text(1)); + classes.push_back(cur->get_text(2)); + lecturers.push_back(cur->get_text(3)); + rooms.push_back(cur->get_text(4)); + startTiming.push_back(cur->get_text(5)); + endTiming.push_back(cur->get_text(6)); + } + + + } + catch( sqlite::exception e ){ + cerr << e.what() << endl; + } + + } + + + std::vector get_modules(){ + select1_db(); + return modules; + } + std::vector get_classes(){ + select1_db(); + return classes; + } + std::vector get_lecturers(){ + select1_db(); + return lecturers; + } + std::vector get_rooms(){ + select1_db(); + return rooms; + } + std::vector get_startTiming(){ + select1_db(); + return startTiming; + } + std::vector get_endTiming(){ + select1_db(); + return endTiming; + } + + //this part doesn’t work so my lessons don’t come and i remove it do it doesn't stop the program + /*string printingeverything(){ + try + { + sqlite::sqlite db("Timetable.db"); + + auto cur = db.get_statement(); + cur->set_sql("SELECT * FROM Work;"); + cur->prepare(); + cur->step(); + + + string return_statement = cur->get_int(0); + + if(return_statement.empty()){ + return "NULL"; + }else{ + + return return_statement; + } + + + + } + catch( sqlite::exception e ){ + cerr << e.what() << endl; + return "Not In Database"; + } + }*/ + + +}; + +#endif \ No newline at end of file