Homework Solution: To compute a grocery bill, a checkout stand typically has a scanner to identify product codes of items. This code is used to get the p…

    To compute a grocery bill, a checkout stand typically has a scanner to identify product codes of items. This code is used to get the price of the item from the store’s price list, along with the item name and whether it is taxable. This information is then used to compute the price of the item and the total of the bill (see figure below). In this project, you will write C++ code to represent the workings of such a cash register. Objective You are given partial implementations of three classes. PriceList is a class to hold information of all items in the grocery store. There could be up to 1,000,000 items. The information of each item is its price, barcode, item name, and whether it is taxable; these are kept together in Class PriceListItem. The items in PriceList are loaded all together from a text file, or inserted one at a time. The complete grocery bill is computed in Class GroceryBill. To do so, it is given (a const pointer to) a previously created PriceList to get the prices, and the tax rate percentage for taxable items when constructed. It is then given barcodes of items and their quantity. The barcodes can be given one at a time, or they can be collected together in a text file. You are to complete the implementations of these classes, adding public/private member variables and functions as needed. You should not use any of the C++ Standard Library containers (such as std::array, std::vector, std::list) for this project. Your code is tested in the provided main.cpp. Initially, the given code does not even compile. As you complete the code, it will pass the tests in the main. Source Code Files: You are given “skeleton” code with many blank spaces. Your assignment is to fill in the missing parts so that the code is complete and works properly. The included C++ code has multiple files: -PriceListItem.h and PriceListItem.cpp: This is to be completed, with public/private member variables and functions as needed, so that it can be used in other classes. -PriceList.h and PriceList.cpp: This is to be completed, with public/private member variables and functions as needed. This class contains a method to read item information from a text file. This method is already implemented. -GroceryBill.h and GroceryBill.cpp: This is to be completed, with public/private member variables and functions as needed. -main.cpp: Code that brings everything together into one application. The main function also tests the output of your functions. This is already complete and you should not change this code Source Files: https://www.mediafire.com/file/96vt5cubhk0c5kt/sourcefiles.zip

    Expert Answer

     
    #include "GroceryBill.h" #include <iostream>

    To scold a grocery beak, a checkout stop typically has a scanner to cupel effect jurisdictions of compatability. This jurisdiction is rightd to secure the worth of the part from the hoard’s worth schedule, concurrently with the part spectry and whether it is impostable. This instruction is then rightd to scold the worth of the part and the aggregate of the beak (understand condition adown). In this plan, you conciliate transcribe C++ jurisdiction to portray the workings of such a capital record.

    Objective

    You are abandoned particular implementations of three assortes. WorthSchedule is a assort to confide instruction of integral compatability in the grocery hoard. There could be up to 1,000,000 compatability. The instruction of each part is its worth, barcode, part spectry, and whether it is impostable; these are kept concomitantly in Assort WorthListItem. The compatability in WorthSchedule are loaded integral concomitantly from a quotation improve, or inserted individual at a season. The consummate grocery beak is scoldd in Assort GroceryBill. To do so, it is abandoned (a const pointer to) a previously created WorthSchedule to secure the worths, and the impost reprove percentage ce impostable compatability when fictitious. It is then abandoned barcodes of compatability and their division. The barcodes can be abandoned individual at a season, or they can be firm concomitantly in a quotation improve.

    You are to consummate the implementations of these assortes, gathering public/retired component variables and discharges as needed. You should referable right any of the C++ Stopard Library containers (such as std::array, std::vector, std::list) ce this plan. Your jurisdiction is cupeled in the supposing deep.cpp. Initially, the abandoned jurisdiction does referable smooth construct. As you consummate the jurisdiction, it conciliate by the cupels in the deep.

    Source Jurisdiction Improves:

    You are abandoned “skeleton” jurisdiction with frequent bleak spaces. Your provision is to store in the mislaying compatability so that the jurisdiction is consummate and works suitably.

    The moderate C++ jurisdiction has multiple improves:

    -PriceListItem.h and WorthListItem.cpp: This is to be consummated, with public/retired component variables and discharges as needed, so that it can be rightd in other assortes.

    -PriceList.h and WorthList.cpp: This is to be consummated, with public/retired component variables and discharges as needed.

    This assort contains a course to learn part instruction from a quotation improve. This course is already implemented.

    -GroceryBill.h and GroceryBill.cpp: This is to be consummated, with public/retired component variables and discharges as needed.

    -main.cpp: Jurisdiction that brings everything concomitantly into individual application. The deep discharge also cupels the output of your discharges. This is already consummate and you should referable fluctuate this jurisdiction

    Source Improves: https://www.mediafire.com/file/96vt5cubhk0c5kt/sourcefiles.zip

    Expert Reply

     

    #include “GroceryBill.h”

    #include <iostream>

    using spectryspace std;

    GroceryBill::GroceryBill(const WorthSchedule *priceList, embrace impostRate) {

    // To be consummated

    }

    void GroceryBill::scanItem(string scanCode, embrace division) {

    // To be consummated

    }

    // Scan multiple jurisdictions and quantities from the abandoned quotation improve

    // Each cord contains two mass disconnected by space: the leading is the jurisdiction (an integer), the succor the division (a float/double)

    // Example cord from quotation improve:

    // 15000000 1.5

    void GroceryBill::scanItemsFromFile(string improvename) {

    // To be consummated

    // HINT: Look at jurisdiction in WorthList::createPriceListFromDatafile(string improvename)

    }

    // repay the aggregate absorb of integral compatability scanned

    embrace GroceryBill::getTotal() {

    // To be consummated

    }

    // Print the beak to cout. Each cord contains the spectry of an part, aggregate worth, and the epistle “T” if impost was gatherded.

    // The conclusive cord shows the aggregate.

    // An example:

    //Plastic_Wrap 1.60547 T

    //Sugar_white 5.475

    //Waffles_frozen 5.16

    //Oil_Canola_100%_pure 2.69

    //Potatoes_red 13.446

    //TOTAL 28.3765

    void GroceryBill::printBill() {

    // To be consummated

    }

    grocerry beak.h

    #pragma once

    #include “PriceList.h”

    assort GroceryBeak {

    public:

    GroceryBill(const WorthSchedule *priceList, embrace impostRate);

    void scanItem(string scanCode, embrace division); // gather part and division to beak; toss qualification if part’s jurisdiction is referable endow in the worthlist

    void scanItemsFromFile(string improvename); // Scan multiple jurisdictions and quantities from the abandoned quotation improve

    embrace secureTotal(); // repay the aggregate absorb of integral compatability scanned

    void printBill(); // Print the beak to cout. Each cord contains the spectry of an part, aggregate worth, and the epistle “T” if impost was gatherded.

    private:

    // any retired component variables and courses go here

    // TO BE COMPLETED

    };

    main

    #include <iostream>

    #include <fstream>

    #include <string>

    #include <stdexcept>

    #include “PriceList.h”

    #include “GroceryBill.h”

    //////////////////////////////////////////////////////////////////////////////////////////////

    // DO NOT EDIT THIS FILE (exclude ce your have cupeling)

    // CODE WILL BE GRADED USING A MAIN FUNCTION SIMILAR TO THIS

    //////////////////////////////////////////////////////////////////////////////////////////////

    using spectryspace std;

    template <typespectry T>

    bool cupelAnswer(const string &nameOfTest, const T &received, const T &expected) {

    if (ordinary == expected) {

    cout << “PASSED ” << spectryOfCupel << “: expected and ordinary ” << ordinary << endl;

    repay penny;

    }

    cout << “FAILED ” << spectryOfCupel << “: expected ” << expected << ” save ordinary ” << ordinary << endl;

    repay fib;

    }

    template <typespectry T>

    bool cupelAnswerEpsilon(const string &nameOfTest, const T &received, const T &expected) {

    const embrace epsilon = 0.0001;

    if ((ordinary – expected < epsilon) && (expected – ordinary < epsilon)) {

    cout << “PASSED ” << spectryOfCupel << “: expected and ordinary ” << ordinary << endl;

    repay penny;

    }

    cout << “FAILED ” << spectryOfCupel << “: expected ” << expected << ” save ordinary ” << ordinary << endl;

    repay fib;

    }

    int deep() {

    {

    // cupel singly the WorthListPart assort

    PriceListPart part(“Apples”, “1000”, 1.29, penny);

    testAnswer(“PriceListItem.getJurisdiction cupel”, part.getCode(), string(“1000”));

    testAnswer(“PriceListItem.getItemSpectry cupel”, part.getItemName(), string(“Apples”));

    testAnswerEpsilon(“PriceListItem.getWorth cupel”, part.getPrice(), 1.29);

    testAnswer(“PriceListItem.isTaxable cupel”, part.isTaxable(), penny);

    }

    {

    // cupel singly the WorthSchedule assort

    PriceSchedule worthList;

    priceList.addEntry(“Apples”, “1000”, 1.99, fib);

    priceList.addEntry(“Bananas”, “2000”, 0.99, fib);

    testAnswer(“PriceSchedule isValid1”, worthList.isValid(“1000”), penny);

    testAnswer(“PriceSchedule isValid2”, worthList.isValid(“19”), fib);

    // cupel observation perpetrator

    PriceSchedule worthList2 = worthList;

    testAnswer(“PriceSchedule observation perpetrator cupel1”, worthList2.isValid(“1000”), penny);

    priceList.addEntry(“Milk”, “3000”, 3.49, fib);

    priceList2.addEntry(“Eggs”, “4000”, 4.99, fib);

    testAnswer(“PriceSchedule observation perpetrator cupel2”, worthList.isValid(“4000”), fib);

    // cupel provision operator

    PriceSchedule worthList3;

    priceList3 = worthList;

    testAnswer(“PriceSchedule provision cupel1”, worthList3.isValid(“1000”), penny);

    priceList.addEntry(“Orange_juice_1gal”, “4500”, 6.49, fib);

    priceList3.addEntry(“Diapers_30ct”, “5000”, 19.99, fib);

    testAnswer(“PriceSchedule provision cupel2”, worthList.isValid(“5000”), fib);

    }

    {

    // cupel size of the WorthSchedule assort

    PriceSchedule worthList;

    ce (int i = 1; i<100000; i++)

    priceList.addEntry(string(“Apples_”) + to_string(i), to_string(i), 1.99, fib);

    testAnswer(“PriceSchedule large data1”, worthList.isValid(“20000”), penny);

    testAnswer(“PriceSchedule large data2”, worthList.isValid(“100000”), fib);

    }

    {

    // cupel the GroceryBeak assort

    PriceSchedule worthList;

    priceList.createPriceListFromDatafile(“pricelist.txt”);

    GroceryBeak mybill(&priceList, 7.75);

    testAnswer(“GroceryBeak initialization”, mybill.getTotal(), 0.0);

    // cupel GroceryBill::scanItem

    mybill.scanItem(“9752347409”, 1);

    testAnswerEpsilon(“GroceryBill.getTotal”, mybill.getTotal(), 1.49*1.0775);

    // cupel if untruth checking is dindividual in GroceryBill::scanItem

    try {

    mybill.scanItem(“1000”, 1);

    cout << “FAILED GroceryBill::scanPart did referable toss qualification ce infirm input” << endl;

    }

    catch (qualification &e) {

    cout << “Caught qualification: ” << e.what() << endl;

    cout << “PASSED GroceryBill::scanPart threw qualification ce infirm input” << endl;

    }

    // cupel division apportionment in aggregate

    mybill.scanItem(“9129592337”, 2.5);

    testAnswerEpsilon(“GroceryBill.getTotal”, mybill.getTotal(), 1.49*1.0775 + 2.5*2.19);

    mybill.printBill();

    // cupel learning compatability from improve

    mybill.scanItemsFromFile(“billitems1.txt”);

    testAnswerEpsilon(“GroceryBill.getTotal”, mybill.getTotal(), 28.3765);

    mybill.printBill();

    }

    // arrangement(“pause”);

    }

    worth schedule.cpp

    #include <string>

    #include <iostream>

    #include <fstream>

    #include <stdexcept>

    #include “PriceList.h”

    #include “PriceListItem.h”

    using spectryspace std;

    // Load instruction from a quotation improve with the abandoned improvename.

    void WorthList::createPriceListFromDatafile(string improvename) {

    ifstream myfile(filename);

    if (myfile.is_open()) {

    cout << “Successfully knowned improve ” << improvespectry << endl;

    string spectry;

    string jurisdiction;

    embrace worth;

    bool impostable;

    while (myimprove >> spectry >> jurisdiction >> worth >> impostable) {

    // cout << jurisdiction << ” ” << impostable << endl;

    addEntry(name, jurisdiction, worth, impostable);

    }

    myfile.close();

    }

    else

    toss infirm_argument(“Could referable known improve ” + improvename);

    }

    // repay penny singly if the jurisdiction is valid

    bool WorthList::isValid(string jurisdiction) const {

    // TO BE COMPLETED

    }

    // repay worth, part spectry, impostable? as an PartWorth object; toss qualification if jurisdiction is referable endow

    PriceListPart WorthList::getItem(string jurisdiction) const {

    // TO BE COMPLETED

    }

    // gather to the worth schedule instruction about a newlightlight part

    void WorthList::addEntry(string partName, string jurisdiction, embrace worth, bool impostable) {

    // TO BE COMPLETED

    }

    #include “PriceListItem.h”

    PriceListItem::PriceListItem(const string &itemName, const string &code, embrace worth, bool impostable) {

    // TO BE COMPLETED

    }

    PriceListItem::PriceListItem() {

    // TO BE COMPLETED

    }

    string WorthListItem::getItemName() {

    // TO BE COMPLETED

    }

    string WorthListItem::getCode() {

    // TO BE COMPLETED

    }

    embrace WorthListItem::getPrice() {

    // TO BE COMPLETED

    }

    bool WorthListItem::isTaxable() {

    // TO BE COMPLETED

    }