Question: Having trouble with this project where my copy contructors arent working I will post all files on here please copy and paste all of them

Having trouble with this project where my copy contructors arent working I will post all files on here please copy and paste all of them into a c++ compiler and press run. The output will show you where the errors are occuring

GROCERYITEM.h

#pragma once

#include

#include

#include

using namespace std;

class GroceryItem

{

public:

//constructor

GroceryItem()

{

}

//constructor with only name

//used this in comparing objects; //default

GroceryItem(string name)

{

setName(name);

} //used for comparing

GroceryItem(const string& n, const int& q, const float& p, const bool& t)

{

//setting all properties

setName(n);

setQuantity(q);

setUnitPrice(p);

setTaxable(t);

}

//Destructor

virtual ~GroceryItem()

{

}

string getName() const //getter for name

{

return _name;

}

;

void setName(const string& n)

{

_name = n;

}

int getQuantity() const

{

return _quantity;

}

void setQuantity(const int& q)

{

_quantity = q;

}

float getUnitPrice() const

{

return _unitPrice;

}

void setUnitPrice(const float&p)

{

_unitPrice = p;

}

bool isTaxable() const

{

return _taxable;

}

void setTaxable(const bool& t)

{

_taxable = t;

}

string toString()

{

string output = "name : "+getName()+"; Qty : "+to_string(getQuantity())+"; Price : "+to_string(getUnitPrice())+"; Taxable : "+to_string(isTaxable());

return output;

}

//overriding == operator to compare two objects

//friend function

friend bool operator==(GroceryItem &lhs, GroceryItem &rhs)

{

{

string n1 = lhs.getName(); //getting names of two items

string n2 = rhs.getName();

transform(n1.begin(), n1.end(), n1.begin(), ::toupper); //making them identical cases

transform(n2.begin(), n2.end(), n2.begin(), ::toupper);

return (n1 == n2);

}

}

protected:

private:

string _name;

int _quantity;

float _unitPrice;

bool _taxable;

};

-----------------------------------------------------

GROCERYINVENTORY.H

#pragma once

#include

#include

#include

#include

#include "GroceryItem.h"

using namespace std;

class GroceryInventory {

private:

vector _inventory;

float _taxRate;

public:

GroceryInventory()

{

}

//get grocery item by name from the list

//if found returns the object or returns hallow object

GroceryItem& getEntry(const string& name)

{

GroceryItem temp(name);

for(int i=0; i< _inventory.size(); i++)

{

if(_inventory[i] == temp)

temp = _inventory[i];

}

return temp;

}

//method to add entry

void addEntry(const string& n, const int& q, const float& p, const bool& t)

{

GroceryItem item(n,q,p,t);

_inventory.push_back(item);

}

//getter for tax rate

float getTaxRate() const

{

return _taxRate;

}

//setter for tax rate

void setTaxRate(const float& t)

{

_taxRate = t;

}

//method to calculate and returns unitrevinue

float calculateUnitRevenue() const

{

float unitrevinue = 0;

for(int i=0; i< _inventory.size(); i++)

{

GroceryItem temp = _inventory[i];

unitrevinue = unitrevinue + (temp.getUnitPrice()*temp.getQuantity()); //adding each items revenue

}

return unitrevinue;

}

//method to calculate tax revenue

float calculateTaxRevenue() const

{

float taxrevenue = 0;

for(int i=0; i< _inventory.size(); i++)

{

GroceryItem temp = _inventory[i];

taxrevenue = taxrevenue + (temp.getUnitPrice()*temp.getQuantity() * getTaxRate()); //applying tax on each purchase

}

return taxrevenue;

}

//method to calculate total revenue

float calculateTotalRevenue() const

{

float taxrevinue = calculateTaxRevenue() + calculateUnitRevenue(); //adding total revenue;

return taxrevinue;

}

//returns item at perticular index from inventory vector

GroceryItem& operator[](const int& i)

{

GroceryItem item;

while(_inventory.size() > 0 && i >= 0)

item = _inventory[i];

return item;

}

//print entire list

void createListFromFile(const string& filename)

{

ifstream input_file(filename);

if (input_file.is_open())

{

cout << "Successfully opened file " << filename << endl;

string name;

int quantity;

float unit_price;

bool taxable;

while (input_file >> name >> quantity >> unit_price >> taxable)

{

addEntry(name, quantity, unit_price, taxable);

//cout <

}

input_file.close();

}

else

{

throw invalid_argument("Could not open file " + filename);

}

}

};

-----------------------------------------------

MAIN.CPP

#include

#include "GroceryItem.h"

#include "GroceryInventory.h"

using namespace std;

template

bool testAnswer(const string&, const T&, const T&);

template

bool testAnswerEpsilon(const string&, const T&, const T&);

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

// DO NOT EDIT THIS FILE (except for your own testing) //

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

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

int main() {

// test only the GroceryItem class

GroceryItem item("Apples", 1000, 1.29, true);

testAnswer("GroceryItem.getName() test", item.getName(), string("Apples"));

testAnswer("GroceryItem.getQuantity() test", item.getQuantity(), 1000);

testAnswerEpsilon("GroceryItem.getPrice test", item.getUnitPrice(), 1.29f);

testAnswer("GroceryItem.isTaxable test", item.isTaxable(), true);

// test only the GroceryInventory class

GroceryInventory inventory;

inventory.addEntry("Apples", 1000, 1.99, false);

inventory.addEntry("Bananas", 2000, 0.99, false);

testAnswerEpsilon("GroceryInventory.getEntry() 1", inventory.getEntry("Apples").getUnitPrice(), 1.99f);

testAnswerEpsilon("GroceryInventory.getEntry() 2", inventory.getEntry("Bananas").getUnitPrice(), 0.99f);

// test copy constructor

GroceryInventory inventory2 = inventory;

testAnswer("GroceryInventory copy constructor 1", inventory2.getEntry("Apples").getUnitPrice(), 1.99f);

inventory.addEntry("Milk", 3000, 3.49, false);

inventory2.addEntry("Eggs", 4000, 4.99, false);

// Expect the following to fail

string nameOfTest = "GroceryInventory copy constructor 2";

try {

testAnswerEpsilon(nameOfTest, inventory.getEntry("Eggs").getUnitPrice(), 3.49f);

cout << "FAILED " << nameOfTest << ": expected to recieve an error but didn't" << endl;

} catch (const exception& e) {

cout << "PASSED " << nameOfTest << ": expected and received error " << e.what() << endl;

}

// test assignment operator

GroceryInventory inventory3;

inventory3 = inventory;

testAnswerEpsilon("GroceryInventory assignment operator 1", inventory3.getEntry("Apples").getUnitPrice(), 1.99f);

inventory.addEntry("Orange Juice", 4500, 6.49, false);

inventory3.addEntry("Diapers", 5000, 19.99, false);

// Expect the following to fail

nameOfTest = "GroceryInventory assignment operator 2";

try {

testAnswerEpsilon(nameOfTest, inventory.getEntry("Diapers").getUnitPrice(), 19.99f);

cout << "FAILED " << nameOfTest << ": expected to recieve an error but didn't" << endl;

} catch (const exception& e) {

cout << "PASSED " << nameOfTest << ": expected and received error " << e.what() << endl;

}

// test the GroceryInventory class

GroceryInventory inventory4;

inventory4.createListFromFile("shipment.txt");

inventory4.setTaxRate(7.75);

testAnswer("GroceryInventory initialization", inventory4.getEntry("Lettuce_iceberg").getQuantity(), 9541);

testAnswerEpsilon("GroceryInventory.calculateUnitRevenue()", inventory4.calculateUnitRevenue(), 1835852.375f);

testAnswerEpsilon("GroceryInventory.calculateTaxRevenue()", inventory4.calculateTaxRevenue(), 11549.519531f);

testAnswerEpsilon("GroceryInventory.calculateTotalRevenue()", inventory4.calculateTotalRevenue(), 1847401.875f);

return 0;

}

template

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

if (received == expected) {

cout << "PASSED " << nameOfTest << ": expected and received " << received << endl;

return true;

}

cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;

return false;

}

template

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

const double epsilon = 0.0001;

if ((received - expected < epsilon) && (expected - received < epsilon)) {

cout << fixed << "PASSED " << nameOfTest << ": expected and received " << received << endl;

return true;

}

cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;

return false;

}

------------------------------------

shipment.txt

Soda_can 8793 2.29 1

Red_Cabbage 3242 1.99 0

Tomato_Sauce 5134 0.29 0

Tuna_chunky_in_water 763 0.59 0

Salad_Dressing 8904 1.39 0

Oat_Meal 216 1.49 0

Yogurt_Fage_2%_plain 5366 4.99 0

Potatoes_Russet_ 7417 2.89 0

Pork_Tenderloin_small 648 3.99 0

Ribs_Spare_Back_(pork_unseasoned) 5083 3.99 0

Chicken_Nuggets_frozen 2161 3.99 0

Mustard_dijon 2558 0.99 0

Cereal_Muesli_style 6693 4.49 0

Croissants 7700 2.49 0

Cheese_Brie 3834 2.99 0

Fish_3_frozen 7090 3.99 0

Soda_bottle_(Coke_product) 3086 1.56 1

Carrots_whole 2695 1.29 0

Soda_can_(Coke_product) 6183 0.89 1

Nutella 8373 1.89 0

Cheese_shredded_Mozarella 6148 2.99 0

Onions_yellow 6013 1.69 0

Granola_Bars_regular 1639 1.59 0

Fish_2_frozen_(tilapia) 3342 4.49 0

Kielbasa 1002 1.99 0

Pasta_Ellbow_Maccaroni 2132 1.69 0

Fruit_1_frozen_(strawberries) 290 1.99 0

Beer_cans 1369 4.49 1

Corn_Flakes_regular 2249 1.69 0

Wine_table_Cabernet 6752 2.89 1

Cold_Cuts_turkey_variety 8353 5.99 0

Eggs_regular 121 1.09 0

Cheese_sliced_deli 3724 5.99 0

Salami_whole_(2) 720 3.56 0

Brats_4-6_pack 4629 1.99 0

Cold_Cuts_ham_or_chicken 1623 3.29 0

Beef_Stew_Meat 9495 4.19 0

Pasta_Penne_Rigate 2814 0.99 0

Pepper_black_ground 8588 1.99 0

Water_regular/drinking 7111 2.49 0

Cheese_block_(regular) 8471 1.99 0

Cheese_sliced_regular 2314 1.99 0

Water_Sparkling/Mineral 4259 1.99 0

Yoghurt_Dannon_(etc.) 8146 1.79 0

Fruit_2_frozen_(cherries) 2687 2.99 0

Lettuce_iceberg 9541 0.99 0

Tea_green_bags 8418 1.19 0

Oil_Olive_100%_pure 6364 2.99 0

Bread_Crumbs 1451 0.89 0

Oil_Olive_extra_virgin 2192 3.49 0

Pretzels 246 1.29 0

Pears 1510 1.99 0

Wine_table_Chardonnay 6730 2.89 1

Tomato_Paste 8983 0.39 0

Apples_Gala_bag 5397 2.99 0

Butter_real_unsalted/salted 282 2.29 0

Corn_Flakes_sugar_frosted 2612 1.79 0

Ground_Beef_(sirloin_90/10) 381 3.49 0

Cream_heavy_whipping 9636 1.69 0

Mandarin_Oranges_canned 8229 0.49 0

Mushrooms_stems/pieces 7019 0.59 0

Paper_Towels 928 5.99 1

Syrup_breakfast 5872 1.59 0

Yogurt_greek_style_plain 7781 0.89 0

Milk_organic 4705 1.79 0

Salami_sliced 1107 2.79 0

Pasta_Spaghetti 2568 1.59 0

Yogurt_flavored_cup 8347 0.39 0

Apple_Sauce 7079 1.29 0

Cheese_Brie_2 7478 5.49 0

Barbeque_Sauce 2704 0.89 0

Margarine/Spread 7308 0.99 0

Hot_Dogs_beef 4580 2.29 0

Cheese_shredded_Mexican_style 5874 2.79 0

Mushrooms_Button_whole 8234 0.99 0

Mayonnaise 2735 2.19 0

Ribs_Baby_Back_(pork_unseasoned) 4848 3.49 0

Veggies_1_frozen_(peas) 1756 0.89 0

Breakfast_Sausage_frozen 6276 0.89 0

Cottage_Cheese 4806 1.99 0

Orange_Juice_not_from_concentrate 2447 2.39 0

Salt_iodized 5192 0.35 0

Mustard_yellow 3064 0.69 0

Ground_Beef_(chuck_80/20) 9342 2.89 0

Preserves_strawberry 9938 1.59 0

Soup_Tomato_condensed 8670 0.49 0

Cocoa_Rice_Cereal 1818 1.69 0

Cheese_wedge_deli 6008 5.99 0

Yogurt_plain 2983 1.99 0

Rice_instant_white 2128 2.49 0

Potatoes_gold_(Yukon) 1691 2.99 0

Soda_bottle 7490 0.69 1

Ice_Cream_simple 8062 1.99 0

Cheese_Parmesan_jar 1114 2.39 0

Rice_regular 2997 1.69 0

Bacon 1971 2.99 0

Cheese_Boursin 8304 4.99 0

Eggs_cage_free 6829 1.79 0

Pizza_frozen_(premium) 7736 3.89 0

Sugar_powdered 8522 1.49 0

Ketchup 3630 1.49 0

Spaghetti_Sauce 8799 1.19 0

White_Bread/Toast_enriched 5613 0.79 0

Hot_Dog_Buns 6363 0.99 0

Chips_potato_chips 5176 1.49 0

Soup_organic 4136 3.99 0

Honey 4369 4.49 0

Pasta_Rotini/Rotelle/Fusilli 9834 1.49 0

Yogurt_Fage_w/_flavor 4240 1.19 0

Ground_Beef_frozen 8091 2.79 0

Potatoes_red 7763 2.49 0

Green_Beans_canned 3315 0.59 0

Bagles_plain 7464 1.49 0

Salami_whole_(1) 2010 3.24 0

Apples_Red/Golden_Delicious_(and/or_other)_bag 585 3.29 0

Baguette/French_Bread 4948 4.19 0

Oranges 4906 2.99 0

Pancetta_or_Ham_diced 9589 1.89 0

Fish_1_frozen_(flounder) 9385 3.99 0

Aluminum_Foil 4198 1.99 1

Pasta_Egg_Noodles 2880 0.99 0

Peanut_Butter 734 2.29 0

Milk_Chocolate_Bar 4588 1.49 0

Grapes_red 4243 2.99 0

Soup_Tomato_regular 1349 1.99 0

Milk 6062 1.99 0

Baguette_Rolls_frozen 9375 3.99 0

Chicken_Breasts_frozen 1498 5.49 0

Chocolate_Chip_Cookie_Dough 8285 1.99 0

Tuna_solid_in_water 8754 1.15 0

Cream_Cheese 8491 1.19 0

Tomatoes_slicer 2236 1.59 0

Wine_table_White_Zinfandel 9167 2.89 1

Granola_Bars_high_fiber 6678 1.89 0

Pizza_Dough 3566 3.99 0

Chicken_Tenderloins_frozen 7574 5.99 0

Flour_self_rising 3234 1.59 0

Flour_all_purpose 5616 1.59 0

Sugar_brown 8202 1.49 0

Lemons 1467 1.99 0

Beer_bottle_pilsener_import 3327 5.99 1

Sugar_white 1751 2.19 0

Waffles_frozen 2943 1.29 0

Ice_Cream_premium 7926 2.49 0

Oil_Canola_100%_pure 2926 2.69 0

Coffee 4080 4.99 0

Ground_Turkey 855 2.99 0

Pizza_frozen_(simple) 3989 1.99 0

Coconut_Milk 9194 1.89 0

Vanilla_Extract_pure_(not_imitation) 6321 1.99 0

Soup_Chicken_Noodle_regular 5872 1.39 0

Bread_12-grain/multi-grain 5108 1.89 0

Jalopeno_Peppers_canned 6577 1.19 0

Honey_Crunch_Oats 867 1.89 0

Cheese_Singles_(imitation) 1570 0.99 0

Ham_boneless 8176 2.99 0

Peanuts_roasted 6376 2.69 0

French_Fries_frozen 3299 1.89 0

Sour_Cream 960 1.29 0

Plastic_Wrap 5343 1.49 1

Ground_Turkey_frozen 4293 1.69 0

Apple_Juice 6671 1.69 0

Soup_Chicken_Noodle_condensed 4529 0.59 0

Salsa_medium 6000 1.49 0

Veggies_2_frozen_(other) 8116 0.65 0

Cherry_Pie_Filling 5710 1.79 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 Databases Questions!