Write the class Calculator including: a function called addthat takes two parame
ID: 3770693 • Letter: W
Question
Write the class Calculator including: a function called addthat takes two parameters containing double values and returns their sum a function called subtractthat takes two parameters containing double values and returns their difference (subtract the second from the first) a function called multiply that takes two parameters containing double values and returns their product a function called divide that takes two parameters containing double values and returns the value of the first divided by the second. If the second number is a zero, do not divide, and return "You can't divide by zero!"
Explanation / Answer
class Calculator{
public:
double add(double a,double b){
return a+b;
}
double subtrac(double a,double b){
return a-b;
}
double multiply(double a,double b){
return a*b;
}
double divide(double a,double b){
if (b==0){
cout<<"You can't divide by zero!";
return 0;
}
else
return a/b;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.