diff options
| author | Fuwn <[email protected]> | 2023-09-26 22:39:21 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-26 22:39:21 -0700 |
| commit | 826353dfcc7da180e3a92e7d19ad87ae09838b23 (patch) | |
| tree | 7ff1dee68876a102912559399e7cd746d5b9a799 /week_1/review_program/textbook.cpp | |
| parent | style(review_program): rename symbols (diff) | |
| download | cs260-826353dfcc7da180e3a92e7d19ad87ae09838b23.tar.xz cs260-826353dfcc7da180e3a92e7d19ad87ae09838b23.zip | |
style(review_program): implement styles
Diffstat (limited to 'week_1/review_program/textbook.cpp')
| -rw-r--r-- | week_1/review_program/textbook.cpp | 102 |
1 files changed, 66 insertions, 36 deletions
diff --git a/week_1/review_program/textbook.cpp b/week_1/review_program/textbook.cpp index fe39be4..eff0e92 100644 --- a/week_1/review_program/textbook.cpp +++ b/week_1/review_program/textbook.cpp @@ -1,79 +1,109 @@ +/* textbook.cpp + * Summary: Implementation file for the Textbook class + * Author: Zoltan Szabatin + * Created: September 26th, 2023 + */ + #include "textbook.h" #include <iomanip> #include <iostream> -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; } +namespace wk1_reviewProgram_zSzabatin { + +// Getters +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; + return this->prospective_enrollment_; } -bool Textbook::GetIsRequired() const { return this->_is_required; } + +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; } +uint64_t Textbook::GetAmountToOrder() const { return this->amount_to_order_; } + +double Textbook::GetTotalCost() const { return this->total_cost_; } + +// Setters +void Textbook::SetCode(uint64_t code) { this->code_ = code; } + void Textbook::SetSingleCopyPrice(double single_copy_price) { - this->_single_copy_price = 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; + this->number_on_hand_ = number_on_hand; } + void Textbook::SetProspectiveEnrollment(uint64_t prospective_enrollment) { - this->_prospective_enrollment = prospective_enrollment; + this->prospective_enrollment_ = prospective_enrollment; } -void Textbook::SetIsRequired(bool required) { this->_is_required = required; } + +void Textbook::SetIsRequired(bool required) { this->is_required_ = required; } + void Textbook::SetIsUsed(bool used) { this->_is_used = used; } +// Printers 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") + 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::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; +} + +// Evaluators 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 = + uint64_t amount_to_order = static_cast<uint64_t>( - static_cast<double>(this->_prospective_enrollment) * factor) - - this->_number_on_hand; + static_cast<double>(this->prospective_enrollment_) * factor) - + this->number_on_hand_; + + this->amount_to_order_ = amount_to_order; }; // Determine amount to order based on given percentages - if (this->_is_required && !this->_is_used) { + if (this->is_required_ && !this->_is_used) { set_amount_to_order(0.9); - } else if (this->_is_required && this->_is_used) { + } else if (this->is_required_ && this->_is_used) { set_amount_to_order(0.65); - } else if (!this->_is_required && !this->_is_used) { + } else if (!this->is_required_ && !this->_is_used) { set_amount_to_order(0.4); - } else if (!this->_is_required && this->_is_used) { + } else if (!this->is_required_ && this->_is_used) { set_amount_to_order(0.2); } // Calculate total cost - this->_total_cost = - static_cast<double>(this->_amount_to_order) * this->_single_copy_price; -} + double total_cost = + static_cast<double>(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; + this->total_cost_ = total_cost; } +// Operator overloads bool Textbook::operator==(const Textbook &other) const { - return this->_code == other._code; + return this->code_ == other.code_; } + bool Textbook::operator!=(const Textbook &other) const { - return this->_code != other._code; + return this->code_ != other.code_; } -} // namespace Textbook + +} // namespace wk1_reviewProgram_zSzabatin |