OOP: Calculator using Constructor

Create a C++ program to perform all the task of a calculator. This program will allow all Arithmetic Operators with Value from the user. Here, some Input and Output sample stated below:

Sample Input: 1 + 4
            Sample Output: 5
            Sample Input: 8 % 2
            Sample Output: 0
            Sample Input: 6 / 2
            Sample Output: 3
            Sample Input: 5 / 2
            Sample Output: 2.5

Complete This task using Constructor with necessary Parameter

Best of Luck

 

1 comment:

  1. //স্যার কনস্ট্রাকটর টা এখন ও ক্লিয়ার হয় নি। তাই নরমাল ক্লাস দিয়েই করেছি । মূল প্রোগ্রাম আগামীকাল দেব।


    #include
    using namespace std;
    class calc
    {
    public:
    double a;
    double b;
    double add();
    double deduct();
    double multiplication();
    double division();
    int module();

    };
    double calc::add()
    {
    return a+b;
    }
    double calc::deduct()
    {
    return a-b;
    }
    double calc::multiplication()
    {
    return a*b;
    }
    double calc::division()
    {
    return a/b;
    }
    int calc::module()
    {
    return a%b;
    }
    int main()
    {
    calc value;
    value.a;
    cout<<"Enter first number: "<>value.a;
    value.b;
    cout<<"Enter second number: "<>value.b;
    // sum=value.a+value.b;
    cout<<"Addition of these two number is: "<<value.add()<<endl;
    //cout<<value.add()<<endl;
    //cout<<value.deduct()<<endl;
    cout<<"Deduction of these two number is: "<<value.deduct()<<endl;
    cout<<"Multiplication of these two number is: "<<value.multiplication()<<endl;
    cout<<"Division of these two number is: "<<value.division()<<endl;
    //
    cout<<"Modulus of these two number is: "<<value.module()<<endl;
    return 0;
    }

    ReplyDelete

Comment Here