Area functions work with query string

parent fcf543c3
Pipeline #20945 passed with stages
in 2 minutes and 50 seconds
#ifndef AREA_AREAFUNCTION_H_
#define AREA_AREAFUNCTION_H_
#include "areaFunction.h"
float areaOfSquareWithSides(float side) { return side * side; }
float areaOfCircleWithRadius(float radius) {
return (3.14 * (radius * radius));
}
#endif // AREA_AREAFUNCTION_H_
#ifndef AREA_AREAFUNCTION_H_
#define AREA_AREAFUNCTION_H_
float areaOfSquareWithSides(float side);
float areaOfCircleWithRadius(float radius);
#endif // AREA_AREAFUNCTION_H_
#include "areaFunction.h"
#include <cstring>
#include <iostream>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char *s = std::getenv("QUERY_STRING");
if (s == nullptr || strlen(s) < 3 || s[0] != 's' || s[1] != '=') {
std::cerr << "Usage: QUERY_STRING=\"s=N\" area" << std::endl;
return 1;
}
s += 2; // advance the string pointer beyond "s=" to point to the number
// "atoi()" is C++'s method of converting a string to an integer
float argument = atof(s);
if (argument == 0) {
std::cout << "Value must be an integer above 0" << std::endl;
return 1;
}
float squareArea = areaOfSquareWithSides(argument);
float circleArea = areaOfCircleWithRadius(argument);
std::cout << "The area of a square with sides of " << argument << " units is "
<< squareArea << " units." << std::endl;
std::cout << "The area of a circle with a radius of " << argument
<< " units is " << circleArea << " units." << std::endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment