Question: can you write me the code please my code is not working Introduction This homework aims to make students comfortable with classes and vectors (writing

can you write me the code please my code is not working  can you write me the code please my code is not
working Introduction This homework aims to make students comfortable with classes and
vectors (writing member functions and storing the data with vectors) in C++
as well as using computational approaches to solve analytical questions. For this
homework, you must use the vectors and the structs. Description First let
us review the Database concept. A database is a collection of data
records stored in a computer in a systematic way. In this way,
a computer program can be used to answer queries about the data
stored in the database by searching the records. In this homework, you
will write a console application that would take two database files as
input and display the output on console according to the user inputs.
Your program will take the database file names as input to open
and read the files according to the shop list file. These two
database files will contain QR codes of items, their names and their
prices. This is similar to a supermarket database in a primitive way.
Your program will utilize this database and offer a menu with 7
options to the user until he chooses the exit option. The seven
options are as follows: 1- Adding an item to the shop list
with qr code and amount. 2- Deleting an existing item from the
shop list with qr code. 3- Editing an existing item's amount with
qr code. 4- Printing the current receipt. 5- Printing the current receipt
in ascending order with respect to total prices of the products. 6-

Introduction This homework aims to make students comfortable with classes and vectors (writing member functions and storing the data with vectors) in C++ as well as using computational approaches to solve analytical questions. For this homework, you must use the vectors and the structs. Description First let us review the Database concept. A database is a collection of data records stored in a computer in a systematic way. In this way, a computer program can be used to answer queries about the data stored in the database by searching the records. In this homework, you will write a console application that would take two database files as input and display the output on console according to the user inputs. Your program will take the database file names as input to open and read the files according to the shop list file. These two database files will contain QR codes of items, their names and their prices. This is similar to a supermarket database in a primitive way. Your program will utilize this database and offer a menu with 7 options to the user until he chooses the exit option. The seven options are as follows: 1- Adding an item to the shop list with qr code and amount. 2- Deleting an existing item from the shop list with qr code. 3- Editing an existing item's amount with qr code. 4- Printing the current receipt. 5- Printing the current receipt in ascending order with respect to total prices of the products. 6- Printing the current receipt in descending order with respect to total prices of the products. 7- Exit the menu. You cannot write all of your code under the main function, i.e. you must write user-defined functions and use them. fpragma once Hinclude Hinclude *Include Hinclude Hinclude \#include \#include "strutils.h" using namespace std; struct Product string name, qr_code; int amount; float price; Product () \{\}; 1; class Products 1 private: vector 1 ten_11st) vectoreproduct> ahop_11at; publict Products (); Products (conat products 5 p); vector get item iist () const; vector get_shop_1ist() const; // you are going to implement these member functions void read_files(ifstream t qr, ifatream o price); bool find(string qr_code); bool findinshopList(string qr_code); vold add_item(string qr, int amount); void edit_item(string qr, int amount); vold remove_item (string qr); void printcurrentReceipt(); void printCurrentReceiptAscending(); void printCurrentReceiptDescending(); ; 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 filename 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 item to the shopping list 2. Delete iten from the shopping tist 3. Edit the anount 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: 51424 please enter the amount to add: 2 MENU 1. Add item to the shopping tist 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 order 7. Exit Enter your choice: 5 Nikon Lens * 2 1998.0 VAT(18%):359.6 Total: 2357.6 MENU 1. Add item to the shopping tist 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: 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 (330ml)14 28.0 VAT(185) : 5.0 Total: 33.0 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 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 item 4. Print current receipt 5. Print current receipt in order 6. Print current receipt in reverse order 7. Exit Enter your chotce: 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 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: 90817 Please enter the amount to add: 25 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: 2 Please enter the QR code to delete: 51423 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: 40125 Invalid QR code, try again 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: 1 Sample Run 3 Please enter a filename for QR database: qr.txt Please enter a filename for Price database: pric 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 chotce: 1 Please enter the QR code to add: 4a123 Please enter the amount to add: 9 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: 4a124 Please enter the amount to add: s 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: 3 Please enter the QR code to edit: 4a124 Please enter the amount to edit: 6 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 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 \begin{tabular}{lll} Coca Cola (5ml) & 6 & 18.0 \\ Coca Cola (33ml) & 9 & 18.0 \\ & & 6.5 \\ \hline VAT (188): & 42.5 \end{tabular} 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 4 Please enter a filename for QR database: qr.txt Please enter a filename for Price database: price.txt NENU 1. Add iten 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: 4a1.23 Please enter the amount to add: 17 NENU 1. Add iten 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: 401.23 Item is already in the shoplist, if you want to edit the amount please choose option 3 NENU 1. Add iten 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: 3 Please enter the QR code to edit: 40123 Please enter the amount to edit: 1 MENU 1. Add iten 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: 7 Goodbye! Products Class and Product Struct You must use the structure below while implementing homework 5 . There are 9 member functions and a Product struct in order to complete the Products class. Products p; p.read_files(qr, price); struct Product \{ // You need to fill here with necessary member variables // You can add a constructor and simple functions as well \}; class Products \{ private: vector item_list; vector shop_list; public: Products(); Products(const Products \& p); vector get_item_list() const; vector get_shop_list() const; // you are going to implement these member functions void read_files(ifstream \& qr, ifstream \& price); // it reads ar and price files and stores them into item_list bool find(string qr_code); // given ar code it searches that inside item_list bool findInShoplist(string qr_code); // given ar code it searches that inside shop_list void add_item(string qr, int amount); // adds an item to the shop_list void edit_item(string qr, int amount); // edits an item in teh shop_list void remove_item(string qr); // removes an item from the shop_list void printCurrentReceipt(); // prints the current receipt void printCurrentReceiptAscending(); // prints the current receipt in ascending order void printCurrentReceiptDescending(); // prints the current receipt in descending order 4A123 Coca Cola (330ml) 4 AA124 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 83222243.79 514231599 51424999 73918799.90 439001.19 \#ifndef STRUTILS_H \#define STRUTILS_H \#include \#include \#include \#include \#include \#include \#include \#include "strutils.h" using namespace std; struct Product \{ string name, qr_code; int amount; float price; Product () \{\} Product(string n="n, int a=1, float p=1, string qr="a ) : name( n ), amount(a), price( \}; class Products \{ private: vector item_list; vector shop_1ist; public: Products () \{\} Products(const Products \&p) : item_list(p.item_list), shop_list(p.shop_list) \{\} vector get_item_1ist () const \{ return item_list; \} vector get_shop_Iist () const f return shop_list; class Products \{ void read_files(ifstream \&qr, ifstream \&price) \{ string qr_code, name; float price_val; int amount; item_list.emplace_back(name, , price_val, qr_code); \} while (price qr_code amount) \{ auto it = find_if(item_list.begin(), item_list.end(), [qr_code](const Product \&p) { return pqrcode \( ==q r_{\text {_ }} \) code; } ); if (it 1= item_list.end()) \{ it amount = amount; \} \} \} bool find(string ar_code) \{ return any_of(item_list.begin(), item_list.end(), [qr_code] (const Product \&p) \{ return p.qr_code = = qr_code; } ); \} bool findinshopList(string qr_code) f return any_of(shop_list.begin(), shop_1ist.end(), [qr_code] (const Product \&p) \{ return p.qr_code \( ==q r_{\text {_ }} \) code; } ); \} void add_iten(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 I= item_list.end()) ( it amount += amount; if (IfindInShoplist(qr)) \{ ehon 7 iet nueh hark (i+1. void add item (string qr, int asount) \{ shop_list.push_back(*it); ) \} \} void edit_item(string qr, int amount) \{ auto it = find_if(shop_list.begin () , shop_list.end () , [qr](const Product \&p) { return p.qr_code =qr; \}); if (it I= shop_list.end()) f it amount = amount; \} r void remove_item(string ar) 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() \& float total =0.; float vat =0.0; for (const auto \&product : shop_list) 1 float subtotal = product.price * product.amount; total += subtotal; cout product. name * * " product. amount " * subtotal endl; \} vat =total.18 cout "VAT(189s): " vat endl; cout "Total: " total + vat endl; \} void printCurrentReceiptAscending() \& void printCurrentReceiptAscending() 1 sort(shop_list.begin(), shop_list, end(), [](const Product \&a, const Product \&b) \{ return a.name =8.0; float vat =0.6; for (const auto eproduct : shop_1ist) 1 float subtotal = product.price * product. amount; total += subtotal; cout product, name * * " product. amount " " subtotal endl; \} vat =total8.18; cout "VAT(18s) : " vat endl; cout "Total: " total + vat endl; \} void printCurrentReceiptDescending() \{ sort(shop_1ist,begin(), shop_1ist, end(), [](const Product \&a, const Product 8b) \& return (a.price * a.amount) > (b.price * b.amount); ); float total =8.8; float vat =.; for (const auto \&product : shop_1ist) ( float subtotal = product.price * product.amount; total += subtotal; cout product, name * * " product, amount & subtotal endl; \} vat =total0.18 void printCurrentReceiptDescending() \{ cout "VAT (18\%): " vat end1; cout "Total: * total + vat endl; \} ; int main () 1 ifstream qr_file, price_file; string qr_filename, price_filename; while (true) 1 cout "Please enter a filename for OR database: "; cin qr_filename; qr_file.open(qr_filename); if (tar_file) 4 cout "The QR file does not exist" endl; qr_file,clear(); cin.ignore(numeric_limits: :max( ), ' '); \} else \{ break; \} \} bool priceFileExists = false; while (true) 1 cout "Please enter a filename for Price database: "; cin price_filename; price_file.open(price_filename); if (tprice_file) t cout "The Price file does not exist" endl; price_file.clear(); cin.ignore(numeric_limits: :max (),(n); \} else f priceFileExists = true; int main(0) break; \} \} Products p; p.read_files(qr_file, price_file); int choice; do f cout "MENU 1. Add item to the shopping listln2. Delete item from the shopping 1 istln" "3. Edit the amount of existing itemin4. Print current receiptin5. Print current receipt in order "6. Print current receipt in reverse orderln7. Exitin--InEnter your choice:"; cin choice; switch (choice) t case 1: 1 string qr_code; int amount; cout Please enter the QR code to add: "; cin qr_code; cout "Please enter the amount to add: "; cin amount; p.add_iten (qr_code, amount) ; break; \} case 2: \{ string qrcode; cout Please enter the QR code to delete; "; cin qr_code; p. remove_item(qr_code); break; ) case 3:1 string qr_code; int amount; cout PPlease enter the QR code to edit: "; cin qr_code; sout "please anter the naw amaunt: "t int main () f cin amount; p.edit_item(qr_code, amount); break; \} case 4: cout "Current Receipt:" endi; 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)." endi; break; \} t while (true); return 0 ; \}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!