Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- template<class T>
- class calculator{
- T n1, n2;
- public:
- calculator(){
- n1 = 0;
- n2 = 0;
- }
- void input(){
- cout << "Enter num1: " << endl;
- cin >> n1;
- cout << "Enter num2: " << endl;
- cin >> n2;
- }
- void display(){
- cout << n1 << " + " << n2 << " = " << add() << endl;
- cout << n1 << " - " << n2 << " = " << subtract() << endl;
- cout << n1 << " * " << n2 << " = " << product() << endl;
- cout << n1 << " / " << n2 << " = " << divide() << endl;
- cout << n1 << " ^ 2 " << " = " << squaren1() << endl;
- cout << n2 << " ^ 2 " << " = " << squaren2() << endl;
- cout << n1 << " ^ " << n2 << " = " << power() << endl << endl;
- }
- T add(){
- return n1 + n2;
- }
- T subtract(){
- return n1 - n2;
- }
- T product(){
- return n1 * n2;
- }
- T divide(){
- return n1 / n2;
- }
- T squaren1(){
- return pow(n1, 2);
- }
- T squaren2(){
- return pow(n2, 2);
- }
- T power(){
- return pow(n1, n2);
- }
- };
- int main()
- {
- calculator<float> a;
- a.input();
- a.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement