Computer Science Homework Solutions
Problem
#27082

Objects and classes

Design an inventory Class that can hold information and calculate data for items in a hardware store's inventory. The Class should have the following private member attributes:
(See attachment for full question)

Attached file(s):
Attachments
praticelab.txt  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

praticelab.txt

Program Statement:

Design an inventory Class that can hold information and calculate data for items in a hardware store’s inventory. The Class should have the following private member attributes:

* itemNumber: An integer that hold the item number.
* quantity: An integer for holding the quantity of the items on hand.
* cost: A float for holding the wholesale price per unit.
* totalCost: A float for holding the total inventory cost of the item
(quantity * cost)
The class should have the following public member functions (methods):

These functions should be written in a separate.cpp file(inventory .cpp) outside the class declaration:

* Default constructor: sets all member variables to 0.
* Constructor #2: Accepts an item’s number, unit cost, and quantity as
arguments. It should copy these values in attributes, and then call set totalCost function.

* setItemNumber: Accept an integer argument and assign it to itemNumber
attribute. Do not accept negative value, use default value 0.
* setQuantity: Accept an integer argument and assign it to quantity
attribute. Do not accept negative value, use default value 0.
* setCost Accept float argument and assign it to cost attribute.
Do not accept negative value, use default value 0.

The following member functions must be written as inline functions in class declaration:

> SetTotalCost: Calculate the total inventory cost for the item, and store it
in totalCost attribute.
> getItemNumber: Return’s item’s item #
> getQuantity: Return quantity
> getCost: Return cost
> getTotalCost: Return item’s total inventory cost.
> Destructor: Simply display the item # of the object being destroyed.



Program details:

1. Type the class declaration that includes the private attributes, and public inline member functions in a header file. Name the file inventory.h. This file should be saved in Header Files folder.
2. Type the other member functions in a separate .cpp file. Name it inventory.cpp. This file should be in the Source folder.
3. Make sure to pay attention to validation rules, and do not accept negative values for unit cost, quantity, and item number. Use default value 0 for attributes when invalid value is being stored in them.
4. Compile and test your inventory Class with the following driver program:

#include
#include
#include “inventory.h”

using namespace std;

int main()
{
//Declare an object:

inventory brush; // default constructor will get triggered
cout <<"\n Information about Object brush: \n";
cout <<" ================================\n";
cout << setw(10) << "item # : " << setw(4)
< cout << setw(10)<< "Number in inventory : "
<< brush.getQuantity() << endl;
cout << setw(10)<< "Unit Cost : $" << brush.getCost() << endl;


//Declare nail object with initial values:

Inventory nail(12, 1.29, 1000);
cout <<" Information about Object nail: \n";
cout <<" ================================\n";
cout << setw(10) << "item # : " << setw(4) <<
nail.getItemNumber() << endl;
cout << setw(10)<< "# in inventory : " << nail.getQuantity()
<< endl;
cout << setw(10)<< "Unit Cost : $" << nail.getCost() << endl;

cout << setw(10)<< "Total cost : $" << nail.getTotalCost()
<< endl;



//Declare screw object:

Inventory screw;

// assign the same values as nail to it:

screw = nail;

// Change its item #:

screw.setItemNumber(15);

cout <<"\n Information about Object screw: \n";
cout <<" ================================\n";
cout << setw(10) << "item # : " << setw(4) <<
screw.getItemNumber() << endl;
cout << setw(10)<< "Number in inventory : " <<
screw.getQuantity() << endl;
cout << setw(10)<< "Unit Cost : $" << screw.getCost() << endl;

cout << setw(10)<< "Total cost : $" << screw.getTotalCost()
<< endl;
return 0;
}

Solution
What is this?
By OTA - Overall OTA Rating
Jane Chen, MSc - 5/5
Purchase Cost Now
$2.19 CAD (was ~$15.96)
Included in Download
  • Plain text response
  • Attached file(s):
    • Inventory.zip
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
Browse