Question: I have this but when i debug I get errors in priceList.cpp and groceryBill.cpp //priceList.h #pragma once #include #include #include PriceListItem.h using namespace std; class

I have this but when i debug I get errors in priceList.cpp and groceryBill.cpp
//priceList.h
#pragma once #include
===============================================================
//priceListItem.h
#ifndef PRICELIST_ITEM #define PRICELIST_ITEM #include
//groceryBill.h
#include "PriceList.h" #include
class GroceryBill { private: //Grocery items are stored in linked list GroceryItem * head = NULL; PriceList *list; double taxRate; public: GroceryBill(PriceList *priceList, double taxRate); void scanItem(int scanCode, double quantity); // add item and quantity to bill; throw exception if item's code is not found in the pricelist void scanItemsFromFile(string filename); // Scan multiple codes and quantities from the given text file double getTotal(); // return the total cost of all items scanned void printBill(); // Print the bill to cout. Each line contains the name of an item, total price, and the letter "T" if tax was addded. };
===========================================================================================
//priceList.cpp
#include
// Load information from a text file with the given filename. void PriceList::createPriceListFromDatafile(string filename) { item_added = 0; ifstream myfile(filename); if (myfile.is_open()) { cout > name >> code >> price >> taxable) { // cout getCode().compare(code) == 0) { //code found return true; } //check if it has more items in there while (temp->nextItem != NULL) { //compare the code with each item code, if found return true if (temp->getCode().compare(code) == 0) { //item found return true; } //go to the next item temp = temp->nextItem; } } //item with this code not found, so return false //item not valid return false; } // return price, item name, taxable? as an ItemPrice object; throw exception if code is not found PriceListItem PriceList::getItem(string code) const { PriceListItem *temp = priceItemListHead; //check if there is item in the list if (temp != NULL) { //compare the code with the first item if (temp->getCode().compare(code) == 0) { //item found, return item return *temp; } //check if there are more items, if not found previously while (temp->nextItem != NULL) { //compare code with each item's code if (temp->getCode().compare(code) == 0) { //code matches, return item return *temp; } //go to the next item temp = temp->nextItem; } } //item not found in the item list //return nothing //////return nullptr; } // add to the price list information about a new item void PriceList::addEntry(string itemName, string code, double price, bool taxable) { //check if list is not exceeding the limit if (item_added >= MAX_NUMBER_OF_ITEMS) return; //create a new item PriceListItem item(itemName, code, price, taxable);
//make item next to NULL, if you have declared a nextItem pointer in PriceListItem item.nextItem = NULL;
//copy the list in temp pointers PriceListItem *temp = priceItemListHead; //if the list is not empty if (temp != NULL) { while (temp->nextItem != NULL) { //go to next item, since we want to add this item in the last temp = temp->nextItem; } //insert item at the end. temp->nextItem = &newItem; } //if the list is empty else { //make it the first item of the list priceItemListHead = &newItem; } //increase number of items added item_added++; } /* //will return the item list, if required PriceListItem* PriceList::getPriceList() { return itemList; } */
===========================================================================
//priceListItem.cpp
#include
===========================================================================
//groceryBill.cpp
#include "GroceryBill.h" #include
void GroceryBill::scanItem(int scanCode, double quantity) { GroceryItem * item = (GroceryItem *)malloc(sizeof(GroceryItem)); item->code = scanCode; item->quantity = quantity; item->next = NULL; if (head == NULL) { head = item;
} else { GroceryItem *cur = head; while (cur->next != NULL) { cur = cur->next; } cur->next = item; } } // Scan multiple codes and quantities from the given text file // Each line contains two numbers separated by space: the first is the code (an integer), the second the quantity (a float/double) // Example line from text file: // 15000000 1.5 void GroceryBill::scanItemsFromFile(string filename) {
int code; double quantity;
ifstream file; //Repalce your file path file.open(filename);
string line;
while (!(file.eof())) { if (!(file >> code)) break; file >> quantity; scanItem(code, quantity); getline(file, line); } file.close(); }
// return the total cost of all items scanned double GroceryBill::getTotal() { GroceryItem *cur = head; double total = 0; while (cur != NULL) {
PriceListItem * item = this->list->getItem(cur->code); if (item != NULL) total += (cur->quantity * item->getPrice()); cur = cur->next;
} } // Print the bill to cout. Each line contains the name of an item, total price, and the letter "T" if tax was addded. // The last line shows the total. // 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() { GroceryItem *cur = head; while (cur != NULL) {
PriceListItem *item = this->list->getItem(cur ->code); cout getName() quantity * item->getPrice()) isTaxable() ? "T" : "") next; } }
=================================================================================
// main.cpp
#include
#include "PriceList.h" #include "GroceryBill.h"
using namespace std;
template template int main() { { // test only the PriceListItem class PriceListItem item("Apples", "1000", 1.29, true); testAnswer("PriceListItem.getCode test", item.getCode(), string("1000")); testAnswer("PriceListItem.getItemName test", item.getItemName(), string("Apples")); testAnswerEpsilon("PriceListItem.getPrice test", item.getPrice(), 1.29); testAnswer("PriceListItem.isTaxable test", item.isTaxable(), true); } { // test only the PriceList class PriceList priceList; priceList.addEntry("Apples", "1000", 1.99, false); priceList.addEntry("Bananas", "2000", 0.99, false); testAnswer("PriceList isValid1", priceList.isValid("1000"), true); testAnswer("PriceList isValid2", priceList.isValid("19"), false); // test copy constructor PriceList priceList2 = priceList; testAnswer("PriceList copy constructor test1", priceList2.isValid("1000"), true); priceList.addEntry("Milk", "3000", 3.49, false); priceList2.addEntry("Eggs", "4000", 4.99, false); testAnswer("PriceList copy constructor test2", priceList.isValid("4000"), false); // test assignment operator PriceList priceList3; priceList3= priceList; testAnswer("PriceList assignment test1", priceList3.isValid("1000"), true); priceList.addEntry("Orange_juice_1gal", "4500", 6.49, false); priceList3.addEntry("Diapers_30ct", "5000", 19.99, false); testAnswer("PriceList assignment test2", priceList.isValid("5000"), false); } { // test capacity of the PriceList class PriceList priceList; for (int i = 1; i // test if error checking is done in GroceryBill::scanItem try { mybill.scanItem("1000", 1); cout // test quantity calculation in total mybill.scanItem("9129592337", 2.5); testAnswerEpsilon("GroceryBill.getTotal", mybill.getTotal(), 1.49*1.0775 + 2.5*2.19); mybill.printBill(); // test reading items from file mybill.scanItemsFromFile("billitems1.txt"); testAnswerEpsilon("GroceryBill.getTotal", mybill.getTotal(), 28.3765); mybill.printBill(); } // system("pause"); }
Step by Step Solution
There are 3 Steps involved in it
To debug and complete the implementation of the PriceList and GroceryBill classes youll need to address several issues in your current code Lets review the main problems and how you might fix them Iss... View full answer
Get step-by-step solutions from verified subject matter experts
