Thursday, March 13, 2025

Java program for a hospital management system

 Here's a simple Java program for a hospital management system:


```

import java.util.ArrayList;

import java.util.Scanner;


class Patient {

    private String name;

    private int age;

    private String disease;

    private String doctor;


    public Patient(String name, int age, String disease, String doctor) {

        this.name = name;

        this.age = age;

        this.disease = disease;

        this.doctor = doctor;

    }


    public String getName() {

        return name;

    }


    public int getAge() {

        return age;

    }


    public String getDisease() {

        return disease;

    }


    public String getDoctor() {

        return doctor;

    }

}


class Doctor {

    private String name;

    private String specialization;


    public Doctor(String name, String specialization) {

        this.name = name;

        this.specialization = specialization;

    }


    public String getName() {

        return name;

    }


    public String getSpecialization() {

        return specialization;

    }

}


public class HospitalManagement {

    private ArrayList<Patient> patients;

    private ArrayList<Doctor> doctors;

    private Scanner scanner;


    public HospitalManagement() {

        patients = new ArrayList<>();

        doctors = new ArrayList<>();

        scanner = new Scanner(System.in);

    }


    public void addPatient() {

        System.out.print("Enter patient name: ");

        String name = scanner.nextLine();

        System.out.print("Enter patient age: ");

        int age = scanner.nextInt();

        scanner.nextLine(); // Consume newline left-over

        System.out.print("Enter patient disease: ");

        String disease = scanner.nextLine();

        System.out.print("Enter doctor's name: ");

        String doctorName = scanner.nextLine();

        patients.add(new Patient(name, age, disease, doctorName));

    }


    public void addDoctor() {

        System.out.print("Enter doctor's name: ");

        String name = scanner.nextLine();

        System.out.print("Enter doctor's specialization: ");

        String specialization = scanner.nextLine();

        doctors.add(new Doctor(name, specialization));

    }


    public void displayPatients() {

        System.out.println("\nPatient List:");

        for (Patient patient : patients) {

            System.out.println("Name: " + patient.getName());

            System.out.println("Age: " + patient.getAge());

            System.out.println("Disease: " + patient.getDisease());

            System.out.println("Doctor: " + patient.getDoctor());

            System.out.println();

        }

    }


    public void displayDoctors() {

        System.out.println("\nDoctor List:");

        for (Doctor doctor : doctors) {

            System.out.println("Name: " + doctor.getName());

            System.out.println("Specialization: " + doctor.getSpecialization());

            System.out.println();

        }

    }


    public void run() {

        while (true) {

            System.out.println("\nHospital Management System");

            System.out.println("1. Add Patient");

            System.out.println("2. Add Doctor");

            System.out.println("3. Display Patients");

            System.out.println("4. Display Doctors");

            System.out.println("5. Exit");

            System.out.print("Enter your choice: ");

            int choice = scanner.nextInt();

            scanner.nextLine(); // Consume newline left-over

            switch (choice) {

                case 1:

                    addPatient();

                    break;

                case 2:

                    addDoctor();

                    break;

                case 3:

                    displayPatients();

                    break;

                case 4:

                    displayDoctors();

                    break;

                case 5:

                    System.exit(0);

                    break;

                default:

                    System.out.println("Invalid choice. Please try again.");

            }

        }

    }


    public static void main(String[] args) {

        HospitalManagement management = new HospitalManagement();

        management.run();

    }

}

```


*Example Output:*

```

Hospital Management System

1. Add Patient

2. Add Doctor

3. Display Patients

4. Display Doctors

5. Exit

Enter your choice: 1


Enter patient name: John Doe

Enter patient age: 30

Enter patient disease: Flu

Enter doctor's name: Dr. Smith


Hospital Management System

1. Add Patient

2. Add Doctor

3. Display Patients

4. Display Doctors

5. Exit

Enter your choice: 3


Patient List:

Name: John Doe

Age: 30

Disease: Flu

Doctor: Dr. Smith

```


This program defines three classes: `Patient`, `Doctor`, and `HospitalManagement`. The `Patient` class has private member variables for patient details and public methods for accessing those details. The `Doctor` class has private member variables for doctor details and public methods for accessing those details. The `HospitalManagement` class has private member variables for patient and doctor lists, as well as public methods for adding patients and doctors,

C++ program for a medical shop

 Here's a simple C++ program for a medical shop:



#include <iostream>

#include <string>

using namespace std;


class Medicine {

private:

    string name;

    double price;

    int quantity;


public:

    void inputDetails() {

        cout << "Enter medicine name: ";

        cin.ignore();

        getline(cin, name);

        cout << "Enter medicine price: ";

        cin >> price;

        cout << "Enter medicine quantity: ";

        cin >> quantity;

    }


    void displayDetails() {

        cout << "\nMedicine Details\n";

        cout << "Name: " << name << endl;

        cout << "Price: $" << price << endl;

        cout << "Quantity: " << quantity << endl;

    }


    double calculateTotalPrice(int qty) {

        return price * qty;

    }


    void updateQuantity(int qty) {

        quantity -= qty;

    }

};


class MedicalShop {

private:

    string shopName;

    string address;

    Medicine medicines[10];

    int numberOfMedicines;


public:

    void inputShopDetails() {

        cout << "Enter shop name: ";

        cin.ignore();

        getline(cin, shopName);

        cout << "Enter shop address: ";

        getline(cin, address);

    }


    void addMedicine() {

        medicines[numberOfMedicines].inputDetails();

        numberOfMedicines++;

    }


    void displayMedicineDetails() {

        for (int i = 0; i < numberOfMedicines; i++) {

            medicines[i].displayDetails();

        }

    }


    void sellMedicine() {

        string medicineName;

        int quantity;

        cout << "Enter medicine name: ";

        cin.ignore();

        getline(cin, medicineName);

        cout << "Enter quantity to sell: ";

        cin >> quantity;

        for (int i = 0; i < numberOfMedicines; i++) {

            if (medicines[i].name == medicineName) {

                if (medicines[i].quantity >= quantity) {

                    double totalPrice = medicines[i].calculateTotalPrice(quantity);

                    medicines[i].updateQuantity(quantity);

                    cout << "Total price: $" << totalPrice << endl;

                } else {

                    cout << "Insufficient quantity." << endl;

                }

                return;

            }

        }

        cout << "Medicine not found." << endl;

    }


    void displayShopDetails() {

        cout << "\nShop Details\n";

        cout << "Name: " << shopName << endl;

        cout << "Address: " << address << endl;

    }

};


int main() {

    MedicalShop shop;

    int choice;

    shop.numberOfMedicines = 0;

    shop.inputShopDetails();

    while (true) {

        cout << "\nMedical Shop Management System\n";

        cout << "1. Add medicine\n";

        cout << "2. Display medicine details\n";

        cout << "3. Sell medicine\n";

        cout << "4. Display shop details\n";

        cout << "5. Exit\n";

        cout << "Enter your choice: ";

        cin >> choice;

        switch (choice) {

            case 1:

                shop.addMedicine();

                break;

            case 2:

                shop.displayMedicineDetails();

                break;

            case 3:

                shop.sellMedicine();

                break;

            case 4:

                shop.displayShopDetails();

                break;

            case 5:

                return 0;

            default:

                cout << "Invalid choice. Please try again.\n";

        }

    }

    return 0;

}


*Example Output:*


Enter shop name: Medical Shop

Enter shop address: 123 Main St


Medical Shop Management System

1. Add medicine

2. Display medicine details

3. Sell medicine

4. Display shop details

5. Exit

Enter your choice: 1


Enter medicine name: Paracetamol

Enter medicine price: 10

Enter medicine quantity: 100


Medical Shop Management System

1. Add medicine

2. Display medicine details

3. Sell medicine

4. Display shop details

5. Exit

Enter your choice: 3


Enter medicine name: Paracetamol

Enter quantity to sell: 5


Total price: $50


Medical Shop Management System

1. Add medicine

2. Display medicine details

3. Sell medicine

4. Display shop details

5. Exit

Enter your choice: 4


Shop Details

Name: Medical Shop

Address: 123 Main St



This program defines two classes: `Medicine` and `MedicalShop`. The `Medicine` class has private member variables for medicine details and public methods for inputting details, displaying details, calculating the total price, and updating the quantity. The `MedicalShop` class has private member variables for shop details and medicine data, as well as public methods for inputting shop

C++ program to make mobile application

 Creating a mobile application using C++ is a complex task that requires a deep understanding of mobile app development, C++ programming, and the underlying mobile platform (e.g., Android or iOS). Here's a simplified example of a C++ program that demonstrates basic mobile app functionality:


*Android App using C++ (via Android NDK)*

To create an Android app using C++, you'll need to use the Android NDK (Native Development Kit). Here's a basic example:


```

// main.cpp

#include <android/native_activity.h>

#include <android/native_window.h>

#include <android/rect.h>


void android_main(struct android_app* app) {

    // Initialize the app

    app->onInit();


    // Create a window

    ANativeWindow* window = app->window;

    if (window) {

        // Set the window dimensions

        ANativeWindow_setWidth(window, 800);

        ANativeWindow_setHeight(window, 600);


        // Draw something on the window

        ANativeWindow_Buffer buffer;

        if (ANativeWindow_lockBuffer(window, &buffer, NULL)) {

            // Draw a red rectangle

            memset(buffer.bits, 0xFF0000, buffer.width * buffer.height * 4);

            ANativeWindow_unlockBuffer(window, &buffer);

        }

    }


    // Clean up

    app->onDestroy();

}

```


*iOS App using C++ (via Objective-C++)*

To create an iOS app using C++, you'll need to use Objective-C++ (a combination of Objective-C and C++). Here's a basic example:


```

// main.mm

#import <UIKit/UIKit.h>


class MyApp : public UIApplication {

public:

    MyApp() {}

    ~MyApp() {}


    void applicationDidFinishLaunching(UIApplication *application) {

        // Create a window

        UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


        // Create a view

        UIView *view = [[UIView alloc] initWithFrame:window.bounds];

        view.backgroundColor = [UIColor redColor];


        // Add the view to the window

        [window addSubview:view];


        // Make the window visible

        [window makeKeyAndVisible];

    }

};


int main(int argc, char *argv[]) {

    @autoreleasepool {

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyApp class]));

    }

}

```


Note that these examples are highly simplified and don't demonstrate a real-world mobile app. To create a more complex app, you'll need to use a framework or library that provides a higher-level API for mobile app development.


Some popular frameworks for mobile app development using C++ include:


- Qt (cross-platform)

- SDL (cross-platform)

- Cocos2d-x (cross-platform)

- Android NDK (Android-specific)

- Objective-C++ (iOS-specific)


Keep in mind that using C++ for mobile app development can be challenging due to the complexity of the underlying mobile platforms. You may want to consider using a higher-level language like Java or Swift, or a cross-platform framework like React Native or Flutter.

C++ program to calculate an employee's salary

 Here's a simple C++ program to calculate an employee's salary:



#include <iostream>

#include <string>

using namespace std;


class Employee {

private:

    string name;

    int employeeId;

    string department;

    double basicSalary;

    double allowance;

    double deduction;

    double netSalary;


public:

    void inputDetails() {

        cout << "Enter employee name: ";

        cin.ignore();

        getline(cin, name);

        cout << "Enter employee ID: ";

        cin >> employeeId;

        cout << "Enter department: ";

        cin.ignore();

        getline(cin, department);

        cout << "Enter basic salary: ";

        cin >> basicSalary;

        cout << "Enter allowance: ";

        cin >> allowance;

        cout << "Enter deduction: ";

        cin >> deduction;

    }


    void calculateNetSalary() {

        netSalary = basicSalary + allowance - deduction;

    }


    void displayDetails() {

        cout << "\nEmployee Details\n";

        cout << "Name: " << name << endl;

        cout << "Employee ID: " << employeeId << endl;

        cout << "Department: " << department << endl;

        cout << "Basic Salary: $" << basicSalary << endl;

        cout << "Allowance: $" << allowance << endl;

        cout << "Deduction: $" << deduction << endl;

        cout << "Net Salary: $" << netSalary << endl;

    }

};


int main() {

    Employee employee;

    employee.inputDetails();

    employee.calculateNetSalary();

    employee.displayDetails();

    return 0;

}



*Example Output:*


Enter employee name: John Doe

Enter employee ID: 123

Enter department: HR

Enter basic salary: 5000

Enter allowance: 1000

Enter deduction: 500


Employee Details

Name: John Doe

Employee ID: 123

Department: HR

Basic Salary: $5000

Allowance: $1000

Deduction: $500

Net Salary: $5500



This program defines an `Employee` class with private member variables for employee details and public methods for inputting details, calculating the net salary, and displaying details.


In the `main()` function, an `Employee` object is created, and the user is prompted to input employee details. The program then calculates the net salary and displays the employee details.

C++ program for a school management system

Here's a simple C++ program for a school management system:


#include <iostream>
#include <string>
using namespace std;

class Student {
private:
    string name;
    int rollNumber;
    int age;
    string className;

public:
    void inputDetails() {
        cout << "Enter student name: ";
        cin.ignore();
        getline(cin, name);
        cout << "Enter roll number: ";
        cin >> rollNumber;
        cout << "Enter age: ";
        cin >> age;
        cout << "Enter class name: ";
        cin.ignore();
        getline(cin, className);
    }

    void displayDetails() {
        cout << "\nStudent Details\n";
        cout << "Name: " << name << endl;
        cout << "Roll Number: " << rollNumber << endl;
        cout << "Age: " << age << endl;
        cout << "Class Name: " << className << endl;
    }
};

class Teacher {
private:
    string name;
    string subject;
    int age;

public:
    void inputDetails() {
        cout << "Enter teacher name: ";
        cin.ignore();
        getline(cin, name);
        cout << "Enter subject: ";
        getline(cin, subject);
        cout << "Enter age: ";
        cin >> age;
    }

    void displayDetails() {
        cout << "\nTeacher Details\n";
        cout << "Name: " << name << endl;
        cout << "Subject: " << subject << endl;
        cout << "Age: " << age << endl;
    }
};

class School {
private:
    string schoolName;
    string address;
    Student students[10];
    Teacher teachers[10];
    int numberOfStudents;
    int numberOfTeachers;

public:
    void inputSchoolDetails() {
        cout << "Enter school name: ";
        cin.ignore();
        getline(cin, schoolName);
        cout << "Enter school address: ";
        getline(cin, address);
    }

    void addStudent() {
        students[numberOfStudents].inputDetails();
        numberOfStudents++;
    }

    void addTeacher() {
        teachers[numberOfTeachers].inputDetails();
        numberOfTeachers++;
    }

    void displayStudentDetails() {
        for (int i = 0; i < numberOfStudents; i++) {
            students[i].displayDetails();
        }
    }

    void displayTeacherDetails() {
        for (int i = 0; i < numberOfTeachers; i++) {
            teachers[i].displayDetails();
        }
    }

    void displaySchoolDetails() {
        cout << "\nSchool Details\n";
        cout << "Name: " << schoolName << endl;
        cout << "Address: " << address << endl;
    }
};

int main() {
    School school;
    int choice;
    school.numberOfStudents = 0;
    school.numberOfTeachers = 0;
    school.inputSchoolDetails();
    while (true) {
        cout << "\nSchool Management System\n";
        cout << "1. Add student\n";
        cout << "2. Add teacher\n";
        cout << "3. Display student details\n";
        cout << "4. Display teacher details\n";
        cout << "5. Display school details\n";
        cout << "6. Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;
        switch (choice) {
            case 1:
                school.addStudent();
                break;
            case 2:
                school.addTeacher();
                break;
            case 3:
                school.displayStudentDetails();
                break;
            case 4:
                school.displayTeacherDetails();
                break;
            case 5:
                school.displaySchoolDetails();
                break;
            case 6:
                return 0;
            default:
                cout << "Invalid choice. Please try again.\n";
        }
    }
    return 0;
}
```

*Example Output:*
```
Enter school name: ABC School
Enter school address: 123 Main St

School Management System
1. Add student
2. Add teacher
3. Display student details
4. Display teacher details
5. Display school details
6. Exit
Enter your choice: 1

Enter student name: John Doe
Enter roll number: 1
Enter age: 12
Enter class name: 7th

School Management System
1. Add student
2. Add teacher
3. Display student details
4. Display teacher details
5. Display school details
6. Exit
Enter your choice: 3

Student Details
Name: John Doe
Roll Number: 1
Age: 12
Class Name: 7th

School Management System
1. Add student
2. Add teacher
3. Display student details
4. Display teacher details
5. Display school details
6. Exit
Enter your choice: 5

School Details
Name: ABC School
Address: 123 Main St

C++ program for a hospital

Here's a simple C++ program for a hospital:


#include <iostream>
#include <string>
using namespace std;

class Patient {
private:
    string name;
    int age;
    string disease;
    string doctor;

public:
    void inputDetails() {
        cout << "Enter patient name: ";
        cin.ignore();
        getline(cin, name);
        cout << "Enter patient age: ";
        cin >> age;
        cout << "Enter patient disease: ";
        cin.ignore();
        getline(cin, disease);
        cout << "Enter doctor's name: ";
        getline(cin, doctor);
    }

    void displayDetails() {
        cout << "\nPatient Details\n";
        cout << "Name: " << name << endl;
        cout << "Age: " << age << endl;
        cout << "Disease: " << disease << endl;
        cout << "Doctor: " << doctor << endl;
    }
};

class Hospital {
private:
    string hospitalName;
    string address;
    Patient patients[10];
    int numberOfPatients;

public:
    void inputHospitalDetails() {
        cout << "Enter hospital name: ";
        cin.ignore();
        getline(cin, hospitalName);
        cout << "Enter hospital address: ";
        getline(cin, address);
    }

    void addPatient() {
        patients[numberOfPatients].inputDetails();
        numberOfPatients++;
    }

    void displayPatientDetails() {
        for (int i = 0; i < numberOfPatients; i++) {
            patients[i].displayDetails();
        }
    }

    void displayHospitalDetails() {
        cout << "\nHospital Details\n";
        cout << "Name: " << hospitalName << endl;
        cout << "Address: " << address << endl;
    }
};

int main() {
    Hospital hospital;
    int choice;
    hospital.numberOfPatients = 0;
    hospital.inputHospitalDetails();
    while (true) {
        cout << "\nHospital Management System\n";
        cout << "1. Add patient\n";
        cout << "2. Display patient details\n";
        cout << "3. Display hospital details\n";
        cout << "4. Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;
        switch (choice) {
            case 1:
                hospital.addPatient();
                break;
            case 2:
                hospital.displayPatientDetails();
                break;
            case 3:
                hospital.displayHospitalDetails();
                break;
            case 4:
                return 0;
            default:
                cout << "Invalid choice. Please try again.\n";
        }
    }
    return 0;
}


*Example Output:*

Enter hospital name: Apollo Hospital
Enter hospital address: 123 Main St

Hospital Management System
1. Add patient
2. Display patient details
3. Display hospital details
4. Exit
Enter your choice: 1

Enter patient name: John Doe
Enter patient age: 30
Enter patient disease: Flu
Enter doctor's name: Dr. Smith

Hospital Management System
1. Add patient
2. Display patient details
3. Display hospital details
4. Exit
Enter your choice: 2

Patient Details
Name: John Doe
Age: 30
Disease: Flu
Doctor: Dr. Smith

Hospital Management System
1. Add patient
2. Display patient details
3. Display hospital details
4. Exit
Enter your choice: 3

Hospital Details
Name: Apollo Hospital
Address: 123 Main St


This program defines two classes: `Patient` and `Hospital`. The `Patient` class has private member variables for patient details and public methods for inputting and displaying patient details. The `Hospital` class has private member variables for hospital details and patient data, as well as public methods for inputting hospital details, adding patients, displaying patient details, and displaying hospital details.

In the `main()` function, a `Hospital` object is created, and the user is presented with a menu to add patients, display patient details, display hospital details, or exit the program.

C++ program for a restaurant

 Here's a simple C++ program for a restaurant:



#include <iostream>

#include <string>

using namespace std;


class Restaurant {

private:

    string itemName[10];

    int itemPrice[10];

    int itemQuantity[10];

    int numberOfItems;


public:

    void addItem() {

        cout << "Enter item name: ";

        cin.ignore();

        getline(cin, itemName[numberOfItems]);

        cout << "Enter item price: ";

        cin >> itemPrice[numberOfItems];

        cout << "Enter item quantity: ";

        cin >> itemQuantity[numberOfItems];

        numberOfItems++;

    }


    void displayMenu() {

        cout << "\nRestaurant Menu\n";

        for (int i = 0; i < numberOfItems; i++) {

            cout << (i + 1) << ". " << itemName[i] << " - $" << itemPrice[i] << " (" << itemQuantity[i] << " available)\n";

        }

    }


    void placeOrder() {

        int choice, quantity;

        cout << "Enter the item number to order: ";

        cin >> choice;

        cout << "Enter the quantity to order: ";

        cin >> quantity;

        if (choice > 0 && choice <= numberOfItems && quantity <= itemQuantity[choice - 1]) {

            cout << "Order placed successfully!\n";

            itemQuantity[choice - 1] -= quantity;

        } else {

            cout << "Invalid choice or insufficient quantity.\n";

        }

    }


    void displayOrderSummary() {

        cout << "\nOrder Summary\n";

        for (int i = 0; i < numberOfItems; i++) {

            if (itemQuantity[i] < itemQuantity[i]) {

                cout << itemName[i] << " x " << (itemQuantity[i] - itemQuantity[i]) << "\n";

            }

        }

    }

};


int main() {

    Restaurant restaurant;

    int choice;

    restaurant.numberOfItems = 0;

    while (true) {

        cout << "\nRestaurant Management System\n";

        cout << "1. Add item to menu\n";

        cout << "2. Display menu\n";

        cout << "3. Place order\n";

        cout << "4. Display order summary\n";

        cout << "5. Exit\n";

        cout << "Enter your choice: ";

        cin >> choice;

        switch (choice) {

            case 1:

                restaurant.addItem();

                break;

            case 2:

                restaurant.displayMenu();

                break;

            case 3:

                restaurant.placeOrder();

                break;

            case 4:

                restaurant.displayOrderSummary();

                break;

            case 5:

                return 0;

            default:

                cout << "Invalid choice. Please try again.\n";

        }

    }

    return 0;

}



*Example Output:*


Restaurant Management System

1. Add item to menu

2. Display menu

3. Place order

4. Display order summary

5. Exit

Enter your choice: 1


Enter item name: Burger

Enter item price: 10

Enter item quantity: 5


Restaurant Management System

1. Add item to menu

2. Display menu

3. Place order

4. Display order summary

5. Exit

Enter your choice: 2


Restaurant Menu

1. Burger - $10 (5 available)


Restaurant Management System

1. Add item to menu

2. Display menu

3. Place order

4. Display order summary

5. Exit

Enter your choice: 3


Enter the item number to order: 1

Enter the quantity to order: 2


Order placed successfully!


Restaurant Management System

1. Add item to menu

2. Display menu

3. Place order

4. Display order summary

5. Exit

Enter your choice: 4


Order Summary

Burger x 2



This program defines a `Restaurant` class with private member variables for menu items, prices, and quantities. The class includes public methods for adding items to the menu, displaying the menu, placing orders, and displaying order summaries.


In the `main()` function, a `Restaurant` object is created, and a simple text-based menu is displayed. The user can interact with the program by choosing options to add items, display the menu, place orders, or display order summaries.

Program to develop for cost saving in hotel industry

 To develop a program for cost-saving in a hotel, you can consider the following features: Key Features 1. *Room Management*: Optimize room ...