summaryrefslogtreecommitdiff
path: root/week_1/review_program/textbook.cc
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-26 21:51:32 -0700
committerFuwn <[email protected]>2023-09-26 21:51:32 -0700
commit77915dd4326e16c98c766d9cbb785f5f128a54aa (patch)
tree3b466b01e250cfac4d068093cd0973f9c8c371a8 /week_1/review_program/textbook.cc
downloadcs260-77915dd4326e16c98c766d9cbb785f5f128a54aa.tar.xz
cs260-77915dd4326e16c98c766d9cbb785f5f128a54aa.zip
feat(week_1): preview_program
Diffstat (limited to 'week_1/review_program/textbook.cc')
-rw-r--r--week_1/review_program/textbook.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/week_1/review_program/textbook.cc b/week_1/review_program/textbook.cc
new file mode 100644
index 0000000..6eeee7c
--- /dev/null
+++ b/week_1/review_program/textbook.cc
@@ -0,0 +1,88 @@
+#include "textbook.hh"
+
+#include <iomanip>
+#include <iostream>
+
+namespace textbook {
+auto Textbook::code() const -> uint64_t { return this->_code; }
+auto Textbook::single_copy_price() const -> double {
+ return this->_single_copy_price;
+}
+auto Textbook::number_on_hand() const -> uint64_t {
+ return this->_number_on_hand;
+}
+auto Textbook::prospective_enrollment() const -> uint64_t {
+ return this->_prospective_enrollment;
+}
+auto Textbook::required() const -> bool { return this->_required; }
+auto Textbook::used() const -> bool { return this->_used; }
+auto Textbook::amount_to_order() const -> uint64_t {
+ return this->_amount_to_order;
+}
+auto Textbook::total_cost() const -> double { return this->_total_cost; }
+
+auto Textbook::set_code(uint64_t code) -> void { this->_code = code; }
+auto Textbook::set_single_copy_price(double single_copy_price) -> void {
+ this->_single_copy_price = single_copy_price;
+}
+auto Textbook::set_number_on_hand(uint64_t number_on_hand) -> void {
+ this->_number_on_hand = number_on_hand;
+}
+auto Textbook::set_prospective_enrollment(uint64_t prospective_enrollment)
+ -> void {
+ this->_prospective_enrollment = prospective_enrollment;
+}
+auto Textbook::set_required(bool required) -> void {
+ this->_required = required;
+}
+auto Textbook::set_used(bool used) -> void { this->_used = used; }
+
+auto Textbook::print() const -> void {
+ // Pretty print all values, minus evaluated values
+ std::cout << "Book: " << this->_code << "\nPrice: $"
+ << this->_single_copy_price
+ << "\nInventory: " << this->_number_on_hand
+ << "\nEnrollment: " << this->_prospective_enrollment
+ << "\nRequired: " << this->_required << "\nUsed: " << this->_used
+ << std::endl;
+}
+
+auto Textbook::evaluate_needs() -> void {
+ /// Calculate the total cost of the books to order based on an input factor
+ const auto set_amount_to_order = [this](double factor) -> void {
+ this->_amount_to_order =
+ static_cast<uint64_t>(
+ static_cast<double>(this->_prospective_enrollment) * factor) -
+ this->_number_on_hand;
+ };
+
+ // Determine amount to order based on given percentages
+ if (this->_required && !this->_used) {
+ set_amount_to_order(0.9);
+ } else if (this->_required && this->_used) {
+ set_amount_to_order(0.65);
+ } else if (!this->_required && !this->_used) {
+ set_amount_to_order(0.4);
+ } else if (!this->_required && this->_used) {
+ set_amount_to_order(0.2);
+ }
+
+ // Calculate total cost
+ this->_total_cost =
+ static_cast<double>(this->_amount_to_order) * this->_single_copy_price;
+}
+
+auto Textbook::print_needs() const -> void {
+ // Pretty print the amount to order and total cost
+ std::cout << "Need to order: " << this->_amount_to_order << "\nTotal cost: $"
+ << std::fixed << std::setprecision(2) << this->_total_cost
+ << std::endl;
+}
+
+auto Textbook::operator==(const Textbook &other) const -> bool {
+ return this->_code == other._code;
+}
+auto Textbook::operator!=(const Textbook &other) const -> bool {
+ return this->_code != other._code;
+}
+} // namespace textbook