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

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.

Featured posts

स्मार्ट इन्वेस्टिंग फॉर बिगिनर्स:

 स्मार्ट इन्वेस्टिंग फॉर बिगिनर्स:  पैसिव इनकम कमाने का आसान रास्ता"।  इसमें मैंने बताया है कि कैसे छोटी रकम से शुरुआत करके, म्यूचुअल फ...

Popular posts