Initial work on calculator program.

This commit is contained in:
2026-06-28 11:02:36 -04:00
parent c2e6810a9e
commit 912e12399d
7 changed files with 83 additions and 0 deletions

1
calculator/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
calc

2
calculator/Makefile Normal file
View File

@@ -0,0 +1,2 @@
calc: *.cpp *.h
clang++ -std=c++20 -O0 -g -o calc *.cpp

17
calculator/Product.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef SATISFACTORY_PRODUCT_H
#define SATISFACTORY_PRODUCT_H
#include <string>
class Product {
public:
Product() {}
~Product() {}
std::string Name() const { return name; }
private:
std::string name;
};
#endif

20
calculator/Recipe.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <exception>
#include <format>
#include <string>
#include "Recipe.h"
std::vector<std::pair<Product, float> > 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<std::pair<Product, float> > rtn;
for(const auto &ingredient : ingredients)
rtn.push_back({ingredient.first, ingredient.second * overclock});
return rtn;
}

27
calculator/Recipe.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef SATISFACTORY_RECIPE
#define SATISFACTORY_RECIPE
#include "Product.h"
#include <vector>
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<Product, float> Produces() const { return produces; }
std::vector<std::pair<Product, float> > Ingredients(float overclock = 1.0f);
private:
std::pair<Product, float> produces;
std::vector<std::pair<Product, float> > ingredients;
};
#endif

15
calculator/main.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include <iostream>
#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;
}