From d308a99359dbd627cdd3f3dfc94050e82ff3b0a5 Mon Sep 17 00:00:00 2001 From: Kristina Novikova Date: Sun, 5 Dec 2021 18:56:29 +0300 Subject: [PATCH] ... --- DZ1_part2/DZ1_part2/DZ1_part2.cpp | 131 ++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 DZ1_part2/DZ1_part2/DZ1_part2.cpp diff --git a/DZ1_part2/DZ1_part2/DZ1_part2.cpp b/DZ1_part2/DZ1_part2/DZ1_part2.cpp new file mode 100644 index 0000000..e1f32b8 --- /dev/null +++ b/DZ1_part2/DZ1_part2/DZ1_part2.cpp @@ -0,0 +1,131 @@ +#include +#include "S.h" + + + +void printMenu() { + + std::cout << std::endl; + std::cout << "---------------------------- MENU ----------------------------" << std::endl << std::endl; + std::cout << "1. Create a new file \"Journal.bin\" and write data into it." << std::endl; + std::cout << "2. Add data to \"Journal.bin\"." << std::endl; + std::cout << "3. Output products into Result.txt\"." << std::endl; + std::cout << "4. Search by storage id." << std::endl; + std::cout << "5. Search by product code." << std::endl; + std::cout << "6. Search by arrival date." << std::endl; + std::cout << "7. Search for expired products." << std::endl; + std::cout << "8. Search for not-expired products." << std::endl; + std::cout << "9. Delete a product." << std::endl; + std::cout << "10. Update a product." << std::endl; + std::cout << "0. Exit." << std::endl << std::endl; +} + +int main() { + + Storage newJournal("Journal.bin", "Result.txt"); + + int option = 1; + while (option != 0) { + printMenu(); + + std::cout << "Enter a number: "; + std::cin >> option; + + std::string tmp; + int ind; + Date curr_date; + + switch (option) { + case 1: + try { + newJournal.create_and_write(); + } + catch (std::runtime_error err) { + std::cout << err.what() << std::endl; + } + break; + + case 2: + try { + newJournal.add_product(); + } + catch (std::runtime_error err) { + std::cout << err.what() << std::endl; + } + break; + + case 3: + try { + newJournal.load_out_txt(); + } + catch (std::runtime_error err) { + std::cout << err.what() << std::endl; + } + break; + + case 4: + std::cout << std::endl; + std::cout << "Input the storage id: "; + std::cin >> ind; + newJournal.search_storage_id(ind); + break; + + case 5: + std::cout << std::endl << "Input the product code: "; + int ind; + std::cin >> ind; + newJournal.search_product_code(ind); + break; + + case 6: + std::cout << std::endl << "Input the arrival date: "; + std::cin >> curr_date; + newJournal.search_arrival_date(curr_date); + break; + + case 7: + std::cout << std::endl << "Input the current date: "; + std::cin >> curr_date; + newJournal.search_overdue_products(curr_date); + break; + + case 8: + std::cout << std::endl << "Input the current date: "; + std::cin >> curr_date; + newJournal.search_not_overdue_products(curr_date); + break; + + case 9: + std::cout << std::endl << "Input index of product you want to delete: "; + std::cin >> ind; + try { + newJournal.delete_product(ind); + } + catch (std::runtime_error err) { + std::cout << err.what() << std::endl; + } + break; + + case 10: + std::cout << std::endl << "Input index of the record you want to update: "; + std::cin >> ind; + try { + newJournal.change_product(ind); + } + catch (std::runtime_error err) { + std::cout << err.what() << std::endl; + } + break; + + case 0: + std::cout << std::endl << std::endl << "Goodbye!" << std::endl << std::endl; + break; + + default: + std::cout << std::endl << std::endl << "I don't know such a command... Try again please." << std::endl << std::endl; + } + } + + return 0; +} + -- GitLab