#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <fstream>
using namespace std;
// Event Node Class
class EventNode {
public:
string name, id, location;
string from, till;
double charges;
EventNode(string n, string i, string loc, string f, string t, double c)
: name(n), id(i), location(loc), from(f), till(t), charges(c) {}
void display() const {
cout << "Event Name: " << name << ", ID: " << id << ", Location: " <<
location
<< ", From: " << from << ", Till: " << till << ", Charges: " <<
charges << endl;
}
};
// Hall Class for Event Venue Management
class Hall {
public:
int id;
string name;
bool isAvailable;
Hall(int id, const string& name, bool availability = true)
: id(id), name(name), isAvailable(availability) {}
void display() const {
cout << "Hall: " << name << ", ID: " << id
<< ", Available: " << (isAvailable ? "Yes" : "No") << endl;
}
};
// User Class for User Management
class User {
public:
string username, password, contactInfo;
// Default constructor
User() : username(""), password(""), contactInfo("") {}
// Parameterized constructor
User(string u, string p, string c) : username(u), password(p), contactInfo(c)
{}
void display() const {
cout << "Username: " << username << ", Contact: " << contactInfo << endl;
}
};
// Event List Class
class EventList {
public:
vector<EventNode> events; // Store events
vector<Hall> halls; // Store halls
unordered_map<string, User> users; // Store user accounts
void addEvent(const EventNode& event) {
if (events.size() < 20) {
events.push_back(event);
cout << "Event added successfully!" << endl;
} else {
cout << "Event limit reached!" << endl;
}
}
void addHall(const Hall& hall) {
if (halls.size() < 20) {
halls.push_back(hall);
cout << "Hall added successfully!" << endl;
} else {
cout << "Hall limit reached!" << endl;
}
}
void displayEvents() const {
for (const auto& event : events) {
event.display();
}
}
void displayHalls() const {
for (const auto& hall : halls) {
hall.display();
}
}
void searchEvents(const string& searchTerm) const {
bool found = false;
for (const auto& event : events) {
if (event.name == searchTerm || event.from == searchTerm || event.till
== searchTerm) {
event.display();
found = true;
}
}
if (!found) cout << "No events found." << endl;
}
bool bookEvent(const string& eventName, const string& hallName) {
for (auto& hall : halls) {
if (hall.name == hallName && hall.isAvailable) {
hall.isAvailable = false;
return true;
}
}
return false;
}
void cancelEvent(const string& eventID) {
auto it = remove_if(events.begin(), events.end(),
[eventID](const EventNode& e) { return e.id ==
eventID; });
if (it != events.end()) {
events.erase(it, events.end());
cout << "Event cancelled successfully!" << endl;
} else {
cout << "Event not found!" << endl;
}
}
void createUserAccount(const string& username, const string& password, const
string& contact) {
users[username] = User(username, password, contact);
}
bool loginUser(const string& username, const string& password) {
if (users.find(username) != users.end() && users[username].password ==
password) {
return true;
}
return false;
}
};
void registerAdminOrUser(EventList& eventList) {
string username, password, contactInfo;
cout << "Enter username: ";
cin >> username;
cout << "Enter password: ";
cin >> password;
cout << "Enter contact info: ";
cin >> contactInfo;
eventList.createUserAccount(username, password, contactInfo);
cout << "Registration successful!" << endl;
}
bool loginAdmin(EventList& eventList) {
string username, password;
cout << "Enter admin username: ";
cin >> username;
cout << "Enter password: ";
cin >> password;
return eventList.loginUser(username, password);
}
void bookEventAndHall(EventList& eventList) {
string eventName, hallName, from, till;
double pricePerHour = 1000.0;
cout << "Enter event name: ";
cin >> eventName;
cout << "Enter hall name: ";
cin >> hallName;
cout << "Enter from (date/time): ";
cin >> from;
cout << "Enter till (date/time): ";
cin >> till;
// Calculate the charges
double hours = 24; // Assume 24-hour booking for simplicity
double charges = hours * pricePerHour;
EventNode event(eventName, "ID_001", hallName, from, till, charges);
eventList.addEvent(event);
// Try to book hall
if (eventList.bookEvent(eventName, hallName)) {
cout << "Event booked successfully!" << endl;
} else {
cout << "Hall not available!" << endl;
}
}
void adminMenu(EventList& eventList) {
int option;
bool isAdminLoggedIn = false;
while (true) {
cout << "\nAdmin Menu\n";
cout << "1. Event Booking\n";
cout << "2. Hall Booking\n";
cout << "3. Cancel Event\n";
cout << "4. View Events\n";
cout << "5. Exit\n";
cout << "Choose an option: ";
cin >> option;
switch (option) {
case 1:
bookEventAndHall(eventList);
break;
case 2:
bookEventAndHall(eventList); // Same function for hall booking for
now
break;
case 3: {
string eventID;
cout << "Enter event ID to cancel: ";
cin >> eventID;
eventList.cancelEvent(eventID);
break;
}
case 4:
eventList.displayEvents();
break;
case 5:
return; // Exit admin menu
default:
cout << "Invalid option. Try again." << endl;
}
}
}
int main() {
EventList eventList;
// Add sample halls
eventList.addHall(Hall(1, "Main Hall"));
eventList.addHall(Hall(2, "Conference Room"));
int option;
bool isAdminLoggedIn = false;
while (true) {
cout << "\nWelcome to the Event Management System\n";
cout << "1. Register\n";
cout << "2. Login as Admin\n";
cout << "3. Exit\n";
cout << "Choose an option: ";
cin >> option;
switch (option) {
case 1:
registerAdminOrUser(eventList);
break;
case 2:
isAdminLoggedIn = loginAdmin(eventList);
if (isAdminLoggedIn) {
cout << "Admin logged in successfully.\n";
adminMenu(eventList); // Go to Admin Menu
} else {
cout << "Invalid login credentials.\n";
}
break;
case 3:
cout << "Exiting the system...\n";
return 0; // Exit program
default:
cout << "Invalid option. Try again." << endl;
}
}
}