This is a simple REST API calculator built using the Crow C++ microframework. It supports basic arithmetic operations, trigonometric functions, and compound interest calculations.
http://localhost:18080
Endpoint: /basic_math
Method: GET
Description: Perform basic arithmetic operations (addition, subtraction, multiplication, division).
Request Body:
{
"operation": "add" | "subtract" | "multiply" | "divide",
"a": <number>,
"b": <number>
}Example Request:
curl -X GET -d '{"operation": "add", "a": 5, "b": 3}' http://localhost:18080/basic_mathResponse:
{
"result": <number>
}Possible Arguments:
operation: The arithmetic operation to perform. Possible values areadd,subtract,multiply,divide.a: The first operand (number).b: The second operand (number).
Endpoint: /trig_functions
Method: GET
Description: Perform trigonometric functions (sine, cosine, tangent).
Request Body:
{
"operation": "sin" | "cos" | "tan",
"angle": <number>
}Example Request:
curl -X GET -d '{"operation": "sin", "angle": 1.5708}' http://localhost:18080/trig_functionsResponse:
{
"result": <number>
}Possible Arguments:
operation: The trigonometric function to perform. Possible values aresin,cos,tan.angle: The angle in radians (number).
Endpoint: /compound_interest
Method: GET
Description: Calculate compound interest.
Request Body:
{
"principal": <number>,
"rate": <number>,
"times": <integer>,
"years": <integer>
}Example Request:
curl -X GET -d '{"principal": 1000, "rate": 0.05, "times": 4, "years": 5}' http://localhost:18080/compound_interestResponse:
{
"result": <number>
}Possible Arguments:
principal: The initial amount of money (number).rate: The annual interest rate (number).times: The number of times interest is compounded per year (integer).years: The number of years the money is invested or borrowed for (integer).
-
Basic Math Operations (
/basic_math):curl -X GET -d '{"operation": "add", "a": 5, "b": 3}' http://localhost:18080/basic_math -
Trigonometric Functions (
/trig_functions):curl -X GET -d '{"operation": "sin", "angle": 1.5708}' http://localhost:18080/trig_functions -
Compound Interest Calculation (
/compound_interest):curl -X GET -d '{"principal": 1000, "rate": 0.05, "times": 4, "years": 5}' http://localhost:18080/compound_interest
Make sure you have the Asio library included. Here is an example Makefile:
CXX = g++
CXXFLAGS = -std=c++11 -pthread -I/path/to/asio/include
TARGET = calculator
SRCS = main.cpp
all: $(TARGET)
$(TARGET): $(SRCS)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(SRCS)
clean:
rm -f $(TARGET)Replace /path/to/asio/include with the actual path to the Asio include directory.
Compile and run the project:
make
./calculatorThis will start the Crow web server on port 18080, and you can send GET requests with a body to the respective endpoints for different types of calculations.