Thursday, March 13, 2025

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.

Featured posts

Ethiopian culture calendar language

Ethiopian culture, calendar, language  The Ethiopian language, specifically Amharic, uses a script called Ge'ez script. It consists of 3...

Popular posts