🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

A Cruise Management System is used to maintain details of cruises, bookings for passengers, and actions like adding cruise options and displaying booking details.
Cruise Management: Stores information about cruises, including ID, destination, and capacity.
Passenger Bookings: Allows booking for different cruises.
User Interface: A menu-driven system for easy interaction.
Data Storage: Uses arrays and classes to manage cruise and passenger data.
This company operates multiple cruise ships with thousands of reservations daily. Their management system tracks passenger details, cabin availability, and special requests like dietary restrictions.
Similar to the Passenger and Cruise classes in the code, their backend system relies on Object-Oriented Programming (OOP) to handle reservations and ensure no overbooking.
They use a centralized system to manage seasonal cruise trips, such as winter trips to the Caribbean. Passengers can reserve excursions or upgrade cabins via an interface.
The menu-driven user interface of this project mirrors the Carnival Cruise portal for viewing and managing reservations.
A boutique cruise company with smaller ships manages passenger lists, itineraries, and emergency contacts using a basic system.
The project’s data storage using arrays aligns with simple operations where complex data persistence is unnecessary.
A cruise company accidentally accepted more reservations than its capacity due to a lack of real-time validation.
A function like bookPassenger()
was implemented to prevent overbooking by checking:
if (bookedPassengers >= maxCapacity) {
cout << "Booking Failed: Cruise is at full capacity!" << endl;
return false;
}
A travel agency lost booking data due to a server crash.
File-based storage (CSV/JSON) was introduced for persistent data storage. Instead of arrays, file input/output methods were used:
#include <fstream>
void saveCruises(const vector<Cruise> &cruises) {
ofstream file("cruises.txt");
for (const auto& cruise : cruises) {
file << cruise.id << "," << cruise.destination << "," << cruise.maxCapacity << "\n";
}
}
Cruise customers found the booking interface too complex.
A simplified menu-driven approach, like the while (true)
loop in the project’s code, ensures clear navigation with options like "Book Passenger" and "Add Cruise."
The code originally used fixed-size arrays (e.g., Cruise cruises[numCruises]
), limiting scalability.
Replaced arrays with std::vector
for dynamic storage:
#include <vector>
std::vector<Cruise> cruises;
cruises.push_back(Cruise()); // Adding a new cruise
The code lacked validation for user inputs like invalid cruise numbers.
A loop was added to ensure valid user inputs:
int cruiseID;
while (true) {
cout << "Enter Cruise ID: ";
if (cin >> cruiseID && cruiseID > 0 && cruiseID <= cruises.size()) break;
cin.clear(); // Reset error flags
cin.ignore(1000, '\n'); // Discard invalid input
cout << "Invalid ID! Try again.\n";
}
All data was lost when the program exited.
Implemented file-based storage for loading and saving cruise data:
#include <fstream>
void saveCruises(const vector<Cruise> &cruises) {
ofstream file("cruises.txt");
for (const auto& cruise : cruises) {
file << cruise.id << "," << cruise.destination << "," << cruise.maxCapacity << "\n";
}
}
#include<iostream>
#include<string>
using namespace std;
class Passenger {
public:
string name;
int age;
string contact;
Passenger() : name(""), age(0), contact("") {}
void addPassengerDetails() {
cout << "Enter Passenger Name: ";
cin.ignore();
getline(cin, name);
cout << "Enter Age: ";
cin >> age;
cout << "Enter Contact Number: ";
cin >> contact;
}
};
class Cruise {
public:
int cruiseID;
string destination;
int maxCapacity;
int bookedPassengers;
Passenger passengers[100];
Cruise() : cruiseID(0), destination(""), maxCapacity(0), bookedPassengers(0) {}
void addCruiseDetails(int id) {
cruiseID = id;
cout << "Enter Destination: ";
cin >> destination;
cout << "Enter Maximum Capacity: ";
cin >> maxCapacity;
}
bool bookPassenger() {
if (bookedPassengers >= maxCapacity) {
cout << "Booking Failed: Cruise is at full capacity!" << endl;
return false;
}
cout << "Booking Passenger for Cruise ID: " << cruiseID << endl;
passengers[bookedPassengers].addPassengerDetails();
bookedPassengers++;
return true;
}
};
int main() {
const int numCruises = 3;
Cruise cruises[numCruises];
int choice, cruiseID;
while (true) {
cout << "\n------ Cruise Management System ------\n";
cout << "1. Add Cruise Details\n";
cout << "2. Display All Cruises\n";
cout << "3. Book Passenger\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
for (int i = 0; i < numCruises; ++i) {
cout << "Adding details for Cruise " << (i + 1) << endl;
cruises[i].addCruiseDetails(i + 1);
}
break;
case 2:
for (int i = 0; i < numCruises; ++i) {
cout << "Cruise ID: " << cruises[i].cruiseID << " Destination: " << cruises[i].destination << " Capacity: " << cruises[i].maxCapacity << endl;
}
break;
case 3:
cout << "Enter Cruise ID to book a passenger: ";
cin >> cruiseID;
if (cruiseID > 0 && cruiseID <= numCruises) {
cruises[cruiseID - 1].bookPassenger();
} else {
cout << "Invalid Cruise ID!\n";
}
break;
case 4:
return 0;
}
}
}
Comments
Post a Comment