1 answer

You are given a partial implementation of two classes. GroceryItem is a class that holds the...

Question:

You are given a partial implementation of two classes. GroceryItem is a class that holds the information for each grocery item. GroceryInventory is a class that holds an internal listing of GroceryItems as well as the tax rate for the store. Your inventory could be 100 items it could be 9000 items. You won’t know until your program gets the shipment at runtime. For this you should use the vector class from the C++ standard library.

I've completed the GroceryItem.h list but don't know how to implent the things on GroceryInventory.h list. The main.cpp was already provided and should not be touched.  

//GROCERYITEM.H

#pragma once

#ifndef GROCERYITEM_H

#define GROCERYITEM_H

#include <iostream>

#include <vector>

#include <string>

using namespace std;

class GroceryItem {

private:

string _name;

int _quantity;

float _unitPrice;

bool _taxable;

public:

GroceryItem();

GroceryItem(const string&, const int&, const float&, const bool&);

string getName() const;

void setName(const string&);

int getQuantity() const;

void setQuantity(const int&);

float getUnitPrice() const;

void setUnitPrice(const float&);

bool isTaxable() const;

void setTaxable(const bool&);

};

GroceryItem::GroceryItem() {

_name = " ";

_quantity = 0;

_unitPrice = 0.0;

_taxable = true;

}

GroceryItem::GroceryItem(const string& itemName, const int& itemQuan, const float& price, const bool& b) {

setName(itemName);

setQuantity(itemQuan);

setUnitPrice(price);

setTaxable(b);

};

void GroceryItem::setName(const string &itemName) {

_name = itemName;

}

string GroceryItem::getName() const {

return _name;

}

void GroceryItem::setQuantity(const int &itemQuan) {

_quantity = itemQuan;

}

int GroceryItem::getQuantity() const {

return _quantity;

}

void GroceryItem::setUnitPrice(const float &price) {

_unitPrice = price;

}

float GroceryItem::getUnitPrice() const {

return _unitPrice;

}

void GroceryItem::setTaxable(const bool &b) {

_taxable = b;

}

bool GroceryItem::isTaxable() const {

return _taxable;

}

#endif // !GROCERYITEM_H

// GROCERYINVENTORY.H!

#pragma once

#ifndef GROCERYINVENTORY.H

#define GROCERYINVENTORY.H

#include <vector>

#include <iostream>

#include <fstream>

#include <stdexcept>

#include "GroceryItem.h"

using namespace std;

class GroceryInventory {

private:

vector<GroceryItem> _inventory;

float _taxRate;

public:

GroceryInventory();

GroceryItem& getEntry(const string&);

void addEntry(const string&, const int&, const float&, const bool&);

float getTaxRate() const;

void setTaxRate(const float&);

void createListFromFile(const string&);

float calculateUnitRevenue() const;

float calculateTaxRevenue() const;

float calculateTotalRevenue() const;

GroceryItem& operator[](const int&);

};

GroceryInventory::GroceryInventory(){

_taxRate = 0.0;

}

GroceryItem& getEntry(const string& item){

}

void GroceryInventory::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);

}

input_file.close();

}

else {

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

}

}

#endif // !GROCERYINVENTORY.H

// MAIN.CPP

#include <string>

#include "GroceryItem.h"

#include "GroceryInventory.h"

using namespace std;

template <typename T>

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

template <typename T>

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 <typename T>

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 <typename T>

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;

}


Answers

In GroceryInventory use the List to store 'GroceryItem'. You can declare a private or public member of GroceryItem some thing like this in GroceryInventory.h:

Private List<GroceryItem> listOfAllGroceryItems;

and create some function like AddToListOfItems() //Which will add GroceryItem in the List named listOfAllGroceryItems.

Method would be something like:

Public void AddToList( GroceryItem gItem ) { listOfAllGroceryItems.pushback(gItem); }

This concet of having GroceryItem class in GroceryInventory is called Assosiation.

//Feel free to contact me back if you need any further assistence

//You can use this

.

Similar Solved Questions

1 answer
BIU- 三三三 Merge & Center - $ - %, 8-98 Conditional Formats Cell Formatting Table Styles...
BIU- 三三三 Merge & Center - $ - %, 8-98 Conditional Formats Cell Formatting Table Styles Styles Chipboard Font Alignment Number J32 х ✓ fo A B с D 27 28 Resort Bicycle Rental Bicycle Inventory Valuation Sunday, September 21, 2020 29 Revenue as Cost of curren...
1 answer
Sandhill Corporation has outstanding 2,981,000 shares of common stock with a par value of $10 each....
Sandhill Corporation has outstanding 2,981,000 shares of common stock with a par value of $10 each. The balance in its Retained Earnings account at January 1, 2020, was $24,083,000, and it then had Paid-in Capital in Excess of Par—Common Stock of $4,991,000. During 2020, the company’s ne...
1 answer
I need help with question 22? 16 the lab and turn two identical heating U heat...
I need help with question 22? 16 the lab and turn two identical heating U heat 100 of pure water and 100 of me 5 are at room temperature, Aer couple of minutes of we temperature of methanol is higher than that of water. What is observation? a Liquid water has a higher boiling point than liquid metha...
1 answer
4. Fortsman Inc. began operations on January 1, 20X4. It prepares financial statements in accordance with...
4. Fortsman Inc. began operations on January 1, 20X4. It prepares financial statements in accordance with IFRS. The following is a summary of selected financial information for the year ended December 31, 20X4: • Equipment was purchased and brought into use on March 1, 20X4, at a cost of $300,0...
1 answer
A capital structure decision concerns Select one: a. how much capital is needed to invest in...
A capital structure decision concerns Select one: a. how much capital is needed to invest in positive net present value projects. b. the mix of debt and equity used to finance a firm's operations. c. the evaluation of projects based on their estimated cash flows and net present values. d. the ra...
1 answer
Suppose that a car dealership wishes to see if efficiency wages will help improve its salespeople's...
Suppose that a car dealership wishes to see if efficiency wages will help improve its salespeople's productivity. Currently, each salesperson sells an average of 1 car per day while being paid $26 per hour for an 8-hour day. a. What is the current labor cost per car sold? per car b.Suppose that ...
1 answer
3. A patient requests his x-rays to take home and show to the family. Role-play how...
3. A patient requests his x-rays to take home and show to the family. Role-play how you would handle this matter. 4. Privacy means many different things in a medical setting. Distinguish between the patient’s right to physical privacy and privacy of privileged communication. 5. As a medical as...
1 answer
Orange Corp, has two divisions: Fruit and Flower. The following information for the past year is...
Orange Corp, has two divisions: Fruit and Flower. The following information for the past year is available for each division Flow $ $ Fra Division 1.400.000 1. ORD.000 360,000 Sales revenue Cost of goods sold and operating expenses Net operating income Average invested assets 2.160000 1.620.000 $ 3....
1 answer
F=20 N 45 For this problem, m=10 kg and we assume there is no friction as...
F=20 N 45 For this problem, m=10 kg and we assume there is no friction as well. Please answer the following: A) What is the acceleration in the x direction? B) What is the normal force? C) If the total length of the incline is 155 m and the block was initially at rest. What is the height (h) after 5...
1 answer
ˇ恤 Homework Assignment Chapter 10 Help Save & ExitSubmit 4 1 (measured in years. (You may...
ˇ恤 Homework Assignment Chapter 10 Help Save & ExitSubmit 4 1 (measured in years. (You may find it useful to reference the appropriate in years) on the longevity of 40 refrigerators for Brand A two brands of refrigerators, Brand A and Brand B. He collects data and repeats the sampling...
1 answer
For following parts (a) and (b), show all your work and label your answer with appropriate...
For following parts (a) and (b), show all your work and label your answer with appropriate probability notation. (a) The random variable X N(H.o2). The lower quartile of X is 20 and the upper quartile ofXis 40. Find μ and σ2. (b) The time for an automated system in a warehouse to locate a p...
1 answer
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety...
You have just been hired as a financial analyst for Lydex Company, a manufacturer of safety helmets. Your boss has asked you to perform a comprehensive analysis of the company’s financial statements, including comparing Lydex’s performance to its major competitors. The company’s fi...
1 answer
6) An electron has a velocity of 6.0 x10 m/s in the positve x direction at...
6) An electron has a velocity of 6.0 x10 m/s in the positve x direction at a point where the magnetic field has the components, Bx, By and Bz, whose values are as shown in the Table below. Determine the magnitude of the acceleration of the electron at this point. (electron charge = -1.602 x 10°C...
1 answer
Path Home Chapter 01 Homework omework Saved Help S. On October 1, Ebony Ernst organized trnst...
Path Home Chapter 01 Homework omework Saved Help S. On October 1, Ebony Ernst organized trnst Consulting; on October 3, the owner contributed $84,000 in assets in exchange for its common stock to launch the business. On October 31, the company's records show the followin items and amounts. Retai...
1 answer
Paul’s Pool Service provides pool cleaning, chemical application, and pool repairs for residential customers. Clients are...
Paul’s Pool Service provides pool cleaning, chemical application, and pool repairs for residential customers. Clients are billed weekly for services provided and usually pay 50 percent of their fees in the month the service is provided. In the month following service, Paul collects 40 percent ...
1 answer
5. A series of Shear Box tests were carried out on a dry sand in the...
5. A series of Shear Box tests were carried out on a dry sand in the compacted State and in a loose state and yielded the following results a. b. Normal Load(N) Peak Shearing Load (N) Compacted Sand Loose Sand...
1 answer
Define *() = -5 + 8x - 6x + 2x on 1 <=52 and 8(1) =...
Define *() = -5 + 8x - 6x + 2x on 1 <=52 and 8(1) = 27 - 40z +18r? - 22 on 2 <=3 Verify that s(2) is a cubic spline function on 1,3]. Is it a natural spline function on this interval?...
1 answer
Write Prolog rules as described in the questions below. You may use any Prolog builtin predicates....
Write Prolog rules as described in the questions below. You may use any Prolog builtin predicates. A binary tree is defined by the structure node(left,right), where left and right can be either another node or any Prolog data item. Write the rule isBalanced(Tree) that determines if the tree is balan...