summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-05-26 18:01:25 -0700
committerFuwn <[email protected]>2024-05-26 18:01:25 -0700
commitfa3595d69f817ad1a67b7189ed65dbde1ba9f77d (patch)
treeae85e0ba5f132ce89021cc1e4bcea4e642ffee6c /include
downloadcst_136_assignment_eight-fa3595d69f817ad1a67b7189ed65dbde1ba9f77d.tar.xz
cst_136_assignment_eight-fa3595d69f817ad1a67b7189ed65dbde1ba9f77d.zip
feat: initial commit
Diffstat (limited to 'include')
-rw-r--r--include/book_store/book.hh62
-rw-r--r--include/book_store/book_count.hh37
-rw-r--r--include/book_store/member.hh41
-rw-r--r--include/book_store/person.hh36
-rw-r--r--include/book_store/price.hh39
-rw-r--r--include/book_store/random.hh66
6 files changed, 281 insertions, 0 deletions
diff --git a/include/book_store/book.hh b/include/book_store/book.hh
new file mode 100644
index 0000000..23420da
--- /dev/null
+++ b/include/book_store/book.hh
@@ -0,0 +1,62 @@
+#ifndef BOOK_HH
+#define BOOK_HH
+
+#include <iostream>
+#include <ostream>
+#include <string>
+#include <vector>
+
+#include "book_count.hh"
+#include "person.hh"
+#include "price.hh"
+
+namespace book_store::product {
+class book {
+public:
+ using size_type = book_count;
+ using price_type = price::usd;
+
+private:
+ std::string _title;
+ std::vector<consumer::person> _authors;
+ std::string _publisher;
+ std::string _isbn;
+ price_type _price_usd;
+ size_type _copies;
+
+public:
+ book(std::string title, std::vector<consumer::person> authors,
+ std::string publisher, std::string isbn, price::usd price,
+ size_type copies)
+ : _title(std::move(title)), _authors(std::move(authors)),
+ _publisher(std::move(publisher)), _isbn(std::move(isbn)),
+ _price_usd(price), _copies(copies) {}
+ book() noexcept : _authors({}), _price_usd(0.0), _copies(0) {}
+ book(const book &) noexcept = default;
+ book(book &&) noexcept = default;
+
+ [[nodiscard]] auto title() const noexcept -> std::string_view;
+ [[nodiscard]] auto authors() const noexcept -> std::vector<consumer::person>;
+ [[nodiscard]] auto publisher() const noexcept -> std::string_view;
+ [[nodiscard]] auto isbn() const noexcept -> std::string_view;
+ [[nodiscard]] auto price_usd() const noexcept -> price_type;
+ [[nodiscard]] auto copies() const noexcept -> size_type;
+
+ auto title(std::string_view title) noexcept -> book &;
+ auto authors(std::vector<consumer::person> authors) -> book &;
+ auto author(const consumer::person &author) -> book &;
+ auto remove_author_by_id(std::size_t author_id) -> book &;
+ auto publisher(std::string_view publisher) noexcept -> book &;
+ auto isbn(std::string_view isbn) noexcept -> book &;
+ auto price_usd(price_type price) noexcept -> book &;
+ auto copies(size_type copies) noexcept -> book &;
+
+ auto operator=(const book &) -> book & = default;
+ auto operator=(book &&) -> book & = default;
+
+ friend auto operator<<(std::ostream &output_stream, const book &book)
+ -> std::ostream &;
+};
+} // namespace book_store::product
+
+#endif // BOOK_HH
diff --git a/include/book_store/book_count.hh b/include/book_store/book_count.hh
new file mode 100644
index 0000000..a9c68c1
--- /dev/null
+++ b/include/book_store/book_count.hh
@@ -0,0 +1,37 @@
+#ifndef BOOK_COUNT_HH
+#define BOOK_COUNT_HH
+
+#include <ostream>
+#include <string>
+
+namespace book_store::product {
+class book_count {
+public:
+ using book_count_type = std::size_t;
+
+private:
+ book_count_type _count;
+
+public:
+ book_count() = default;
+ book_count(book_count_type count) : _count(count) {}
+
+ friend auto operator<<(std::ostream &output_stream, const book_count &price)
+ -> std::ostream & {
+ output_stream << price._count;
+
+ return output_stream;
+ }
+
+ friend auto operator==(const book_count &lhs, const book_count &rhs) -> bool {
+ return lhs._count == rhs._count;
+ }
+
+ friend auto operator+(const book_count &lhs, const book_count &rhs)
+ -> book_count {
+ return {lhs._count + rhs._count};
+ }
+};
+} // namespace book_store::product
+
+#endif // BOOK_COUNT_HH
diff --git a/include/book_store/member.hh b/include/book_store/member.hh
new file mode 100644
index 0000000..0796a11
--- /dev/null
+++ b/include/book_store/member.hh
@@ -0,0 +1,41 @@
+#ifndef MEMBER_HH
+#define MEMBER_HH
+
+#include <cstddef>
+
+#include "book.hh"
+#include "person.hh"
+#include "price.hh"
+
+namespace book_store::consumer {
+class member : person {
+
+private:
+ product::book::book::size_type _books_bought;
+ product::price::usd _amount_spent;
+
+public:
+ member(std::string last_name, std::string first_name, std::size_t member_id)
+ : person(std::move(last_name), std::move(first_name), member_id),
+ _books_bought(0), _amount_spent(0) {}
+ member(std::string last_name, std::string first_name, std::size_t member_id,
+ product::book::size_type books_baught,
+ product::price::usd amount_spent)
+ : person(std::move(last_name), std::move(first_name), member_id),
+ _books_bought(books_baught), _amount_spent(amount_spent) {}
+ member() = default;
+ member(const member &) = default;
+ member(member &&) = default;
+
+ [[nodiscard]] auto books_bought() const noexcept -> product::book::size_type;
+ [[nodiscard]] auto amount_spent() const noexcept -> product::price::usd;
+
+ auto books_bought(product::book::size_type books_bought) noexcept -> void;
+ auto amount_spent(product::price::usd amount_spent) noexcept -> void;
+
+ auto operator=(const member &) -> member & = default;
+ auto operator=(member &&) -> member & = default;
+};
+} // namespace book_store::consumer
+
+#endif // MEMBER_HH
diff --git a/include/book_store/person.hh b/include/book_store/person.hh
new file mode 100644
index 0000000..46b9d59
--- /dev/null
+++ b/include/book_store/person.hh
@@ -0,0 +1,36 @@
+#ifndef PERSON_HH
+#define PERSON_HH
+
+#include <string>
+
+namespace book_store::consumer {
+class person {
+private:
+ std::string _last_name;
+ std::string _first_name;
+ std::size_t _id;
+
+public:
+ person(std::string last_name, std::string first_name, std::size_t person_id)
+ : _last_name(std::move(last_name)), _first_name(std::move(first_name)),
+ _id(person_id) {}
+ person() = default;
+ person(const person &) = default;
+ person(person &&) = default;
+
+ [[nodiscard]] auto last_name() const noexcept -> std::string_view;
+ [[nodiscard]] auto first_name() const noexcept -> std::string_view;
+ [[nodiscard]] auto full_name(bool last_first = false) const noexcept
+ -> std::string;
+ [[nodiscard]] auto id() const noexcept -> std::size_t;
+
+ auto last_name(std::string_view last_name) noexcept -> person &;
+ auto first_name(std::string_view first_name) noexcept -> person &;
+ auto id(std::size_t person_id) noexcept -> person &;
+
+ auto operator=(const person &) -> person & = default;
+ auto operator=(person &&) -> person & = default;
+};
+} // namespace book_store::consumer
+
+#endif // PERSON_HH
diff --git a/include/book_store/price.hh b/include/book_store/price.hh
new file mode 100644
index 0000000..39f14b8
--- /dev/null
+++ b/include/book_store/price.hh
@@ -0,0 +1,39 @@
+#ifndef PRICE_HH
+#define PRICE_HH
+
+#include <ostream>
+#include <string>
+
+namespace book_store::product::price {
+class usd {
+public:
+ using price_type = double;
+
+private:
+ price_type _price;
+
+public:
+ usd() = default;
+ usd(price_type price) : _price(price) {}
+ usd(const std::string &price) : _price(std::stod(price)) {}
+
+ auto operator=(const std::string &value) -> usd & {
+ _price = std::stod(value);
+
+ return *this;
+ }
+
+ friend auto operator<<(std::ostream &output_stream, const usd &price)
+ -> std::ostream & {
+ output_stream << price._price;
+
+ return output_stream;
+ }
+
+ friend auto operator==(const usd &lhs, const usd &rhs) -> bool {
+ return std::abs(lhs._price - rhs._price) < 0.0001;
+ }
+};
+} // namespace book_store::product::price
+
+#endif // PRICE_HH
diff --git a/include/book_store/random.hh b/include/book_store/random.hh
new file mode 100644
index 0000000..e279feb
--- /dev/null
+++ b/include/book_store/random.hh
@@ -0,0 +1,66 @@
+#ifndef RANDOM_HH
+#define RANDOM_HH
+
+#include <array>
+#include <cstddef>
+#include <random>
+#include <string>
+#include <string_view>
+#include <vector>
+
+#include "book.hh"
+#include "person.hh"
+
+namespace book_store::utility::random {
+constexpr std::array<std::string_view, 50> names = {
+ "James", "John", "Robert", "Michael", "William", "David",
+ "Richard", "Joseph", "Thomas", "Charles", "Daniel", "Matthew",
+ "Anthony", "Donald", "Mark", "Paul", "Steven", "Andrew",
+ "Kenneth", "Joshua", "George", "Kevin", "Brian", "Edward",
+ "Ronald", "Timothy", "Jason", "Jeffrey", "Ryan", "Jacob",
+ "Gary", "Nicholas", "Eric", "Stephen", "Jonathan", "Larry",
+ "Justin", "Scott", "Brandon", "Frank", "Benjamin", "Gregory",
+ "Samuel", "Raymond", "Patrick", "Alexander", "Jack", "Dennis",
+ "Jerry", "Tyler"};
+constexpr std::array<std::string_view, 50> book_title_parts = {
+ "The", "A", "An", "In", "Of", "And",
+ "To", "For", "With", "On", "At", "By",
+ "From", "Up", "About", "Into", "Over", "After",
+ "Between", "Out", "Against", "Under", "Without", "Within",
+ "Along", "Across", "Behind", "Beyond", "Through", "Around",
+ "Among", "Upon", "Beside", "Toward", "Against", "Upon",
+ "Amongst", "Between", "Within", "Without", "Underneath", "Under",
+ "Over", "Into", "About", "Up", "From", "By",
+ "At", "On"};
+constexpr std::array<std::string_view, 10> publishers = {
+ "Penguin", "Random House", "HarperCollins", "Simon & Schuster",
+ "Macmillan", "Hachette", "Harlequin", "Scholastic",
+ "Pearson", "Houghton Mifflin"};
+
+class book_random_engine {
+private:
+ std::mt19937 _random_number_generator;
+
+public:
+ book_random_engine() : _random_number_generator(std::random_device{}()) {}
+ explicit book_random_engine(std::mt19937 random_number_generator)
+ : _random_number_generator(random_number_generator) {}
+ book_random_engine(const book_random_engine &) = default;
+ book_random_engine(book_random_engine &&) = default;
+
+ auto title() -> std::string;
+ auto name() -> std::string;
+ auto author() -> consumer::person;
+ auto authors() -> std::vector<consumer::person>;
+ auto publisher() -> std::string;
+ auto isbn() -> std::string;
+ auto price_usd() -> double;
+ auto copy_count() -> product::book::size_type;
+ auto id() -> std::size_t;
+
+ auto operator=(const book_random_engine &) -> book_random_engine & = default;
+ auto operator=(book_random_engine &&) -> book_random_engine & = default;
+};
+} // namespace book_store::utility::random
+
+#endif // RANDOM_HH