0% found this document useful (0 votes)
27 views2 pages

Task No 03 PF

The document defines a template calculator class that can perform mathematical operations like addition, subtraction, division, multiplication and square root on template types. It declares a calculator class with template types for integers and floats, defines the mathematical methods, and demonstrates their use in a main function.

Uploaded by

Joshua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Task No 03 PF

The document defines a template calculator class that can perform mathematical operations like addition, subtraction, division, multiplication and square root on template types. It declares a calculator class with template types for integers and floats, defines the mathematical methods, and demonstrates their use in a main function.

Uploaded by

Joshua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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