/* 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 #include namespace wk1_reviewProgram_zSzabatin { void InputToTextbook(Textbook &textbook) { // Obtain and set all non-evaluated values for textbook textbook.SetCode(InputToTextbookValue("Book")); textbook.SetSingleCopyPrice(InputToTextbookValue("Price")); textbook.SetNumberOnHand(InputToTextbookValue("Number on hand")); textbook.SetProspectiveEnrollment( InputToTextbookValue("Enrollment")); textbook.SetIsRequired( InputToTextbookValue("Required (1 = required, 0 = optional)")); textbook.SetIsUsed(InputToTextbookValue("Used (1 = used, 0 = new)")); } // void InputToTextbook(Textbook &textbook) template T InputToTextbookValue(const std::string &message) { // Helper for repetitive textbook value prompts T value = 0; std::cout << message << ": "; std::cin >> value; return value; } // template T InputToTextbookValue(const std::string &message) void TextbookInputHandler(std::vector &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 &textbooks) void FullTextbookPurchaseSummary(const std::vector &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 &textbooks) } // namespace wk1_reviewProgram_zSzabatin int main() { bool run_again = false; std::vector 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()