Program#2: Classes and Objects Modified(10/5/2017 @ 5:30 am)

In this project you are to construct a simple Auto Parts database.  In order to make it simple we will keep the parts in an array.  Each part is defined by a part class and the Data Base is also a Class. If you see a problem with the specification it is you responsibility to bring it to my attention quickly.  Use the Visual Studio support to add these classes as discussed in class.

Part Class 

Each part has a Name of type string, a 9 digit ID number of type string, a weight of type double,  maximum in-store count of type int and an actual in-store count of type int.  These should all be private. The class that defines this type should also include a parameterized constructor.

            Part Class Specification
Private Attributes:
  _name : string      // Name of part
  _ID : string        // ID of part eg 132436353
  _weight : double    // eg 23.4 oz
  _count : integer    // 10 items in store
  _maxCount: integer  // Store has room for 15 parts of this type
Public Methods:
  Part(name,id,wt,ct,max) // constructor
  ~Part() // destructor is not used in this project
  string GetID()  // returns the 9 digit ID string
  string GetName() // returns the name of this part
  double GetWeight() //returns the weight
  int GetCount() // returns the in-store count.
  void SetCount(int i)  // update count       << -- modified 9/20/2017
  int GetMax() // returns the maximum number of parts for this part
  void AddToInv(int i) // Add i parts to this parts inventory ie update _count
  void RemoveFromInv(int i) // remove i parts from this parts inventory ie update _count

PartBase Class

This class encapsulates an array of Parts.  This is basically an inventory of all the car parts in the store. You can set the array size to 10 for this project since the number of parts kept at the store is less than 10.

            PartBase Class specification
Private Attributes:
   _partList[10]:Part   // array of a maximum of 10 parts
   _size : integer  // number of different part types in DB
Public Methods:
   int AddNewPart(Part p) // adds NEW part type to inventory, inc size
                           // returns -1 if database full, -2 if part
                           // already in database. Do nothing in this case
   int AddToInv(PartID, i) // add i to part count, ie AddToInv(), return  <<- modified 9/19/17
                           // -1 if part p is not in database. return -2
                           // if i+_count>_maxCount. Do nothing
   int Sell(PartID, i) // sell i copies of Part PartID. ie RemoveFromInv(), return <<-Modified
                          // -1 if part p is not in database. If there are
                          // not enough parts to fill order return -2 ,do
                          // not update part p.
   int GetPartCt(PartID)  // return the number of parts of type p on the shelf <<-Modified
                          // return -1 if part is not in database
   string GetPartName(PartID) // return name, "" if not in data base <<--Added if you need it
   double GetWeightOfDB()  // return the total weight of the database
   void Print()            // prints the parts in database using format below

You project is to implement the above two classes and then write a main program that reads in and processes a list of transactions.  There are 4 types of transactions( AddPart, Sell, AddToInv and Print) The format of these transactions are shown in the example below. When a transaction is properly performed you should print the following for each type.

  • AddPart ::        New Part name (ID) added to inventory  ( AddPart name id wt ct max )
  • Sell ::                 Sold  ct  name (ID) parts,  # parts left
  • AddToInv::      ct new name(IDparts added to inventory, # parts available
  • Print::      each line should have this format -> Fuel_Pump 234343213 123.4 5 5 with weight and total part count added at the end
If there is an error in the transaction then print the error as follows
  • AddPart ::        Error:DataBase Full  or   Error:Part ID is already in DataBase
  • Sell ::              Error:Not enough name(ID) parts available or Error:Part name(ID) not in DataBase on Sell
  • AddToInv::    Error:No room available for part name(ID) or Error:Part name(ID) not in DataBase on AddToInv
  • Print::      This should work
Example Transactions
AddPart Fuel_Pump 234343213 123.4 5 5  //adds new part to db
AddPart Hose 344343223 23.4 4 10
AddPart Hose 123243543 18.5 2 5
AddPart Water_Pump 44300223 23.4 2 4
AddPart Antifreeze 545343211 23.4 3 5
Sell 344343223 1                       // updates this parts _count
Sell 44300223 2
AddToInv 545343211 2                   // updates this parts _count
Sell 44300223 1                        // no more parts
Print                               // print out the database. the last
                                    // line should be Total Weight = #, Total Part count = #

In developing this project you need to create a lot more transactions to test your code.  Be sure and create transactions that will create all the possible errors.  I will give you the required transaction data a couple days before it is due so test carefully.  Also document as I have requested. See program documentation and submission format a the top of this page.

//Data Transactions to use for turning in your project
// Be sure and set array size for the database to 10
AddPart Fuel_Pump 234343213 123.4 5 5
AddPart Hose 344343223 23.4 4 10
AddPart Hose 123243543 18.5 2 5
AddPart Water_Pump 443002213 23.4 2 4
AddPart Water_Pump 443002214 25.4 2 4
AddPart Antifreeze 545343211 23.4 3 5
AddPart Wipers 234182394 10.5 2 6
Sell 344343223 1
Sell 443002213 2
Sell 234182394 2
AddToInv 545343211 2
AddToInv 123243543 3
Sell 44300223 1
AddPart Hose 344343223 23.4 4 4
AddToInv 234182394 6
Sell 443002214 3
AddToInv 234343213 2
Sell 123456789 1
AddPart Oil 934122394 24.5 2 3
Sell 934122394 2
AddToInv 934122394 3
AddToInv 934122394 1
AddPart Filter 232343546 123.5 2 10
AddPart Dipstick 345456576 15.3 1 2
AddPart FloorMat 987657654 22.0 2 3

Comments are closed.