From c6caab0c7eea7463563d3e535a7545ce7873111d Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Sat, 6 Dec 2025 14:38:09 -0800 Subject: [PATCH] Attempting in c++ --- 05/Makefile | 36 ++++++++++++++++++++++++++++++++++++ 05/src/main.cpp | 24 ++++++++++++++++++++++++ 05/src/produce_database.cpp | 19 +++++++++++++++++++ 05/src/produce_database.h | 20 ++++++++++++++++++++ 05/src/read_input.cpp | 22 ++++++++++++++++++++++ 05/src/read_input.h | 13 +++++++++++++ 6 files changed, 134 insertions(+) create mode 100644 05/Makefile create mode 100644 05/src/main.cpp create mode 100644 05/src/produce_database.cpp create mode 100644 05/src/produce_database.h create mode 100644 05/src/read_input.cpp create mode 100644 05/src/read_input.h diff --git a/05/Makefile b/05/Makefile new file mode 100644 index 0000000..ff06b3c --- /dev/null +++ b/05/Makefile @@ -0,0 +1,36 @@ +# Compiler +CXX = g++ + +# Compiler flags +CXXFLAGS = -Wall -g + +# Target executable +TARGET = main + +# For deleting the target +TARGET_DEL = main + +# Source files +SRCS = src/main.cpp src/produce_database.cpp src/read_input.cpp + +# Object files +OBJS = $(SRCS:.cpp=.o) + +# Default rule to build and run the executable +all: $(TARGET) run + +# Rule to link object files into the target executable +$(TARGET): $(OBJS) + $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS) + +# Rule to compile .cpp files into .o files +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +# Rule to run the executable +run: $(TARGET) + $(TARGET) + +# Clean rule to remove generated files +clean: + del $(TARGET_DEL) $(OBJS) \ No newline at end of file diff --git a/05/src/main.cpp b/05/src/main.cpp new file mode 100644 index 0000000..a9eec56 --- /dev/null +++ b/05/src/main.cpp @@ -0,0 +1,24 @@ +/* Filename: main.cpp + * Author: Alice Winters + * Created: 05/12/2025 + */ + +#include +#include +#include + +#include "produce_database.h" +#include "read_input.h" + +const std::string INPUT_FILEPATH = "input/test_ingredients.txt"; + +int main() +{ + produce_database produce_db = read_input_from_file(INPUT_FILEPATH); + for (int i = 0; i < produce_db.get_fresh_ranges_size(); i++) + { + std::cout << produce_db.get_fresh_range_from_index(i) << std::endl; + } + + return 0; +} diff --git a/05/src/produce_database.cpp b/05/src/produce_database.cpp new file mode 100644 index 0000000..7a111b3 --- /dev/null +++ b/05/src/produce_database.cpp @@ -0,0 +1,19 @@ +#include "produce_database.h" +#include +#include + +int produce_database::get_fresh_ranges_size() +{ + return this->fresh_ingredient_id_ranges.size(); +} + +std::string produce_database::get_fresh_range_from_index(int index) +{ + return this->fresh_ingredient_id_ranges[index]; +} + +void produce_database::add_fresh_range(std::string range) +{ + this->fresh_ingredient_id_ranges.push_back(range); + return; +} \ No newline at end of file diff --git a/05/src/produce_database.h b/05/src/produce_database.h new file mode 100644 index 0000000..95c548f --- /dev/null +++ b/05/src/produce_database.h @@ -0,0 +1,20 @@ +#ifndef PRODUCE_DATABASE_H + +#define PRODUCE_DATABASE_H + +#include +#include + +class produce_database +{ +private: + std::vector fresh_ingredient_id_ranges; + std::vector available_ingredient_ids; + +public: + int get_fresh_ranges_size(); + std::string get_fresh_range_from_index(int index); + void add_fresh_range(std::string range); +}; + +#endif \ No newline at end of file diff --git a/05/src/read_input.cpp b/05/src/read_input.cpp new file mode 100644 index 0000000..3363504 --- /dev/null +++ b/05/src/read_input.cpp @@ -0,0 +1,22 @@ +#include "read_input.h" +#include +#include +#include +#include +#include "produce_database.h" + +using namespace std; + +produce_database read_input_from_file(string filepath) +{ + produce_database produce_db; + ifstream input_file(filepath); + string input_buffer = " "; + while (input_buffer != "") + { + getline(input_file, input_buffer); + produce_db.add_fresh_range(input_buffer); + } + input_file.close(); + return produce_db; +} \ No newline at end of file diff --git a/05/src/read_input.h b/05/src/read_input.h new file mode 100644 index 0000000..ef4c71d --- /dev/null +++ b/05/src/read_input.h @@ -0,0 +1,13 @@ +#ifndef READ_INPUT_H + +#define READ_INPUT_H + +#include +#include +#include +#include +#include "produce_database.h" + +produce_database read_input_from_file(std::string filepath); + +#endif \ No newline at end of file