/***************************************************************** * SimpleCalculator by Dustin Luca * file: SimpleCalculator.cpp * * Something I LOVE doing in programming is screwing with the * assignment in any and all ways possible. I didn't like * how it simply used two values and did the math. So, to solve * this issue, I created a new function (DoTheMath) that did the * math and printed the four functions automatically...from there, * I have it use A as 10 and B as 20, since the assignment demands * it, then I give the user an opportunity to use his or her own * values if he or she wants, and then it just uses the function * again, except with those values. * *****************************************************************/ #include "SimpleCalculator.h" #include using std::cin; using std::cout; using std::endl; double SimpleCalculator::add(double a, double b) const { return a + b; } //end add function double SimpleCalculator::subtract(double a, double b) const { return a - b; } //end subtract function double SimpleCalculator::multiply(double a, double b) const { return a * b; } //end multiply function double SimpleCalculator::divide(double a, double b) const { return a / b; } //end divide function void SimpleCalculator::DoTheMath(double a, double b) { SimpleCalculator calc; double addition, subtraction, multiplication, division; addition = calc.add(a,b); subtraction = calc.subtract(a,b); multiplication = calc.multiply(a,b); division = calc.divide(a,b); cout << "Adding a and b yields " << addition << endl; cout << "Subtracting a from b yields " << subtraction << endl; cout << "Multiplying a and b yields " << multiplication << endl; cout << "Dividing a by b yields " << division; }