Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

my code is not working can you fix it according to the samples i provided #include #include Hinclude #include using namespace std; struct Product {

my code is not working can you fix it according to the samples i provided
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
\#include \#include Hinclude \#include using namespace std; struct Product \{ string qr_code; string name; double price; int amount; Product(string qr, string n, double p, int a) : qr _code(qr), name (n), price(p), asount(a) \{\} ; class Products private: vector item_1ist; vectoreproduct> shop_1ist; public: Products ()= default; Products (const Products \&p) : item_list(p.item_1ist), shop_1ist(p.shop_1ist) \{\} vector get_item_1ist() const 1 return item_list; \} vector get_shop_1ist () const \& 1 return shop_list; \} void read_files(ifstream \&qr, ifstream \&price) \{ // Read QR and price files and store them into item_list string ar code, name: void read_files(ifstream \&qr, ifstream \&price) \{ // Read QR and price files and store them into item_list string qr_code, name; double price_val; int amount; item_1ist.emplace_back(qr_code, name, price_val, ) ; \} while (price qr_code amount) ( auto it = find_if(item_list.begin(), item_list.end () , [qr_code] (const Product \&p) { return p.qrcode ==qrcode; }); if (it l= item_list.end()) \{ it amount = amount; \} \} bool find(string qr_code) return any_of(item_list.begin(), item_list.end(), [qr_code] (const Product \& q ) { return p.qr_code =q=rcode; \}); \} bool findinshopList(string qr_code) f return any_of(shop_list.begin(), shop_list.end(), [qr_code](const Product \&p) \{return p.qr_code = = qr_code; \}); \} void add_item(string qr, int amount) \{ auto it = find_if(item_list.begin(), item_list.end(), [qr] (const Product \&p) \{return p.qr_code ==qr;} ); if (it l= item_list.end()) \{ it amount += amount; shop_1ist.push_back(*it); 2 void edit_item(string qr, int amount) f auto it = find_if(shop_list.begin(), shop_list.end ), [qr] (const Product \&p) { return \( p \cdot q r_{\text {_code }}^{=} \)ar; }); if (it l= shop_list,end()) \{ it amount = amount ; \} \} void remove_item (string qr) 1 shop_list.erase(remove_if(shop_list.begin(), shop_list.end(), [qr](const Product \&p) ( return p.qr_code =qr;}), shop_list.end()); \} void printCurrentReceipt() \{ double total =.; double vat =0.; I/ Print the current receipt for (const auto \&product : shop_1ist) f double subtotal = product.price * product.amount; total + subtotal; cout product. name " * " product.amount " " subtotal end1; r I/ Calculate VAT vat = total 0.18;// Assuming 18K VAT I/ Print VAT and total cout "VAT (188): : vat endl; cout "Total: " total + vat endl; \} void printCurrentReceiptAscending() \{ // Sort the shop_list in ascending order (e.g., alphabetically by product name) 4 DHW5 void printCurrentReceiptAscending( ) \& // Sort the shoplist in ascending order (e.g., alphabetically by product name) sort(shop_list.begin(), shop_list.end(), [](const Product \&a, const Product \&b) f return a.name =0.; double vat =0.; // Print the current receipt in ascending order. for (const auto \&product : shop_1ist) \{ double subtotal = product.price product. amount; total += subtotal; cout product. name " * " product. amount a " subtotal endl; r // Calculate VAT vat = total 0.18;// Assuming 18x VAT I/ Print VAT and total cout "VAT (18%) : " vat endl; cout "Total: " total + vat endl; \} void printcurrentReceiptDescending() \{ // Sort the shop_list in descending order based on subtotal (price * asount) sort(shop_list.begin(), shop_list.end(), [](const Product \&a, const Product \&b) \& return (a.price * a.amount) > (b.price * b.amount); ); double total =0.; double vat =0.0; // Print the current receipt in descending order for (const auto \&product : shop_1ist) \{ double subtotal = product.price product. amount; total += subtotal; cout product. name " * product. amount " " subtotal endl; \} void printcurrentreceiptoescending () i // Calculate VAT vat = total 0.18;// Assuming 1856 VAT 1/ Print VAT and total cout "VAT(18\%): " vat end I; cout "Total: " total + vat endl; \} ; ; int main()t ifstrean ar_file, price_file; string qr_filename, price_filename; do 1 cout "Please enter a filename for QR database: "; cin qr_filename; qr_file.open(qr_filename); if (lar_file) \{ cout "The QR file does not exist" endl; qr_file.clear(); // Clear error flags qr_file.ignore(numeric_limits::max(), ' ): // clear input buffer \} th while (tar_file); bool pricefileExists = false; do 1 cout "Please enter a filename for Price database: "; cin price.filename; price_file.open(price_filename); if (Iprice_file) \{ cout "The Price file does not exist" endi; price_file.clear(); // clear error flags price_file.ignore(numeric_limits: amax(), ' '); // clear input buffer \} else \{ priceFileExists = true; // set the flag to true if the file-exists \} \} while (IpriceFileExists); Products P; p. read files(or file, price file): int choice; do 1 1/ Display menu options cout "MENUln1. Add item to the shopping listln2. Delete item fros the shopping listln" 3. Edit the amount of existing itenln6. Print current receiptln5. Print current receipt in orderln" 6. Print current receipt in reverse orderla7. Exitin--inEnter your choice: "; cin choice; switch (choice) 1 case 1: 1 string qr_code; int amount; cout "Please enter the OR code to add: "; cin qr_code; cout "Please enter the amount to add: "; cin amount; p.add_iten(qr_code, amount); break; t. case 2:4 string qr_code; cout "Please enter the OR code to delete: "i cin qr_code; p.remove_item (qr_code); break; \} case 3:1 string qr_code; int amount; cout "Please enter the CR code to edit: "; cin qr_code; cout "Please enter the now amount: "; oin amount; p.edit_item(qr_code, anount); break; \} case 4 : cout "Current Receipt:" endl; p. printcurrentRecoipt(); break; case 5 : cout "Current Receipt in ordert" endl; P.printCurrentReceiptAscending(); break: cin qr_code; cout "Please enter the new amount: "; cin amount; p.edit_item(qr_code, amount); break; \} case 4: cout "Current Receipt:" endl; p.printCurrentReceipt(); break; case 5: cout "Current Receipt in order:" endl; p.printCurrentReceiptAscending(); break; case 6 : cout "Current Receipt in reverse order:" endl; p.printCurrentReceiptDescending (); break; case 7: cout "Goodbyel" endl; break; default: cout "Invalid choice. Please enter a valid choice (1-7)." endl; break; \} ) while (true); // Loop indefinitely unless ' 7 ' is selected return 8; \} Sample Runs Below, we provide some sample runs of the program that you will develop. The italic and bold phrases are inputs taken from the user. You have to display the required information in the same order and with the same words and characters as below. Sample Run 1 Please enter a fitename for QR database: q.txt The QR file does not exists Please enter a filename for QR database: qr,txt Please enter a filename for Price database: p.txt The Price file does not exists Please enter a filename for Price database: price, txt MENU 1. Add titem to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 51424 please enter the amount to add: 2 MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 5 Nikon Lens * 2 |1998.6 VAT (18%):359.6 Total: NENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 2 Please enter the QR code to delete: 51424 MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing iten 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 4 Coca Cola (33emt) * 14 28. VAT (185) : Total: 33.0 MENU 1. Add item to the shopping list 2. Delete iten from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 7 Goodbye! Sample Run 2 Please enter a filename for QR database: qr.txt Please enter a filename for Price database: price.txt MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing iten 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 51423 Please enter the amount to add: 2 MENU 1. Add item to the shopping list 2. Delete iten from the shopping Itst 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 90817 please enter the amount to add: 25 MENU 1. Add item to the shopping list 2. Delete iten from the shopping list 3. Edit the anount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse ordec 7. Exit Enter your choice: 2 Please enter the QR code to delete: 51423 MENU 1. Add item to the shopping tist 2. Delete item from the shopping list 3. Edit the amountrof existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 40125 Invalid QR code, try again MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current recelpt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 4a124 Please enter the amount to add: 61 Invalid amount, try again MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 40124 Please enter the amount to add: 11 MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: }5 \begin{tabular}{l|l||} VAT(18%) & 9.5 \end{tabular} Total: 62.2 MENU 1. Add item to the shopping list 2. Delete iten from the shopping list 3. Edit the amount of existing iten 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse orden 7. Exit Enter your choice: 7 Goodbye: Sample Run 3 Please enter a filename for QR database: qr.txt Please enter a filename for Price database: price.txt MENU 1. Add item to the shopping list 2. Delete item from the shopping tist: 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 40123 Please enter the amount to add: 9 MENU 1. Add item to the shopping Itist 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 4a124 please enter the amount to add: 5 MENU 1. Add item to the shopping tist 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 3 Please enter the QR code to edit: 4a124 Please enter the anount to edit: 6 MENU 1. Add item to the shopping list: 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 6 coca Cola (500mL) * 18. Coca Cota (330mt) I 18.0 VAT(18%) : 6.5 Total: 42.5 MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 7 Goodbye! Sample Run 4 Please enter a filename for QR database: qr.txt Please enter a filename for Price database: price.txt MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 4a123 Please enter the amount to add: 17 MENU 1. Add item to the shopping tist 2. Detete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the Qf code to add: 40123 Item is already in the shoplist, if you want to edit the amount please choose option 3 MENU 1. Add item to the shopping tist 2. Delete item from the shopping tist 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 3 Please enter the QR code to edit: 40123 Please enter the amount to edit: 1 MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit MENU 1. Add item to the shopping list 2. Delete item from the shopping list 3. Edit the amount of existing item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit I Enter your choice: 7 Goodbye: 4A123 Coca Cola (330ml) 4 A124 Coca Cola (500mt) 90321 Snickers 90817 Albeni 83222 Wi-Fi Router 51423 Nikon DSLR 51424 Nikon Lens 73918 LG 32" LED TV 43900 Kinder. Bueno 4A1232 4A1243 903210.99 908170.79 83222 243.79 514231599 51424999 73918799.90 439001.19

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions