summaryrefslogtreecommitdiff
path: root/week_1/review_program/review_program.cpp
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-26 22:14:57 -0700
committerFuwn <[email protected]>2023-09-26 22:14:57 -0700
commit199ec09e5b1ab397acf36c192d1e381a89083be8 (patch)
tree29d9f70ca0a963df7f49bb387b290b5675a7d7b7 /week_1/review_program/review_program.cpp
parentstyle(review_program): move main function order (diff)
downloadcs260-199ec09e5b1ab397acf36c192d1e381a89083be8.tar.xz
cs260-199ec09e5b1ab397acf36c192d1e381a89083be8.zip
style(review_program): rename symbols
Diffstat (limited to 'week_1/review_program/review_program.cpp')
-rw-r--r--week_1/review_program/review_program.cpp51
1 files changed, 24 insertions, 27 deletions
diff --git a/week_1/review_program/review_program.cpp b/week_1/review_program/review_program.cpp
index 38fb0f3..d89d206 100644
--- a/week_1/review_program/review_program.cpp
+++ b/week_1/review_program/review_program.cpp
@@ -4,21 +4,20 @@
#include <cstdint>
#include <iostream>
-namespace review_program {
-auto textbook_input(textbook::Textbook &textbook) -> void {
+namespace ReviewProgram {
+void InputToTextbook(Textbook &textbook) {
// Obtain and set all non-evaluated values for textbook
- textbook.set_code(input_textbook_value<uint64_t>("Book"));
- textbook.set_single_copy_price(input_textbook_value<double>("Price"));
- textbook.set_number_on_hand(input_textbook_value<uint64_t>("Number on hand"));
- textbook.set_prospective_enrollment(
- input_textbook_value<uint64_t>("Enrollment"));
- textbook.set_required(
- input_textbook_value<bool>("Required (1 = required, 0 = optional)"));
- textbook.set_used(input_textbook_value<bool>("Used (1 = used, 0 = new)"));
+ 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)"));
}
-template <typename T>
-auto input_textbook_value(const std::string &message) -> T {
+template <typename T> T InputToTextbookValue(const std::string &message) {
// Helper for repetitive textbook value prompts
T value = 0;
@@ -28,38 +27,36 @@ auto input_textbook_value(const std::string &message) -> T {
return value;
}
-auto textbook_input_loop_handler(std::vector<textbook::Textbook> &textbooks)
- -> void {
+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 textbook;
+ Textbook textbook;
- review_program::textbook_input(textbook);
+ ReviewProgram::InputToTextbook(textbook);
std::cout << "---" << std::endl;
- textbook.print();
+ textbook.Print();
std::cout << "---" << std::endl;
- textbook.evaluate_needs();
- textbook.print_needs();
+ textbook.EvaluateNeeds();
+ textbook.PrintNeeds();
std::cout << "---" << std::endl;
textbooks.push_back(textbook);
}
-auto full_purchase_summary(const std::vector<textbook::Textbook> &textbooks)
- -> void {
+void FullTextbookPurchaseSummary(const std::vector<Textbook> &textbooks) {
double total_for_all_books = 0.0;
// Calculate total cost for all books
for (const auto &textbook : textbooks) {
- total_for_all_books += textbook.total_cost();
+ total_for_all_books += textbook.GetTotalCost();
}
// Print total cost for all books and expected profits
@@ -67,22 +64,22 @@ auto full_purchase_summary(const std::vector<textbook::Textbook> &textbooks)
<< std::endl;
std::cout << "Expected profit: $" << total_for_all_books * 0.2 << std::endl;
}
-} // namespace review_program
+} // namespace ReviewProgram
-auto main() -> int {
+int main() {
bool run_again = false;
- std::vector<textbook::Textbook> textbooks;
+ std::vector<Textbook::Textbook> textbooks;
// Loop until user is done entering textbooks
do {
- review_program::textbook_input_loop_handler(textbooks);
+ ReviewProgram::TextbookInputHandler(textbooks);
std::cout << "Enter 1 to do another book, 0 to stop. ";
std::cin >> run_again;
} while (run_again);
// Print full purchase summary
- review_program::full_purchase_summary(textbooks);
+ ReviewProgram::FullTextbookPurchaseSummary(textbooks);
return 0;
}