Hotel Management System (According to user requirements)
Client's Document:
(Download PDF)
Code:
// Hotel Management System
// Special Requirements to use this system:
// 1) Must Enter UserName in letters
// 2) Must Enter Email of >5 letters, it must include dot(.) & at the rate symbol(@)
// 3) Password must contain all these (Lowercase, Uppercase, A number and a Symbol) atleast 1 of each should be present to makeup a successful password.
// 4) Business Rule: We don't require login for eating food based on our hotel or other food services.
// 5) Hostels and Food should be selected based on list, don't even change the letter case or else they won't be found
// 6) Enter only first name in username as it is string, it doesn't catch (space)
// 7) There may be problems in calculation of Total cost as for it to be applicable another calculator function with file handling being done is required, it would be out of your PF course
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// Function prototypes
int validateUsername(const char* username);
int validateAge(int age);
int validateEmail(const char* email);
int validatePassword(const char* password, const char* confirmPassword);
int validateMobileNumber(const char* mobileNumber);
int accountExists(const char* username);
void signup();
void login();
void searchByFood();
void searchByHotels();
void orderByHotel();
void orderByFood();
void cart();
// Global variables
char loggedInUser[100] = ""; // Store the username of the logged-in user
int main() {
int option;
char ch;
// Main menu
do
{
printf("Welcome to Food Ordering System!\n");
printf("1. Signup\n");
printf("2. Login\n");
printf("3. Search by Food\n");
printf("4. Search by Hotels\n");
printf("5. Order by Hotel\n");
printf("6. Order by Food\n");
printf("7. Cart\n");
printf("Enter your choice: ");
scanf("%d", &option);
// Perform action based on user's choice
switch (option)
{
char choice = ' ';
case 1:
do
{
signup();
printf("Do you want to signup again? (y,n)\n");
scanf("%d", &choice);
} while (choice == 'y');
break;
case 2:
do
{
login();
printf("Do you want to login again? (y,n)\n");
scanf("%d", &choice);
} while (choice == 'y');
break;
case 3:
do
{
searchByFood();
printf("Do you want to search by food again? (y,n)\n");
scanf("%d", &choice);
} while (choice == 'y');
break;
case 4:
do
{
searchByHotels();
printf("Do you want to search by Hotels again? (y,n)\n");
scanf("%d", &choice);
} while (choice == 'y');
break;
case 5:
do
{
orderByHotel();
printf("Do you want to order by Hotel again? (y,n)\n");
scanf("%d", &choice);
} while (choice == 'y');
break;
case 6:
do
{
orderByFood();
printf("Do you want to order by food again? (y,n)\n");
scanf("%d", &choice);
} while (choice == 'y');
break;
case 7:
do
{
cart();
printf("Do you want to perform cart activity again? (y,n)\n");
scanf("%d", &choice);
} while (choice == 'y');
break;
default:
printf("Invalid choice!\n");
}
printf("If you don't want to go to the main screen again press (n)\n");
scanf("%c", &ch);
} while (ch == 'n');
return 0;
}
int validateUsername(const char* username)
{
// Check if username contains only alphabets
for (int i = 0; i < strlen(username); i++)
{
//Function isalpha used with header file #include<stdlib.h>
if (!isalpha(username[i]))
{
return 0;
}
}
return 1;
}
int validateAge(int age)
{
// Check if age is greater than 10 ( Business Rule: Children smaller than 9 can't check in without parents consent)
return (age > 8);
}
int validateEmail(const char* email)
{
// Check if email contains '@', a dot, and length is greater than 5
int len = strlen(email);
int atPos = -1, dotPos = -1;
for (int i = 0; i < len; i++)
{
if (email[i] == '@')
{
atPos = i;
}
if (email[i] == '.')
{
dotPos = i;
}
}
return (atPos != -1 && dotPos != -1 && len > 5);
}
int validatePassword(const char* password, const char* confirmPassword)
{
// Check if password meets the criteria and matches with the confirm password
int len = strlen(password);
int uppercase = 0, lowercase = 0, number = 0, specialChar = 0;
if (len >= 8 && len <= 12) // Valid Length of password from 8 to 12
{
for (int i = 0; i < len; i++)
{
if (isupper(password[i]))
{
uppercase = 1;
}
else if (islower(password[i]))
{
lowercase = 1;
}
else if (isdigit(password[i]))
{
number = 1;
}
else
{
specialChar = 1;
}
}
}
return (uppercase && lowercase && number && specialChar && strcmp(password, confirmPassword) == 0);
}
int validateMobileNumber(const char* mobileNumber)
{
// Check if mobile number contains only digits and has exactly 11 digits (For Pakistan)
int len = strlen(mobileNumber);
if (len != 11)
{
return 0;
}
for (int i = 0; i < len; i++)
{
if (!isdigit(mobileNumber[i]))
{
return 0;
}
}
return 1;
}
int accountExists(const char* username)
{
// Check if the account already exists
// Code for checking account existence goes here
// Return 1 if account exists, 0 otherwise
return 0;
}
void signup()
{
char username[100];
int age;
char email[100];
char password[100];
char confirmPassword[100];
char mobileNumber[100];
// Input the user details
printf("Enter username: ");
scanf("%s", username);
printf("Enter age: ");
scanf("%d", &age);
printf("Enter email: ");
scanf("%s", email);
printf("Enter password: ");
scanf("%s", password);
printf("Confirm password: ");
scanf("%s", confirmPassword);
printf("Enter mobile number: ");
scanf("%s", mobileNumber);
// Validate the inputs
if (!validateUsername(username))
{
printf("Invalid username!\n");
return;
}
if (!validateAge(age))
{
char ch = ' ';
printf("Invalid age!\n");
printf("Parents alive(y/n)?");
return;
}
if (!validateEmail(email))
{
printf("Invalid email!\n");
return;
}
if (!validatePassword(password, confirmPassword))
{
printf("Invalid password!\n");
return;
}
if (!validateMobileNumber(mobileNumber))
{
printf("Invalid mobile number!\n");
return;
}
if (accountExists(username))
{
printf("Account already exists!\n");
return;
}
// Signup successful
printf("Signup successful!\n");
}
void login()
{
char username[100];
char password[100];
// Input the login credentials
printf("Enter username: ");
scanf("%s", username);
printf("Enter password: ");
scanf("%s", password);
// Code for login validation (Only basic validation, if advanced required, perform in the Database)
if (strcmp(username, "admin") == 0 && strcmp(password, "password") == 0)
{
// Login successful
strcpy(loggedInUser, username);
printf("Login successful!\n");
}
else
{
// Login failed
printf("Invalid username or password!\n");
}
// You can check against a database or hardcoded credentials for simplicity
// Assuming login is successful for demonstration
strcpy(loggedInUser, username);
printf("Login successful!\n");
}
void searchByFood()
{
// Implementation of search by food functionality
char food[25];
printf("Enter the food item to search: ");
scanf("%s", food);
// Perform search operation based on the food item
// Replace the code below with your actual implementation
char foodItems[8][25] =
{
"Pizza",
"Burger",
"Pasta",
"Biryani",
"EggBurger",
"Nihari",
"BeefPulao",
"Egg",
};
int found = 0;
// Check if the entered food item matches any of the available food items
for (int i = 0; i < 8; i++)
{
if (strcmp(food, foodItems[i]) == 0)
{
found = 1;
printf("Food item '%s' found!\n", food);
break;
}
}
if (!found)
{
do
{
printf("Food item '%s' not found!\n", food);
printf("Menu:\n Pizza \n Burger \n Pasta \n Biryani \n EggBurger \n Nihari \n BeefPulao \n Egg \n");
printf("Enter the food item again to search: ");
scanf("%s", food);
for (int i = 0; i < 8; i++)
{
if (strcmp(food, foodItems[i]) == 0)
{
found = 1;
printf("Food item '%s' found!\n", food);
break;
}
}
} while (found != 1);
}
printf("Searching by food...\n");
}
void searchByHotels()
{
// Implementation of search by hotels functionality
char hotel[20];
printf("Enter the hotel name to search: ");
scanf("%s", hotel);
// Perform search operation based on the hotel name
// Replace the code below with your actual implementation
// Dummy hotel data for demonstration
char hotels[5][20] =
{
"Shinwari",
"QuettaHotel",
"KFC",
"savour",
"McDonalts"
};
int found = 0;
// Check if the entered hotel name matches any of the available hotels
for (int i = 0; i < 5; i++)
{
if (strcmp(hotel, hotels[i]) == 0)
{
found = 1;
printf("Hotel '%s' found!\n", hotel);
break;
}
}
if (!found)
{
do
{
printf("Hotel '%s' not found!\n", hotel);
printf("Search from: \n Shinwari \n QuettaHotel \n KFC \n Savour \n McDonalts");
printf("Enter the hotel name again to search: ");
scanf("%s", hotel);
for (int i = 0; i < 5; i++)
{
if (strcmp(hotel, hotels[i]) == 0)
{
found = 1;
printf("Hotel '%s' found!\n", hotel);
break;
}
}
} while (found != 1);
}
printf("Searching by hotels...\n");
}
void orderByHotel()
{
// Implementation of order by hotel functionality
char hotel[20];
printf("Enter the hotel name to place an order: ");
scanf("%s", hotel);
// Perform order operation based on the selected hotel
// Dummy hotel data for demonstration
char hotels[5][20] =
{
"Shinwari",
"Quetta Hotel",
"KFC",
"savour",
"McDonalts"
};
// Dummy food data for demonstration
char foodItems[10][25] =
{
"Pizza",
"Burger",
"Pasta",
"Biryani",
"EggBurger",
"Nihari",
"BeefPulao",
"Egg",
"BeefKema",
"ChickenKarahi"
};
// Dummy food cost data for demonstration
int costs[10] = { 1000, 350, 450, 200, 120, 300, 350, 60, 220, 180 };
int found = 0;
// Check if the entered hotel name matches any of the available hotels
for (int i = 0; i < 5; i++)
{
if (strcmp(hotel, hotels[i]) == 0)
{
found = 1;
printf("Hotel '%s' found!\n", hotel);
// Display the food menu of the selected hotel
printf("Food Menu for Hotel '%s':\n", hotel);
for (int j = 0; j < 10; j++)
{
printf("%d. %s - $%d\n", j + 1, foodItems[j], costs[j]);
}
break;
}
if (!found)
{
printf("Hotel '%s' not found!\n", hotel);
printf("Search from : \n Shinwari \n QuettaHotel \n KFC \n savour \n McDonalts \n");
printf("Enter the hotel name again to place an order: \n");
scanf("%s", hotel);
do
{
for (int i = 0; i < 5; i++)
{
if (strcmp(hotel, hotels[i]) == 0)
{
found = 1;
printf("Hotel '%s' found!\n", hotel);
// Display the food menu of the selected hotel
printf("Food Menu for Hotel '%s':\n", hotel);
for (int j = 0; j < 10; j++)
{
printf("%d. %s - $%d\n", j + 1, foodItems[j], costs[j]);
}
break;
}
}
} while (found != 1);
}
printf("Ordering by hotel...\n");
}
}
void orderByFood()
{
// Implementation of order by food functionality
char food[25];
int quantity;
printf("Enter the food name to place an order: ");
scanf("%s", food);
printf("Enter the quantity: ");
scanf("%d", &quantity);
// Perform order operation based on the selected food
// Replace the code below with your actual implementation
// Dummy food data for demonstration
char foods[8][25] =
{
"Pizza",
"Burger",
"Pasta",
"Biryani",
"EggBurger",
"Nihari",
"BeefPulao",
"Egg",
};
// Dummy food cost data for demonstration
int costs[8] = { 1000, 350, 450, 200, 120, 300, 350, 60 };
int found = 0;
int cost = 0;
// Check if the entered food name matches any of the available foods
for (int i = 0; i < 8; i++)
{
if (strcmp(food, foods[i]) == 0)
{
found = 1;
printf("Food '%s' found!\n", food);
// Calculate the total cost of the selected food
cost = costs[i] * quantity;
printf("Total Cost: $%d\n", cost);
break;
}
}
if (!found)
{
printf("Food '%s' not found!\n", food);
printf("Enter the food name again to place the order again: ");
printf("Menu:\n Pizza\n Burger\n Pasta\n Biryani\n EggBurger\n Nihari\n BeefPulao\n Egg \n");
scanf("%s", food);
printf("Enter the quantity: ");
scanf("%d", &quantity);
do
{
for (int i = 0; i < 8; i++)
{
if (strcmp(food, foods[i]) == 0)
{
found = 1;
printf("Food '%s' found!\n", food);
// Calculate the total cost of the selected food
cost = costs[i] * quantity;
printf("Total Cost: $%d\n", cost);
break;
}
}
} while (found != 1);
}
printf("Ordering by food...\n");
}
void cart()
{
// Implementation of cart functionality
int totalCost = 0;
// Perform operations to calculate the total cost of orders
int item1Cost = 1000;
int item2Cost = 350;
int item3Cost = 450;
int item4Cost = 200;
int item5Cost = 120;
int item6Cost = 300;
int item7Cost = 350;
int item8Cost = 60;
totalCost = item1Cost + item2Cost + item3Cost + item4Cost + item5Cost + item6Cost + item7Cost + item8Cost; // Calculate the total cost
// Display the total cost of orders and confirm the order
printf("Total cost of your orders: $%d\n", totalCost);
printf("Confirm your order and enjoy your food!\n");
printf("Viewing cart...\n");
}
0 comments:
Post a Comment