diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/calculator/.gitignore b/calculator/.gitignore new file mode 100644 index 0000000..1ddbbca --- /dev/null +++ b/calculator/.gitignore @@ -0,0 +1 @@ +calc diff --git a/calculator/Makefile b/calculator/Makefile new file mode 100644 index 0000000..4c389bc --- /dev/null +++ b/calculator/Makefile @@ -0,0 +1,2 @@ +calc: *.cpp *.h + clang++ -std=c++20 -O0 -g -o calc *.cpp diff --git a/calculator/Product.h b/calculator/Product.h new file mode 100644 index 0000000..8772893 --- /dev/null +++ b/calculator/Product.h @@ -0,0 +1,17 @@ +#ifndef SATISFACTORY_PRODUCT_H +#define SATISFACTORY_PRODUCT_H + +#include + +class Product { +public: + Product() {} + ~Product() {} + + std::string Name() const { return name; } + +private: + std::string name; +}; + +#endif diff --git a/calculator/Recipe.cpp b/calculator/Recipe.cpp new file mode 100644 index 0000000..3656239 --- /dev/null +++ b/calculator/Recipe.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +#include "Recipe.h" + +std::vector > Recipe::Ingredients(float overclock) +{ + if(overclock < 0.0f || overclock > 2.5f) + { + auto error = std::format("Invalid overclock of {:.2f}%.", (overclock * 100.0f)); + throw std::invalid_argument(error); + } + + std::vector > rtn; + for(const auto &ingredient : ingredients) + rtn.push_back({ingredient.first, ingredient.second * overclock}); + + return rtn; +} diff --git a/calculator/Recipe.h b/calculator/Recipe.h new file mode 100644 index 0000000..81c87c7 --- /dev/null +++ b/calculator/Recipe.h @@ -0,0 +1,27 @@ +#ifndef SATISFACTORY_RECIPE +#define SATISFACTORY_RECIPE + +#include "Product.h" + +#include + +class Recipe { +public: + Recipe() + { + // TEST: + ingredients.push_back({Product(), 20.0}); + ingredients.push_back({Product(), 4.0}); + ingredients.push_back({Product(), 60.0}); + } + ~Recipe() {} + + std::pair Produces() const { return produces; } + std::vector > Ingredients(float overclock = 1.0f); + +private: + std::pair produces; + std::vector > ingredients; +}; + +#endif diff --git a/calculator/main.cpp b/calculator/main.cpp new file mode 100644 index 0000000..acae5a8 --- /dev/null +++ b/calculator/main.cpp @@ -0,0 +1,15 @@ +#include + +#include "Recipe.h" + +int main() +{ + Recipe test; + auto ingredients = test.Ingredients(); + ingredients = test.Ingredients(2.5); + + for(const auto &i : ingredients) + std::cout << i.first.Name() << ", " << i.second << std::endl; + + return 0; +}