Showing posts with label template calculator. Show all posts
Showing posts with label template calculator. Show all posts

Monday, May 9, 2022

Write a class template that shows the working of a calculator.

 #include <iostream>

using namespace std;
template <class T1, class T2>
class calc
{
    T1 num1;
    T2 num2;

public:
    calc()
    {
        cout << "enter num1 \n";
        cin >> num1;
        cout << "enter num2 \n";
        cin >> num2;
    }
    void choice(int choice)
    {
        if (choice == 1)
        {

            cout << "sum is " << num1 + num2 << endl;
        }
        else if (choice == 2)
        {

            cout << "difference is " << num1 - num2 << endl;
        }
        else if (choice == 3)
        {

            cout << "product  is " << num1 * num2 << endl;
        }
        else if (choice == 4)
        {

            if (num2 != 0)
            {

                cout << "division  is " << num1 / num2 << endl;
            }
            else if (num2 == 0)
            {
                cout << "denominator can't be zero re enter details\n";
            }
        }
    }
};
int main()
{

    calc<float, float> obj;
    int choice;

    cout << "\n enter 1 , 2, 3 , 4\n for sum , difference and product respectively \n";
    cin >> choice;
    obj.choice(choice);
    return 0;
}

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...

Popular Posts