#include <iostream>
using namespace std;
template <class T>
class sum{
T c;
public:
sum (T a,T b){
c=a+b;
}
T display(){
cout<<" value of c is "<<c<<endl;
T d=c*c;
cout<<"Value of c's square is "<<d<<endl;
return d ;
}
};
template <class T>
class calculator{
T a;
T b;
public:
T sum(T c,T d){
a=c;
b=d;
return a+b;
}
T difference(T c,T d){
a=c;
b=d;
return a-b;
}
T product(T c,T d){
a=c;
b=d;
return a*b;
}
T quotient(T c,T d){
a=c;
b=d;
return a/b;
}
void display(T c,T d){
a=c;
b=d;
cout<<" the sum of a and b is "<<sum(c,d)<<endl;
cout<<" the difference of a and b is "<<difference(c,d)<<endl;
cout<<" the product of a and b is "<<product(c,d)<<endl;
cout<<" the quotient of a and b is "<<quotient(c,d)<<endl;
}
};
int main() {
calculator<double> c;
c.display(5,6);
return 0;
}
No comments:
Post a Comment