Not sure if this is homework, so I will give an additional short version. In particular, I would go down the path of the pattern template .
template <typename T> T add(T n1,T n2){
return n1 + n2;
}
and use it:
int s = add<int> (1,3);
Considering what you are asking about classes, I would exclude the setNumbers function and make each static function and get numbers that I could work on as parameters. Also, I would make it a template class .
? , . , , , 1.5 3.2? int, 1 3, . ? , . 3 0.5 . ? , : . , template class / function . , integerCalculator ( , ).
template <typename T> calculator {
static T add (T n1 ,T n2){
return n1 + n2;
}
};
Integer
class integerCalculator{
public:
int divideNumber(){
if (number2 == 0)
return number1/number2;
}
};
:
number1 number2 , , setNumber()? (private apropiate).
class Calculator{
int n1;
int n2;
public: void setNumbers(int n1,int n2){...}
}
, a, d, m, s . ...