|
| 1 | +#include <iostream> |
| 2 | +#include <string> |
| 3 | +#include <sstream> |
| 4 | +#include <cmath> |
| 5 | +#include <vector> |
| 6 | +#include "calculate.h" |
| 7 | + |
| 8 | +std::ofstream writeHistory; |
| 9 | + |
| 10 | +std::string calculate::add(double numA, double numB) |
| 11 | +{ |
| 12 | + double add = numA + numB; |
| 13 | + std::stringstream sadd; |
| 14 | + sadd << "The sum of the two numbers are "; |
| 15 | + sadd << add; |
| 16 | + sadd << std::endl; |
| 17 | + std::string fina = sadd.str(); |
| 18 | + writeHistory << numA << " + " << numB << " = " << add<<std::endl; |
| 19 | + return fina; |
| 20 | +} |
| 21 | +std::string calculate::subtract(double numA, double numB) |
| 22 | +{ |
| 23 | + double subtract = numA - numB; |
| 24 | + std::stringstream ssub; |
| 25 | + ssub << "The difference of the two numbers are "; |
| 26 | + ssub << subtract; |
| 27 | + ssub << std::endl; |
| 28 | + std::string fins = ssub.str(); |
| 29 | + writeHistory << numA << " - " << numB << " = " << subtract << std::endl; |
| 30 | + return fins; |
| 31 | +} |
| 32 | +std::string calculate::multiply(double numA, double numB) |
| 33 | +{ |
| 34 | + double multiply = numA * numB; |
| 35 | + std::stringstream smul; |
| 36 | + smul << "The product of the two numbers you put in are "; |
| 37 | + smul << multiply; |
| 38 | + smul << std::endl; |
| 39 | + std::string finm = smul.str(); |
| 40 | + writeHistory << numA << " * " << numB << " = " << multiply << std::endl; |
| 41 | + return finm; |
| 42 | +} |
| 43 | +std::string calculate::divide(double numA, double numB) |
| 44 | +{ |
| 45 | + double divide = numA / numB; |
| 46 | + std::stringstream sdiv; |
| 47 | + sdiv << "The dividend of the two numbers you put in are "; |
| 48 | + sdiv << divide; |
| 49 | + sdiv << std::endl; |
| 50 | + std::string find = sdiv.str(); |
| 51 | + writeHistory << numA << " / " << numB << " = " << divide << std::endl; |
| 52 | + return find; |
| 53 | +} |
| 54 | +std::string calculate::power(double numA, double numB) |
| 55 | +{ |
| 56 | + double power = pow(numA, numB); |
| 57 | + std::stringstream spow; |
| 58 | + spow << numA; |
| 59 | + spow << " to the power of "; |
| 60 | + spow << numB; |
| 61 | + spow << " is "; |
| 62 | + spow << power; |
| 63 | + spow << std::endl; |
| 64 | + std::string finp = spow.str(); |
| 65 | + writeHistory << numA << " ^ " << numB << " = " << power << std::endl; |
| 66 | + return finp; |
| 67 | +} |
| 68 | +std::string calculate::square(double numA, double numB) |
| 69 | +{ |
| 70 | + double square = sqrt(numA); |
| 71 | + std::stringstream ssqu; |
| 72 | + ssqu << "The square root of "; |
| 73 | + ssqu << numA; |
| 74 | + ssqu << " is "; |
| 75 | + ssqu << square; |
| 76 | + ssqu << std::endl; |
| 77 | + std::string fins = ssqu.str(); |
| 78 | + writeHistory << "Square root of: " << numA << " = " << square << std::endl; |
| 79 | + return fins; |
| 80 | +} |
0 commit comments