blob: fe39be4c5d08bb942fd0ecf3858bfa4aade51d95 (
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
|
#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; }
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<uint64_t>(
static_cast<double>(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<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;
}
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
|