From bf63e83c71ccd3a266546bcde31494bf38db5e6e Mon Sep 17 00:00:00 2001 From: Mihir Patel <47681434+ToadHanks@users.noreply.github.com> Date: Sun, 25 Aug 2019 20:11:26 -0400 Subject: [PATCH] Add files via upload --- Calendar_IO.cpp | 179 ++++++++++++++++++++++++++++++++++++++++ Calendar_IO.h | 52 ++++++++++++ Log_IO.cpp | 134 ++++++++++++++++++++++++++++++ Log_IO.h | 55 ++++++++++++ Menstrual_Guide.cpp | 188 ++++++++++++++++++++++++++++++++++++++++++ Menstrual_Guide.h | 44 ++++++++++ Menstrual_archive.txt | 50 +++++++++++ Period.cpp | 89 ++++++++++++++++++++ Period.h | 85 +++++++++++++++++++ main.cpp | 59 +++++++++++++ users.txt | 1 + 11 files changed, 936 insertions(+) create mode 100644 Calendar_IO.cpp create mode 100644 Calendar_IO.h create mode 100644 Log_IO.cpp create mode 100644 Log_IO.h create mode 100644 Menstrual_Guide.cpp create mode 100644 Menstrual_Guide.h create mode 100644 Menstrual_archive.txt create mode 100644 Period.cpp create mode 100644 Period.h create mode 100644 main.cpp create mode 100644 users.txt diff --git a/Calendar_IO.cpp b/Calendar_IO.cpp new file mode 100644 index 0000000..0d48035 --- /dev/null +++ b/Calendar_IO.cpp @@ -0,0 +1,179 @@ +/* + Author: Mihir K Patel + Purpose: Following is a implementation file for the CalendarIO.h. This contains function defintions + for those in its header file. Main properties of this file are: + 1) To do computation on the Date. + 2) To write a .csv format calendar to the folder, which is more readable than .txt file. + 3) Most importantly, to transfer the control from Main() using istream. +*/ +#include "Calendar_IO.h" +/*Counter*/ +short int CalendarIO::cycle_counter = 0; +/*Defaults constructor of CalendarIO*/ +CalendarIO::CalendarIO() { + month = 0; + day = 0; +} +/*Guesses the next period*/ +void CalendarIO::guess_the_day() { + for (std::vector::iterator itr = length_container.begin(); itr != length_container.end(); ++itr) { + next_cycle_guess = next_cycle_guess + *itr; + if (itr == length_container.end() - 1) { + next_cycle_guess = (static_cast(next_cycle_guess / cycle_counter)) - OFFSET_DOS; + } + } +} +/*This function shifts the date accordingly to guess_the_day() helper function*/ +void CalendarIO::adjust_day_month(int* days_arr, short int remaining_days) { + try { + if (days_arr != nullptr) { + for (int x = 0; x <= remaining_days; ++x) { /*For loop runs until the remaining days are added to the day*/ + if (day < days_arr[month - 1]) { + ++day; + } + else if ((day == days_arr[month - 1]) && (month < 12)) { + day = 1; + ++month; + } + else if ((day == days_arr[month - 1]) && (month == 12)) { + day = 1; + month = 1; + } + else { + throw (""); + } + } + } + else { throw (""); } + } + catch (...) { + std::cerr << "Date shifting failed.\n" << std::endl; + } +} +/*Writes the .csv formatted calendar to a folder*/ +void CalendarIO::write_calendar(CalendarIO & C_IO, std::string * months_arr) { + try { + srand((unsigned int)time(nullptr)); + int rand_quote = 1 + rand() % 7; + std::ofstream outputFile("VaccationPlanner.csv"); + if (outputFile.is_open() && (months_arr != nullptr)) { + /*2D vector creates a grid where months are in column and days in rows*/ + std::vector> cal_mat(32, std::vector(13)); + /*This creates the rows and columns*/ + for (size_t x = 0; x < 32; x++) { /*{Prints the rows*/ + for (size_t y = 0; y < 13; y++) { /*Prints the columns*/ + if ((x == 0) && (y > 0)) cal_mat[x][y] = " " + months_arr[y - 1]; /*Prints months*/ + else if ((y == 0) && (x > 0)) cal_mat[x][y] = std::to_string(x); /*Prints the numbers*/ + else cal_mat[x][y] = " "; + cal_mat[C_IO.day][C_IO.month] = " X,"; /*Marker to give visual representation of expected date*/ + outputFile << cal_mat[x][y] + ","; /*Comma seperates the columns*/ + } + outputFile << std::endl; + } + outputFile << C_IO.quotes_array[0] << std::endl << C_IO.quotes_array[rand_quote]; /*Prints random quote in the end*/ + outputFile.close(); + } + else { throw (""); } + } + catch (...) { + std::cerr << "File writing failed.\n" << std::endl; + } + +} +/* Output the next date using ostream overridden virtual functions*/ +std::ostream& CalendarIO::print_out(std::ostream & out) const { + out << KBCYN << "\nREMINDER!" << KNRM << std::endl << "->Next Period will be on: " << get_month() << "/" << get_day() << '\n'; + out << "->On average, Menstrual Cycle would last " << (get_next_cycle_guess() + OFFSET_DOS) << " days." << '\n'; + return out; +} +/*This istream takes in all of the necessary input from the user to give his closed-by/her next menstrual date*/ +std::istream & operator>> (std::istream & in, CalendarIO & C_IO) { + char choice = ' '; + std::string day_s = ""; + std::string cycle_len_s = ""; + for (;;) { + try { + std::cout << "Enter first day of your or your relative's last Period (mm/dd) or (mm-dd): "; + std::getline(in, day_s); + /*Takes the string of date, do the operation in its substring*/ + C_IO.month = std::stoi(day_s.substr(0, 2)); + C_IO.day = std::stoi(day_s.substr(3, 2)); + /*Input validation for the day and month*/ + if ((C_IO.month >= 1 && C_IO.month <= 31) && !isdigit(C_IO.month)) { + if ((C_IO.day >= 1 && C_IO.day <= 31) && !isdigit(C_IO.day) && (C_IO.month == 1 || C_IO.month == 3 || C_IO.month == 5 + || C_IO.month == 7 || C_IO.month == 8 || C_IO.month == 10 || C_IO.month == 12)) { + break; + } + else if ((C_IO.day >= 1 && C_IO.day <= 30) && !isdigit(C_IO.day) && (C_IO.month == 4 || C_IO.month == 6 || C_IO.month == 9 + || C_IO.month == 11)) { + break; + } + else if ((C_IO.day >= 1 && C_IO.day <= 28) && !isdigit(C_IO.day) && (C_IO.month == 2)) { break; } + else if (C_IO.day == 29 && C_IO.month == 2 && !isdigit(C_IO.day)) { break; } + else { throw (""); } + } + else { throw (""); } + } + catch (...) { + std::cerr << KBRED << "Invalid Date entry. Kindly try again." << KNRM << std::endl; + in.clear(); + } + } + /*Asks for the Menstrual Cycle days, with its normal input validation*/ + for (;;) { + try { + std::cout << "What is the usual duration (in days) between monthly Periods: "; + + while (true) { + std::getline(in, cycle_len_s); + C_IO.cycle_length = std::stoi(cycle_len_s.substr(0, 2)); + if (!isdigit(C_IO.cycle_length) && !(C_IO.cycle_length >= 20 && C_IO.cycle_length <= 40)) { throw(""); } + + C_IO.length_container.push_back(C_IO.cycle_length); + CalendarIO::cycle_counter++; + + std::cout << "Would you like to give any more of Menstrual Cycles (days between periods)?"; + choice = Period::check_choice(); + if (tolower(choice) == 'y') { + std::cout << "Ok, how many days did the Cycle before previous Cycle lasted?: "; + } + if (tolower(choice) == 'n') { break; } + in.ignore(); + } + break; + } + catch (...) { + in.clear(); + std::cerr << KBRED << "An abnormal cycle given or entry is invalid. If former, contact your primary doctor; else re-try!" << KNRM << std::endl; + } + } + /*Leap year passes the array container which is used by the adjusted_day_month() function*/ + std::cout << "Is this a Leap year?"; + choice = Period::check_choice(); + + if (tolower(choice) == 'y') { + int leap_array[] = { 31,29,31,30,31,30,31,31,30,31,30,31 }; + C_IO.guess_the_day(); + short int days_adjustment = C_IO.get_next_cycle_guess() % 366; /*Adjust the limiting condition for a for-loop and passes it below*/ + C_IO.adjust_day_month(leap_array, days_adjustment); + } + else if (tolower(choice) == 'n') { + int not_leap_array[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; + C_IO.guess_the_day(); + short int days_adjustment = C_IO.get_next_cycle_guess() % 365; + C_IO.adjust_day_month(not_leap_array, days_adjustment); + } + /*Self explanitpry, check choice, if y, write the calendar*/ + std::cout << "Finally, would you like to get a Calendar with expected Period starting date?"; + choice = Period::check_choice(); + in.ignore(); + + if (tolower(choice) == 'y') { + CalendarIO::write_calendar(C_IO, C_IO.months_array); + std::cout << KBYEL << "\nA CSV file 'VacationPlanner' has been made in patel_mihir_FP2 folder." + << "Don't forget to enable the Gridlines option in Page Layout Option when printing." << KNRM << std::endl; + } + return in; +} + +CalendarIO::~CalendarIO() { } \ No newline at end of file diff --git a/Calendar_IO.h b/Calendar_IO.h new file mode 100644 index 0000000..757c727 --- /dev/null +++ b/Calendar_IO.h @@ -0,0 +1,52 @@ +/* + Author: Mihir K Patel + Purpose: Following is a Header file for the CalendarIO.cpp. This inherits a parent class named Period.h + This contains function protypes. Few of the main prototypes are adjust_day_month(array, int), which + shifts the date to give an accurate result for the next Period. A static function + write_function(CalendarIO, array) which makes a CSV format calendar that reflects next Period with + a marker. A virtual function of overridden ostream<< that prints the results displaying date change and + expected date. Lastly, a friend function of istream>> that allows interaction with this class. +*/ +#ifndef DOT_MATE_A_GUIDE_TO_MENSTRUATION_CALENDERIO +#define DOT_MATE_A_GUIDE_TO_MENSTRUATION_CALENDERIO +#define OFFSET_DOS 2 +/*Class specific overhead*/ +#include "Period.h" +#include + +class CalendarIO :public Period +{ +private: + static short int cycle_counter; /*Counter for cycle input*/ + short int month = 0; /*Holds the month*/ + short int day = 0; /*Holds the day*/ + + std::string months_array[12]{ "January","February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December" };/*Months container*/ + /*Prints quote in the VacationPlanner.csv (comma-delimited)*/ + std::string quotes_array[8]{ "Today's, quotes:,", + "Last time, one man, said to, a woman, that she, can't fly, a plane, then she, flew one, around, the world.,", + "Men are, without, a vagina, therefore, there's, a $20B, market, for the, Sanitary, Pads.,", + "If you, want to, compare, genders, then let, me tell, you: Wo,men are, not only ,competin,g they're, beating, you!,", + "So you, were told, to shut u,p. To clos,e your eye,s & to po,p your ear,drums....,my questi,on is: Wi,ll you?,", + "My body,can be, put on, chains., But my, soul will, never be, able to, comply.,", + "God gave, us hands, to love, and to, work and, most im,portantly-, to slap, when the, need arise.,", + "Duty for, my count,ry is first, but duty, for you, comes later.," }; + + /*Pure function that guesses the next period days which would get added into date*/ + void guess_the_day(); + void adjust_day_month(int* days_arr, short int remaining_days); /*Offsets the date with next_cycle_guess*/ + + static void write_calendar(CalendarIO&, std::string* months_arr); /*Prototype for writing a calendar to folder*/ +public: + CalendarIO(); + + /*Simple getters to get the day and month*/ + int get_day() const { return day; } + int get_month() const { return month; } + + virtual std::ostream& print_out(std::ostream& out) const override; /*Prototype for ostream virtual function*/ + friend std::istream& operator>> (std::istream&, CalendarIO&); /*Prototype for istream friend function*/ + ~CalendarIO(); +}; +#endif // !DOT_MATE_A_GUIDE_TO_MENSTRUATION_CALENDERIO \ No newline at end of file diff --git a/Log_IO.cpp b/Log_IO.cpp new file mode 100644 index 0000000..3feed61 --- /dev/null +++ b/Log_IO.cpp @@ -0,0 +1,134 @@ +/* + Author: Mihir K Patel + Purpose: Following is a implementation file for the LogIO.h. This contains function defintions + for those in its header file. Main properties of this file are: + 1) To create a log file with users names. + 2) Take user names. + 3) To greet the users. + 4) To make user-specific log file +*/ +#include "Log_IO.h" +LogIO::LogIO() { /*Simple constructor*/ + original_user_name = ""; + log_file_name = ""; +} +/*Simple setter*/ +void LogIO::set_name(std::string name_para) { /*Set the name in correct format*/ + name_para.erase(std::remove_if(name_para.begin(), name_para.end(), ::isspace), name_para.end()); /*Removes the spaces*/ + transform(name_para.begin(), name_para.end(), name_para.begin(), ::tolower); /*Lowers the letters*/ + *user_name = name_para; + set_file_name(user_name); +} +/*Writes the names to file*/ +void LogIO::write_user_names(std::string user_name_para) { + std::ofstream name_file; ///--------->>>Want to make the users.txt, currently premade one exist + try { + /*t makes it refrence to current time, then *tm ptr get the time out of the system time.*/ + std::time_t t = std::time(0); + std::tm* now = std::localtime(&t); + + name_file.open("users.txt", std::ios::out | std::ios::app); + if (name_file.fail()) { throw ("Name write failed."); } + /*Prints the date::time, and then tab then name and then new line in a file*/ + name_file << (now->tm_mon + 1) << '/' << (now->tm_mday) << '/' << (now->tm_year + 1900) << "::" << (now->tm_hour) << ':' << (now->tm_min) << ' '; + name_file << user_name_para << std::endl; + + name_file.close(); + } + catch (const std::exception & e) { std::cerr << e.what() << std::endl; } ///------>>Check these since these are not stl +} +/*Writes the question to the file*/ +void LogIO::write_search(std::string search_para, std::string log_file_name_para) { + try { + std::time_t t = std::time(0); + std::tm* now = std::localtime(&t); + custom_file.open(log_file_name_para, std::ios::out | std::ios::app); //name_missing + if (custom_file.fail()) { throw ("Search write failed."); } + custom_file << (now->tm_mon + 1) << '/' << (now->tm_mday) << '/' << (now->tm_year + 1900) << "::" << (now->tm_hour); + for (int x = 0; x <= 80; ++x) { custom_file << '.'; } + search_para[0] = std::toupper(search_para[0]); + custom_file << '\n' << search_para << '?' << std::endl; //put time and dashes in another mini function before calling + custom_file.close(); + } + catch (const std::exception & e) { + std::cerr << e.what() << std::endl; + } +} +/*Writes the the search result into the user file*/ +void LogIO::write_queries(std::string queries_para, std::string log_file_name_para) { + try { + custom_file.open(log_file_name_para, std::ios::out | std::ios::app); + if (custom_file.fail()) { throw ("Query write failed."); } + custom_file << ' ' << ' ' << queries_para << std::endl; + custom_file << std::endl; + custom_file.close(); + } + catch (const std::exception & e) { + std::cerr << e.what() << std::endl; + } +} + +/*Sees if user names is in the file, if yes, return 1*/ +bool LogIO::check_returned_user(std::string user_name_para) { + try { + std::ifstream name_file; + name_file.open("users.txt", std::ios::in); + if (name_file.is_open()) { + + std::string line = ""; + std::string dummy = ""; + std::string name = ""; + while (std::getline(name_file, line)) { + std::istringstream iss(line); + if (iss >> dummy >> name) { if (name == user_name_para) { return true; } } + } + name_file.close(); + } + else { throw ("Name read failed."); } + } + catch (const std::exception & e) { std::cerr << e.what() << std::endl; } + return false; +} +/*istream take the input*/ +std::istream& operator>> (std::istream & in, LogIO & L_IO) { + + std::string local_user_name = ""; + /*Draws/ slows the console output so the bar appears as if it is loading*/ + std::cout << KBBLU << "|||" << KNRM << std::flush; L_IO.sleepcp(1000); + std::cout << KBBB << " " << KNRM << std::flush; L_IO.sleepcp(1000); + std::cout << KBBC << " " << KNRM << std::flush; L_IO.sleepcp(0100); + std::cout << KBBG << " " << KNRM << std::flush; L_IO.sleepcp(0100); + std::cout << KBBGR << " " << KNRM << std::flush; L_IO.sleepcp(0100); + std::cout << KBBR << " " << KNRM << std::flush; L_IO.sleepcp(0010); + std::cout << KBBY << " " << KNRM << std::flush; L_IO.sleepcp(0010); + std::cout << KBYEL << "|||" << KNRM << KNRM << std::flush << std::endl; L_IO.sleepcp(0010); + + do { + try { /*Asking name with validation*/ + std::cout << "\nTo begin, please type your name: "; + std::getline(in, local_user_name); + if (local_user_name.length() == 0) { throw std::invalid_argument("Type your name first."); } + else { break; } + } + catch (const std::exception & e) { in.clear(); std::cerr << e.what() << std::endl; } + } while (true); + + L_IO.original_user_name = local_user_name; + L_IO.set_name(local_user_name); /*Sets the user_name to correct format*/ + + if (L_IO.check_returned_user(*(L_IO.user_name)) == true) { /*If the name match say Welcome*/ + std::cout << "Welcome back " << local_user_name << '!' << std::endl; + L_IO.write_user_names(*(L_IO.user_name)); + } + else { + L_IO.write_user_names(*(L_IO.user_name)); + std::cout << "Hello! " << local_user_name << ". Glad you're here.\n"; + } + return in; +} +/*ostream prints the good-bye message*/ +std::ostream& operator<< (std::ostream & out, const LogIO & L_IO) { + out << KBCYN << "\nThank you, " << L_IO.original_user_name << " for using this program today!\n" << KNRM; + return out; +} +LogIO::~LogIO() { delete user_name; } //----->Do I need a copy constructor or copy assinment here??? \ No newline at end of file diff --git a/Log_IO.h b/Log_IO.h new file mode 100644 index 0000000..a5e63aa --- /dev/null +++ b/Log_IO.h @@ -0,0 +1,55 @@ +/* + Author: Mihir K Patel + Purpose: Following is a Header file for the LogIO.cpp. This is a composition class and has no inheritance. + Period.h is imported only to supply few stadard libraries, and ANSI global variables. Purpose of + this file is to get the names of the users, and to greet them back if they return. +*/ +#ifndef DOT_MATE_A_GUIDE_TO_MENSTRUATION_LOGIO +#define DOT_MATE_A_GUIDE_TO_MENSTRUATION_LOGIO +#define _CRT_SECURE_NO_WARNINGS /*Suppresses the time warning. It is VS annoying thing*/ +#include "Period.h" +#include + +#ifdef _WIN32 +#include /*This gaurd makes the delay in the console cross-platform*/ +#else +#include +#endif // WIN32 + +class LogIO +{ +private: + std::string original_user_name; + std::string log_file_name; + std::string* user_name = new std::string(); /*Used for input*/ + + bool check_returned_user(std::string user_name_para); /*Prototype to see if user has returned*/ + + void set_name(std::string name_para); /*Prototype to set name in good format*/ + void set_file_name(std::string* user_name_para) { log_file_name = *(user_name_para)+"_logs.txt"; } /*Puts the file name*/ + + static void write_user_names(std::string user_name_para); /*Prototype to write strings in correct format*/ + + friend std::istream& operator>> (std::istream& in, LogIO& L_IO); /*Prototype for input*/ + friend std::ostream& operator<< (std::ostream& out, const LogIO& L_IO); /*Prototype for output*/ +protected: + /*Ostream writeup for user inqueries*/ + std::ofstream custom_file; +public: + void write_queries(std::string queries_para, std::string log_file_name_para); + void write_search(std::string search_para, std::string log_file_name_para); + + std::string get_log_file_name() { return log_file_name; } /*Getter for file log*/ + + void sleepcp(int millisec) { /*This is a function rather than pre-built function from the header*/ +#ifdef _WIN32 + Sleep(millisec);/*Sleep() is a function of */ +#else + usleep(millisec * 1000); /*This is function of */ +#endif //WIN32 + } + + LogIO(); /*Constructor, simple*/ + ~LogIO();/*Destructor, simple*/ +}; +#endif // !DOT_MATE_A_GUIDE_TO_MENSTRUATION_LOGIO \ No newline at end of file diff --git a/Menstrual_Guide.cpp b/Menstrual_Guide.cpp new file mode 100644 index 0000000..07efe54 --- /dev/null +++ b/Menstrual_Guide.cpp @@ -0,0 +1,188 @@ +/* + Author: Mihir K Patel + Purpose: Following is a implementation file for the Menstrual_Guide.h. This contains function defintions + for those in its header file. Main properties of this file are: + 1) To give user a string from map, when he/she asks a question. + 2) To give user an ability to interact with whole program using statements (strings). + 4) To load the text file into map, so search results can occur + 5) Lastly, to display program logo, and few tips in the beginning. +*/ +#include "Menstrual_Guide.h" +/*Default constructor and a simple getter*/ +Menstrual_Guide::Menstrual_Guide() { + fuzzy_string = ""; + user_focused_file = ""; +} +std::string Menstrual_Guide::get_archive_answer() const { + return archive_answer; +} +/*Handler for the edit distance algorithmn in Period class*/ +std::string Menstrual_Guide::search_archive(std::string to_look_para) { + + load_information(); /*Loads the map at each call.*/ + std::stringstream ss; /*String stream for removing spaces*/ + std::string close_match_key = ""; + std::string close_match_value = ""; + std::string temp_data = ""; + std::string temp_key = ""; + std::string original_string = to_look_para; + original_string = Period::fix_user_string(original_string);/*Removes the numbers and punctuation marks*/ + + ss << to_look_para; /* to_look_para gets loaded into string stream*/ + to_look_para = ""; + temp_data.clear(); + while (!ss.eof()) { /*This loop copies the ss info back to temp_data without any spaces*/ + ss >> temp_data; + to_look_para = to_look_para + temp_data; + } + temp_data.clear(); + ss.clear(); + + data_string.clear(); + key_word_string.clear(); + data_string = ""; + + int levenshtein_distace = 0; + /*This for loop iterates through the map, comparing the user string to the information in the map*/ + for (std::map::iterator itr = information_map.begin(); itr != information_map.end();) { + + int* ptr = &levenshtein_distace; + + ss << itr->first; /*Key from map gets loaded into ss, and gets the space removed*/ + + key_word_string = ""; + while (!ss.eof()) { + ss >> temp_key; + key_word_string = key_word_string + temp_key; + } + temp_key.clear(); + ss.clear(); + /*These return the length of the function*/ + int curr_itr_length = strlen(key_word_string.c_str()); + int to_look_length = strlen(to_look_para.c_str()); + /*Pointers then equals to the number of edits made*/ + *ptr = did_you_mean_this(key_word_string, to_look_para, curr_itr_length, to_look_length); + /*If edits are closed, we print Value associated with its Key*/ + if (*ptr >= 0 && *ptr < 6) { + temp_data = itr->second; + L_IO.write_search(itr->first , user_focused_file); /*Writes the history in user specific text files*/ + L_IO.write_queries(temp_data , user_focused_file); + return temp_data; + } + else if (*ptr >= 6 && *ptr <= 10) { /*Gets the second most closest result/s and store them in the other map*/ + close_match_key = itr->first; + close_match_key[0] = std::toupper(close_match_key[0]); + close_match_value = itr->second; + other_possible_results[close_match_key] = close_match_value; + } + *ptr = 0; + ++itr; + } + temp_data = original_string; /*If no closest match occur, return the original user string*/ + return temp_data; +} +/*This function reads from the text file with a delimiter and loads them into a map*/ +void Menstrual_Guide::load_information() { + std::ifstream input_file("Menstrual_archive.txt", std::ios::in); + + if (input_file.is_open()) { + std::string local_line; + while (std::getline(input_file, local_line)) { /*Read line by line, and split them using delimiter*/ + std::istringstream iss(local_line); + std::getline(iss, key_word_string, '\t'); + std::getline(iss, data_string, '\n'); + information_map[key_word_string] = data_string; /*Store unique Keys and its associated unique map*/ + } + } + else { + std::cout << KBRED << "Archive file is missing, place the text file in the folder.\n" << KNRM << std::flush; + exit(0); + } + input_file.close(); +} +/*Prints the title and few tips for the program*/ +std::ostream& Menstrual_Guide::print_out(std::ostream& out) const { + + out << KBMAG << " __ __ _______ ______ \n" + " | \\/ | /\\ |__ __|| ____|\n" + " | \\ / | / \\ | | | |__ \n" + " | |\\/| | / /\\ \\ | | | __| \n" + " | | | | / ____ \\ | | | |____ \n" + " (O)|_| |_|/_/ \\_\\ |_| |______|\n" << KNRM; + out << std::setw(13); out << TBOLD << TUND << "A GUIDE TO MENSTRUATION" << TUNDO << TOFF; + out << "!\n" << std::flush; + out << TBOLD << "\nHello! At any time, you can type \"...exit...\" to end .MATE program.\n" << TOFF + << TUND << "\nFor a tailored experience make sure you are doing the following" << TUNDO << TOFF; + out << ": " << std::flush; + out << "\n[1] To check next Period, type, for e.g., \"We are planning for a vacation....\".\n" + << "[2] To find any Menstrual related information please type a question, for e.g., \"What is....\".\n" + << "[3] Use concise and complete sentences.\n" + << "[4] Avoid typing multiple questions into one sentence.\n" + << "[5] Avoid excessive spelling errors. Double checking will lead to better result.\n" + << "[6] Please use only words/letters for your queries.\n" + << "[7] Put punctuations only where they are necessary.\n" + << "[8] To report crashes, or any errors, please send them at mkpatel@mail.usf.edu\n\n" + << TBOLD << "Thanks in advance and I hope you enjoy using .MATE today!\n" << TOFF << std::endl; + + return out; +} +/*This function takes the input, makes program flow in a circular manner */ +std::istream& operator>> (std::istream& in, Menstrual_Guide& M_G) { + char choice = 'y'; + std::string temp = ""; + std::string attempt_this = ""; + + while (tolower(choice) == 'y') { + M_G.archive_answer.clear(); + M_G.key_word_string.clear(); + temp.clear(); + M_G.fuzzy_string.clear(); + + std::cout << std::flush << "\nWhat would you like to ask?: " << std::flush; + std::getline(in, temp); + attempt_this = temp; + + M_G.fuzzy_string = Period::fix_user_string(temp); /*Remove everything but only keep the letters into a string*/ + transform(M_G.fuzzy_string.begin(), M_G.fuzzy_string.end(), M_G.fuzzy_string.begin(), ::tolower); /*Turns characters to lower case*/ + M_G.archive_answer = M_G.search_archive(M_G.fuzzy_string); /*Stores the Value returned from the function above*/ + + temp.clear(); + temp = M_G.archive_answer; + transform(temp.begin(), temp.end(), temp.begin(), ::tolower); + /*strstr is a prebuilt C/C++ function that chops the string into word and compares each word with speical sentinals*/ + if ((strstr(temp.c_str(), CALENDAR)) || (strstr(temp.c_str(), CALCULATOR)) || (strstr(temp.c_str(), CALCULATE)) || + (strstr(temp.c_str(), EXIT)) || (strstr(temp.c_str(), COMPUTE)) || (strstr(temp.c_str(), VACATION)) || + (strstr(temp.c_str(), HOLIDAY)) || (strstr(temp.c_str(), HOLIDAYS)) || (strstr(temp.c_str(), TOUR)) || + (strstr(temp.c_str(), BREAK)) || (strstr(temp.c_str(), TRIP)) || (strstr(temp.c_str(), VACATION))) { + break; /*Sends the control back to main upon catching a keyword*/ + } + else { + if (M_G.fuzzy_string == temp || temp.length() <= 100) { /*If the orginal string match with the return, we display this match*/ + std::cout << KBYEL << "\nSorry, no suitable result to show at the moment." << KNRM << std::flush; + + if (M_G.other_possible_results.size() >= 0) { + if (!M_G(attempt_this)) { /*Overloaded operator/functor sees if there are anything else other than letters in the user string*/ + std::cout << KBCYN << "\nAn attempt was made to fix your input! Your input matters for a better result.\n" << KNRM; + } + for (auto& opr : M_G.other_possible_results) { /*Prints the second most matches*/ + std::cout << '\n' << opr.first << '?' << '\n' << opr.second << std::endl; + } + M_G.other_possible_results.clear();/*Clears the second buffer*/ + } + + std::cout << KBYEL << "\nWould you like you try again?" << KNRM << std::flush; + M_G.fuzzy_string.clear(); + choice = Period::check_choice(); /*Gives y or n prompts*/ + in.ignore(); + + if (tolower(choice) == 'n') { break; } + } + else { + std::cout << KBGRN << '\n' << M_G.archive_answer << KNRM << std::endl; + } + } + } + return in; +} + +Menstrual_Guide::~Menstrual_Guide() { } \ No newline at end of file diff --git a/Menstrual_Guide.h b/Menstrual_Guide.h new file mode 100644 index 0000000..6d739be --- /dev/null +++ b/Menstrual_Guide.h @@ -0,0 +1,44 @@ +/* + Author: Mihir K Patel + Purpose: Following is a Header file for the Menstrual_Guide.cpp. This inherits a parent class named Period.h + This contains function protypes. Few of the main prototypes are load_information() which reads the + text containing info, and loads them into a map data member. Then there is, search_arhive(string) which is a + part 2 of the main algorithm that gets a user his search results back. Lastly, we have a friend + function using an overloaded istream& that allows input for data members of this class, and then a + pure virtual overriden ostream << that prints aesthetics of this problem. +*/ +#ifndef DOT_MATE_A_GUIDE_TO_MENSTRUATION_MENSTRUAL_GUIDE +#define DOT_MATE_A_GUIDE_TO_MENSTRUATION_MENSTRUAL_GUIDE +#define OFFSET_UNO 1 +/*Class specific headers*/ +#include "Period.h" +#include +#include +#include +#include +#include "Log_IO.h" +class Menstrual_Guide :public Period +{ +private: + + std::map information_map; /*Stores the file data*/ + std::map other_possible_results; /*Stores closest results that weren't found*/ + + LogIO L_IO; /*Composition object to give writing functions*/ + std::string fuzzy_string; /*Holds the user search queries*/ + std::string archive_answer; /*Stores the value from Key-Value map*/ + std::string user_focused_file; /*Custom file for each user*/ + + std::string search_archive(std::string to_look_para); /*Part 2 of the searching function. This uses the did_you_mean_this() function*/ + void load_information();/*Prototypes for function that loads everything into a map*/ +public: + Menstrual_Guide(); + + void set_user_focused_file(std::string focused_file_para) { user_focused_file = focused_file_para; } + std::string get_archive_answer() const; /*Simple getter to get the value*/ + + friend std::istream& operator>> (std::istream&, Menstrual_Guide&);/*Friend overloaded istream operator prototype*/ + virtual std::ostream& print_out(std::ostream& out) const override; /*Overridden ostream virtual function prototype*/ + ~Menstrual_Guide(); +}; +#endif // !DOT_MATE_A_GUIDE_TO_MENSTRUATION_MENSTRUAL_GUIDE \ No newline at end of file diff --git a/Menstrual_archive.txt b/Menstrual_archive.txt new file mode 100644 index 0000000..86b88d1 --- /dev/null +++ b/Menstrual_archive.txt @@ -0,0 +1,50 @@ +what is a period The menstrual period (menstruation), which we commonly refer to as just a "period," is the shedding of uterine lining. Blood and endometrial tissue flow down through cervix and vagina.{reference: womenhealth.gov} +what is menstrual cycle The menstrual cycle is the monthly hormone cycle a female's body goes through to prepare for pregnancy. Woman's menstrual cycle is counted from the first day of your period up to the first day of her next period. Your hormone levels usually change throughout this cycle and can menstrual symptoms.{reference: womenhealth.gov} +how long is typical menstrual cycle The typical menstrual cycle is 28-29 days long. But each woman is different. Also, a woman's menstrual cycle length might be different from month-to-month. Your periods are still regular if they usually come every 24 to 38 days. This means that the time from the first day of your last period up to start of your next period is at least 24 days but not more than 38 days.{reference: womenhealth.gov} +why does period happen A period releases the tissue that grew to support a possible pregnancy. It happens after each menstrual cycle in the which a pregnancy does not occur-i.e. when an egg hasn't been fertilized and/or attached itself to the uterine wall. The uterous then sheds the lining which had grown to receive a fertilized egg.{reference: helloclue.com} +what is the point of getting period Period happen as a result of hormones released from a gland at the base of female brain called the pituitary gland. These hormones cause an egg to be released. At the same time, the lining of a uterous (or womb) is becoming thicker- like a soft and spongy bed, ready for the egg.{reference: helloclue.com} +can a womans period change Period can change. It can fluctuate for a while after it first start. But if a woman had her period for a few years, it should generally be about the same length and volume each cycle. She may still notice changes from time to time, though- the heaviness and length of her period depends on her hormones, which can fluctuate.{reference: helloclue.com} +what other way can a womans period change Hormones can change a woman's period temporarily because of things like stress, over-excercising, diet, or taking an emergency contraception pill.{reference: helloclue.com} +does not ovulating makes difference The period will also be different than normal if a woman don't ovulate each cycle- she may miss a period, or it may come later than usual, and/or be heavier or lighter and shorter or longer than her norm. Not ovulating regularly- anovulation- is common during adolescence and perimenopause, and is a common cause of temporarily absent and/or heavy menstrual periods.{reference: helloclue.com} +what is considered to be normal A period that happens every 24-38 days, a period that lasts between 4-8 days. A period of between 5-80 ml(that's up to 6 tablespoons). An average period sheds about 2 to 3 tablespoons of blood and tissue. Peope who are in the upper 5-6 tablespoons are considered to have heavy menstrual bleeding. Ask your partner/ friend/ relative about any problem and then talk to a doctor if the woman you know has her period- heavy (or painful) that it interferes with her daily activities. Prolonged heavy menstrual bleeding leads to anemia.{reference: helloclue.com} +what is normal amount of bleeding during my period The average woman loses about two to three tablespoons of blood during her period. Your periods may be lighter or heavier than the average amount. What is normal for you may not be the same for someone else. Also, the flow may be lighter or heavier from month to month.{reference: womenhealth.gov} +when should i see a doctor A prolonged period with heavy menstrual bleeding and painful is sign of needing medical assistance. However, ask your loved one/friend/relative if she is noticing clumps or clots especially on heaviest days and noticing changes in color of her menstrual blood over her period is normal. Darker colors are common when flow is light.{reference: helloclue.com} +how much period does one person has in one lifetime Half the population spends roughly 40 reproductive years with a menstrual cycle.That adds up about 450 periods over one person's lifetime.{reference: helloclue.com} +what is menstrual cycle The mestrual cycle is more than just a period. It's how the female body prepares to get pregnant. Hormonal changes happen on every day of the cycle, creating symptoms that are subtle (cervical fluid) and not subtle (painful cramps). Every cycle, extra blood and tissue are added to the lining of the uterus (the endometrium) and an ovary releases an egg for fertilization (ovulation). The lining of the uterus is where a fertilized egg can attach and grow. If there is no fertilized egg, or if pregnancy doesn't occur, that extra blood and tissue is expelled from the body. That's what the Period is. The period is not just blood, but also contains clots of endometrial tissue and the dissolved remnants of a tiny egg.{reference: helloclue.com} +what are premenstrual symptoms Premenstrual symptoms are a set of symptoms that repeat every month in the days before the period starts. Contrary to what pop culture tell us, premenstrual symptoms are not only about mood swing and chocolate cravings.{reference: helloclue.com} +tell me more about premenstrual symptoms Some of the obvious symptoms are : 1)Up to 88% of women experience cramps every cycle. Painful cramps can make it difficult to concentrate. 2)~60% of women get acne breakouts. 3)~70% have sore breats 4)~60% feel bloated 5)~25% have diarrhea. As for emotional symptoms, it's important to note that despire cultural messaging, not everyone's emotiopns change change when experiecing premenstrual symptoms. (Though, it stands to reason that anybody who's going through a lot of physical discomfort is likely to be grumpy). However, please note that emotional symptoms and their intensity are unique to each person, from mild, to debilitating. Try learning about the premenstrual symptoms and coping strategies of women you're close to. If they have painful cramps, for example, there may be something you can do to help out.{reference: helloclue.com} +what is normal menstrual cycle The regular cycle is 23-35 days long and may vary by as many as (+-) 8 days from month to month. The body is not a clock. Every woman's cycle is different. The heaviest bleeding is usually one of the first few days of the period, so when the period, so when the period has surprise start, it could be on the heaviest day. Menstrual cycles that fall outside of these ranges are considered clinically irregular - as are periods that very long, heavy or painful. These can show some serious medical condition. If a woman in your life, has irregular cycles, they should talk to their healthcare provider and find out why.{reference: helloclue.com} +is it true that a woman is only fertile for about 7 days every month Remember what you were taught in school, that sex on any day can lead to pregnancy? It's not true, but it's the safest thing to say when kids can't stop giggling long enough to understand the details. Even now, you may be surprised to learn that the seven-day timeframe when intercourse can lead to pregnancy (called the "fertile window") is seven days long because that's how long your sperm can live inside her body. While her egg only lives for up to 24 hours, she can still get pregnant if you have sex six days before her egg is ready(ovulation).{reference: helloclue.com} +what is ovulation It refers to a mature egg being released from the ovary. But, it takes a few steps and hormones to get there. During the first half of your cycle, multiple follicles-fluid-filled sacs containing immature eggs-grows until one emerges as dominant. Eventually, the dominant one secretes estradiol which leads to a surge in luteinizing hotmone, causing the dominant follicle to rupture, and a mature egg is released. {reference: avawomen.com} +when is the best time to get pregnant According to major studies, best chances of conceiving are highest two days before ovulation. However, counting days to determing ovulation can create risks of pregnancy when that's not wanted, or make it harder to get pregnant if you're trying.{reference: avawomen.com} +how to avoid unwanted pregnancy For men, the simple answer for cotraception is to use a condom every time and use it correctly. Find a condom that fits you well and use a bit of lube on the tip, before putting her condom on, This can help condoms be less of a turnoff. Chafting from condoms goes both ways. It's also good for you to learn where she needs lube when using condoms. Besides condoms, reliable contraceptive options for men are limited. They include getting a vasectomy, only engaging in nonintercourse sex play or just never having sex. {reference: helloclue.com} +what happens during the typical 28 day menstrual cycle Day 1 starts with the first day of period. The blood and tissue lining the uterus breaks down and leave the body. This is your period. For many women, bleeding lasts from 4 to 8 days. Hormone levels are low. Low levels of the hormone estrogen can make a woman feel depressed or irritiable. Day 1-5 of the cycle, fluid-filled pockets called follicles develop on the ovaries. Each follicle contains an egg. Day 5-7, just one folluicle continues growing while the others stop growing and are absorbed back into the ovary. Levels of the hormone estrogen from the ovaries continue rising. By Day 8 the follicle puts out incresing levels of estrogen and grows larger. Usually by Day 8, period bleeding has stopped. Higher estrogen levels from the follicle make the lining of the uterus grow and thicken. Then uterine lining is rich in blood and nutrients and will help nourish the embryo if a pregnancy happens. Estrogen helps boost endorphines, which are the "feel good" brain chemicals that are also released during physical activity. Woman may have more energy and feel relaxed or calm. Day 14, a few days before Day 14, woman's estrogen levels peak and cause a sharp rise in the level of luteinizing hormone. LH cause the mature follicle to burst and release an egg from ovary on Day 14. Day 15 to 24, the fallopian tubes help the newly released egg travel away from the ovary toward uterus. Lastly, Day 24-28 if the egg is not fertilized, it breaks apart. Around Day 24, woman's estrogen and progesterone levels drop if woman is not pregnant. This rapid change in the levels of strogen and progesterone can cause woman's moods to change. In the final step of the menstrual cycle, the unfertilized egge leaves the body along with the uterine linig, beginning on Day 1 of woman's next period and menstrual cycle. {reference: womenhealth.gov} +what is luteinizing hormone LH is a hormone released by woman's brain that tells the ovary to release an egg.{reference: womenhealth.gov} +how does my menstrual cycle change as woman gets older Often, periods are heavier when a woman's younger (in her teens) and usually get lighter in her 20s and 30s. This is normal. For few years after her first period, menstrual cycles longer than 30 days are common. Girls usually get more regular cycles within three years of starting their periods. If longer or irregular cycles last beyond that, see you doctor. In her 20s and 30s, womans cycles are usually regular and can last anywhere from 24 to 38 days. In her 40s, as her body starts the transition to menopause, her cycles might become irregular. Woman's menstrual periods might stop for a month or few months and then start again. They also might be shorter or last longer than usual, or be lighter or heavier than normal. {reference: womenhealth.gov} +why should i keep track of my menstrual cycle If your periods are regular tracking them will help you know when you ovulate, when you are most likely to get pregnant, and when to expect your next period to start. If your periods are not regularm tracking them can help you share any problems with your doctor or nurse. Finally, if you have period pain or bleeding that causes you to miss school or work, tracking these period symptoms will help you and your doctor or nurse find treatments that work for you. Sever pain or bleeding that causes you to miss regular activities is not normal and can be treated. {reference: womenhealth.gov} +when does a girl usually get her first period The average age for a girl in the United States to get her first period is 12. This doesn't mean that all girls start at same age. A girl may start her period anytime between 8 and 15. The first period normally starts about two years after breasts first start to develop and pubic hair begins to grow. The age at which a girl's mother started her period can help predict when a girl may start her period.{reference: womenhealth.gov} +when should a girl see a doctor A girl should see her doctor if: 1) she starts her period before age 8. 2) She has not had her first period by age 15. 3) She has not had first period within three years of breasts growth {reference: womenhealth.gov} +how long does a woman usually have periods On average, women get a period for about 40 years of their life. Most women have regular periods until premenopause, the time when your body begins the change to menopause. Perimenopause, or transition to menopausem may take a few years. During this time your period may not come regularly.{reference: womenhealth.gov} +when does menopause happen Menopause happen when you have not had a period for 12 months in a row. For most women, this happens between the ages of 45 and 55. The average age of menopause in in the United States is 52.{reference: womenhealth.gov} +does period stops during pregnancy Yes, period also stop during pregnancy and may not come back right away if you breastfeed.{reference: womenhealth.gov} +what are symptoms of heavy menstrual bleeding Symptoms of heavy menstrual bleeding include: 1) Bleeding through one or more pads or tampons every one to two hours. 2) Passing blood clots longer than the size of quarters. 3) Bleeding that often lasts longer than eight days. {reference: womenhealth.gov} +how often should i change my pad or tampon Follow the instructions that came with your period product. Try to change or rinse your feminine hygiene product before it becomes soacked through or full. For pads, most women change their pads every few hours. A tampon should not be worn for more than 8 hours because of the risk of toxic shock syndrome(TSS).{reference: womenhealth.gov} +how often should i change menstrual cup, sponge or period panties Follow the instructions that came with your period product. Try to change or rinse your feminine hygiene product before it becomes soacked through or full. Menstrual cups and sponges may only need to be rinsed once or twice a day. Period panties (underwear with washable menstrual pads sewn in) can usually last about a day, depending on the style and your flow. Follow the instructions that came with your period product. Try to change or rinse your feminine hygiene product before it becomes soacked through or full.Follow the instructions that came with your period product. Try to change or rinse your feminine hygiene product before it becomes soacked through or full.{reference: womenhealth.gov} +what is toxic shock syndrome TSS is a rare but sometimes deadly condition caused by bacteria that make toxins or poisons.{reference: womenhealth.gov} +can tampons cause toxic shock syndrome In old days there was a certain brand of super absorbency tampons which said to cause this, and they were taken off the market. Today, mosts cases of TSS are not caused by tampons as they were uses to. But, you could be at risk for TSS if you use more absorbent tampons than you need for your bleeding or if you don't change your tampon often enough (at least every eight hours). Menstrual cups, cervical caps and songes are also known to increrase the risk of TSS if they're left in place for too long (usually 24 hours). Remove sponges within 30 hours and cervical caps within 48 hours.{reference: womenhealth.gov} +are pads better than tampons Unlike tampons, pads aren't associated with toxic shock syndrome. They can however, still put you at risk for other infections if not changed at a resonable rate.{reference: womenhealth.gov} +what are symptoms of toxic shock syndrome or tss Symptoms of TSS are 1) Sudden high fever 2) Muscle aches 3) Vomiting 4) Nausea 5) Diarrhea 6) Rash 7) Kidney or other organ faliure.{reference: womenhealth.gov} +how does the menstrual cycle affect other health problems The changing hormone levels throughout the menstrual cycle can also affect other health problems. Depressions and anxiety disorders, Asthma, Irritable bowel syndrome(IBS) and Bladder pain syndrome are most common among women. Please don't hesitate to seek medical help if you have any health related issues.{reference: womenhealth.gov} +what is menopause phase Menopause is a normal condition that all women experience as they age. The term menopause can describe any of the the changes a woman goes through either just before or after she stops menstruating, making the end of her reproductive period.{reference: webmd.com} +what causes menopause Menopause happens when the ovaries no longer release an egg every month and menstruation stops.{reference: webmd.com} +what is perimenopause phase Perimenopause typically begins several years before menopause, when the ovaries gradually make less estrogen. +what is progesterone hormone Progesterone is an endrogenous steroid and progesterone sex hormone involved in the menstrual cycle, and pregnancy. {reference: womenhealth.gov} +what is estrogen hormone Estrogen or oestrogen is the primary female sex hormone. It is responsible for the development and regulation of the female reproductive system and secondary sex characteristics.{reference: womenhealth.gov} +what is premenstrual syndrome or pms PMS is a combination of physical and emotional symptoms that many women get after ovulation and before the start of their menstrual period. As many is three in four women say they get PMS at some point of their lifetime.{reference: womenhealth.gov} +does pms change with age Yes, PMS may get worse as you reach your late 30s or 40s and approach menopause are in the transition to menopause, called perimenopause.{reference: womenhealth.gov} +what causes pms Researchers do not know exactly what causes PMS. Changes in hormone levels durting the menstrual cycle may play a role. {reference: womenhealth.gov} +what is premenstrual dysphoric disorder or pmdd PMDD is a condition similar to PMS that also happens in the weekor two before your period starts as hormone levels begin to fall after ovulation. PMDD causes more severe symptoms than PMS, including severe depression, irritiablilty, and tension.{reference: womenhealth.gov} +which type of food to avoid during period Avoid eating and drinking carbonated drinks, excess sugar & salt, too-much processed foods, fried foods, and high-fat foods since they can adversely affect your ongoing cycle. Instead of these, choose fruits and vegetables or fish. {reference: byrdie.com} +what to do when i get my first period Don't worry! Tell a parent, friend, or teacher. Adults or older siblings can help you get the right informaion and products you need. {reference: rubycup.com} +will anyone know i am on my period Unless you decide to tell, it's very unlikely anybody else will know that you are on your period. Be sure to wear a safe menstrual product, like a menstrual cup and no one will be able to tell you're menstruating. However, it is a good idea to ask a family or a friend for help if you feel worried. NEVER FEEL ASHAMED OF YOUR PERIOD! {reference:rubycup.com} +can i go swimming or play sports Yes! some menstrual products let you excercise, swim, and play sports as usual. One of the products becoming more and more popular among active menstruating people are menstrual cups. {reference:rubycup.com} diff --git a/Period.cpp b/Period.cpp new file mode 100644 index 0000000..eab6f0d --- /dev/null +++ b/Period.cpp @@ -0,0 +1,89 @@ +/* + Author: Mihir K Patel + Purpose: Following is an implementation file for the Period.h. This contains function defintions + for those in its header file. Main properties of this file are: + 1) To apply prebuilt function of C++ to remove numbers and punctutations in a user string. + 2) To check y-n options with a local try_catch block. + 3) To have a helper function that uses recursion to return the min using C++ built-in function. + 4) Finally, an algorithmn that inserts, delete, or replace a character of two strings to make them equal. +*/ +#include "Period.h" +/*Default constructor for Period class*/ +Period::Period() { + cycle_length = 0; + next_cycle_guess = 0; + data_string = ""; + key_word_string = ""; +} +/*These functions are lambda expressions, the underlying function is built-in C++. And are + imported using overhead*/ +std::string Period::fix_user_string(std::string user_string_para) { + + user_string_para.erase(std::remove_if(user_string_para.begin(), + user_string_para.end(), + [](unsigned char c) { return std::ispunct(c); }), + user_string_para.end()); + + user_string_para.erase(std::remove_if(user_string_para.begin(), + user_string_para.end(), + [](unsigned int i) { return std::isdigit(i); }), + user_string_para.end()); + + return user_string_para; +} +/*Invalid check for y or n input. Contains the exception to handle any error*/ +char Period::check_choice() { + char y_n_para = ' '; + for (;;) {//---------->>>Just know that therer is a garbage ifyou put in yfghfhghg or ndfgfdgdfgd + try { + std::cout << "\nPlease specify your choice (Y or N): "; + std::cin >> y_n_para; + + if (!std::cin.fail() && (tolower(y_n_para) != 'y') && (towlower(y_n_para) != 'n')) { + throw std::invalid_argument("Wrong Choice given. Kindly try again."); + } + else { break; } + } + catch (const std::invalid_argument & p) { + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + std::cerr << KBRED << p.what() << KNRM << std::endl; + } + } + return y_n_para; +} +/*Helper function for did_you_mean_this() function that returns the minimum value between the three parameters*/ +int Period::distance(size_t upper, size_t diagonal, size_t lower_right) { + return std::min(std::min(upper, diagonal), lower_right); /*Calls recursively*/ +} +/*This is also known as Levenshtein Distance/Edit Distance. The basic functionality of this algorithmn is to + find the minimum edits (insert, remove, replace a character) in two strings to make them equal*/ +int Period::did_you_mean_this(std::string itr_para, std::string to_look_para, size_t itr_len_para, size_t to_look_len_para) { + + /*2-D dynamic container that puts header info on stack but allocates the elements on the heap*/ + std::vector > edits_grid(itr_len_para + 1, std::vector(to_look_len_para + 1)); + + /*Nested for loops, locks a character and then compares that chracter to every chracter of the second string*/ + for (size_t x = 0; x <= itr_len_para; ++x) { + for (size_t y = 0; y <= to_look_len_para; ++y) { + + /*If the length of any string becomes null, set amount of edits made to make two strings equal*/ + if (x == 0) { edits_grid[x][y] = y; } + else if (y == 0) { edits_grid[x][y] = x; } + + /*If last elements are same, don't do any operation, simply decrement the string*/ + else if (itr_para[x - 1] == to_look_para[y - 1]) { + edits_grid[x][y] = edits_grid[x - 1][y - 1]; + } + + /*If characters at an index are different use the helper function to either do an Insert, Replace, or Remove so + the current substring is equal to the other string, and add one, because an operation is performed*/ + else { + edits_grid[x][y] = 1 + distance(edits_grid[x][y - 1], edits_grid[x - 1][y], edits_grid[x - 1][y - 1]); + } + } + } + return edits_grid[itr_len_para][to_look_len_para]; /*After recursion is over, simply return the number of edits*/ +} + +Period::~Period() { } \ No newline at end of file diff --git a/Period.h b/Period.h new file mode 100644 index 0000000..588d3ba --- /dev/null +++ b/Period.h @@ -0,0 +1,85 @@ +/* + Author: Mihir K Patel + Purpose: Following is an Abstract parent class of CalendarIO.h, and Menstrual_Guide.h and a Header file for the Period.cpp. + This class provides important data members and member functions which are mind of this OOP project. + Some of the immportant member functions are fix_user_string(string) which removes the numbers and punctuation marks; + check_choice(), checks the entry of Y or N, distance(int, int, int), a helper-recursive function which calculates the + minimum for array values passed in until the condition in the did_you_mean_this(string, string, size_t, size_t) function + return the total numbers of edits. did_you_mean_this(string, string, size_t, size_t) is the edit distace algorithm, + which finds the minimum distance for strings the user put in, and the string that iterator point to in map in subclass + Menstrual_guide.h. Lastly there is a pure virtual ostream>> operator which gives each class an ability to + print their own local ostream>> using Period.h's data members. +*/ +#ifndef DOT_MATE_A_GUIDE_TO_MENSTRUATION_PERIOD +#define DOT_MATE_A_GUIDE_TO_MENSTRUATION_PERIOD +/*These are ANSI color schemes*/ /***CLANG_SPECIFIC***/ +#define KNRM "\x1b[0m" +#define KBRED "\x1b[91m" +#define KBGRN "\x1b[92m" +#define KBYEL "\x1b[93m" +#define KBMAG "\x1b[95m" +#define KBBLU "\x1b[94m" +#define KBCYN "\x1b[96m" +#define KBBR "\x1b[101m" +#define KBBG "\x1b[102m" +#define KBBY "\x1b[103m" +#define KBBB "\x1b[104m" +#define KBBC "\x1b[106m" +#define KBBW "\x1b[107m" +#define KBBGR "\x1b[100m" +/*These are ANSI text effects*/ /***CLANG_SPECIFIC***/ +#define TBOLD "\x1b[1m" +#define TUND "\x1b[4m" +#define TUNDO "\x1b[24m" +#define TOFF "\x1b[0m" +/*Global constants, and a sentinal- exit*/ +#define CALCULATOR "calculator" +#define CALCULATE "calculate" +#define EXIT "exit" +#define CALENDAR "calendar" +#define COMPUTE "compute" +#define HOLIDAYS "holidays" +#define HOLIDAY "holiday" +#define VACATION "vacation" +#define BREAK "break" +#define TRIP "trip" +#define TOUR "tour" +/*Appropriate overhead that supply C++ functions to one or more classes*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class Period { +protected: + short int cycle_length; /* Stores the Menstrual cycle length*/ + short int next_cycle_guess; /*Gives the result after calculations*/ + std::string data_string; /*This stores the value string from the map*/ + std::string key_word_string; /*This stores the key string from the map*/ +public: + std::vector length_container; /*Contains all of the lengths, if user decides to put in*/ + + Period(); + + int get_next_cycle_guess() const { return next_cycle_guess; } /*Getter for next_cycle_guess which returns the date expected date need to be shifted*/ + + static std::string fix_user_string(std::string user_string_para); /*Function prototype to set string to letters only*/ + static char check_choice(); /*Input validation prototypes for yes or no*/ + bool operator() (std::string& str_para) { return std::all_of(str_para.begin(), str_para.end(), ::isalpha); } /*Overloded check for letters in string*/ + + int distance(size_t upper, size_t diagonal, size_t lower_right); /*Helper function using recursion- a prototype.*/ + int did_you_mean_this(std::string itr_para, std::string to_look_para, size_t itr_len_para, size_t to_look_len_para); /*Edit algorithmn prototype*/ + + virtual std::ostream& print_out(std::ostream& out) const = 0;/*Pure virtual function prototype*/ + friend std::ostream& operator<< (std::ostream& left, const Period& right) { /*A friended helper function for this pure virtual ostream&*/ + return right.print_out(left); + } + ~Period(); +}; +#endif // !DOT_MATE_A_GUIDE_TO_MENSTRUATION_PERIOD \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..f5fe064 --- /dev/null +++ b/main.cpp @@ -0,0 +1,59 @@ +/* + Author: Mihir K. Patel (COP 3331-s) + Purpose: Following program is meant to be serve as an information tool for Menstruation. The user + has an offline repository where he/she can find information about that. User may also + calculate her/his-relative's Period and get a calendar for a visual reminder. + This program is NOT IN ANY WAY exclusively made for particular audience, everyone is more + than welcome to use it! + + This is a Driver file, it is dependant on CalendarIO.h, and Menstrual_Guide.h +*/ +#include "Menstrual_Guide.h" +#include "Calendar_IO.h" +#include "Log_IO.h" +int main() +{ + CalendarIO cal_io; /*Class objects*/ + Menstrual_Guide menstrual_guide; + LogIO log_io; + + try + { + std::cout << menstrual_guide; /*Virtual function allows to output*/ + std::cin >> log_io; + menstrual_guide.set_user_focused_file(log_io.get_log_file_name()); + + beginning: + std::string guide_response = ""; + guide_response.clear(); + std::cin >> menstrual_guide; /*Overloaded istream allows the input from the user*/ + + guide_response = menstrual_guide.get_archive_answer(); /* Sets the answer here and sees if any unique transfer keys are present*/ + transform(guide_response.begin(), guide_response.end(), guide_response.begin(), ::tolower); + + while (!(strstr(guide_response.c_str(), EXIT))) { + if ((strstr(guide_response.c_str(), CALENDAR)) || (strstr(guide_response.c_str(), CALCULATOR)) || + (strstr(guide_response.c_str(), CALCULATE)) || (strstr(guide_response.c_str(), HOLIDAY)) || + (strstr(guide_response.c_str(), COMPUTE)) || (strstr(guide_response.c_str(), HOLIDAYS)) || + (strstr(guide_response.c_str(), TOUR)) || (strstr(guide_response.c_str(), BREAK)) || + (strstr(guide_response.c_str(), TRIP)) || (strstr(guide_response.c_str(), VACATION))) { + std::cin >> cal_io; /*If any keywords are present related to CalendarIO class, CalendarIO gets invoke*/ + std::cout << cal_io; /*Prints the Period date*/ + } + else { + std::cout << TBOLD << "\nPlease type \"...exit...\" to end this program." << TOFF << std::endl; + } + goto beginning; /*Jumps in the beginning to allow circular interaction*/ + } + std::cout << log_io; + std::cout << TBOLD << "\nLeave feedback/comments to mkpatel@mail.usf.edu for any improvements :)\n" + << "For collaboration use the email above. If you would like to reuse any code, feel free to do so!\n" << TOFF << std::endl; + } + catch (...) { + std::cerr << "Please report this crash to mkpatel@mail.usf.edu. In the email do tell what have you done " + << "prior to the program crash. Sorry for this inconvenience.\n"; + exit(0); + } + + return 0; +} \ No newline at end of file diff --git a/users.txt b/users.txt new file mode 100644 index 0000000..d3f5a12 --- /dev/null +++ b/users.txt @@ -0,0 +1 @@ +