blob: 672b1459f0b0f6113476ec7fca71e825b57762ee (
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
|
/* review_program.cpp
* Summary: Implementation for main program functionality
* Test Cases:
* - 1221 69.95 30 150 1 1; 4686.65 937.33
* - 8392 60 30 150 1 1; 4020 804
* - 8392 60 30 150 1 1; 1800 360
* - 8392 60 30 100 1 1; 600 120
* Author: Zoltan Szabatin
* Created: April 2nd, 2024
*/
#include "review_program.h"
#include "textbook.h"
#include <cstdint>
#include <iostream>
namespace wk1_reviewProgram_zSzabatin {
void InputToTextbook(Textbook &textbook) {
// Obtain and set all non-evaluated values for textbook
textbook.SetCode(InputToTextbookValue<uint64_t>("Book"));
textbook.SetSingleCopyPrice(InputToTextbookValue<double>("Price"));
textbook.SetNumberOnHand(InputToTextbookValue<uint64_t>("Number on hand"));
textbook.SetProspectiveEnrollment(
InputToTextbookValue<uint64_t>("Enrollment"));
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
T value = 0;
std::cout << message << ": ";
std::cin >> value;
return value;
} // template <typename T> T InputToTextbookValue(const std::string &message)
void TextbookInputHandler(std::vector<Textbook> &textbooks) {
// 1. Input textbook
// 2. Print textbook
// 3. Evaluate textbook needs
// 4. Print textbook needs
// 5. Add textbook to running count
Textbook textbook;
InputToTextbook(textbook);
std::cout << "---" << std::endl;
textbook.Print();
std::cout << "---" << std::endl;
textbook.EvaluateNeeds();
textbook.PrintNeeds();
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;
// Calculate total cost for all books
for (const Textbook &textbook : textbooks) {
total_for_all_books += textbook.GetTotalCost();
}
// Print total cost for all books and expected profits
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
int main() {
bool run_again = false;
std::vector<wk1_reviewProgram_zSzabatin::Textbook> textbooks;
// Loop until user is done entering textbooks
do {
wk1_reviewProgram_zSzabatin::TextbookInputHandler(textbooks);
std::cout << "Enter 1 to do another book, 0 to stop. ";
std::cin >> run_again;
} while (run_again);
// Print full purchase summary
wk1_reviewProgram_zSzabatin::FullTextbookPurchaseSummary(textbooks);
return 0;
} // int main()
|