diff options
| author | Fuwn <[email protected]> | 2024-05-31 00:00:12 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-05-31 00:20:41 -0700 |
| commit | 968e1c4af014b7f40bfaa4f57fcc0f38e5e0d847 (patch) | |
| tree | df80525ad0cc9e4b561bfb0772c30ccc5b64b4a2 /source/main.cc | |
| parent | feat: initial commit (diff) | |
| download | cst_136_assignment_eight-main.tar.xz cst_136_assignment_eight-main.zip | |
Diffstat (limited to 'source/main.cc')
| -rw-r--r-- | source/main.cc | 107 |
1 files changed, 15 insertions, 92 deletions
diff --git a/source/main.cc b/source/main.cc index 5d262f7..39cff8e 100644 --- a/source/main.cc +++ b/source/main.cc @@ -1,99 +1,22 @@ -#include <algorithm> -#include <array> -#include <cstdlib> -#include <exception> -#include <iostream> -#include <random> -#include <ranges> -#include <string> -#include <string_view> +#include <cstddef> -#include <book_store/book.hh> -#include <book_store/member.hh> -#include <book_store/random.hh> +#include <book_store/library.hh> +#include <book_store/store.hh> auto main() -> int { using namespace book_store; - - std::array<product::book, 100> books; - std::array<std::string, 100> book_titles; - std::array<consumer::member, 100> members; - std::array<std::size_t, 100> member_ids; - std::mt19937 random_number_generator(std::random_device{}()); - utility::random::book_random_engine random(random_number_generator); - auto perform = [](std::string_view name, auto action) { - std::cout << name << " ..."; - - action(); - - std::cout << " ok.\n"; - }; - auto clear_cerr = []() { - if (!std::cerr.good()) { - std::cerr.clear(); - } - }; - - perform("populating books and book_titles", [&]() { - for (auto [index, book] : std::ranges::views::enumerate(books)) { - auto random_title = random.title(); - - book_titles[static_cast<std::size_t>(index)] = random_title; - book = - product::book{random_title, random.authors(), random.publisher(), - random.isbn(), random.price_usd(), random.copy_count()}; - } - }); - perform("verifying all books are present", [&]() { - for (const auto &title : book_titles) { - if (std::ranges::find(book_titles, title) == book_titles.end()) { - clear_cerr(); - - std::cerr << "error: title not found" << '\n'; - - std::terminate(); - } - } - }); - perform("verifying book copy count increment", [&]() { - for (int i = 0; i < 100; ++i) { - auto &book = books[std::uniform_int_distribution<std::size_t>( - 0, books.size() - 1)(random_number_generator)]; - auto copy_count = book.copies(); - auto random_copy_count = static_cast<product::book::size_type>( - std::uniform_int_distribution<std::size_t>(0, 100)( - random_number_generator)); - - book.copies(copy_count + random_copy_count); - - if (book.copies() != copy_count + random_copy_count) { - clear_cerr(); - - std::cerr << "error: invalid copy count after increment" << '\n'; - - std::terminate(); - } - } - }); - perform("populating members and member_ids", [&]() { - for (auto [index, member] : std::views::enumerate(members)) { - auto random_name = random.name(); - auto random_surname = random.name(); - auto random_id = random.id(); - - member_ids[static_cast<std::size_t>(index)] = random_id; - member = consumer::member{random_name, random_surname, random_id}; - } - }); - perform("verifying all members are present", [&]() { - for (auto member_id : member_ids) { - if (std::ranges::find(member_ids, member_id) == member_ids.end()) { - std::cerr << "error: id not found" << '\n'; - - std::terminate(); - } - } - }); + using namespace book_store::library; + + constexpr std::size_t LIBRARY_BOOK_SIZE = 1000; + constexpr std::size_t LIBRARY_CUSTOMER_SIZE = 500; + constexpr std::size_t YEARLY_MEMBERSHIP_FEE_USD = 10; + constexpr std::size_t MEMBER_DISCOUNT_PERCENT = 5; + book_store::store store(LIBRARY_BOOK_SIZE, LIBRARY_CUSTOMER_SIZE, + YEARLY_MEMBERSHIP_FEE_USD, MEMBER_DISCOUNT_PERCENT); + + populate_books(store, LIBRARY_BOOK_SIZE); + populate_consumers(store); + manage(store); return 0; } |