#include "textbook.h" #include #include namespace Textbook { uint64_t Textbook::GetCode() const { return this->_code; } double Textbook::GetSingleCopyPrice() const { return this->_single_copy_price; } uint64_t Textbook::GetNumberOnHand() const { return this->_number_on_hand; } uint64_t Textbook::GetProspectiveEnrollment() const { return this->_prospective_enrollment; } bool Textbook::GetIsRequired() const { return this->_is_required; } bool Textbook::GetIsUsed() const { return this->_is_used; } uint64_t Textbook::GetAmountToOrder() const { return this->_amount_to_order; } double Textbook::GetTotalCost() const { return this->_total_cost; } void Textbook::SetCode(uint64_t code) { this->_code = code; } void Textbook::SetSingleCopyPrice(double single_copy_price) { this->_single_copy_price = single_copy_price; } void Textbook::SetNumberOnHand(uint64_t number_on_hand) { this->_number_on_hand = number_on_hand; } void Textbook::SetProspectiveEnrollment(uint64_t prospective_enrollment) { this->_prospective_enrollment = prospective_enrollment; } void Textbook::SetIsRequired(bool required) { this->_is_required = required; } void Textbook::SetIsUsed(bool used) { this->_is_used = used; } void Textbook::Print() const { // 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->_is_required ? "Yes" : "No") << "\nUsed: " << (this->_is_used ? "Yes" : "No") << std::endl; } void Textbook::EvaluateNeeds() { /// 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( static_cast(this->_prospective_enrollment) * factor) - this->_number_on_hand; }; // Determine amount to order based on given percentages if (this->_is_required && !this->_is_used) { set_amount_to_order(0.9); } else if (this->_is_required && this->_is_used) { set_amount_to_order(0.65); } else if (!this->_is_required && !this->_is_used) { set_amount_to_order(0.4); } else if (!this->_is_required && this->_is_used) { set_amount_to_order(0.2); } // Calculate total cost this->_total_cost = static_cast(this->_amount_to_order) * this->_single_copy_price; } void Textbook::PrintNeeds() const { // 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; } bool Textbook::operator==(const Textbook &other) const { return this->_code == other._code; } bool Textbook::operator!=(const Textbook &other) const { return this->_code != other._code; } } // namespace Textbook