Skip to content

Commit 573d627

Browse files
author
Quincy
authored
Create calculator.cpp
1 parent abce396 commit 573d627

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

3.0/calculator.cpp

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

0 commit comments

Comments
 (0)