Home / Expert Answers / Computer Science / the-struct-structure-is-really-important-introduction-this-homework-aims-to-make-students-comforta-pa700

(Solved): the struct structure is really important Introduction This homework aims to make students comforta ...



the struct structure is really important

student submitted image, transcription available below


student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below


student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
student submitted image, transcription available below
Introduction This homework aims to make students comfortable with classes and vectors (writing member functions and storing the data with vectors) in 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. 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 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: Please enter the amount to add: 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: 5 Nikon Lens * 2 1998.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: 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 item 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 filenane 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: Please enter the amount to add: 2 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: 1 Please enter the QR code to add: 90817 Please enter the amount to add: 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 code to add: Invalid 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 receipt in order 6. Print current receipt in reverse order 7. Exit Enter your choice: 1 Please enter the QR code to add: 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 code to add: 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}{ll} Albent * 25 & 19.8 \\ Coca Cola & 33.0 \end{tabular} : 9.5 Total: 62.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: 7 Goodbye ! Sample Run 3 Please enter a filename for QR database: qr,txt Please enter a filename for Price database: price. 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: 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 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: Please enter the amount to add: 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: 3 Please enter the QR code to edit: Please enter the amount 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 Enter your choice: 4 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}{lcc} Coca Cola & 6 & 18.0 \\ Coca Cola & 9 & 18.0 \\ VAT & & 6.5 \\ \hline Total: & & 42.5 \end{tabular} 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 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: Please enter the amount to add: 17 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: Item is already in the shoplist, if you want to edit the amount please choose option 3 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: Please enter the amount to edit: 1 MENU 1. Add item to 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: 4 \begin{tabular}{lc} Coca Cola & 2.0 \\ VAT(18\%): & 0.4 \\ \hline Total: & 2.4 \end{tabular} 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 qr 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 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 qr 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 903210.99 83222243.79 514231599 51424999 73918799.90 439001.19 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 () \{\}; 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 qr, ifatream o price); bool find(string qr_code); bool findinshopList(string qr_code); vold add_item(string , int amount); void edit_item(string qr, int amount); vold remove_item (string qr); void printcurrentReceipt(); void printCurrentReceiptAscending(); void printCurrentReceiptDescending(); ; 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 code \( ==q r_{\text {_ }} \) code; ); if (it 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 ; if (it I= item_list.end()) ( it amount += amount; if (IfindInShoplist(qr)) \{ ehon 7 iet nueh hark . void add item (string , int asount) \{ shop_list.push_back(*it); ) \} \} void edit_item(string , int amount) \{ auto it find_if(shop_list.begin () , shop_list.end () , [qr](const Product \&p) return p.qr_code \}); 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 , shop_list,end ( )) ; \} void printCurrentReceipt() \& float total float vat for (const auto \&product : shop_list) 1 float subtotal = product.price * product.amount; total subtotal; cout « product. name « * * " « product. amount « " * « subtotal « endl; \} vat 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 < b.name; ); float total float vat for (const auto eproduct : shop_1ist) 1 float subtotal product.price * product. amount; total subtotal; cout « product, name « * * " « product. amount «" " « subtotal « endl; \} vat 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 float vat ; for (const auto \&product : shop_1ist) ( float subtotal = product.price * product.amount; total subtotal; cout « product, name « * * " « product, amount « subtotal « endl; \} vat 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( ), '\n'); \} 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) cout « "The Price file does not exist" « endl; price_file.clear(); cin.ignore(numeric_limits: :max (); \} else priceFileExists = true; int break; \} \} Products ; p.read_files(qr_file, price_file); int choice; do cout « "MENU\n1. 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) 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 code; cout « Please enter the QR code to delete; "; cin qr_code; p. remove_item(qr_code); break; ) case 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 () 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 ; \}


We have an Answer from Expert

View Expert Answer

Expert Answer



We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe