diff options
| author | Fuwn <[email protected]> | 2023-09-26 22:43:48 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-26 22:43:48 -0700 |
| commit | 61adbbcab7abf608925c8ceeb26b4261fed99961 (patch) | |
| tree | 385a432cc9aaf500c7d64f5de786ba130a4c4fe6 | |
| parent | style(review_program): implement styles (diff) | |
| download | cs260-61adbbcab7abf608925c8ceeb26b4261fed99961.tar.xz cs260-61adbbcab7abf608925c8ceeb26b4261fed99961.zip | |
docs(review_program): comments
| -rw-r--r-- | week_1/review_program/review_program.cpp | 10 | ||||
| -rw-r--r-- | week_1/review_program/textbook.cpp | 18 | ||||
| -rw-r--r-- | week_1/review_program/textbook.h | 18 |
3 files changed, 24 insertions, 22 deletions
diff --git a/week_1/review_program/review_program.cpp b/week_1/review_program/review_program.cpp index e6efe64..399bf96 100644 --- a/week_1/review_program/review_program.cpp +++ b/week_1/review_program/review_program.cpp @@ -27,7 +27,7 @@ void InputToTextbook(Textbook &textbook) { textbook.SetIsRequired( InputToTextbookValue<bool>("Required (1 = required, 0 = optional)")); textbook.SetIsUsed(InputToTextbookValue<bool>("Used (1 = used, 0 = new)")); -} +} // void InputToTextbook(Textbook &textbook) template <typename T> T InputToTextbookValue(const std::string &message) { // Helper for repetitive textbook value prompts @@ -37,7 +37,7 @@ template <typename T> T InputToTextbookValue(const std::string &message) { std::cin >> value; return value; -} +} // template <typename T> T InputToTextbookValue(const std::string &message) void TextbookInputHandler(std::vector<Textbook> &textbooks) { // 1. Input textbook @@ -61,7 +61,7 @@ void TextbookInputHandler(std::vector<Textbook> &textbooks) { std::cout << "---" << std::endl; textbooks.push_back(textbook); -} +} // void TextbookInputHandler(std::vector<Textbook> &textbooks) void FullTextbookPurchaseSummary(const std::vector<Textbook> &textbooks) { double total_for_all_books = 0.0; @@ -75,7 +75,7 @@ void FullTextbookPurchaseSummary(const std::vector<Textbook> &textbooks) { std::cout << "\n---\nTotal cost for all books: $" << total_for_all_books << std::endl; std::cout << "Expected profit: $" << total_for_all_books * 0.2 << std::endl; -} +} // void FullTextbookPurchaseSummary(const std::vector<Textbook> &textbooks) } // namespace wk1_reviewProgram_zSzabatin @@ -95,4 +95,4 @@ int main() { wk1_reviewProgram_zSzabatin::FullTextbookPurchaseSummary(textbooks); return 0; -} +} // int main() diff --git a/week_1/review_program/textbook.cpp b/week_1/review_program/textbook.cpp index eff0e92..09a43bd 100644 --- a/week_1/review_program/textbook.cpp +++ b/week_1/review_program/textbook.cpp @@ -20,7 +20,7 @@ uint64_t Textbook::GetNumberOnHand() const { return this->number_on_hand_; } uint64_t Textbook::GetProspectiveEnrollment() const { return this->prospective_enrollment_; -} +} // uint64_t Textbook::GetProspectiveEnrollment() const bool Textbook::GetIsRequired() const { return this->is_required_; } @@ -35,15 +35,15 @@ 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::SetSingleCopyPrice(double single_copy_price) void Textbook::SetNumberOnHand(uint64_t number_on_hand) { this->number_on_hand_ = number_on_hand; -} +} // void Textbook::SetNumberOnHand(uint64_t number_on_hand) void Textbook::SetProspectiveEnrollment(uint64_t prospective_enrollment) { this->prospective_enrollment_ = prospective_enrollment; -} +} // void Textbook::SetProspectiveEnrollment(uint64_t prospective_enrollment) void Textbook::SetIsRequired(bool required) { this->is_required_ = required; } @@ -58,14 +58,14 @@ void Textbook::Print() const { << "\nEnrollment: " << this->prospective_enrollment_ << "\nRequired: " << (this->is_required_ ? "Yes" : "No") << "\nUsed: " << (this->_is_used ? "Yes" : "No") << std::endl; -} +} // void Textbook::Print() const 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; -} +} // void Textbook::PrintNeeds() const // Evaluators void Textbook::EvaluateNeeds() { @@ -95,15 +95,15 @@ void Textbook::EvaluateNeeds() { static_cast<double>(this->amount_to_order_) * this->single_copy_price_; this->total_cost_ = total_cost; -} +} // void Textbook::EvaluateNeeds() // Operator overloads bool Textbook::operator==(const Textbook &other) const { return this->code_ == other.code_; -} +} // bool Textbook::operator==(const Textbook &other) const bool Textbook::operator!=(const Textbook &other) const { return this->code_ != other.code_; -} +} // bool Textbook::operator!=(const Textbook &other) const } // namespace wk1_reviewProgram_zSzabatin diff --git a/week_1/review_program/textbook.h b/week_1/review_program/textbook.h index 8bb05d3..e546c14 100644 --- a/week_1/review_program/textbook.h +++ b/week_1/review_program/textbook.h @@ -13,17 +13,17 @@ namespace wk1_reviewProgram_zSzabatin { class Textbook { private: // Input values - uint64_t code_; - double single_copy_price_; - uint64_t number_on_hand_; - uint64_t prospective_enrollment_; - bool is_required_; - bool _is_used; + uint64_t code_; // Book code + double single_copy_price_; // Price of a single copy + uint64_t number_on_hand_; // Number of copies on hand + uint64_t prospective_enrollment_; // Number of students expected to enroll + bool is_required_; // Is the book required? + bool _is_used; // Is the book used? // Fix 6 byte misalignment const char PADDING[6] = {0}; // Evaluated values - uint64_t amount_to_order_ = {0}; - double total_cost_ = {0}; + uint64_t amount_to_order_ = {0}; // Number of copies to order + double total_cost_ = {0}; // Total cost of the order public: // Constructors @@ -67,6 +67,8 @@ public: void SetIsUsed(bool); // Procedures + /// Precondition: Values have been set: code_, single_copy_price_, + /// number_on_hand_, prospective_enrollment_, is_required_, _is_used void EvaluateNeeds(); // Printers |