Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Task no .

03
#include<iostream>
using namespace std;

template<class A, class B>


class calculator
{
private :
A integers;
B floats;

public:
calculator(A a, B b)
{
integers = a;
floats = b;
};
A addition(A a, B b);
A subtraction(A a, B b);
A division(A a, B b);
A multiplication(A a, B b);
A squareroot(A a, B b);
};
template<class A, class B>
A calculator<A, B>::addition(A a, B b)
{
return a + b;
}

template<class A, class B>


A calculator<A, B>::subtraction(A a, B b)
{
return a - b;
}

template<class A, class B>


A calculator<A, B>::division(A a, B b)
{
return a / b;

template<class A, class B>


A calculator<A, B>::multiplication(A a, B b)
{
return a * b;
}
template<class A, class B>
A calculator<A, B>::squareroot(A a, B b)
{
return sqrt(a);
}
void display()
{
cout << "addition :\t" <<a+b << "\n";
cout << "subtraction :\t" << a - b << "\n";
cout << "division :\t" << a / b << "\n";
cout << "multiplication :\t" << a * b << "\n";
cout << "Square_root :\t" << sqrt(a) << "\n";

}
int main()
{
calculator<int, int>c(6, 6);
c.addition;
calculator<int, float>c1(5, 6.98);
c1.addition;
calculator<float, int>c2(7.99,98);
c2.subtraction;
calculator<int, int>c3(11,15);
c3.division;
calculator<float, int>c4(67.1,12);
c4.multiplication;
calculator<int, float>c5(17,3.34);
c5.division;
calculator<int, int>c6(4,8);
c6.squareroot;
calculator<float, int>c7(7.31,20);
c7.squareroot;

system("pause");
return 0;
}

You might also like