Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <windows.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- #include <stddef.h>
- #define POUND_SIGN 156
- #define MAX_NUM_CITY 40
- #define MAX_NUM_ACC 20
- #define MAX_NUM_TICKETS 40
- #define MAX_LEN_NAME 15
- #define MAX_LEN_SURNAME 20
- #define MAX_LEN_EMAIL 30
- #define MIN_LEN_PASSWORD 5
- #define MAX_LEN_PASSWORD 15
- #define MAX_LEN_ADDRESS 30
- #define MAX_LEN_CITY 20
- #define MAX_LEN_POSTCODE 8
- #define MAX_LEN_DATE 10
- #define MAX_LEN_DEPARTMENT 50
- #define GRADE1 8.5
- #define GRADE2 10
- #define GRADE3 13.5
- #define MAX_LEN_TITLE 20
- #define MAX_NUM_STAFF 200
- #define MAX_LEN_NAMEONCARD 30
- #define MAX_LEN_CARDNUMBER 16
- #define MAX_LEN_EXPDATE 2
- #define MAX_LEN_SECURITYCODE 3
- #define MAX_LEN_SEAT 50
- #define MAX_LEN_CITY 15
- #define MAX_LEN_DEPPTIME 10
- #define MAX_LEN_ARRTIME 10
- #define MAX_LEN_CODE 3
- #define MIN_PRICE (float) 1
- #define MAX_PRICE (float) 2000
- #define START_DATE (int) 8
- #define END_DATE (int) 8
- int GetValidatedInteger(int min, int max);
- float GetValidatedFloat(float Min, float Max);
- char GetValidatedString(char ValidatedString[], int MinLength, int MaxLength);
- char GetValidatedYesNo();
- void Clearstdin();
- void ShowMainMenuLogOut();
- void ShowMainMenuLogIn();
- void LogInMenu();
- void SignUpMenu(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *LogInCheck);
- int Password(char TemporaryPass2[]);
- void PasswordStr(int HowManyInt, int HowManyChar, char TemporaryPass[]);
- void RandomCode(char Robot[], int HowManyChar);
- void SignUpText();
- void Email(struct CustomerAccount AllRecords[], char TemporaryEmail[], int *NumCustomerAcc, int *At, int *Dot, int *Counter);
- ///// staff account functions
- void CreateStaffAcc(struct StaffAccount AllStaff[], int *NumStaffAcc);
- void AdminAccLayout(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck);
- void ManageStaff(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData);
- void ManageDestinations(struct City_Country AllCities[], int *NumOfCities);
- void DisplayDestinations(struct City_Country AllCities[], int *NumOfCities);
- void GradeMenu();
- void DisplayStaff(struct StaffAccount AllStaff[], int *NumStaffAcc);
- void DisplayStaffAll(struct StaffAccount AllStaff[], int *NumStaffAcc);
- void SearchRecords(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData);
- void SearchRecordsSurname(struct StaffAccount AllStaff[], int *NumStaffAcc);
- void ChoiceMenu();
- void UpdateRecords(struct StaffAccount AllStaff[], int *NumStaffAcc);
- char StaffAccDetailsUpdate();
- void StaffHoliday(struct StaffAccount AllStaff[], int *NumStaffAcc);
- ///// external files
- void SaveAllRecordsToFile(struct CustomerAccount AllRecords[], int NumCustomerAcc);
- int ReadAllRecordsFromFile(struct CustomerAccount AllRecords[], int NumCustomerAcc);
- int ReadAllStaffFromFile(struct StaffAccount AllStaff[], int NumStaffAcc);
- void SaveAllStaffToFile(struct StaffAccount AllStaff[], int NumStaffAcc);
- int ReadAllCitiesFromFile(struct City_Country AllCities[], int NumOfCities);
- void SaveAllCitiesToFile(struct City_Country AllCities[], int NumOfCities);
- ///// login for staff and customers
- void LogInCustomer(struct CustomerAccount AllRecords[], int NumCustomerAcc, int *LogInCheck, int *WhatData);
- void LogInStaff(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck);
- ///// customer account functions
- void CustomerAccLayout(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *LogInCheck);
- void CustomerAccPersonalDeatils(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData);
- char CustomerAccPersonalDetailsUpdate();
- void CustomerAccManageAcc(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *Delete);
- void CustomerAccManageCard(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData);
- void CustomerAccAddCreditCard(struct CustomerAccount AllRecords[], int *WhatData);
- int NumberCheck(char ToCheck[], int CorrectSize);
- ///// ticket functions
- void SearchFlights(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2);
- void Options(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2);
- void Payment(struct CustomerAccount AllRecords[], struct Ticket AllTickets[], int *NumOfTickets, int *WhatData);
- struct CustomerAccount
- {
- char Name[MAX_LEN_NAME + 1];
- char Surname[MAX_LEN_SURNAME + 1];
- char Email[MAX_LEN_EMAIL + 1];
- char Password[MAX_LEN_PASSWORD + 1];
- char MemorablePassword[MAX_LEN_PASSWORD + 1];
- int Lock;
- int KeepLogin;
- int Theme;
- int CreditCardCheck;
- char NameOnCard[MAX_LEN_NAMEONCARD + 1];
- char CardNumber[MAX_LEN_CARDNUMBER + 1];
- char ExpDateMonth[MAX_LEN_EXPDATE + 1];
- char ExpDateYear[MAX_LEN_EXPDATE + 1];
- char SecurityCode[MAX_LEN_SECURITYCODE + 1];
- };
- struct StaffAccount
- {
- char Name[MAX_LEN_NAME + 1];
- char Surname[MAX_LEN_SURNAME + 1];
- char Login[MAX_LEN_EMAIL + 1];
- char Password[MAX_LEN_PASSWORD + 1];
- char Address[MAX_LEN_ADDRESS + 1];
- char City[MAX_LEN_CITY + 1];
- char Postcode[MAX_LEN_CITY + 1];
- char DOB[MAX_LEN_DATE + 1];
- char JobTitle[MAX_LEN_TITLE + 1];
- char Department[MAX_LEN_DEPARTMENT + 1];
- float PayGrade;
- char StartDate[MAX_LEN_DATE + 1];
- int Lock;
- int Admin;
- int Start_date[END_DATE + 1];
- int End_date[END_DATE + 1];
- };
- struct City_Country
- {
- char City[MAX_LEN_CITY + 1];
- char Country[MAX_LEN_CITY + 1];
- char AirportCode[MAX_LEN_CODE + 1];
- int Popularity;
- int Place;
- };
- struct Ticket
- {
- char DepartureCountry[MAX_LEN_CITY + 1];
- char ArrivalCountry[MAX_LEN_CITY + 1];
- char DepartureCity[MAX_LEN_CITY + 1];
- char ArrivalCity[MAX_LEN_CITY + 1];
- char DepartureTime[MAX_LEN_DEPPTIME + 1];
- int DepartureDay;
- int DepartureMonth;
- int DepartureYear;
- int DepartureHour;
- int DepartureMin;
- float Price;
- int FirstClass;
- int BussinessClass;
- int ThirdClass;
- int NumberOfAdults;
- int NumberOfChildren;
- int NumberOfInfants;
- int WayBackOrNo;
- char Seats[MAX_LEN_SEAT + 1];
- int Who;
- };
- int main()
- {
- SetConsoleTitle("Airline portal managment");
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
- COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
- c2.X = 80; // szerokoœæ na 120 szerokoœci znaków
- c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
- SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
- SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
- sr.Left = 0; // na zero
- sr.Top = 0; // na zero
- sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
- sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
- SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
- struct City_Country AllCities[MAX_NUM_CITY];
- struct CustomerAccount AllRecords[MAX_NUM_ACC];
- struct StaffAccount AllStaff[MAX_NUM_ACC];
- struct Ticket AllTickets[MAX_NUM_TICKETS];
- int NumOfCities = 0;
- int NumCustomerAcc = 0;
- int NumStaffAcc = 0;
- int NumOfTickets = 0;
- int MenuChoice = 0, MenuChoice2 = 0;
- int LogInCheck = 0;
- //SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
- //SaveAllCitiesToFile(AllCities, NumOfCities);
- //SaveAllStaffToFile(AllStaff, NumStaffAcc);
- NumCustomerAcc = ReadAllRecordsFromFile(AllRecords, MAX_NUM_ACC);
- NumStaffAcc = ReadAllStaffFromFile(AllStaff, MAX_NUM_ACC);
- NumOfCities = ReadAllCitiesFromFile(AllCities, MAX_NUM_CITY);
- int Airport1 = -1;
- int Airport2 = -1;
- int Counter = 0;
- int WhatData = 0;
- for (int i = 0; i < NumCustomerAcc; i++)
- {
- if (AllRecords[i].KeepLogin == 1)
- {
- LogInCheck = 1;
- WhatData = Counter;
- switch (AllRecords[WhatData].Theme)
- {
- case 1:
- system("color 70");
- break;
- case 2:
- system("COLOR 67");
- break;
- case 3:
- system("color 30");
- break;
- case 4:
- system("color 07");
- break;
- }
- }
- else
- {
- Counter++;
- }
- }
- do
- {
- if (LogInCheck == 0) ShowMainMenuLogOut();
- if (LogInCheck == 1) ShowMainMenuLogIn();
- MenuChoice = _getch();
- switch (MenuChoice)
- {
- case '1':
- {
- system("cls");
- if (LogInCheck == 0)
- {
- LogInMenu();
- do
- {
- MenuChoice2 = _getch();
- switch (MenuChoice2)
- {
- case '1':
- LogInCustomer(AllRecords, NumCustomerAcc, &LogInCheck, &WhatData);
- break;
- case '2':
- LogInStaff(AllStaff, AllCities, &NumStaffAcc, &NumOfCities, &WhatData, &LogInCheck);
- SaveAllCitiesToFile(AllCities, NumOfCities);
- SaveAllStaffToFile(AllStaff, NumStaffAcc);
- break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice2 != '0' && MenuChoice2 != '1' && MenuChoice2 != '2');
- }
- else if (LogInCheck == 1)
- {
- AllRecords[WhatData].KeepLogin = 0;
- SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
- WhatData = -1;
- Sleep(150);
- LogInCheck = 0;
- system("color 07");
- system("cls");
- }
- break;
- }
- case '2':
- if (LogInCheck == 0)
- {
- SignUpMenu(AllRecords, &NumCustomerAcc, &LogInCheck);
- SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
- }
- else if (LogInCheck == 1)
- {
- CustomerAccLayout(AllRecords, &NumCustomerAcc, &WhatData, &LogInCheck);
- SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
- }
- break;
- case '3':
- if (LogInCheck == 1)
- {
- SearchFlights(AllCities, AllTickets, &NumOfCities, &NumOfTickets, &Airport1, &Airport2);
- if (Airport1 != -1 && Airport2 != -1)
- {
- Options(AllCities, AllTickets, &NumOfCities, &NumOfTickets, &Airport1, &Airport2);
- Payment(AllRecords, AllTickets, &NumOfTickets, &WhatData);
- SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
- }
- }
- else
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n Please log in or sign up to buy tickets.");
- Sleep(2300);
- system("cls");
- }
- break;
- case '4':
- DisplayDestinations(AllCities, &NumOfCities);
- break;
- case '5':
- CreateStaffAcc(AllStaff, &NumStaffAcc);
- SaveAllStaffToFile(AllStaff, NumStaffAcc);
- break;
- case '6':
- break;
- case '0':
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n Closing the program.");
- Sleep(800);
- break;
- default:
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- return(0);
- }
- int GetValidatedInteger(int min, int max)
- {
- const int cTrue = 1;
- const int cFalse = 0;
- float Input = 0;
- int Itemread = cFalse;
- int Valid = cFalse;
- do
- {
- Itemread = scanf_s("%f", &Input);
- Clearstdin();
- if (Itemread == cFalse) { printf("Must be a number. (%d - %d)\n", min, max); }
- else if (Input != (int)Input) { printf("Must be a intiger. (%d - %d)\n", min, max); }
- else if ((Input < min) || (Input > max)) { printf("Out of range. (%d - %d)\n", min, max); }
- else Valid = cTrue;
- } while (Valid == cFalse);
- return((int)Input);
- }
- float GetValidatedFloat(float Min, float Max)
- {
- const int cTrue = 1;
- const int cFalse = 0;
- int ItemRead = cTrue;
- float Input = 0;
- int Valid = cFalse;
- scanf_s("%f", &Input);
- do
- {
- Clearstdin();
- if (ItemRead == cFalse)
- {
- printf("Invalid - must be a number! Please try again.");
- Sleep(500);
- printf("\nEnter the Price (%c%1.2f - %c%1.2f): %c", POUND_SIGN, MIN_PRICE, POUND_SIGN, MAX_PRICE, POUND_SIGN);
- scanf_s("%f", &Input);
- }
- else if ((Input < Min) || (Input > Max))
- {
- printf("Invalid - out-of-range! Please try again.");
- Sleep(500);
- printf("\nEnter the Price (%c%1.2f - %c%1.2f): %c", POUND_SIGN, MIN_PRICE, POUND_SIGN, MAX_PRICE, POUND_SIGN);
- scanf_s("%f", &Input);
- }
- else
- {
- Valid = cTrue;
- }
- } while (Valid == cFalse);
- return(Input);
- }
- char GetValidatedString(char ValidatedString[], int MinLength, int MaxLength)
- {
- const char cFalse = 0, cTrue = 1;
- char Success = cFalse;
- char YesorNo;
- char Input[255];
- size_t InputArrayMaxLen = sizeof(Input) - 2;
- size_t Length;
- if (MaxLength > (int)InputArrayMaxLen)
- {
- printf("\n\nRequired maximum length for called GetValidatedString() function""\ncannot exceed %d characters", (int)InputArrayMaxLen);
- printf("\nData not read. Please contact developer.");
- getchar();
- return(Success);
- }
- do
- {
- do
- {
- YesorNo = 'Y';
- Input[InputArrayMaxLen + 1] = 'z';
- Input[InputArrayMaxLen] = 'z';
- fgets(Input, sizeof(Input), stdin);
- if ((Input[InputArrayMaxLen + 1] == '\0') && (Input[InputArrayMaxLen] != '\n'))
- {
- printf("\n\nRequired maximum length for called GetValidatedString() function " "\ncannot exceed %d characters", InputArrayMaxLen);
- printf("\n\nDo you wish to try again (Y/N)?: ");
- YesorNo = GetValidatedYesNo();
- if (YesorNo == 'N')
- {
- printf("Data not read. Please contact developer.");
- getchar();
- return(Success);
- }
- else
- {
- printf("\nRe-enter(%d - %d characters): ", MinLength, MaxLength);
- }
- }
- else
- {
- YesorNo = 'N';
- }
- } while (YesorNo == 'Y');
- Length = strlen(Input) - 1;
- Input[Length] = '\0';
- if ((Length < (size_t)MinLength) || (Length >(size_t)MaxLength))
- {
- printf("\n Invalid! Please try again (Length %d-%d): ", MinLength, MaxLength);
- printf("\n ---> ");
- }
- else
- {
- Success = cTrue;
- }
- } while (Success == cFalse);
- strcpy_s(ValidatedString, MaxLength + 1, Input);
- return(Success);
- }
- char GetValidatedYesNo()
- {
- char reply;
- do
- {
- reply = _getch();
- reply = toupper(reply);
- } while ((reply != 'Y') && (reply != 'N'));
- return reply;
- }
- void Clearstdin()
- {
- char Discard[255] = "";
- fgets(Discard, sizeof(Discard), stdin);
- }
- void ShowMainMenuLogOut()
- {
- printf("0.Quit 1.LogIn 2.SignUp\n");
- printf(" \n");
- printf(" Most popular destination \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" 3. Buy tickets \n");
- printf(" 4. Display all destinations \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- }
- void ShowMainMenuLogIn()
- {
- printf("0.Quit 1.LogOut 2.Account\n");
- printf(" \n");
- printf(" Most popular destination \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" 3. Buy tickets \n");
- printf(" 4. Display all destinations \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- }
- void LogInMenu()
- {
- //SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
- printf("0.Back to Main Menu \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" \n");
- printf(" 1. Log in as a customer \n");
- printf(" \n");
- printf(" \n");
- printf(" 2. Log in as a staff \n");
- }
- void SignUpMenu(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *LogInCheck)
- {
- Sleep(100);
- system("cls");
- char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
- char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
- printf("0.Back to Main Menu \n");
- SignUpText();
- printf(" First Name: ");
- GetValidatedString(AllRecords[*NumCustomerAcc].Name, 1, MAX_LEN_NAME);
- if (strcmp(AllRecords[*NumCustomerAcc].Name, "0") == 0) { AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1]; system("cls"); return; }
- printf(" Last Name: ");
- GetValidatedString(AllRecords[*NumCustomerAcc].Surname, 1, MAX_LEN_SURNAME);
- if (strcmp(AllRecords[*NumCustomerAcc].Surname, "0") == 0) { AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1]; system("cls"); return; }
- ///////////////////////////////////////////////////////////////////////////////Email//////////////////////////////////////////////////////////////////////////////////////////
- char TemporaryEmail[MAX_LEN_EMAIL + 1] = "";
- int Counter2 = 0;
- int At = 0;
- int Dot = 0;
- do
- {
- system("cls");
- printf("0.Back to Main Menu \n");
- SignUpText();
- printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
- printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
- printf(" Email Address: ");
- GetValidatedString(TemporaryEmail, 1, MAX_LEN_EMAIL);
- if (strcmp(TemporaryEmail, "0") == 0) { AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1]; system("cls"); return; }
- Email(AllRecords, TemporaryEmail, NumCustomerAcc, &At, &Dot, &Counter2);
- } while (Counter2 != *NumCustomerAcc || At == 0 || At > 1 || Dot == 0);
- strcpy_s(AllRecords[*NumCustomerAcc].Email, MAX_LEN_EMAIL, TemporaryEmail);
- for (int i = 0; i < MAX_LEN_EMAIL; i++)
- {
- TemporaryEmail[i] = NULL;
- }
- ////////////////////////////////////////////////////////////////////////////////Password/////////////////////////////////////////////////////////////////////////////////////////
- system("cls");
- printf(" \n");
- SignUpText();
- printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
- printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
- printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
- printf(" \n");
- printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n At least one number and one capital letter. \n");
- printf(" \n");
- printf(" <Password strength> ");
- int Counter = 0;
- int Counter3 = 0;
- int DeleteChar = 0;
- int ArrayCounter = 0;
- int HowManyChar = 0;
- int HowManyInt = 0;
- do
- {
- char Pass[2];
- do
- {
- if (Counter3 > 0)
- {
- printf("\n\n You did not use either a number or a capital letter.");
- printf("\n Please retype your password.");
- Sleep(2400);
- system("cls");
- printf(" \n");
- SignUpText();
- printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
- printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
- printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
- printf(" \n");
- printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n At least one number and one capital letter. \n");
- printf(" \n");
- printf(" <Password strength> ");
- Pass[0] = NULL;
- for (int i = 0; i < MAX_LEN_PASSWORD; i++)
- {
- TemporaryPass[i] = NULL;
- }
- HowManyChar = 0;
- HowManyInt = 0;
- ArrayCounter = 0;
- DeleteChar = 0;
- }
- Pass[0] = NULL;
- while ((strlen(TemporaryPass) <= MAX_LEN_PASSWORD && Pass[0] != 13) || (strlen(TemporaryPass) < MIN_LEN_PASSWORD && Pass[0] == 13))
- {
- PasswordStr(HowManyInt, HowManyChar, TemporaryPass);
- if (Counter3 > 0)
- {
- printf("\n\n Password: ");
- Counter3 = 0;
- }
- else
- {
- printf("\n\n Password: ");
- for (int i = 0; i < DeleteChar; i++)
- {
- printf("*");
- }
- }
- Pass[0] = _getch();
- Pass[1] = '\0';
- int ToCheck = Pass[0];
- if (DeleteChar > 0 && ToCheck == 8)
- {
- int ToCheck2 = TemporaryPass[ArrayCounter - 1];
- if (65 <= ToCheck2 && ToCheck2 <= 90) HowManyChar--;
- if (48 <= ToCheck2 && ToCheck2 <= 57) HowManyInt--;
- DeleteChar--;
- TemporaryPass[ArrayCounter - 1] = NULL;
- ArrayCounter--;
- }
- if (strlen(TemporaryPass) != MAX_LEN_PASSWORD)
- {
- if (Pass[0] != 13 && Pass[0] != 8)
- {
- int ToCheck = Pass[0];
- if (65 <= ToCheck && ToCheck <= 90) HowManyChar++;
- if (48 <= ToCheck && ToCheck <= 57) HowManyInt++;
- printf("%c", Pass[0]);
- Sleep(150);
- strcat_s(TemporaryPass, sizeof(TemporaryPass), Pass);
- DeleteChar++;
- ArrayCounter++;
- }
- }
- system("cls");
- printf(" \n");
- SignUpText();
- printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
- printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
- printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
- printf(" \n");
- printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n At least one number and one capital letter. \n");
- printf(" \n");
- printf(" <Password strength> ");
- }
- PasswordStr(HowManyInt, HowManyChar, TemporaryPass);
- if (HowManyChar == 0 || HowManyInt == 0) Counter3++;
- else Counter3 = 0;
- } while (HowManyChar == 0 || HowManyInt == 0);
- HowManyChar = 0;
- HowManyInt = 0;
- ArrayCounter = 0;
- printf("\n\n Password: ");
- for (int i = 0; i < DeleteChar; i++)
- {
- printf("*");
- }
- DeleteChar = 0;
- //////////////////////////////////////////////////////////////Password confirmation/////////////////////////////////////////////////////////////////////////
- printf("\n Confirm Password: ");
- Pass[0] = NULL;
- Password(TemporaryPass2);
- if (strcmp(TemporaryPass, TemporaryPass2) != 0)
- {
- printf("\n\n Your passwords don't match.");
- printf("\n Please retype your password to confirm it.");
- Sleep(2400);
- system("cls");
- printf(" \n");
- SignUpText();
- printf(" First Name: %s\n", AllRecords[0 + *NumCustomerAcc].Name);
- printf(" Last Name: %s\n", AllRecords[0 + *NumCustomerAcc].Surname);
- printf(" Email Address: %s\n", AllRecords[0 + *NumCustomerAcc].Email);
- printf(" \n");
- printf("\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n At least one number and one capital letter. \n");
- printf(" \n");
- printf(" <Password strength> ");
- }
- else
- {
- Counter++;
- strcpy_s(AllRecords[*NumCustomerAcc].Password, MAX_LEN_PASSWORD, TemporaryPass);
- }
- for (int i = 0; i < MAX_LEN_PASSWORD; i++)
- {
- TemporaryPass[i] = NULL;
- TemporaryPass2[i] = NULL;
- }
- } while (Counter == 0);
- ///////////////////////////////////////////////////////////Choice///////////////////////////////////////////////////
- printf("\n\n\n 0.Cancel || 1.Next step \n");
- int Choice = 0;
- do
- {
- Choice = 0;
- Choice = _getch();
- switch (Choice)
- {
- case '0':
- {
- AllRecords[0 + *NumCustomerAcc] = AllRecords[*NumCustomerAcc + 1];
- Sleep(350);
- break;
- }
- case '1':
- {
- system("cls");
- char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
- int StarsToDisplay = 0;
- do
- {
- printf(" \n");
- printf(" \n");
- printf(" Please enter your memorable password. \n");
- printf(" You will need it, if you forget your main password. \n");
- printf("\n \n");
- printf("\n Memorable password must be between %d and %d characters. \n", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n\n Memorable Password: ");
- StarsToDisplay = 0;
- StarsToDisplay = Password(TemporaryPass2);
- strcpy_s(AllRecords[*NumCustomerAcc].MemorablePassword, MAX_LEN_PASSWORD, TemporaryPass2);
- for (int i = 0; i < MAX_LEN_PASSWORD; i++)
- {
- TemporaryPass2[i] = NULL;
- }
- printf("\n Confirm Memorable Password: ");
- Password(TemporaryPass2);
- if (strcmp(AllRecords[*NumCustomerAcc].MemorablePassword, TemporaryPass2) != 0)
- {
- printf("\n\n Your passwords don't match.");
- printf("\n Please retype your password to confirm it.");
- Sleep(2400);
- system("cls");
- for (int i = 0; i < MAX_LEN_PASSWORD; i++)
- {
- TemporaryPass2[i] = NULL;
- }
- AllRecords[0 + *NumCustomerAcc].MemorablePassword[MAX_LEN_PASSWORD + 1] = AllRecords[*NumCustomerAcc + 1].MemorablePassword[MAX_LEN_PASSWORD + 1];
- }
- } while (strcmp(AllRecords[*NumCustomerAcc].MemorablePassword, TemporaryPass2) != 0);
- char UserRobot[25 + 1] = "";
- char Robot[15 + 1] = "";
- do
- {
- for (int i = 0; i < sizeof(UserRobot); i++)
- {
- UserRobot[i] = NULL;
- }
- for (int i = 0; i < sizeof(Robot); i++)
- {
- Robot[i] = NULL;
- }
- RandomCode(Robot, 5);
- system("cls");
- printf(" \n");
- printf(" \n");
- printf(" Please enter your memorable password. \n");
- printf(" You will need it, if you forget your main password. \n");
- printf("\n \n");
- printf("\n Memorable password must be between %d and %d characters. \n", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n\n Memorable Password: ");
- for (int i = 0; i < StarsToDisplay; i++)
- {
- printf("*");
- }
- printf("\n Confirm Memorable Password: ");
- for (int i = 0; i < StarsToDisplay; i++)
- {
- printf("*");
- }
- printf("\n\n\n\n : Please, re-type this security code : ");
- printf("\n : to confirm you are not a robot : \n");
- printf("\n ---> %s <---\n", Robot);
- printf("\n ");
- GetValidatedString(UserRobot, 0, 25);
- } while (strcmp(UserRobot, Robot) != 0);
- printf("\n\n Press ENTER to finish registration. \n");
- char Finish;
- do
- {
- Finish = _getch();
- } while (Finish != 13);
- for (int i = 3; i >= 0; i--)
- {
- if (i != 3) Sleep(1000);
- system("cls");
- printf("\n\n\n\n\n\n\n\n Thank You for completing your registration. \n");
- if (i == 3) Sleep(1500);
- printf("\n Now you can fully use our service. \n");
- if (i == 3) Sleep(1500);
- printf("\n Do not waste your time and find the best flights for you! \n");
- if (i == 3) Sleep(1500);
- printf("\n\n You will be redirected to a main page in a moment. \n");
- printf("\n %d", i);
- }
- AllRecords[*NumCustomerAcc].Lock = 0;
- AllRecords[*NumCustomerAcc].KeepLogin = 0;
- AllRecords[*NumCustomerAcc].Theme = 0;
- AllRecords[*NumCustomerAcc].CreditCardCheck = 0;
- (*NumCustomerAcc)++;
- break;
- }
- }
- } while (Choice != '0' && Choice != '1');
- system("cls");
- }
- int Password(char TemporaryPass2[])
- {
- int DeleteChar = 0;
- int ArrayCounter = 0;
- char Pass[2] = "";
- char TemporaryArray[MAX_LEN_PASSWORD + 1] = "";
- while ((strlen(TemporaryArray) <= MAX_LEN_PASSWORD && Pass[0] != 13) || (strlen(TemporaryArray) < MIN_LEN_PASSWORD && Pass[0] == 13))
- {
- Pass[0] = _getch();
- Pass[1] = '\0';
- int ToCheck = Pass[0];
- if (DeleteChar > 0 && ToCheck == 8)
- {
- DeleteChar--;
- printf("\b");
- printf(" ");
- printf("\b");
- TemporaryArray[ArrayCounter - 1] = NULL;
- ArrayCounter--;
- }
- if (strlen(TemporaryArray) != MAX_LEN_PASSWORD)
- {
- if (Pass[0] != 13 && Pass[0] != 8)
- {
- printf("%c", Pass[0]);
- Sleep(150);
- printf("\b");
- printf("*");
- strcat_s(TemporaryArray, sizeof(TemporaryArray), Pass);
- DeleteChar++;
- ArrayCounter++;
- }
- }
- }
- strcat_s(TemporaryPass2, sizeof(TemporaryArray), TemporaryArray);
- return ArrayCounter;
- }
- void PasswordStr(int HowManyInt, int HowManyChar, char TemporaryPass[])
- {
- int Points = HowManyInt + HowManyChar;
- switch (Points)
- {
- case (0):
- printf("\n LOW");
- break;
- case (1):
- printf("\n LOW");
- break;
- case (2):
- printf("\n LOW");
- break;
- case (3):
- if (strlen(TemporaryPass) <= 5) printf("\n LOW");
- else printf("\n MEDIUM");
- break;
- case (4):
- if (strlen(TemporaryPass) <= 7) printf("\n LOW");
- else printf("\n MEDIUM");
- break;
- case (5):
- if (strlen(TemporaryPass) <= 7) printf("\n MEDIUM");
- else printf("\n GOOD");
- break;
- case (6):
- if (strlen(TemporaryPass) <= 8) printf("\n GOOD");
- else printf("\n VERY GOOD");
- break;
- case (7):
- if (strlen(TemporaryPass) <= 11) printf("\n VERY GOOD");
- else printf("\n EXCELLENT");
- break;
- default:
- printf("\n EXCELLENT");
- break;
- }
- }
- void RandomCode(char Robot[], int HowManyChar)
- {
- srand(time(NULL));
- char TemRandomCode[MAX_LEN_PASSWORD] = "";
- char RandomChar[2] = "";
- int RandomNumber = 0;
- for (int i = 0; i < HowManyChar; i++)
- {
- RandomChar[0] = NULL;
- RandomChar[1] = '\0';
- RandomNumber = 0;
- RandomNumber = rand() % 3;
- switch (RandomNumber)
- {
- case 0:
- {
- RandomNumber = 0;
- RandomNumber = rand() % 25 + 65;
- RandomChar[0] = RandomNumber;
- strcat_s(TemRandomCode, sizeof(TemRandomCode), RandomChar);
- break;
- }
- case 1:
- {
- RandomNumber = 0;
- RandomNumber = rand() % 25 + 97;
- RandomChar[0] = RandomNumber;
- strcat_s(TemRandomCode, sizeof(TemRandomCode), RandomChar);
- break;
- }
- case 2:
- {
- RandomNumber = 0;
- RandomNumber = rand() % 9 + 48;
- RandomChar[0] = RandomNumber;
- strcat_s(TemRandomCode, sizeof(TemRandomCode), RandomChar);
- break;
- }
- }
- }
- strcat_s(Robot, sizeof(Robot), TemRandomCode);
- }
- void SignUpText()
- {
- printf(" \n");
- printf(" Buy tickets, manage your flights, \n");
- printf(" get extra prices and more \n");
- printf(" with your account. \n");
- printf(" \n");
- printf(" Start your jurney today! \n");
- printf(" \n");
- printf(" \n");
- }
- void Email(struct CustomerAccount AllRecords[], char TemporaryEmail[], int *NumCustomerAcc, int *At, int *Dot, int *Counter)
- {
- *Counter = 0;
- *At = 0;
- *Dot = 0;
- for (int i = 1; i <= (*NumCustomerAcc); i++)
- {
- if (_strcmpi(TemporaryEmail, AllRecords[i - 1].Email) == 0)
- {
- printf("\n\n It looks like this Email Address has been already in use. \n");
- printf(" Please retype your Email Address. \n");
- Sleep(2400);
- system("cls");
- for (int i = 0; i < MAX_LEN_EMAIL; i++)
- {
- TemporaryEmail[i] = NULL;
- }
- }
- else
- {
- (*Counter)++;
- }
- }
- for (int i = 0; i <= sizeof(TemporaryEmail); i++)
- {
- if (TemporaryEmail[i] == 64)
- {
- (*At)++;
- }
- else if (TemporaryEmail[i] == 46)
- {
- (*Dot)++;
- }
- }
- if ((*At == 0 || *At > 1 || *Dot == 0) && *Counter == (*NumCustomerAcc))
- {
- printf("\n\n It looks like this is not an Email Address. \n");
- printf(" Please retype your Email Address. \n");
- Sleep(2400);
- system("cls");
- for (int i = 0; i < MAX_LEN_EMAIL; i++)
- {
- TemporaryEmail[i] = NULL;
- }
- }
- }
- ///// staff account functions
- void CreateStaffAcc(struct StaffAccount AllStaff[], int *NumStaffAcc)
- {
- system("cls");
- printf("0.Back to Main Menu\n");
- printf("\n\n\n Add new employee ");
- printf("\n\n\n\n First Name: ");
- GetValidatedString(AllStaff[*NumStaffAcc].Name, 1, MAX_LEN_NAME);
- if (strcmp(AllStaff[*NumStaffAcc].Name, "0") == 0) { system("cls"); return; }
- printf("\n Last Name: ");
- GetValidatedString(AllStaff[*NumStaffAcc].Surname, 1, MAX_LEN_NAME);
- if (strcmp(AllStaff[*NumStaffAcc].Surname, "0") == 0) { system("cls"); return; }
- printf("\n Date of birth in format 99/99/9999: ");
- GetValidatedString(AllStaff[*NumStaffAcc].DOB, 1, MAX_LEN_DATE);
- if (strcmp(AllStaff[*NumStaffAcc].DOB, "0") == 0) { system("cls"); return; }
- printf("\n Home address: ");
- GetValidatedString(AllStaff[*NumStaffAcc].Address, 1, MAX_LEN_ADDRESS);
- if (strcmp(AllStaff[*NumStaffAcc].Address, "0") == 0) { system("cls"); return; }
- printf("\n City: ");
- GetValidatedString(AllStaff[*NumStaffAcc].City, 1, MAX_LEN_CITY);
- if (strcmp(AllStaff[*NumStaffAcc].City, "0") == 0) { system("cls"); return; }
- printf("\n Postcode: ");
- GetValidatedString(AllStaff[*NumStaffAcc].Postcode, 1, MAX_LEN_POSTCODE);
- if (strcmp(AllStaff[*NumStaffAcc].Postcode, "0") == 0) { system("cls"); return; }
- printf("\n Job Title: ");
- GetValidatedString(AllStaff[*NumStaffAcc].JobTitle, 1, MAX_LEN_TITLE);
- if (strcmp(AllStaff[*NumStaffAcc].JobTitle, "0") == 0) { system("cls"); return; }
- printf("\n Department: ");
- GetValidatedString(AllStaff[*NumStaffAcc].Department, 1, MAX_LEN_DEPARTMENT);
- if (strcmp(AllStaff[*NumStaffAcc].Department, "0") == 0) { system("cls"); return; }
- printf("\n Start date in format 99/99/9999: ");
- GetValidatedString(AllStaff[*NumStaffAcc].StartDate, 1, MAX_LEN_DATE);
- if (strcmp(AllStaff[*NumStaffAcc].StartDate, "0") == 0) { system("cls"); return; }
- printf("\n Choose pay grade from below: ");
- int Choice = 0;
- GradeMenu();
- Choice = GetValidatedInteger(1, 3);
- switch (Choice)
- {
- case 1:
- AllStaff[*NumStaffAcc].PayGrade = GRADE1;
- break;
- case 2:
- AllStaff[*NumStaffAcc].PayGrade = GRADE2;
- break;
- case 3:
- AllStaff[*NumStaffAcc].PayGrade = GRADE3;
- break;
- }
- printf("\n Login: ");
- GetValidatedString(AllStaff[*NumStaffAcc].Login, 1, MAX_LEN_EMAIL);
- if (strcmp(AllStaff[*NumStaffAcc].Login, "0") == 0) { system("cls"); return; }
- printf("\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n\n Password: ");
- char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
- Password(TemporaryPass);
- strcpy_s(AllStaff[*NumStaffAcc].Password, MAX_LEN_PASSWORD, TemporaryPass);
- AllStaff[*NumStaffAcc].Lock = 0;
- AllStaff[*NumStaffAcc].Admin = 1;
- (*NumStaffAcc)++;
- printf("\n\n\n\n\n\n Press Enter to finish.");
- getchar();
- system("cls");
- }
- void DisplayStaffAll(struct StaffAccount AllStaff[], int *NumStaffAcc)
- {
- //this function display added records
- system("cls");
- if (NumStaffAcc == 0) //check if number of records is equal 0
- {
- printf("\n\n\n");
- printf("\n\nNo records to display! Add records first!");
- }
- else
- {
- DisplayStaff(AllStaff, NumStaffAcc);
- printf("\n\n\nClick ENTER to go back to menu.");
- getchar();
- }
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
- COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
- c2.X = 80; // szerokoœæ na 120 szerokoœci znaków
- c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
- SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
- SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
- sr.Left = 0; // na zero
- sr.Top = 0; // na zero
- sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
- sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
- SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
- }
- void DisplayStaff(struct StaffAccount AllStaff[], int *NumStaffAcc)
- {
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
- COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
- c2.X = 180; // szerokoœæ na 120 szerokoœci znaków
- c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
- SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
- SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
- sr.Left = 0; // na zero
- sr.Top = 0; // na zero
- sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
- sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
- SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
- printf("\n%-5s%-15s%-25s%-15s%-25s%-20s%-15s%-15s%-15s%-15s", "NO", "FIRST NAME", "LAST NAME", "DOB", "JOB TITLE", "DEPARTMENT", "START DATE", "PAY GRADE", "LOGIN", "PASSWORD");
- printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- int i = 0; //counter for number of records in the for loop
- for (i = 0; i < *NumStaffAcc; i++) //displaying all records (till i gain the same vaue as num of records)
- {
- printf("\n\n%-5d%-15s%-25s%-15s%-25s%-20s%-15s%-15.2f%-15s%-15s", i + 1, AllStaff[i].Name, AllStaff[i].Surname
- , AllStaff[i].DOB, AllStaff[i].JobTitle, AllStaff[i].Department, AllStaff[i].StartDate, AllStaff[i].PayGrade, AllStaff[i].Login, AllStaff[i].Password);
- }
- }
- void GradeMenu()
- {
- printf(" \n\n GRADES SYSTEM");
- printf("\n 1. GRADE 1 - %c%1.2f", POUND_SIGN, GRADE1);
- printf("\n 2. GRADE 2 - %c%d", POUND_SIGN, GRADE2);
- printf("\n 3. GRADE 3 - %c%1.2f", POUND_SIGN, GRADE3);
- printf("\n\n Your choice: ");
- }
- void SearchRecords(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData)
- {
- int ChooseMenu;
- system("cls");
- if (NumStaffAcc == 0)
- {
- printf("\n\n\n");
- printf("\n\nNo employees records to display! Add employee first!");
- printf("\n\nClick ENTER to continue.");
- getchar();
- }
- else
- {
- ChoiceMenu();
- ChooseMenu = GetValidatedInteger(1, 5); // selection in the menu, switch
- system("cls");
- switch (ChooseMenu)
- {
- case 1:
- SearchRecordsSurname(AllStaff, NumStaffAcc);
- getchar();
- break;
- case 2:
- //DisplayRecordsSelectedAuthor(AllRecords, NumRecords); start date
- getchar();
- break;
- case 3:
- //DisplayRecordsSelectedAuthor(AllRecords, NumRecords); title
- getchar();
- break;
- case 4:
- //DisplayRecordsSelectedAuthor(AllRecords, NumRecords); grade
- getchar();
- break;
- case 5:
- ManageStaff(AllStaff, NumStaffAcc, WhatData);
- break;
- }
- }
- }
- void ChoiceMenu()
- {
- printf("\n%-5s%-20s", "1.", "Search employee by surname.");
- printf("\n%-5s%-20s", "2.", "Display all employees by start date.");
- printf("\n%-5s%-20s", "3.", "Display all employees by job title.");
- printf("\n%-5s%-20s", "4.", "Display all employees by pay grade.");
- printf("\n%-5s%-20s", "5.", "Go back to menu.");
- printf("\n\nYour choice: ");
- }
- void SearchRecordsSurname(struct StaffAccount AllStaff[], int *NumStaffAcc)
- {
- int MatchSurname = 0;
- char CheckAnother;
- int i = 0;
- char Surname[MAX_LEN_SURNAME + 1];
- do //do-while loop - captures the integer and store it in "i" variable.
- {
- MatchSurname = 0; // integer set up to make sure we will not have repeated results.
- printf("\nSearch by employee's surname.");
- printf("\nEnter the surname: ");
- GetValidatedString(Surname, 1, MAX_LEN_SURNAME); // getting surname that program will look for from the user
- for (i = 0; i < *NumStaffAcc; i++)
- {
- if (_strcmpi(Surname, AllStaff[i].Surname) == 0) //checking if searched surname exist in the records
- {
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
- COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
- c2.X = 180; // szerokoœæ na 120 szerokoœci znaków
- c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
- SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
- SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
- sr.Left = 0; // na zero
- sr.Top = 0; // na zero
- sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
- sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
- SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
- system("cls");
- printf("\nEmployees with surname: %s", AllStaff[i].Surname);
- printf("\n\n%-5s%-15s%-25s%-15s%-25s%-20s%-15s%-15s%-15s%-15s", "NO", "FIRST NAME", "LAST NAME", "DOB", "JOB TITLE", "DEPARTMENT", "START DATE", "PAY GRADE", "LOGIN", "PASSWORD");
- printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- printf("\n\n%-5d%-15s%-25s%-15s%-25s%-20s%-15s%-15.2f%-15s%-15s", i + 1, AllStaff[i].Name, AllStaff[i].Surname
- , AllStaff[i].DOB, AllStaff[i].JobTitle, AllStaff[i].Department, AllStaff[i].StartDate, AllStaff[i].PayGrade, AllStaff[i].Login, AllStaff[i].Password);
- MatchSurname++; // increment matchsurname
- }
- }
- if (MatchSurname == 0) // no matches
- {
- system("cls");
- printf("\nThere is no employee with this surname in the system!");
- printf("\n\nClick ENTER to continue.");
- }
- else //found match
- {
- printf("\n\nFounded %d match", MatchSurname);
- }
- printf("\n\n\n Do you want to check another record (Y/N) ?"); // adding another record
- CheckAnother = GetValidatedYesNo();
- } while (CheckAnother == 'Y'); // loop as many times as true, if false stop
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // uchwyt standardowego wyjœcia
- COORD c2; // struktura potrzebna do ustawienia rozmiarów bufora pamiêci
- c2.X = 80; // szerokoœæ na 120 szerokoœci znaków
- c2.Y = 26; // wysokoœæ na 40 wysokoœci znaków
- SetConsoleScreenBufferSize(handle, c2); // ustawia rozmiar bufora (wyœwietlanego tekstu)
- SMALL_RECT sr; // struktura wykorzystywana do ustawienia rozmiaru okna
- sr.Left = 0; // na zero
- sr.Top = 0; // na zero
- sr.Right = c2.X - 1; // szerokoϾ o 1 mniejsza od bufora
- sr.Bottom = c2.Y - 1; // wysokoϾ o 1 mniejsza od bufora
- SetConsoleWindowInfo(handle, 1, &sr); // ustawia rozmiar okna (jednostka to szerokoϾ i wysokoϾ pojedynczego znaku)
- }
- char StaffAccDetailsUpdate()
- {
- Sleep(100);
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n The data has been updated.");
- Sleep(1500);
- system("cls");
- char Reply;
- printf("\n\n\n\n\n\n\n\n\n\n\n Do you want to do more updates? (Y/N)");
- Reply = GetValidatedYesNo();
- Sleep(100);
- return Reply;
- }
- void UpdateRecords(struct StaffAccount AllStaff[], int *NumStaffAcc)
- {
- system("cls");
- int RecordChoice = 0;
- int MenuChoice = 0;
- int i = 0;
- printf("\n\n\n");
- if (NumStaffAcc == 0)
- {
- printf("\n\nNo records to display! Add records first!");
- printf("\n\nClick ENTER to continue.");
- getchar();
- }
- else
- {
- do
- {
- printf("\n\n");
- DisplayStaff(AllStaff, NumStaffAcc);
- printf("\nProvide by number, which record you want to update and press ENTER to continue: ");
- printf("\nYour choice: ");
- RecordChoice = GetValidatedInteger(0, MAX_NUM_STAFF); //choosing which record you want to update
- system("cls");
- system("cls");
- printf("0.Back to records\n");
- printf("\n\n\n What do you want to change?");
- printf("\n\n\n\n 1. First name\n");
- printf("\n 2. Last name\n");
- printf("\n 3. Date of birth\n");
- printf("\n 4. Address\n");
- printf("\n 5. City\n");
- printf("\n 6. Postcode\n");
- printf("\n 7. Job title\n");
- printf("\n 8. Departhemt\n");
- printf("\n 9. Start date\n");
- printf("\n 10. Pay grade\n");
- printf("\n 11. Login\n");
- printf("\n 12. Password\n");
- MenuChoice = GetValidatedInteger(0, 12);
- Sleep(100);
- switch (MenuChoice)
- {
- case 1:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new first name?\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].Name, 1, MAX_LEN_NAME);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 2:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new surname?\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].Surname, 1, MAX_LEN_NAME);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 3:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new date of birth?\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].DOB, 1, MAX_LEN_DATE);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 4:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new address?\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].Address, 1, MAX_LEN_ADDRESS);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- break;
- case 5:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new city?\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].City, 1, MAX_LEN_CITY);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 6:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new postcode\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].Postcode, 1, MAX_LEN_POSTCODE);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 7:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new job title\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].JobTitle, 1, MAX_LEN_TITLE);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 8:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new department\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].Department, 1, MAX_LEN_DEPARTMENT);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 9:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new start date?\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].StartDate, 1, MAX_LEN_DATE);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 10:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new pay grade?\n");
- printf("\n --> ");
- int Choice = 0;
- GradeMenu();
- Choice = GetValidatedInteger(1, 3);
- switch (Choice)
- {
- case 1:
- AllStaff[*NumStaffAcc].PayGrade = GRADE1;
- break;
- case 2:
- AllStaff[*NumStaffAcc].PayGrade = GRADE2;
- break;
- case 3:
- AllStaff[*NumStaffAcc].PayGrade = GRADE3;
- break;
- }
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 11:
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is employee new login?\n");
- printf("\n --> ");
- GetValidatedString(AllStaff[RecordChoice - 1].Login, 1, MAX_LEN_EMAIL);
- if (StaffAccDetailsUpdate() == 'N') return;
- break;
- }
- case 12:
- {
- char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n\n What is your new password?\n");
- printf("\n --> ");
- Password(TemporaryPass);
- strcpy_s(AllStaff[RecordChoice - 1].Password, MAX_LEN_PASSWORD, TemporaryPass);
- }
- case 0:
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- }
- void StaffHoliday(struct StaffAccount AllStaff[], int *NumStaffAcc)
- {
- int i = 0;
- int TableMenu;
- char AddAnother ="";
- char DeleteNewRecord = '\0';
- int Record = 0;
- system("cls");
- printf("0.Back to Main Menu\n");
- if (NumStaffAcc == 0)
- {
- printf("\nPlease type in a new record!");
- getchar();
- }
- else
- {
- printf("\n%-5s%-20s", "1.", "Add Holiday");
- printf("\n%-5s%-20s", "2.", "Display all holidays");
- printf("\n%-5s%-20s", "3.", "Delete holiday");
- printf("\n\n Enter your choice: ");
- TableMenu = GetValidatedInteger(1, 4);
- switch (TableMenu)
- {
- case 1:
- printf("\n%-5s%-15s%-25s%-15s%-25s%-20s%-15s%-15s%-15s%-15s", "NO", "FIRST NAME", "LAST NAME", "DOB", "JOB TITLE", "DEPARTMENT", "START DATE", "PAY GRADE", "LOGIN", "PASSWORD");
- printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- do {
- for (int i = 0; i < NumStaffAcc; i++)
- printf("\n\n%-5d%-15s%-25s%-15s%-25s%-20s%-15s%-15.2f%-15s%-15s", i + 1, AllStaff[i].Name, AllStaff[i].Surname
- , AllStaff[i].DOB, AllStaff[i].JobTitle, AllStaff[i].Department, AllStaff[i].StartDate, AllStaff[i].PayGrade, AllStaff[i].Login, AllStaff[i].Password);
- printf("\nChoose employee to book holiday : ");
- Record = GetValidatedInteger(0, MAX_NUM_STAFF);
- printf("\Enter the start date of the employee holiday");
- GetValidatedString(AllStaff[i].Start_date, 1, START_DATE);
- printf("\Enter the end date of the employee holiday");
- GetValidatedString(AllStaff[i].End_date, 1, END_DATE);
- /*if (AddAnother == 'N')
- {
- DisplayRecordsSelected(AllStaff, NumStaffAcc);
- }*/
- } while (AddAnother == 'Y');
- break;
- case 2:
- if (*NumStaffAcc == 0)
- {
- printf("\nPlease type in a new record");
- getchar();
- }
- else
- {
- printf("\n%-5s%-15s%-25s%-15s%-25s%", "NO", "FIRST NAME", "LAST NAME", "Start date", "End date");
- printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- for (i = 0; i < NumStaffAcc; i++)
- {
- printf("\n\n%-5d%-15s%-25s%-15s%-25s%", i + 1, AllStaff[i].Name, AllStaff[i].Surname, AllStaff[i].Start_date, AllStaff[i].End_date);
- }
- getchar();
- }
- break;
- case 3:
- if (NumStaffAcc == 0)
- {
- printf("\nPlease type in a new record");
- getchar();
- }
- else
- {
- do
- {
- system("cls");
- printf("\n%-5s%-15s%-25s%-15s%-25s%", "NO", "FIRST NAME", "LAST NAME", "Start date", "End date");
- printf("\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
- for (int i = 0; i <= (NumStaffAcc - 1); i++)
- printf("\n\n%-5d%-15s%-25s%-15s%-25s%", i + 1, AllStaff[i].Name, AllStaff[i].Surname, AllStaff[i].Start_date, AllStaff[i].End_date);
- printf("\nEnter the record number that you want to delete: ");
- Record = GetValidatedInteger(0, MAX_NUM_STAFF);
- AllStaff[Record - 1] = AllStaff[*NumStaffAcc - 1];
- (*NumStaffAcc);
- printf("\n Do you want to delete another record (Y/N) ?: ");
- DeleteNewRecord = GetValidatedYesNo();
- if (NumStaffAcc == 0)
- {
- system("cls");
- printf("\nNo more records to delete");
- getchar();
- }
- } while (DeleteNewRecord == 'Y' && *NumStaffAcc > 0);
- }
- }
- }
- }
- void AdminAccLayout(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck)
- {
- int MenuChoice = 0;
- do
- {
- system("cls");
- printf(" 1.LogOut\n");
- printf("\n\n\n Hello");
- printf("\n\n\n\n 2. Manage destinations\n");
- printf("\n 3. Manage employees details\n");
- printf("\n 4. Manage customers\n");
- printf("\n 5. ..............\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '1':
- (*WhatData) = -1;
- Sleep(150);
- (*LogInCheck) = 0;
- system("cls");
- return;
- break;
- case '2':
- ManageDestinations(AllCities, NumOfCities);
- break;
- case '3':
- ManageStaff(AllStaff, NumStaffAcc, WhatData);
- break;
- case '4':
- break;
- case '5':
- break;
- }
- } while (MenuChoice != '1');
- }
- void ManageStaff(struct StaffAccount AllStaff[], int *NumStaffAcc, int *WhatData)
- {
- int MenuChoice = 0;
- do
- {
- system("cls");
- printf("0.Back to account page\n");
- printf("\n\n\n");
- printf("\n\n\n\n 2. Add new employee\n");
- printf("\n 3. Display all employees\n");
- printf("\n 4. Search by\n");
- printf("\n 5. Upadate employee details\n");
- printf("\n 6. Probation\n");
- printf("\n 7. Holidays\n");
- printf("\n 8. Payroll\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '2':
- CreateStaffAcc(AllStaff, NumStaffAcc);
- break;
- case '3':
- DisplayStaffAll(AllStaff, NumStaffAcc);
- break;
- case '4':
- SearchRecords(AllStaff, NumStaffAcc, WhatData);
- break;
- case '5':
- UpdateRecords(AllStaff, NumStaffAcc);
- break;
- case '6':
- //UpdateRecords(AllStaff, NumStaffAcc);
- break;
- case '7':
- StaffHoliday(AllStaff, NumStaffAcc);
- break;
- case '8':
- //UpdateRecords(AllStaff, NumStaffAcc);
- break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- void ManageDestinations(struct City_Country AllCities[], int *NumOfCities)
- {
- int MenuChoice = 0;
- do
- {
- system("cls");
- printf("0.Back to account page\n\n\n\n");
- printf("\n\n\n\n 2. Add new city\n");
- printf("\n 3. Update city details\n");
- printf("\n 4. Delete city\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '2':
- system("cls");
- printf("0.Back to account page\n\n\n\n");
- printf(" Add new destination ");
- printf("\n\n\n\n Name of the city: ");
- GetValidatedString(AllCities[*NumOfCities].City, 1, MAX_LEN_CITY);
- if (strcmp(AllCities[*NumOfCities].City, "0") == 0) { system("cls"); return; }
- printf("\n Name of the country: ");
- GetValidatedString(AllCities[*NumOfCities].Country, 1, MAX_LEN_CITY);
- if (strcmp(AllCities[*NumOfCities].Country, "0") == 0) { system("cls"); return; }
- printf("\n Airport code: ");
- GetValidatedString(AllCities[*NumOfCities].AirportCode, 1, MAX_LEN_CODE);
- if (strcmp(AllCities[*NumOfCities].AirportCode, "0") == 0) { system("cls"); return; }
- printf("\n Place (1-10): ");
- AllCities[*NumOfCities].Place = GetValidatedInteger(1, 10);
- if (AllCities[*NumOfCities].Place == 0) { system("cls"); return; }
- printf("\n Popularity (0-100): ");
- AllCities[*NumOfCities].Popularity = GetValidatedInteger(0, 100);
- if (AllCities[*NumOfCities].Popularity == 0) { system("cls"); return; }
- printf("\n\n\n Press ENTER to go back to Main Menu.\n");
- (*NumOfCities)++;
- getchar();
- system("cls");
- break;
- case '3':
- {
- int MenuChoice2 = 0;
- do
- {
- system("cls");
- printf("0.Back to previous page\n");
- printf("\n\n\n What do you want to change?");
- printf("\n\n\n\n 2. Name of the city\n");
- printf("\n 3. Name of the country\n");
- printf("\n 4. Airport code\n");
- printf("\n 5. Place\n");
- printf("\n 6. Popularity\n");
- MenuChoice2 = _getch();
- Sleep(100);
- switch (MenuChoice2)
- {
- case '2':
- break;
- case '3':
- break;
- case '4':
- break;
- case '5':
- break;
- case '6':
- break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- break;
- case '4':
- break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- void DisplayDestinations(struct City_Country AllCities[], int *NumOfCities)
- {
- system("cls");
- printf("\n %-11s%-17s%-18s%-4s", "No.", "City", "Country", "IATA");
- printf("\n ===== ========== ================= ======\n");
- for (int i = 0; i < *NumOfCities; i++)
- {
- printf("\n %-9d%-15s%-22s%-4s\n", i+1, AllCities[i].City, AllCities[i].Country, AllCities[i].AirportCode);
- }
- printf("\n\n\n\n Press ENTER to go back to Main Menu.\n");
- getchar();
- system("cls");
- }
- ///// external files
- int ReadAllRecordsFromFile(struct CustomerAccount AllRecords[], int NumCustomerAcc)
- {
- FILE *fp = NULL;
- if (fopen_s(&fp, "CustomerAccount", "rb") != 0)
- {
- //printf("\nCannot find a file.");
- return;
- }
- else
- {
- int Records;
- Records = fread(AllRecords, sizeof(struct CustomerAccount), NumCustomerAcc, fp);
- fclose(fp);
- return(Records);
- }
- }
- void SaveAllRecordsToFile(struct CustomerAccount AllRecords[], int NumCustomerAcc)
- {
- FILE *fp = NULL;
- if (fopen_s(&fp, "CustomerAccount", "wb") != 0)
- {
- //printf("\nCannot find a file.");
- return;
- }
- else
- {
- NumCustomerAcc = fwrite(AllRecords, sizeof(struct CustomerAccount), NumCustomerAcc, fp);
- fclose(fp);
- }
- }
- int ReadAllStaffFromFile(struct StaffAccount AllStaff[], int NumStaffAcc)
- {
- FILE *fp = NULL;
- if (fopen_s(&fp, "StaffAccount", "rb") != 0)
- {
- //printf("\nCannot find a file.");
- return;
- }
- else
- {
- int Records;
- Records = fread(AllStaff, sizeof(struct StaffAccount), NumStaffAcc, fp);
- fclose(fp);
- return(Records);
- }
- }
- void SaveAllStaffToFile(struct StaffAccount AllStaff[], int NumStaffAcc)
- {
- FILE *fp = NULL;
- if (fopen_s(&fp, "StaffAccount", "wb") != 0)
- {
- //printf("\nCannot find a file.");
- return;
- }
- else
- {
- NumStaffAcc = fwrite(AllStaff, sizeof(struct StaffAccount), NumStaffAcc, fp);
- fclose(fp);
- }
- }
- int ReadAllCitiesFromFile(struct City_Country AllCities[], int NumOfCities)
- {
- FILE *fp = NULL;
- if (fopen_s(&fp, "Destinations", "rb") != 0)
- {
- //printf("\nCannot find a file.");
- return;
- }
- else
- {
- int Records;
- Records = fread(AllCities, sizeof(struct City_Country), NumOfCities, fp);
- fclose(fp);
- return(Records);
- }
- }
- void SaveAllCitiesToFile(struct City_Country AllCities[], int NumOfCities)
- {
- FILE *fp = NULL;
- if (fopen_s(&fp, "Destinations", "wb") != 0)
- {
- //printf("\nCannot find a file.");
- return;
- }
- else
- {
- NumOfCities = fwrite(AllCities, sizeof(struct City_Country), NumOfCities, fp);
- fclose(fp);
- }
- }
- ///// login for customer and staff
- void LogInCustomer(struct CustomerAccount AllRecords[], int NumCustomerAcc, int *LogInCheck, int *WhatData)
- {
- Sleep(100);
- system("cls");
- printf("0.Back to Main Menu\n");
- //////////////////////////////////////////////////////////////////////EMAIL ADDRESS/////////////////////////////////////////////////////
- printf("\n\n Email Address: ");
- char TemporaryEmail[MAX_LEN_EMAIL + 1] = "";
- int Counter = 1, Try = 3, Try2 = 3, RandomNumber1 = 0, RandomNumber2 = 0, RandomNumber3 = 0, StarsToDisplay = 0;
- char MemPassCheck = "", First, Second, Third;
- do
- {
- *WhatData = -1;
- Counter = 1;
- GetValidatedString(TemporaryEmail, 0, MAX_LEN_EMAIL);
- if (strcmp(TemporaryEmail, "0") == 0) { system("cls"); return; }
- if (_strcmpi(TemporaryEmail, AllRecords[0].Email) != 0) *WhatData = -1;
- else *WhatData = 0;
- for (int i = 1; i < NumCustomerAcc; i++)
- {
- if (_strcmpi(TemporaryEmail, AllRecords[i].Email) != 0)
- {
- Counter++;
- }
- else
- {
- *WhatData = Counter;
- }
- }
- if (*WhatData == -1)
- {
- printf("\n\n It looks like this Email Address has not been used yet.\n");
- printf(" Please retype your Email Address.\n");
- Sleep(2400);
- system("cls");
- printf("0.Back to Main Menu\n");
- printf("\n\n Email Address: ");
- for (int i = 0; i < MAX_LEN_EMAIL; i++)
- {
- TemporaryEmail[i] = NULL;
- }
- }
- } while (*WhatData == -1);
- if (AllRecords[*WhatData].Lock == 0)
- {
- //////////////////////////////////////////////////////////PASSWORD/////////////////////////////////////////////////////////////////////////
- char Pass[2] = "";
- char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
- system("cls");
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n Password: ");
- do
- {
- StarsToDisplay = 0;
- StarsToDisplay = Password(TemporaryPass2);
- if (strcmp(TemporaryPass2, AllRecords[*WhatData].Password) != 0)
- {
- Try--; Try2--;
- for (int i = 0; i < MAX_LEN_PASSWORD; i++)
- {
- TemporaryPass2[i] = NULL;
- }
- Pass[0] = NULL;
- if (Try != 0) printf("\n\n Your password is incorrect. Please retype it.\n");
- if (Try > 1) printf(" %d tries left.", Try);
- else if (Try == 1) printf(" %d try left.", Try);
- if (Try != 0) Sleep(2400);
- system("cls");
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n Password: ");
- }
- } while (Try != 0 && strcmp(TemporaryPass2, AllRecords[*WhatData].Password) != 0);
- ///////////////////////////////////////////////////////////////Memorable Password///////////////////////////////////////////////////////////////////////////////////
- if (Try == 0)
- {
- Try = 3;
- int SizeOfMemPass = 0, i = 0;
- srand(time(NULL));
- while (AllRecords[*WhatData].MemorablePassword[i] != '\0')
- {
- SizeOfMemPass++;
- i++;
- }
- if (SizeOfMemPass != 0)
- {
- do
- {
- system("cls");
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n\n\n Your password is incorrect and you do not have any more tries left.\n");
- printf("\n Please enter three characters from your memorable password.\n");
- if (Try > 1) printf("\n %d tries left.", Try);
- else if (Try == 1) printf("\n %d try left.", Try);
- Try--;
- RandomNumber1 = rand() % SizeOfMemPass;
- printf("\n\n %d.", RandomNumber1 + 1);
- First = _getch();
- printf("%c", First);
- do
- {
- RandomNumber2 = rand() % SizeOfMemPass;
- if (RandomNumber2 != RandomNumber1)
- {
- printf(" %d.", RandomNumber2 + 1);
- Second = _getch();
- printf("%c", Second);
- }
- } while (RandomNumber2 == RandomNumber1);
- do
- {
- RandomNumber3 = rand() % SizeOfMemPass;
- if (RandomNumber3 != RandomNumber1 && RandomNumber3 != RandomNumber2)
- {
- printf(" %d.", RandomNumber3 + 1);
- Third = _getch();
- printf("%c", Third);
- Sleep(400);
- }
- } while (RandomNumber3 == RandomNumber1 || RandomNumber3 == RandomNumber2);
- } while ((Try != 0) && (AllRecords[*WhatData].MemorablePassword[RandomNumber1] != First || AllRecords[*WhatData].MemorablePassword[RandomNumber2] != Second || AllRecords[*WhatData].MemorablePassword[RandomNumber3] != Third));
- }
- else Try = 0;
- }
- }
- else
- {
- Try = 0;
- }
- if (Try == 0 && (AllRecords[*WhatData].MemorablePassword[RandomNumber1] != First || AllRecords[*WhatData].MemorablePassword[RandomNumber2] != Second || AllRecords[*WhatData].MemorablePassword[RandomNumber3] != Third))
- {
- if (AllRecords[*WhatData].Lock == 0)
- {
- char Code[15 + 1] = "";
- RandomCode(Code, 7);
- strcpy_s(AllRecords[*WhatData].Password, MAX_LEN_PASSWORD, Code);
- AllRecords[*WhatData].Lock = 1;
- for (int i = 0; i <= MAX_LEN_PASSWORD; i++)
- {
- AllRecords[*WhatData].MemorablePassword[i] = NULL;
- }
- SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
- }
- system("cls");
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n\n\n\n\n Your account has been locked.");
- printf("\n\n Please, write down the code which is down below.");
- printf("\n Use it as a password during next loging in.");
- printf("\n\n ---> %s <---\n", AllRecords[*WhatData].Password);
- printf("\n\n\n\n\n\n\n\n Press ENTER to go back to Main Menu.\n");
- getchar();
- system("cls");
- }
- else
- {
- printf("\n\n\n 1. Keep me log in ( )\n");
- printf("\n\n\n\n Press ENTER to log in.\n");
- AllRecords[*WhatData].KeepLogin = 0;
- Try++;
- int KeepMeLogin = 0;
- do
- {
- KeepMeLogin = 0;
- KeepMeLogin = _getch();
- if (KeepMeLogin == '1')
- {
- system("cls");
- if (Try2 == 0)
- {
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n\n\n Your password is incorrect and you do not have any more tries left.\n");
- printf("\n Please enter three characters from your memorable password.\n");
- if (Try > 1) printf("\n %d tries left.", Try);
- else if (Try == 1) printf("\n %d try left.", Try);
- else if (Try == 0) printf("\n %d try left.", Try);
- printf("\n\n %d.", RandomNumber1 + 1); printf("%c", First);
- printf(" %d.", RandomNumber2 + 1); printf("%c", Second);
- printf(" %d.", RandomNumber3 + 1); printf("%c", Third);
- }
- else
- {
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n Password: ");
- for (int i = 0; i < StarsToDisplay; i++)
- {
- printf("*");
- }
- }
- printf("\n\n\n 1. Keep me log in (x)\n");
- printf("\n\n\n\n Press ENTER to log in.\n");
- AllRecords[*WhatData].KeepLogin = 1;
- }
- if (KeepMeLogin != 13)
- {
- KeepMeLogin = _getch();
- if (KeepMeLogin == '1')
- {
- system("cls");
- if (Try2 == 0)
- {
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n\n\n Your password is incorrect and you do not have any more tries left.\n");
- printf("\n Please enter three characters from your memorable password.\n");
- if (Try > 1) printf("\n %d tries left.", Try);
- else if (Try == 1) printf("\n %d try left.", Try);
- else if (Try == 0) printf("\n %d try left.", Try);
- printf("\n\n %d.", RandomNumber1 + 1); printf("%c", First);
- printf(" %d.", RandomNumber2 + 1); printf("%c", Second);
- printf(" %d.", RandomNumber3 + 1); printf("%c", Third);
- }
- else
- {
- printf("\n\n\n Email Address: %s", TemporaryEmail);
- printf("\n\n Password: ");
- for (int i = 0; i < StarsToDisplay; i++)
- {
- printf("*");
- }
- }
- printf("\n\n\n 1. Keep me log in ( )\n");
- printf("\n\n\n\n Press ENTER to log in.\n");
- AllRecords[*WhatData].KeepLogin = 0;
- }
- }
- } while (KeepMeLogin != 13);
- SaveAllRecordsToFile(AllRecords, NumCustomerAcc);
- (*LogInCheck)++;
- switch (AllRecords[*WhatData].Theme)
- {
- case 1:
- system("color 70");
- break;
- case 2:
- system("COLOR 67");
- break;
- case 3:
- system("color 30");
- break;
- case 4:
- system("color 07");
- break;
- }
- system("cls");
- }
- }
- void LogInStaff(struct StaffAccount AllStaff[], struct City_Country AllCities[], int *NumStaffAcc, int *NumOfCities, int *WhatData, int *LogInCheck)
- {
- Sleep(100);
- system("cls");
- char TemporaryLogin[MAX_LEN_EMAIL + 1] = "";
- char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
- int Try = 3, StarsToDisplay = 0;
- int Counter = 1;
- printf("0.Back to Main Menu\n");
- ////////////////////////////////////////////////////////////////////// Login /////////////////////////////////////////////////////
- printf("\n\n\n\n Login: ");
- do
- {
- *WhatData = -1;
- Counter = 1;
- GetValidatedString(TemporaryLogin, 0, MAX_LEN_EMAIL);
- if (strcmp(TemporaryLogin, "0") == 0) { system("cls"); return; }
- if (_strcmpi(TemporaryLogin, AllStaff[0].Login) != 0) *WhatData = -1;
- else *WhatData = 0;
- for (int i = 1; i < *NumStaffAcc; i++)
- {
- if (_strcmpi(TemporaryLogin, AllStaff[i].Login) != 0)
- {
- Counter++;
- }
- else
- {
- *WhatData = Counter;
- }
- }
- if (*WhatData == -1)
- {
- printf("\n\n It looks like this login has not been used yet.\n");
- printf(" Please retype your login or contact your manager.\n");
- Sleep(2400);
- system("cls");
- printf("0.Back to Main Menu\n");
- printf("\n\n\n\n Login: ");
- for (int i = 0; i < MAX_LEN_EMAIL; i++)
- {
- TemporaryLogin[i] = NULL;
- }
- }
- } while (*WhatData == -1);
- if (AllStaff[*WhatData].Lock == 0)
- {
- //////////////////////////////////////////////////////////PASSWORD/////////////////////////////////////////////////////////////////////////
- char Pass[2] = "";
- system("cls");
- printf("\n\n\n\n\n Login: %s", TemporaryLogin);
- printf("\n\n Password: ");
- do
- {
- StarsToDisplay = 0;
- StarsToDisplay = Password(TemporaryPass);
- if (strcmp(TemporaryPass, AllStaff[*WhatData].Password) != 0)
- {
- Try--;
- for (int i = 0; i < MAX_LEN_PASSWORD; i++)
- {
- TemporaryPass[i] = NULL;
- }
- Pass[0] = NULL;
- if (Try != 0) printf("\n\n Your password is incorrect. Please retype it.\n");
- if (Try > 1) printf(" %d tries left.", Try);
- else if (Try == 1) printf(" %d try left.", Try);
- if (Try != 0) Sleep(2400);
- system("cls");
- printf("\n\n\n\n\n Login: %s", TemporaryLogin);
- printf("\n\n Password: ");
- }
- } while (Try != 0 && strcmp(TemporaryPass, AllStaff[*WhatData].Password) != 0);
- }
- else
- {
- Try = 0;
- }
- if (Try == 0)
- {
- AllStaff[*WhatData].Lock = 1;
- SaveAllStaffToFile(AllStaff, NumStaffAcc);
- system("cls");
- printf("\n\n\n\n\n Login: %s", TemporaryLogin);
- printf("\n\n\n\n\n\n Your account has been locked.");
- printf("\n Please contact your manager to reset your password.");
- printf("\n\n\n\n\n\n\n\n Press ENTER to go back to Main Menu.\n");
- getchar();
- system("cls");
- }
- else
- {
- if (AllStaff[*WhatData].Admin == 1)
- {
- Sleep(500);
- AdminAccLayout(AllStaff, AllCities, NumStaffAcc, NumOfCities, WhatData, LogInCheck);
- }
- //else
- }
- }
- ///// customer account functions
- void CustomerAccLayout(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *LogInCheck)
- {
- int MenuChoice = 0, Delete = 0;
- do
- {
- if (Delete != 0) { system("cls"); *LogInCheck = 0; return; }
- system("cls");
- printf("0.Back to Main Menu 1.LogOut\n");
- printf("\n\n\n Hello, %s", AllRecords[*WhatData].Name);
- printf("\n\n\n\n 2. Manage your flights\n");
- printf("\n 3. Change your personal details\n");
- printf("\n 4. Manage credit card details\n");
- printf("\n 5. Manage account\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '1':
- AllRecords[*WhatData].KeepLogin = 0;
- (*WhatData) = -1;
- Sleep(150);
- (*LogInCheck) = 0;
- system("color 07");
- system("cls");
- return;
- break;
- case '2':
- break;
- case '3':
- CustomerAccPersonalDeatils(AllRecords, NumCustomerAcc, WhatData);
- break;
- case '4':
- CustomerAccManageCard(AllRecords, NumCustomerAcc, WhatData);
- break;
- case '5':
- CustomerAccManageAcc(AllRecords, NumCustomerAcc, WhatData, &Delete);
- break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- void CustomerAccPersonalDeatils(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData)
- {
- int MenuChoice = 0;
- do
- {
- system("cls");
- printf("0.Back to account page\n");
- printf("\n\n\n What do you want to change?");
- printf("\n\n\n\n 1. First name\n");
- printf("\n 2. Last name\n");
- printf("\n 3. Email address\n");
- printf("\n 4. Password\n");
- printf("\n 5. Memorable Password\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '1':
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is your new first name?\n");
- printf("\n --> ");
- GetValidatedString(AllRecords[*WhatData].Name, 1, MAX_LEN_NAME);
- if (CustomerAccPersonalDetailsUpdate() == 'N') return;
- break;
- }
- case '2':
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is your new surname?\n");
- printf("\n --> ");
- GetValidatedString(AllRecords[*WhatData].Surname, 1, MAX_LEN_NAME);
- if (CustomerAccPersonalDetailsUpdate() == 'N') return;
- break;
- }
- case '3':
- {
- char TemporaryEmail[MAX_LEN_EMAIL + 1] = "";
- int At = 0, Dot = 0, Counter = 0;
- do
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n What is your new email address?\n");
- printf("\n --> ");
- GetValidatedString(TemporaryEmail, 1, MAX_LEN_EMAIL);
- Email(AllRecords, TemporaryEmail, NumCustomerAcc, &At, &Dot, &Counter);
- } while (Counter != *NumCustomerAcc || At == 0 || At > 1 || Dot == 0);
- strcpy_s(AllRecords[*WhatData].Email, MAX_LEN_EMAIL, TemporaryEmail);
- for (int i = 0; i < MAX_LEN_EMAIL; i++)
- {
- TemporaryEmail[i] = NULL;
- }
- if (CustomerAccPersonalDetailsUpdate() == 'N') return;
- break;
- }
- case '4':
- {
- char TemporaryPass[MAX_LEN_PASSWORD + 1] = "";
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n\n What is your new password?\n");
- printf("\n --> ");
- Password(TemporaryPass);
- strcpy_s(AllRecords[*WhatData].Password, MAX_LEN_PASSWORD, TemporaryPass);
- if (CustomerAccPersonalDetailsUpdate() == 'N') return;
- }
- break;
- case '5':
- {
- char TemporaryPass2[MAX_LEN_PASSWORD + 1] = "";
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n Password must be between %d and %d characters. ", MIN_LEN_PASSWORD, MAX_LEN_PASSWORD);
- printf("\n\n What is your new memorable password?\n");
- printf("\n --> ");
- Password(TemporaryPass2);
- strcpy_s(AllRecords[*WhatData].MemorablePassword, MAX_LEN_PASSWORD, TemporaryPass2);
- if (CustomerAccPersonalDetailsUpdate() == 'N') return;
- break;
- }
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- char CustomerAccPersonalDetailsUpdate()
- {
- Sleep(100);
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n The data has been updated.");
- Sleep(1500);
- system("cls");
- char Reply;
- printf("\n\n\n\n\n\n\n\n\n\n\n Do you want to do more updates? (Y/N)");
- Reply = GetValidatedYesNo();
- Sleep(100);
- return Reply;
- }
- void CustomerAccManageAcc(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData, int *Delete)
- {
- int MenuChoice = 0;
- do
- {
- system("cls");
- printf("0.Back to account page\n");
- printf("\n\n\n What do you want to do?");
- printf("\n\n\n\n 1. Change theme\n");
- printf("\n 2. Delete account\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '1':
- {
- system("cls");
- printf("0.Back to previous page\n");
- printf("\n\n\n Choose your theme:");
- printf("\n\n\n\n 1. Grey background\n");
- printf("\n 2. Yellow background\n");
- printf("\n 3. Light blue background\n");
- printf("\n 4. Default\n");
- int ThemeChoice = 0;
- ThemeChoice = _getch();
- if (ThemeChoice != '0')
- {
- Sleep(100);
- switch (ThemeChoice)
- {
- case '1':
- system("color 70");
- AllRecords[*WhatData].Theme = 1;
- break;
- case '2':
- system("COLOR 67");
- AllRecords[*WhatData].Theme = 2;
- break;
- case '3':
- system("color 30");
- AllRecords[*WhatData].Theme = 3;
- break;
- case '4':
- system("color 07");
- AllRecords[*WhatData].Theme = 4;
- break;
- }
- if (CustomerAccPersonalDetailsUpdate() == 'N') return;
- }
- }break;
- case '2':
- {
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n Are you sure you want to delete the account? (Y/N)");
- if (GetValidatedYesNo() == 'Y')
- {
- AllRecords[*WhatData] = AllRecords[*NumCustomerAcc + 1];
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n Your account has been deleted.");
- Sleep(1000);
- system("cls");
- printf("\n\n\n\n\n\n\n\n\n\n\n You will be redirected to main page in a moment.");
- Sleep(1000);
- system("cls"); (*Delete)++; (*NumCustomerAcc)--; return;
- }
- }break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- void CustomerAccManageCard(struct CustomerAccount AllRecords[], int *NumCustomerAcc, int *WhatData)
- {
- int MenuChoice = 0;
- do
- {
- system("cls");
- printf("0.Back to account page\n");
- printf("\n\n\n What do you want to do?");
- printf("\n\n\n\n 1. Show saved credit card\n");
- printf("\n 2. Add new credit card\n");
- printf("\n 3. Delete credit card\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '1':
- if (AllRecords[*WhatData].CreditCardCheck == 0) { system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\n None saved credit card details."); Sleep(2000); }
- else
- {
- system("cls");
- printf("\n\n Your credit card details\n");
- printf("\n\n\n\n\n Card holder name: %s", AllRecords[*WhatData].NameOnCard);
- printf("\n\n Card number: %s", AllRecords[*WhatData].CardNumber);
- printf("\n\n Card expires on: %s / %s", AllRecords[*WhatData].ExpDateMonth, AllRecords[*WhatData].ExpDateYear);
- printf("\n\n Security code: %s", AllRecords[*WhatData].SecurityCode);
- printf("\n\n\n\n\n\n\n Press ENTER to go back.");
- getchar();
- }
- break;
- case '2':
- CustomerAccAddCreditCard(AllRecords, WhatData);
- break;
- case '3':
- system("cls");
- if (AllRecords[*WhatData].CreditCardCheck == 0) { system("cls"); printf("\n\n\n\n\n\n\n\n\n\n\n None saved credit card details."); Sleep(2000); }
- else
- {
- AllRecords[*WhatData].NameOnCard[MAX_LEN_NAMEONCARD] = AllRecords[*NumCustomerAcc + 1].NameOnCard;
- AllRecords[*WhatData].CardNumber[MAX_LEN_CARDNUMBER] = AllRecords[*NumCustomerAcc + 1].CardNumber;
- AllRecords[*WhatData].ExpDateMonth[MAX_LEN_EXPDATE] = AllRecords[*NumCustomerAcc + 1].ExpDateMonth;
- AllRecords[*WhatData].ExpDateYear[MAX_LEN_EXPDATE] = AllRecords[*NumCustomerAcc + 1].ExpDateYear;
- AllRecords[*WhatData].SecurityCode[MAX_LEN_SECURITYCODE] = AllRecords[*NumCustomerAcc + 1].SecurityCode;
- AllRecords[*WhatData].CreditCardCheck = 0;
- printf("\n\n\n\n\n\n\n\n\n\n\n Your credit card details has been deleted."); Sleep(2000);
- }
- break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- void CustomerAccAddCreditCard(struct CustomerAccount AllRecords[], int *WhatData)
- {
- system("cls");
- printf("\n\n Please enter your credit card details to finish booking.");
- printf("\n\n\n\n\n Card holder name: ");
- ////////////////////////////////////////////////////////////////////////Name on card//////////////////////////////////////////////////////////////////////////////
- char TemporaryName[MAX_LEN_NAMEONCARD + 1] = "";
- GetValidatedString(TemporaryName, 1, MAX_LEN_NAMEONCARD);
- if (strcmp(TemporaryName, "0") == 0) { system("cls"); return; }
- ////////////////////////////////////////////////////////////////////////Card Number///////////////////////////////////////////////////////////////////////////////
- char TemporaryCardNumber[MAX_LEN_CARDNUMBER + 1] = "";
- int Control = 0;
- do
- {
- system("cls");
- printf("\n\n Please enter your credit card details to finish booking.");
- printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
- printf("\n\n Card number: ");
- Control = 0;
- GetValidatedString(TemporaryCardNumber, 1, MAX_LEN_CARDNUMBER);
- if (strcmp(TemporaryCardNumber, "0") == 0) { system("cls"); return; }
- Control = NumberCheck(TemporaryCardNumber, 16);
- } while (Control == 0);
- //////////////////////////////////////////////////////////////////////Card expires date/////////////////////////////////////////////////////////////////////////////
- char TemporaryMonth[MAX_LEN_EXPDATE + 1] = "";
- do
- {
- system("cls");
- printf("\n\n Please enter your credit card details to finish booking.");
- printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
- printf("\n\n Card number: %s", TemporaryCardNumber);
- printf("\n\n Card expires on: ");
- Control = 0;
- GetValidatedString(TemporaryMonth, 1, MAX_LEN_EXPDATE);
- if (strcmp(TemporaryMonth, "0") == 0) { system("cls"); return; }
- Control = NumberCheck(TemporaryMonth, 2);
- } while (Control == 0);
- char TemporaryYear[MAX_LEN_EXPDATE + 1] = "";
- do
- {
- system("cls");
- printf("\n\n Please enter your credit card details to finish booking.");
- printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
- printf("\n\n Card number: %s", TemporaryCardNumber);
- printf("\n\n Card expires on: %s / ", TemporaryMonth);
- Control = 0;
- GetValidatedString(TemporaryYear, 1, MAX_LEN_EXPDATE);
- if (strcmp(TemporaryYear, "0") == 0) { system("cls"); return; }
- Control = NumberCheck(TemporaryYear, 2);
- } while (Control == 0);
- ///////////////////////////////////////////////////////////////////Secuirty code/////////////////////////////////////////////////////////////////////////////////////////
- char TemporarySecCode[MAX_LEN_SECURITYCODE + 1] = "";
- do
- {
- system("cls");
- printf("\n\n Please enter your credit card details to finish booking.");
- printf("\n\n\n\n\n Card holder name: %s", TemporaryName);
- printf("\n\n Card number: %s", TemporaryCardNumber);
- printf("\n\n Card expires on: %s / %s", TemporaryMonth, TemporaryYear);
- printf("\n\n Security code: ");
- Control = 0;
- GetValidatedString(TemporarySecCode, 1, MAX_LEN_SECURITYCODE);
- if (strcmp(TemporarySecCode, "0") == 0) { system("cls"); return; }
- Control = NumberCheck(TemporarySecCode, 3);
- } while (Control == 0);
- strcpy_s(AllRecords[*WhatData].NameOnCard, MAX_LEN_NAMEONCARD, TemporaryName);
- strcpy_s(AllRecords[*WhatData].CardNumber, MAX_LEN_CARDNUMBER + 1, TemporaryCardNumber);
- strcpy_s(AllRecords[*WhatData].ExpDateMonth, MAX_LEN_EXPDATE + 1, TemporaryMonth);
- strcpy_s(AllRecords[*WhatData].ExpDateYear, MAX_LEN_EXPDATE + 1, TemporaryYear);
- strcpy_s(AllRecords[*WhatData].SecurityCode, MAX_LEN_SECURITYCODE + 1, TemporarySecCode);
- AllRecords[*WhatData].CreditCardCheck = 1;
- printf("\n\n\n\n\n\n Your credit card has been saved.");
- Sleep(2000);
- }
- int NumberCheck(char ToCheck[], int CorrectSize)
- {
- int Size = 0, Counter = 0, Change = 0, j = 0;
- while (ToCheck[j] != '\0')
- {
- Size++;
- j++;
- }
- if (Size == CorrectSize)
- {
- for (int i = 0; i < Size; i++)
- {
- Change = ToCheck[i];
- if (48 <= Change && Change <= 57) Counter++;
- }
- if (Size == Counter) return 1;
- else { printf("\n Incorrect data, please re-type it."); Sleep(2000); return 0; }
- }
- else { printf("\n Incorrect data, please re-type it."); Sleep(2000); return 0; }
- }
- void ManageFlights()
- {
- int MenuChoice = 0;
- do
- {
- system("cls");
- printf("0.Back to account page\n\n\n\n");
- printf("\n\n\n\n 2. See bought tickets\n");
- printf("\n 3. Update flight\n");
- printf("\n 4. Cancel flight\n");
- MenuChoice = _getch();
- Sleep(100);
- switch (MenuChoice)
- {
- case '2':
- break;
- case '3':
- break;
- case '4':
- break;
- case '0':
- system("cls");
- break;
- }
- } while (MenuChoice != '0');
- }
- ///// ticket functions
- void SearchFlights(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2)
- {
- int Check = 1;
- char TemporaryCity[MAX_LEN_CITY + 1] = "";
- char TemporaryCity2[MAX_LEN_CITY + 1] = "";
- do
- {
- Check = 1;
- *Airport1 = -1;
- system("cls");
- printf("0.back to main menu\n");
- printf("\n\n\n Departure from:\n");
- printf("\n\n --> ");
- GetValidatedString(TemporaryCity, 0, MAX_LEN_CITY);
- if (strcmp(TemporaryCity, "0") == 0) { system("cls"); *Airport1 = -1; return; }
- if (_strcmpi(TemporaryCity, AllCities[0].City) != 0) *Airport1 = -1;
- else *Airport1 = 0;
- for (int i = 1; i < *NumOfCities; i++)
- {
- if (_strcmpi(TemporaryCity, AllCities[i].City) != 0)
- {
- Check++;
- }
- else
- {
- *Airport1 = Check;
- }
- }
- if (*Airport1 == -1)
- {
- printf("\n\n We do not fly from this city.");
- Sleep(2000);
- }
- } while (*Airport1 == -1);
- do
- {
- Check = 1;
- *Airport2 = -1;
- printf("\n\n\n Arrival to:\n");
- printf("\n\n --> ");
- GetValidatedString(TemporaryCity2, 0, MAX_LEN_CITY);
- if (strcmp(TemporaryCity2, "0") == 0) { system("cls"); *Airport2 = -1; return; }
- if (_strcmpi(TemporaryCity2, AllCities[0].City) != 0) *Airport2 = -1;
- else *Airport2 = 0;
- for (int i = 1; i < *NumOfCities; i++)
- {
- if (_strcmpi(TemporaryCity2, AllCities[i].City) != 0)
- {
- Check++;
- }
- else
- {
- *Airport2 = Check;
- }
- }
- if (*Airport2 == -1)
- {
- printf("\n\n We do not fly to this city.");
- Sleep(2000);
- system("cls");
- printf("0.back to main menu\n");
- printf("\n\n\n Departure from:\n");
- printf("\n\n --> %s\n", TemporaryCity);
- }
- if (_strcmpi(TemporaryCity2, TemporaryCity) == 0)
- {
- printf("\n\n Your departure city and arrival city are the same.");
- Sleep(2300);
- system("cls");
- printf("0.back to main menu\n");
- printf("\n\n\n Departure from:\n");
- printf("\n\n --> %s\n", TemporaryCity);
- *Airport2 = -1;
- }
- } while (*Airport2 == -1);
- strcpy_s(AllTickets[*NumOfTickets].DepartureCity, sizeof(TemporaryCity), AllCities[*Airport1].City);
- strcpy_s(AllTickets[*NumOfTickets].DepartureCountry, sizeof(TemporaryCity), AllCities[*Airport1].Country);
- AllCities[*Airport1].Popularity++;
- strcpy_s(AllTickets[*NumOfTickets].ArrivalCity, sizeof(TemporaryCity), AllCities[*Airport2].City);
- strcpy_s(AllTickets[*NumOfTickets].ArrivalCountry, sizeof(TemporaryCity), AllCities[*Airport2].Country);
- AllCities[*Airport2].Popularity++;
- system("cls");
- }
- void Options(struct City_Country AllCities[], struct Ticket AllTickets[], int *NumOfCities, int *NumOfTickets, int *Airport1, int *Airport2)
- {
- system("cls");
- char Seat[40] = "";
- int Price = 0, A = 0, B = 0, Adult = 0, Child = 0, Infants = 0, OneWay = 0, Way = 2;
- float TicketPrice = 0, TicketPrice2 = 0, TicketPrice3 = 0, TicketPrice4 = 0, TicketChild = 0, TicketChild2 = 0, TicketChild3 = 0, TicketChild4 = 0;
- A = AllCities[*Airport1].Place;
- B = AllCities[*Airport2].Place;
- Price = abs(A - B);
- srand(time(NULL));
- switch (Price)
- {
- case 0:
- TicketPrice = rand() % 15 + 30;
- TicketPrice2 = rand() % 15 + 30;
- TicketPrice3 = rand() % 15 + 30;
- TicketPrice4 = rand() % 15 + 30;
- break;
- case 1:
- TicketPrice = rand() % 15 + 45;
- TicketPrice2 = rand() % 15 + 45;
- TicketPrice3 = rand() % 15 + 45;
- TicketPrice4 = rand() % 15 + 45;
- break;
- case 2:
- TicketPrice = rand() % 15 + 60;
- TicketPrice2 = rand() % 15 + 60;
- TicketPrice3 = rand() % 15 + 60;
- TicketPrice4 = rand() % 15 + 60;
- break;
- case 3:
- TicketPrice = rand() % 15 + 75;
- TicketPrice2 = rand() % 15 + 75;
- TicketPrice3 = rand() % 15 + 75;
- TicketPrice4 = rand() % 15 + 75;
- break;
- case 4:
- TicketPrice = rand() % 35 + 90;
- TicketPrice2 = rand() % 35 + 90;
- TicketPrice3 = rand() % 35 + 90;
- TicketPrice4 = rand() % 35 + 90;
- break;
- case 5:
- TicketPrice = rand() % 50 + 125;
- TicketPrice2 = rand() % 50 + 125;
- TicketPrice3 = rand() % 50 + 125;
- TicketPrice4 = rand() % 50 + 125;
- break;
- case 6:
- TicketPrice = rand() % 35 + 175;
- TicketPrice2 = rand() % 35 + 175;
- TicketPrice3 = rand() % 35 + 175;
- TicketPrice4 = rand() % 35 + 175;
- break;
- case 7:
- TicketPrice = rand() % 60 + 210;
- TicketPrice2 = rand() % 60 + 210;
- TicketPrice3 = rand() % 60 + 210;
- TicketPrice4 = rand() % 60 + 210;
- break;
- case 8:
- TicketPrice = rand() % 40 + 270;
- TicketPrice2 = rand() % 40 + 270;
- TicketPrice3 = rand() % 40 + 270;
- TicketPrice4 = rand() % 40 + 270;
- break;
- }
- TicketChild = TicketPrice - (TicketPrice * 25) / 100;
- TicketChild2 = TicketPrice2 - (TicketPrice2 * 25) / 100;
- TicketChild3 = TicketPrice3 - (TicketPrice3 * 25) / 100;
- TicketChild4 = TicketPrice4 - (TicketPrice4 * 25) / 100;
- do
- {
- printf("\n\n\n How many people?\n\n");
- printf("\n\n Adults(16+): ");
- Adult = GetValidatedInteger(0, 20);
- if (Adult == 0)
- {
- printf("\n\n Children and infants must travel with at least one adult person.\n");
- Sleep(2000);
- system("cls");
- }
- } while (Adult == 0);
- printf("\n Children(2-15): ");
- Child = GetValidatedInteger(0, 20);
- printf("\n Infants(<2): ");
- Infants = GetValidatedInteger(0, 20);
- printf("\n\n\n 1. ( ) One way\n");
- printf("\n\n\n\n Press ENTER to see available flights.\n");
- do
- {
- OneWay = 0;
- OneWay = _getch();
- if (OneWay == '1')
- {
- system("cls");
- printf("\n\n\n How many people?\n\n");
- printf("\n\n Adults(16+): %d\n", Adult);
- printf("\n Children(2-15): %d\n", Child);
- printf("\n Infants(<2): %d\n", Infants);
- printf("\n\n\n 1. (x) One way\n");
- printf("\n\n\n\n Press ENTER to see available flights.\n");
- Way = 1;
- }
- if (OneWay != 13)
- {
- OneWay = _getch();
- if (OneWay == '1')
- {
- system("cls");
- printf("\n\n\n How many people?\n\n");
- printf("\n\n Adults(16+): %d\n", Adult);
- printf("\n Children(2-15): %d\n", Child);
- printf("\n Infants(<2): %d\n", Infants);
- printf("\n\n\n 1. ( ) One way\n");
- printf("\n\n\n\n Press ENTER to see available flights.\n");
- Way = 2;
- }
- }
- } while (OneWay != 13);
- system("cls");
- struct tm newtime;
- char am_pm[] = "AM";
- time_t long_time;
- char timebuf[26];
- errno_t err;
- // Get time as an integer.
- time(&long_time);
- // Convert to local time.
- err = localtime_s(&newtime, &long_time);
- if (newtime.tm_hour > 12) // Set up extension.
- strcpy_s(am_pm, sizeof(am_pm), "PM");
- if (newtime.tm_hour > 12) // Convert from 24-hour
- newtime.tm_hour -= 12; // to 12-hour clock.
- if (newtime.tm_hour == 0) // Set hour to 12 if midnight.
- newtime.tm_hour = 12;
- // Convert to an ASCII representation.
- err = asctime_s(timebuf, 26, &newtime);
- //printf("%.19s %D\n", timebuf, am_pm);
- //printf("%.19s\n", timebuf);
- printf("\n\n\n These are available dates for flight from %s to %s. \n\n\n", AllTickets[*NumOfTickets].DepartureCity, AllTickets[*NumOfTickets].ArrivalCity);
- printf("\n Date Dep.time Price Adults Price Children");
- printf("\n =============== ============ ================ ==================");
- printf("\n1. %d / %d / %d 10:30 AM %1.2f%c %1.2f%c\n\n", newtime.tm_mday, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice, POUND_SIGN, TicketChild, POUND_SIGN);
- printf("2. %d / %d / %d 07:30 AM %1.2f%c %1.2f%c\n\n", newtime.tm_mday + 2, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice2, POUND_SIGN, TicketChild2, POUND_SIGN);
- printf("3. %d / %d / %d 18:00 AM %1.2f%c %1.2f%c\n\n", newtime.tm_mday + 4, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice3, POUND_SIGN, TicketChild3, POUND_SIGN);
- printf("4. %d / %d / %d 22:45 AM %1.2f%c %1.2f%c\n", newtime.tm_mday + 6, newtime.tm_mon + 1, newtime.tm_year + 1900, TicketPrice4, POUND_SIGN, TicketChild4, POUND_SIGN);
- printf("\n\n Which one would you like to choose? ");
- int Choice = 0;
- Choice = _getch();
- switch (Choice)
- {
- case '1':
- AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday;
- AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
- AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
- AllTickets[*NumOfTickets].DepartureHour = 10;
- AllTickets[*NumOfTickets].DepartureMin = 30;
- break;
- case '2':
- AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday + 2;
- AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
- AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
- AllTickets[*NumOfTickets].DepartureHour = 07;
- AllTickets[*NumOfTickets].DepartureMin = 30;
- break;
- case '3':
- AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday + 4;
- AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
- AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
- AllTickets[*NumOfTickets].DepartureHour = 18;
- AllTickets[*NumOfTickets].DepartureMin = 00;
- break;
- case '4':
- AllTickets[*NumOfTickets].DepartureDay = newtime.tm_mday + 6;
- AllTickets[*NumOfTickets].DepartureMonth = newtime.tm_mon + 1;
- AllTickets[*NumOfTickets].DepartureYear = newtime.tm_year + 1900;
- AllTickets[*NumOfTickets].DepartureHour = 22;
- AllTickets[*NumOfTickets].DepartureMin = 45;
- break;
- }
- system("cls");
- char Yes;
- int Counter = 0;
- if (Child + Adult + Infants > 1)
- {
- printf("\n\n\n\n\n\n\n\n\n\n\n Would you like to book all tickets in the same class?(Y/N) ");
- Yes = GetValidatedYesNo();
- }
- for (int i = 1; i <= Child + Adult + Infants; i++)
- {
- system("cls");
- printf("\n\n\n Our airline offers three classes.\n\n");
- printf("\n Which one wolud you like to choose?\n\n\n");
- switch (Choice)
- {
- case '1':
- printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice + (TicketPrice * 150) / 100), POUND_SIGN;
- printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice + TicketPrice, POUND_SIGN);
- printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice, POUND_SIGN, TicketChild, POUND_SIGN);
- break;
- case '2':
- printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice2 + (TicketPrice2 * 150) / 100, POUND_SIGN);
- printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice2 + TicketPrice2, POUND_SIGN);
- printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice2, POUND_SIGN, TicketChild2, POUND_SIGN);
- break;
- case '3':
- printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice3 + (TicketPrice3 * 150) / 100, POUND_SIGN);
- printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice3 + TicketPrice3, POUND_SIGN);
- printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice3, POUND_SIGN, TicketChild3, POUND_SIGN);
- break;
- case '4':
- printf("\n\n\n 1. First class: %1.2f%c per one person", TicketPrice4 + (TicketPrice4 * 150) / 100, POUND_SIGN);
- printf("\n\n 2. Bussiness class: %1.2f%c per one person", TicketPrice4 + TicketPrice4, POUND_SIGN);
- printf("\n\n 3. 3th class: %1.2f%c adult / %1.2f%c child", TicketPrice4, POUND_SIGN, TicketChild4, POUND_SIGN);
- break;
- }
- int Class = 0;
- do
- {
- Seat[0] = NULL;
- Seat[1] = NULL;
- Class = _getch();
- system("cls");
- switch (Class)
- {
- case '1':
- for (int i = 1; i <= 7; i = i + 3)
- {
- if (i == 1)
- {
- printf("\n\n\n | 0%d | | 0%d | | 0%d |\n\n", i, i + 1, i + 2);
- }
- else if (i == 4)
- {
- printf("\n\n\n | 0%d | | 0%d | | 0%d |\n\n", i, i + 1, i + 2);
- }
- else if (i == 7)
- {
- printf("\n\n\n | 0%d | | 0%d | | 0%d |\n\n", i, i + 1, i + 2);
- }
- }
- printf("\n Your seat: ");
- GetValidatedString(Seat, 2, 39);
- if (Counter == 0)
- {
- strcpy_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
- }
- else
- {
- strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), "|");
- strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
- }
- if (Yes == 'Y')
- AllTickets[*NumOfTickets].FirstClass = Child + Adult;
- else
- AllTickets[*NumOfTickets].FirstClass++;
- Counter++;
- break;
- case '2':
- for (int i = 1; i <= 19; i = i + 6)
- {
- if (i == 1)
- {
- printf("\n\n\n | 0%d | 0%d | | 0%d | 0%d | | 0%d | 0%d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
- }
- else if (i == 7)
- {
- printf("\n\n\n | 0%d | 0%d | | 0%d | %d | | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
- }
- else if (i == 13)
- {
- printf("\n\n\n | %d | %d | | %d | %d | | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
- }
- else if (i == 19)
- {
- printf("\n\n\n | %d | %d | | %d | %d | | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5);
- }
- }
- printf("\n Your seat: ");
- GetValidatedString(Seat, 2, 39);
- if (Counter == 0)
- {
- strcpy_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
- }
- else
- {
- strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), "|");
- strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
- }
- if (Yes == 'Y')
- AllTickets[*NumOfTickets].BussinessClass = Child + Adult;
- else
- AllTickets[*NumOfTickets].BussinessClass++;
- Counter++;
- break;
- case '3':
- for (int i = 1; i < 90; i = i + 10)
- {
- if (i == 1)
- {
- printf("\n\n\n | 0%d | 0%d | 0%d | | 0%d | 0%d | 0%d | 0%d | | 0%d | 0%d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9);
- }
- else
- {
- printf(" | %d | %d | %d | | %d | %d | %d | %d | | %d | %d | %d |\n\n", i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8, i + 9);
- }
- }
- printf("\n Your seat: ");
- GetValidatedString(Seat, 2, 39);
- if (Counter == 0)
- {
- strcpy_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
- }
- else
- {
- strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), "|");
- strcat_s(AllTickets[*NumOfTickets].Seats, sizeof(AllTickets[*NumOfTickets].Seats), Seat);
- }
- if (Yes == 'Y')
- AllTickets[*NumOfTickets].ThirdClass = Child + Adult + Infants;
- else
- AllTickets[*NumOfTickets].ThirdClass++;
- Counter++;
- break;
- }
- } while (Class != '1' && Class != '2' && Class != '3');
- if (Yes == 'Y') i = Child + Adult + Infants;
- }
- switch (Choice)
- {
- case '1':
- AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice + (TicketPrice * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice);
- if (Child == 0)
- {
- AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice;
- }
- else
- {
- AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice;
- AllTickets[*NumOfTickets].Price += Child * TicketChild;
- }
- break;
- case '2':
- AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice2 + (TicketPrice2 * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice2);
- if (Child == 0)
- {
- AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice2;
- }
- else
- {
- AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice2;
- AllTickets[*NumOfTickets].Price += Child * TicketChild2;
- }
- break;
- case '3':
- AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice3 + (TicketPrice3 * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice3);
- if (Child == 0)
- {
- AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice3;
- }
- else
- {
- AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice3;
- AllTickets[*NumOfTickets].Price += Child * TicketChild3;
- }
- break;
- case '4':
- AllTickets[*NumOfTickets].Price = AllTickets[*NumOfTickets].FirstClass * (TicketPrice4 + (TicketPrice4 * 150) / 100) + AllTickets[*NumOfTickets].BussinessClass * (2 * TicketPrice4);
- if (Child == 0)
- {
- AllTickets[*NumOfTickets].Price += AllTickets[*NumOfTickets].ThirdClass * TicketPrice4;
- }
- else
- {
- AllTickets[*NumOfTickets].Price += (Adult - AllTickets[*NumOfTickets].FirstClass - AllTickets[*NumOfTickets].BussinessClass) * TicketPrice4;
- AllTickets[*NumOfTickets].Price += Child * TicketChild4;
- }
- break;
- }
- AllTickets[*NumOfTickets].NumberOfAdults = Adult;
- AllTickets[*NumOfTickets].NumberOfChildren = Child;
- AllTickets[*NumOfTickets].NumberOfInfants = Infants;
- AllTickets[*NumOfTickets].WayBackOrNo = Way;
- }
- void Payment(struct CustomerAccount AllRecords[], struct Ticket AllTickets[], int *NumOfTickets, int *WhatData)
- {
- system("cls");
- if (AllRecords[*WhatData].CreditCardCheck == 0)
- {
- CustomerAccAddCreditCard(AllRecords, WhatData);
- system("cls");
- }
- for (int i = 3; i >= 0; i--)
- {
- if (i != 3) Sleep(1000);
- system("cls");
- printf("\n\n\n\n\n\n\n\n Thank You for completing your booking. \n");
- if (i == 3) Sleep(1500);
- printf("\n Now you can see your booking on your account. \n");
- if (i == 3) Sleep(1500);
- printf("\n Do not waste your time and get ready for your journey! \n");
- if (i == 3) Sleep(1500);
- printf("\n\n You will be redirected to a main page in a moment. \n");
- printf("\n %d", i);
- }
- AllTickets[*NumOfTickets].Who = WhatData;
- system("cls");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement