Question

In: Computer Science

Design an Inventory class that can hold information for an item in a retail store’s inventory.

C++! Becareful following the test case.

7. Inventory Class
Design an Inventory class that can hold information for an item in a retail store’s inventory.
The class should have the following private member variables.

Variable Name   Description
itemNumber   An int that holds the item’s number.
quantity               An int that holds the quantity of the item on hand.
cost    A double that holds the wholesale per-unit cost of the item


The class should have the following public member functions


Member Function               Description
default constructor             Sets all the member variables to 0.
constructor #2                    Accepts an item’s number, quantity, and cost as arguments. Calls other class functions to copy these values into the appropriate member variables. Then calls the setTotalCost function.

setItemNumber      Accepts an int argument and copies it into the itemNumber member variable.
setQuantity             Accepts an int argument and copies it into the quantity member variable.
setCost   Accepts a double argument and copies it into the cost member variable.
getItemNumber     Returns the value in itemNumber.
getQuantity             Returns the value in quantity.
getCost                 Returns the value in cost.
getTotalCost   Computes and returns the totalCost.


Demonstrate the class by writing a simple program that uses it. This program should validate
the user inputs to ensure that negative values are not accepted for item number, quantity, or cost.


Here, your objective is to Create three objects and display their contents. See the following code segment. Here is detail explaination.

1. You create the First object which uses the default constructor. The default constructor initializes all data to 0. You can use the following code to do this.

Inventory part1; // This uses default constructor

2. Second object is created and initialized with the programmer hard coded data as follows:

int i = 1234;

int q = 10;
double p = 2.5;

Inventory part2(i, q, p);

3. To create the third object, you need to collect the data from the user. Once you collect the data from the user, insert this data into the object.

Once you create all the above three objects, all you have to do is to display the contents of the object.

Here are the test cases:

Test Case1:


Enter data for the new item
Item number: 123
Quantity: 30
Price: 20


Part Number : 0
Units On Hand : 0
Price : $0.00
Total Cost : $0.00


Part Number : 1234
Units On Hand : 10
Price : $2.50
Total Cost : $25.00


Part Number : 123
Units On Hand : 30
Price : $20.00
Total Cost : $600.00


Test Case2:

Enter data for the new item
Item number: 342
Quantity: -2
Value must be greater than zero: 50
Price: -20
Value must be greater than zero: 30


Part Number : 0
Units On Hand : 0
Price : $0.00
Total Cost : $0.00


Part Number : 1234
Units On Hand : 10
Price : $2.50
Total Cost : $25.00


Part Number : 342
Units On Hand : 50
Price : $30.00
Total Cost : $1500.00

Solutions

Expert Solution

C++ Program:

#include
#include

using namespace std;

//Class definition
class Inventory
{
//Data Members
private:
int itemNumber;
int quantity;
double cost;

//Public Methods
public:
//Default Constructor
Inventory()
{
itemNumber=0;
quantity=0;
cost=0.0;
}

//Argument Constructor
Inventory(int iNum, int qty, double c)
{
itemNumber = iNum;
quantity = qty;
cost = c;
}

//Setter Methods
void setItemNumber(int iNum)
{
itemNumber = iNum;
}

void setQuantity(int qty)
{
quantity = qty;
}

void setCost(double c)
{
cost = c;
}

//Getter Methods
int getItemNumber()
{
return itemNumber;
}

int getQuantity()
{
return quantity;
}

double getCost()
{
return cost;
}

//Returns total cost
double getTotalCost()
{
return (cost * quantity);
}
};

//Main function
int main()
{
//Crating objects
Inventory part1; // This uses default constructor
int i = 1234;
int q = 10;
double p = 2.5;
Inventory part2(i, q, p);

//Reading data from user
cout << "Enter data for the new item" << endl;
cout << "Item number: ";
cin >> i;
//Validating value
while(i < 0)
{
cout << "Value must be greater than zero: ";
cin >> i;
}
cout << "Quantity: ";
cin >> q;
//Validating value
while(q < 0)
{
cout << "Value must be greater than zero: ";
cin >> q;
}
cout << "Price: ";
cin >> p;
//Validating value
while(p < 0)
{
cout << "Value must be greater than zero: ";
cin >> p;
}
//Creating third object
Inventory part3(i, q, p);

//Setting precision to two decimal places
cout << fixed << setprecision(2);

//Printing values
cout << "Part Number : " << part1.getItemNumber() << endl;
cout << "Units On Hand : " << part1.getQuantity() << endl;
cout << "Price : $" << part1.getCost() << endl;
cout << "Total Cost : $" << part1.getTotalCost() << endl;

cout << "Part Number : " << part2.getItemNumber() << endl;
cout << "Units On Hand : " << part2.getQuantity() << endl;
cout << "Price : $" << part2.getCost() << endl;
cout << "Total Cost : $" << part2.getTotalCost() << endl;

cout << "Part Number : " << part3.getItemNumber() << endl;
cout << "Units On Hand : " << part3.getQuantity() << endl;
cout << "Price : $" << part3.getCost() << endl;
cout << "Total Cost : $" << part3.getTotalCost() << endl;

cout << endl;
return 0;
}
____________________________________________________________________________________________

Sample Run:


Related Solutions

a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields Item Name Item Serial No Item Unit Price Item Stock Level Item Reorder Level It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level. b) Extend the Retail Item class of part a) above...
a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields  Item Name  Item Serial No  Item Unit Price  Item Stock Level  Item Reorder Level  It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level.    b) Extend...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold the following information about a book: title, authors, publisher, ISBN Include the member functions to perform the various operations on the objects of Book. For example, the typical operations that can be performed on the title are to show the title, set the title. Add similar operations for the publisher, ISBN , and authors. Add the appropriate constructors and a destructor (if one is...
Handy Hardware is a retail hardware store. Information about the store’s operations follows. • November 20x1...
Handy Hardware is a retail hardware store. Information about the store’s operations follows. • November 20x1 sales amounted to $200,000. • Sales are budgeted at $220,000 for December 20x1 and $200,000 for January 20x2. • Collections are expected to be 60 percent in the month of sale and 38 percent in the month follow-ing the sale. Two percent of sales are expected to be uncollectible. Bad debts expense is recognized monthly. • The store’s gross margin is 25 percent of...
1. Handy Hardware is a retail hardware store. Information about the store’s operations follows. November 20x1...
1. Handy Hardware is a retail hardware store. Information about the store’s operations follows. November 20x1 sales amounted to $420,000. Sales are budgeted at $460,000 for December 20x1 and $420,000 for January 20x2. Collections are expected to be 60 percent in the month of sale and 38 percent in the month following the sale. Two percent of sales are expected to be uncollectible. Bad debts expense is recognized monthly. The store’s gross margin is 25 percent of its sales revenue....
Handy Hardware is a retail hardware store. Information about the store’s operations follows. November 20x1 sales...
Handy Hardware is a retail hardware store. Information about the store’s operations follows. November 20x1 sales amounted to $450,000. Sales are budgeted at $490,000 for December 20x1 and $450,000 for January 20x2. Collections are expected to be 70 percent in the month of sale and 28 percent in the month following the sale. Two percent of sales are expected to be uncollectible. Bad debts expense is recognized monthly. The store’s gross margin is 25 percent of its sales revenue. A...
Write a class named RetailItem that holds data about an item in retail store.
Python 3Your program will have 2 classes:A) RetailItem ClassWrite a class named RetailItem that holds data about an item in retail store.Attributes: The class should store following data in attributes:>item_Name> PriceMethods:> RetailItem class’s __init__ method should accept an argument for each attribute.> RetailItem class should also have accessor and mutator methods for each attributeB) MainMenu ClassAttributes: The class should store following data in attributes:> List of RetailItem Objects: InventoryMethods:> createInventory(): method to create three RetailItem Objects store in list Inventory...
Retail Inventory Method Turner Corporation uses the retail inventory method. The following information relates to 2016:...
Retail Inventory Method Turner Corporation uses the retail inventory method. The following information relates to 2016: Cost Retail Cost Retail Inventory, January 1 $ 29,000 $ 45,000 Additional markups — $ 50,000 Purchases (gross price) 140,000 190,000 Markup cancellations — 10,000 Purchases discounts taken 3,000 — Markdowns — 15,000 Purchases returns 5,000 8,000 Markdown cancellations — 3,000 Freight-in 20,000 — Net Sales — 190,000 Employee discounts — 3,000 Required: 1. Compute the cost of the ending inventory under each of...
1. The Item class includes two fields: a String for the name and a double for the price of an item that will be added to the inventory.
  1. The Item class includes two fields: a String for the name and a double for the price of an item that will be added to the inventory. 2. The Item class will require one constructor that takes a name and price to initialize the fields. Since the name and price will be provided through TextFields, the parameters can be two Strings (be sure to convert the price to a double before storing this into the field). 3. Write...
Consider the following information on an inventory management system:             Item Cost:                 &nbsp
Consider the following information on an inventory management system:             Item Cost:                                $10             Order Cost:                              $250             Annual Holding Cost:              33% of item cost             Annual Demand:                     25,750             Average Demand:                   515 per week             Std. Dev. of Demand:              125 per week             Leadtime:                                2 weeks          1. Ignoring the uncertainty in the demand (i.e. looking only at average values), find the optimal order quantity and the reorder point. What is the annual inventory holding and ordering cost for this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT