blob: 6eeee7cdf3c6379f7a956e9bf0bee9a48a1ea612 (
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
|
#include "textbook.hh"
#include <iomanip>
#include <iostream>
namespace textbook {
auto Textbook::code() const -> uint64_t { return this->_code; }
auto Textbook::single_copy_price() const -> double {
return this->_single_copy_price;
}
auto Textbook::number_on_hand() const -> uint64_t {
return this->_number_on_hand;
}
auto Textbook::prospective_enrollment() const -> uint64_t {
return this->_prospective_enrollment;
}
auto Textbook::required() const -> bool { return this->_required; }
auto Textbook::used() const -> bool { return this->_used; }
auto Textbook::amount_to_order() const -> uint64_t {
return this->_amount_to_order;
}
auto Textbook::total_cost() const -> double { return this->_total_cost; }
auto Textbook::set_code(uint64_t code) -> void { this->_code = code; }
auto Textbook::set_single_copy_price(double single_copy_price) -> void {
this->_single_copy_price = single_copy_price;
}
auto Textbook::set_number_on_hand(uint64_t number_on_hand) -> void {
this->_number_on_hand = number_on_hand;
}
auto Textbook::set_prospective_enrollment(uint64_t prospective_enrollment)
-> void {
this->_prospective_enrollment = prospective_enrollment;
}
auto Textbook::set_required(bool required) -> void {
this->_required = required;
}
auto Textbook::set_used(bool used) -> void { this->_used = used; }
auto Textbook::print() const -> void {
// 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->_required << "\nUsed: " << this->_used
<< std::endl;
}
auto Textbook::evaluate_needs() -> void {
/// 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->_required && !this->_used) {
set_amount_to_order(0.9);
} else if (this->_required && this->_used) {
set_amount_to_order(0.65);
} else if (!this->_required && !this->_used) {
set_amount_to_order(0.4);
} else if (!this->_required && this->_used) {
set_amount_to_order(0.2);
}
// Calculate total cost
this->_total_cost =
static_cast<double>(this->_amount_to_order) * this->_single_copy_price;
}
auto Textbook::print_needs() const -> void {
// 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;
}
auto Textbook::operator==(const Textbook &other) const -> bool {
return this->_code == other._code;
}
auto Textbook::operator!=(const Textbook &other) const -> bool {
return this->_code != other._code;
}
} // namespace textbook
|