google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C++ program for a medical shop

Thursday, March 13, 2025

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

No comments:

Post a Comment

The rotation of money in business

 The rotation of money in business refers to the flow of funds within a company, encompassing various financial activities and transactions....