Class opeartion CW-21/8/23

#include <iostream>

using namespace std;
class operation
{
    int x, y;

public:
    void input();
    void display();
    operation add(operation);
    operation sub(operation);
    operation mult(operation);
    operation div(operation);
};
void operation::input()
{
    cout << "Enter the two number: ";
    cin >> x >> y;
}
void operation::display()
{
    cout << "x = " << x << endl;
    cout << "Y = " << y << endl;
}
operation operation::add(operation obj)
{
    operation ob;
    ob.x = x + obj.x;
    ob.y = y + obj.y;
    return ob;
}
operation operation::sub(operation obj)
{
    operation ob;
    ob.x = x - obj.x;
    ob.y = y - obj.y;
    return ob;
}
operation operation::mult(operation obj)
{
    operation ob;
    ob.x = x * obj.x;
    ob.y = y * obj.y;
    return ob;
}
operation operation::div(operation obj)
{
    operation ob;
    ob.x = x / obj.x;
    ob.y = y / obj.y;
    return ob;
}
int main()
{
    operation ob1, ob2, ob3;
    char ch;
    while (1)
    {
        cout << "1.add(+) 2.sub(-) 3.mult(*) 4.div(/) 5.exit(x)\n";
        cout << "Enter the operation you want to perform:(+,-,*,/)\n";
        cin >> ch;
        switch (ch)
        {
        case '+':
            ob1.input();
            ob2.input();
            ob3 = ob1.add(ob2);
            ob3.display();
            break;
        case '-':
            ob1.input();
            ob2.input();
            ob3 = ob1.sub(ob2);
            ob3.display();
            break;
        case '*':
            ob1.input();
            ob2.input();
            ob3 = ob1.mult(ob2);
            ob3.display();
            break;
        case '/':
            ob1.input();
            ob2.input();
            ob3 = ob1.div(ob2);
            ob3.display();
            break;
        case 'x':
            cout << "You have exited...";
            return 0;
        default:
            cout << "Wrong Input!!\nplease enter one of the given choices:\n";
            break;
        }
    }
}

Comments

Popular Posts