Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- #include <cstring>
- #include <stdlib.h> //for exit() function
- #include <fstream> //for creating text file
- using namespace std;
- int total = 0;
- int bookingNo = 0;
- class Reservation{
- private:
- int bookingNo;
- string name;
- int phoneNo;
- int paxNo;
- int day;
- int month;
- int year;
- int time;
- int date;
- long dateAndTime;
- public:
- Reservation(){
- bookingNo = 1;
- name = "Tan Phit Huan";
- phoneNo = 0123456777;
- paxNo = 1;
- day = 1;
- month = 1;
- year = 2019;
- time = 1500;
- date = 20190101;
- dateAndTime = 201910201649;
- }
- Reservation(int bNo, string na, int phNo, int pxNo, int d, int mon, int y, int t,int da, long dNt){
- bookingNo = bNo;
- name = na;
- phoneNo = phNo;
- paxNo = pxNo;
- day = d;
- month = mon;
- year = y;
- time = t;
- date = da;
- dateAndTime =dNt;
- }
- void setBookingNo(int bNo){
- bookingNo = bNo;
- }
- int getBookingNo(){
- return bookingNo;
- }
- void setName(string na){
- name = na;
- }
- string getName(){
- return name;
- }
- void setPhoneNo(int phNo){
- phoneNo = phNo;
- }
- int getPhoneNo(){
- return phoneNo;
- }
- void setPaxNo(int pxNo){
- paxNo = pxNo;
- }
- int getPaxNo(){
- return paxNo;
- }
- void setDay(int d){
- day = d;
- }
- int getDay(){
- return day;
- }
- void setMonth(int m){
- month = m;
- }
- int getMonth(){
- return month;
- }
- void setYear(int y){
- year = y;
- }
- int getYear(){
- return year;
- }
- void setTime(int t){
- time = t;
- }
- int getTime(){
- return time;
- }
- void setDate(int da){
- date = da;
- }
- int getDate(){
- return date;
- }
- void setDateAndTime(long dNt){
- dateAndTime = dNt;
- }
- long getDateAndTime(){
- return dateAndTime;
- }
- };
- class linklist{
- private:
- struct node{
- Reservation info;
- node *link;
- }*head;
- public:
- linklist(){
- head=NULL;
- }
- void InsNewNode(int bNo, string na, int phNo, int pxNo, int d, int mon, int y, int t, long dNt){
- node*newNode = new node;
- node*p,*q = head;
- newNode -> info.setBookingNo(bNo);
- newNode -> info.setName(na);
- newNode -> info.setPhoneNo(phNo);
- newNode -> info.setPaxNo(pxNo);
- newNode -> info.setDay(d);
- newNode -> info.setMonth(mon);
- newNode -> info.setYear(y);
- newNode -> info.setTime(t);
- newNode -> info.setDateAndTime(dNt);
- //If no records
- if (head == NULL){
- head = newNode;
- return;
- }
- //Insert at the start of list
- if (head -> info.getDateAndTime() > newNode -> info.getDateAndTime()){
- newNode -> link = head;
- head = newNode;
- return;
- }
- while(q->info.getDateAndTime() < newNode -> info.getDateAndTime() && q->link != NULL){
- p = q;
- q = q->link;
- }
- //Insert at the end of the list
- if(q == NULL){
- q = newNode;
- newNode-> link = NULL;
- return;
- //Insert in the middle of the list
- }else{
- p = q;
- q = q->link;
- p->link = newNode;
- newNode-> link = q;
- return;
- }
- }
- void deleteNode(int bNo){
- node *current;
- current = head;
- while (current != NULL){
- if(bNo == current->info.getBookingNo()){
- if(current == head){
- node*temp = head;
- head = head -> link;
- delete temp;
- }else if(current->link == NULL){
- node*p, *q = head;
- while(q -> link != NULL){
- p = q;
- q = q -> link;
- }
- p->link = NULL;
- delete q;
- }else{
- node*p, *q = head;
- while(q -> info.getBookingNo() != bNo){
- p = q;
- q = q -> link;
- }
- p -> link = q ->link;
- delete q;
- }
- }
- current = current->link;
- }
- total--;
- }
- void PrintList(){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- current = current->link;
- }
- cout<<endl;
- }
- void PrintBookingNoRecords(int bNo){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- //If there is any reservation with the same name
- if(bNo == current->info.getBookingNo()){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- }
- current = current->link;
- }
- cout<<endl;
- }
- void PrintNameRecords(string name){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- //If there is any reservation with the same name
- if(name == current->info.getName()){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- }
- current = current->link;
- }
- cout<<endl;
- }
- void PrintDateRecords(int date){
- node *current;
- current = head;
- cout<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- //If there is any reservation with the same date
- if(date == current->info.getDate()){
- cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- }
- current = current->link;
- }
- cout<<endl;
- }
- void PrintListTextFile(){
- string fileName;
- int count = 0;
- cout << "---------------=CREATE TEXT FILE=---------------" << endl;
- //Create file with the file name user entered
- cout << "Enter file name: ";
- cin >> fileName;
- cout << "Your .txt file can be found in the same folder where your .cpp file is saved." << endl;
- fileName = fileName + ".txt";
- //output to .txt file
- ofstream file(fileName.c_str());
- if (file.is_open()) {
- //output all the reservation records
- node *current;
- current = head;
- file<<setfill(' ')<<setw(5)<<"| No. "
- <<left<<setw(30)<<"Name"
- <<setw(5)<<"Phone No."
- <<right<<setw(16)<<"Pax No."
- <<setw(10)<<"Date"
- <<setw(16)<<"Time |"<<endl
- <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
- while (current != NULL){
- count++;
- file<<"| "<<setfill(' ')<<count<<" "
- <<left<<setw(30)<< current->info.getName()
- <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
- <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
- <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
- <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
- current = current->link;
- }
- file.close(); //close file
- }
- }
- bool checker(int bNo){
- node *current;
- current = head;
- while(current != NULL){
- if(bNo == current->info.getBookingNo()){
- return true;
- }
- current = current->link;
- }
- return false;
- }
- };
- linklist RList;
- void addRecord();
- void updateRecord();
- void deleteRecord();
- void viewRecord();
- void createTextFile();
- bool checkYear();
- bool checkMonth();
- int main() {
- char choice;
- cout << "===============RESTAURANT RESERVATION SYSTEM===============" << endl;
- cout << "Please enter your selection" << endl <<
- "1. Add Reservation Records" << endl <<
- "2. Update Reservation Records" << endl <<
- "3. Delete Reservation Records" << endl <<
- "4. View Reservation Records " << endl <<
- "5. Create text file" << endl <<
- "6. Exit" << endl;
- cout << "Choice: ";
- cin >> choice;
- cin.clear();
- cin.ignore(1, '\n');
- system("CLS");
- switch (choice) {
- //Add Records
- case '1':
- addRecord();
- break;
- //Update Records
- case '2':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- updateRecord();
- break;
- //Delete Records
- case '3':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- deleteRecord();
- break;
- //View Reservation Records
- case '4':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- viewRecord();
- break;
- //Create Text File
- case '5':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- createTextFile();
- break;
- case '6':
- exit(1);
- break;
- default:
- cout << choice << " is not valid choice" << endl;
- main();
- }
- return 0;
- }
- bool checkName(string name);
- bool checkYear(int year);
- bool checkMonth(int month, int year);
- bool checkDay(int day, int month, int year);
- bool checkTime(int time, int day, int month, int year);
- //OPTION 1 : Add Reservation Records
- void addRecord(){
- string name;
- int phoneNo, paxNo, day, month, year, time;
- long dateAndTime;
- int length;
- int correct = 1;
- cout << "-----------------=ADD RECORD=-------------------" << endl;
- cout<<"Enter 0 to return to main menu."<<endl;
- do{
- cout<<"Enter name : ";
- getline(cin, name);
- }while(!checkName(name));
- if(name=="0"){
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
- cin>>phoneNo;
- correct = 1;
- while (correct == 1){
- length = to_string(phoneNo).length();
- if (cin.fail() || phoneNo<0 || length>11){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 11 digits)!" << endl<<endl;
- cout<< "Enter phone number (e.g : 0123456789) : ";
- cin >> phoneNo;
- }else{
- correct = 0;
- }
- }
- correct = 1;
- cout<<endl<<"Enter number of pax (maximum : 50) : ";
- cin>>paxNo;
- while (correct == 1){
- if (cin.fail() || paxNo<0 || paxNo > 50){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum : 50)!" << endl<<endl;
- cout<< "Enter number of pax (maximum : 50) : ";
- cin >> paxNo;
- }else{
- correct = 0;
- }
- }
- correct = 1;
- do{
- cout<<endl<<"Enter year (e.g : 2019): ";
- cin>>year;
- while (correct == 1){
- if (cin.fail() || year > 2021){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
- cout<< "Enter year (e.g : 2019) : ";
- cin >> year;
- }else{
- correct = 0;
- }
- }
- }while(!checkYear(year));
- correct = 1;
- do{
- cout<<endl<<"Enter month (e.g : January = 1) : ";
- cin>>month;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter month (e.g : January = 1) : ";
- cin >> month;
- }else{
- correct = 0;
- }
- }
- }while(!checkMonth(month, year));
- correct = 1;
- do{
- cout<<endl<<"Enter day : ";
- cin>>day;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter day : ";
- cin >> day;
- }else{
- correct = 0;
- }
- }
- }while(!checkDay(day, month, year));
- do{
- cout<<endl<<"Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin>>time;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 4 digits)!" << endl<<endl;
- cout<< "Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin >> time;
- }else{
- correct = 0;
- }
- }
- }while(!checkTime(time, day, month, year));
- bookingNo++;
- cout<<endl<<"Booking Number : "<<bookingNo<<endl;
- //for inserting the node in order according to date and time
- dateAndTime = year*100000000 + month*1000000 + day*10000 + time;
- RList.InsNewNode(bookingNo, name, phoneNo, paxNo, day, month, year, time, dateAndTime);
- total++;
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- //OPTION 2 : Update Reservation Records
- void updateRecord(){
- string name;
- int bNo, phoneNo, paxNo, day, month, year, time;
- long dateAndTime;
- int length;
- int correct = 1;
- cout << "----------------=UPDATE RECORD=-----------------" << endl;
- cout<<"Enter 0 to return to main menu."<<endl;
- cout << "Enter Booking Number : ";
- cin >> bNo;
- if(bNo == 0){
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- if(RList.checker(bNo)){
- cin.clear();
- cin.ignore(1000, '\n');
- cout<<"Enter name : ";
- getline(cin, name);
- cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
- cin>>phoneNo;
- correct = 1;
- while (correct == 1){
- length = to_string(phoneNo).length();
- if (cin.fail() || phoneNo<0 || length>11){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 11 digits)!" << endl<<endl;
- cout<< "Enter phone number (e.g : 0123456789) : ";
- cin >> phoneNo;
- }else{
- correct = 0;
- }
- }
- correct = 1;
- cout<<endl<<"Enter number of pax (maximum : 50) : ";
- cin>>paxNo;
- while (correct == 1){
- if (cin.fail() || paxNo<0 || paxNo > 50){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum : 50)!" << endl<<endl;
- cout<< "Enter number of pax (maximum : 50) : ";
- cin >> paxNo;
- }else{
- correct = 0;
- }
- }
- correct = 1;
- do{
- cout<<endl<<"Enter year (e.g : 2019): ";
- cin>>year;
- while (correct == 1){
- if (cin.fail() || year > 2021){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
- cout<< "Enter year (e.g : 2019) : ";
- cin >> year;
- }else{
- correct = 0;
- }
- }
- }while(!checkYear(year));
- correct = 1;
- do{
- cout<<endl<<"Enter month (e.g : January = 1) : ";
- cin>>month;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter month (e.g : January = 1) : ";
- cin >> month;
- }else{
- correct = 0;
- }
- }
- }while(!checkMonth(month, year));
- correct = 1;
- do{
- cout<<endl<<"Enter day : ";
- cin>>day;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter day : ";
- cin >> day;
- }else{
- correct = 0;
- }
- }
- }while(!checkDay(day, month, year));
- do{
- cout<<endl<<"Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin>>time;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 4 digits)!" << endl<<endl;
- cout<< "Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin >> time;
- }else{
- correct = 0;
- }
- }
- }while(!checkTime(time, day, month, year));
- //for inserting the node in order
- dateAndTime = year*100000000 + month*1000000 + day*10000 + time;
- RList.InsNewNode(bNo, name, phoneNo, paxNo, day, month, year, time, dateAndTime);
- cout<<"Update process complete."<<endl;
- }else{
- cout<<"No existing record with that booking number."<<endl
- <<"Update process cancelled."<<endl;
- }
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- //OPTION 3 : Delete Reservation Records
- void deleteRecord(){
- int bNo;
- char confirm;
- cout << "----------------=DELETE RECORD=-----------------" << endl;
- cout<<"Enter 0 to return to main menu."<<endl;
- cout<<"Enter Booking Number : ";
- cin>>bNo;
- if(bNo == 0){
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- if(RList.checker(bNo)){
- RList.PrintBookingNoRecords(bNo);
- cout<<"Confirm?(y/n) : ";
- cin>>confirm;
- switch (confirm) {
- case 'y':
- RList.deleteNode(bNo);
- cout<<"Deletion process complete."<<endl;
- break;
- default:
- cout<<"Deletion process cancelled."<<endl;
- main();
- }
- }else{
- cout<<"No existing record with that booking number."<<endl;
- }
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- //OPTION 4 : View Reservation Records
- void viewRecord(){
- char choice;
- string name;
- int bNo, year, month, day, date;
- cout << "-----------------=VIEW RECORD=------------------" << endl;
- cout << "Please enter your selection" << endl <<
- "1. View All Reservations" << endl <<
- "2. Search by Booking Number"<< endl <<
- "3. Search by Name" << endl<<
- "4. Search by Date"<< endl <<
- "5. Back to Main Menu"<< endl;
- cout << "Choice: ";
- cin >> choice;
- cin.clear();
- cin.ignore(1, '\n');
- system("CLS");
- switch (choice) {
- //View All Reservations
- case '1':
- RList.PrintList();
- break;
- case '2':
- cout<<"Enter Booking Number : ";
- cin>>bNo;
- RList.PrintBookingNoRecords(bNo);
- break;
- //Search by Name
- case '3':
- cout<<"Enter Name : ";
- getline(cin, name);
- RList.PrintNameRecords(name);
- break;
- case '4':
- cout<<"Enter year (e.g : 2019) : ";
- cin>>year;
- cout<<"Enter month (e.g : January = 1) : ";
- cin>>month;
- cout<<"Enter day : ";
- cin>>day;
- date = year*10000 + month*100 + day;
- RList.PrintDateRecords(date);
- break;
- case '5':
- main();
- break;
- default:
- cout << choice << " is not valid choice" << endl;
- viewRecord();
- }
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- //OPTION 5 : Create Text File
- void createTextFile(){
- RList.PrintListTextFile();
- getchar();
- cout << "-----------------------------------------------------" << endl;
- cout << "Press enter to continue . . .";
- cin.clear();
- cin.ignore(1000, '\n');
- system("CLS");
- main();
- }
- //for checking whether the name is empty
- bool checkName(string name){
- int counter = 0;
- for(int i = 0; i<name.length() ; i++){
- if(name.find_first_not_of(' ') != std::string::npos){
- counter++;
- }
- }
- if(counter == 0){
- cout<<"Invalid Input! Need a name!"<<endl;
- return false;
- }else{
- return true;
- }
- }
- //for getting the current time
- time_t now = time(0);
- tm *ltm = localtime(&now);
- int currentYear = 1900+ltm->tm_year;
- int currentMonth = 1 + ltm->tm_mon;
- int currentDay = ltm->tm_mday;
- int currentHour = ltm->tm_hour;
- int currentMinute = ltm->tm_min;
- bool checkYear(int year){
- if(year < currentYear){
- cout<<"Can't go back in time!"<<endl;
- return false;
- }else{
- return true;
- }
- }
- bool checkMonth(int month, int year){
- if(month < currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- return false;
- }else if(month > 12){
- cout<<"There are only 12 months in a year!"<<endl;
- return false;
- }else{
- return true;
- }
- }
- bool checkDay(int day, int month, int year){
- if(day < currentDay && month == currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- //even months
- }else if(day <= 0){
- cout<<"Can't go back in time!"<<endl;
- }else if(month%2 == 0){
- // if the month is february
- if(month == 2){
- //february in common year that contain 28 days
- if(year%4 != 0 && day>28){
- cout << "Please key in between the day from 1 to 28"<< endl;
- }
- // february in leap year that contain 29 days
- else if(year%4 == 0 && day>29){
- cout << "Please key in between the day from 1 to 29"<< endl;
- }
- else{
- return true;
- }
- }
- // month that are even with 31 days
- else if(month > 7 && day > 31){
- cout << "Please key in between the day from 1 to 31"<< endl;
- }
- // month that are even with 30 days
- else if(month < 7 && day > 30){
- cout << "Please key in between the day from 1 to 30"<< endl;
- }
- else{
- return true;
- }
- // month is odd
- }else if(month%2 != 0){
- // month that are odd with 30 days
- if(month>8 && day > 30){
- cout << "Please key in between the day from 1 to 30"<< endl;
- // month that are odd with 31 days
- }else if(month<8 && day > 31){
- cout << "Please key in between the day from 1 to 31"<< endl;
- }else{
- return true;
- }
- }
- else{
- return true;
- }
- return false;
- }
- bool checkTime(int time, int day, int month, int year){
- int hour = time/100;
- int minute = time - hour*100;
- if(hour > 24){
- cout<<"Only 0 to 24 hours."<<endl;
- return false;
- }else if(hour < currentHour && day == currentDay && month == currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- return false;
- }else{
- return true;
- }
- if(minute > 59){
- cout<<"Only 0 to 59 minutes."<<endl;
- }else if(minute < currentMinute && hour == currentHour && day == currentDay && month == currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- }else{
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement