Simple calculator using class in c++

#include <iostream>

using namespace std;
class calc{
int num1, num2;
public:
    void div()
    {
        int a, b;
        float result;
        cout<<"enter first number \n";
        cin>>a;
        cout<<"enter your second number \n";
        cin>>b;
        result=a/b;
        cout<<"division done, output is : "<<result<<endl;

    }
     void sum()
    {
        int output;
        cout<<"enter your first number \n";
        cin>>num1;
        cout<<"enter your second number \n";
        cin>>num2;
        output=num1+num2;
        cout<<"sum of two numbers is "<<output<<endl;
    }
     void subs()
    {
        int output;
        cout<<"enter your first number \n";
        cin>>num1;
        cout<<"enter your second number \n";
        cin>>num2;
        output=num1-num2;
        cout<<"substraction of two numbers is "<<output<<endl;
    }
     void multi()
    {
        int output;
        cout<<"enter your first number \n";
        cin>>num1;
        cout<<"enter your second number \n";
        cin>>num2;
        output=num1*num2;
        cout<<"multiplication of two numbers is "<<output<<endl;
    }




};

int main()
{
    calc u;
        char check;
        cout<<"enter + for addition - for substraction and * for multiplication  and / for division \n";
        cin>>check;
        switch (check)
        {
        case '+':
            {
               u.sum();
                break;
            }
        case '-':
            {
               u.subs();
                break;
            }
        case '*':
            {
               u.multi();
                break;
            }
        case '/':
            {
                u.div();
                break;
            }
        default:
            cout<<"invallid input \n";
        }

    return 0;
}

Comments

Popular posts from this blog

calculate average marks of five students using array of structure in c.

Display name of five students using structure in c.

C++ for banking transaction demo