Skip to main content

Calculator in C++

 


#include <bits/stdc++.h>
#include <string.h>
using namespace std;

class call
{
    double a, b;
    string s, s1;

public:
    void stringcat(string q, string w)
    {
        s = q;
        s1 = w;

        cout << " " << s + s1 << endl;
    }
    void getdata(int x, int y)
    {
        a = x;
        b = y;
    }
    void calculate()
    {
        int m;
        cout << "Which operation you wanna do! " << endl;
        cout << 1 << ". Addition " << endl;
        cout << 2 << ". Subtration " << endl;
        cout << 3 << ". Multiplication " << endl;
        cout << 4 << ". Division " << endl;
        cout << 5 << ". All " << endl;
        cout << 6 << ". Exit " << endl;
        cin >> m;

        switch (m)
        {
        case 1:
            cout << "Addition of " << a << " and " << b << " is: " << a + b << endl;
            break;
        case 2:
            cout << "Subtration of " << a << " and " << b << " is: " << a - b << endl;
            break;
        case 3:
            cout << "Multiplication of " << a << " and " << b << " is: " << a * b << endl;
            break;
        case 4:
            cout << "Division of " << a << " and " << b << " is: " << a / b << endl;
            break;
        case 5:
            cout << "Addition of " << a << " and " << b << " is: " << a + b << endl;
            cout << "Subtration of " << a << " and " << b << " is: " << a - b << endl;
            cout << "Multiplication of " << a << " and " << b << " is: " << a * b << endl;
            cout << "Division of " << a << " and " << b << " is: " << a / b << endl;
            break;

        case 6:
            exit(0);
        }
    }
};
int main()
{
    call t;
    // int r, e;
    t.getdata(4,2);
    // cout << "Enter two Value: ";
    // cin >> r >> e;
    t.calculate();
 
    // cout<<"Enter the string: ";
    // cin>>s>>s1

    t.stringcat("aak", "ash");

    return 0;
}

Comments