blob: 09a43bd9d5205a0641ddcf526a8c6e4ceb1ff550 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 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_;
} // uint64_t Textbook::GetProspectiveEnrollment() const
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_; }
// Setters
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; }
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")
<< "\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() {
/// Calculate the total cost of the books to order based on an input factor
const auto set_amount_to_order = [this](double factor) -> void {
uint64_t amount_to_order =
static_cast<uint64_t>(
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) {
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
double total_cost =
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
|