Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Program Specifications in c++ Develop an inventory management system for an electronics store. The inventory system should have the following functionalities: BuildInventory: read a text

Program Specifications in c++

Develop an inventory management system for an electronics store. The inventory system should have the following functionalities:

BuildInventory: read a text file containing electronics products information and dynamically store them in an array of pointers.

ShowInventory: display all inventory items.

UpdateInventory: ask for item id and quantity. If found display cost and update Product object info (reduce Product's quantity and potentially update restocking flag).

Terminate: save current inventory to a text file.

This programming assignment illustrates the following concepts:

Text file reading and writing.

Arrays of pointers and dynamic memory allocations with new and delete.

Inheritance.

C++ type casting: static_cast.

NOTE: This assignment is not about polymorphism or dynamic_cast! Your program should not contain any virtual function and/or use of dynamic_cast mechanism or point deductions will apply. You will have opportunity to use polymorphism in the next assignment.

Class Design

You need at least three classes.

class InventoryItem (minimum implementation specified below) - This is the base class.

Protected member data: item id (integer) and restocking (bool).

Public static data:

const integer (item id): initialize to 9999.

const bool (restocking): initialize to false.

Constructors

Default constructor: initialize item id and restocking using the default static data with member initializer syntax.

Non-default constructor: take 2 parameters.

Destructor: output "InventoryItem with restocking destroyed ..."

Public member functions:

mutator/accessor for restocking, item id.

Display: to show InventoryItem item id and restocking (true/false). item id must be displayed as a 4-digit integer with leading 0s if < 1000.

class Product: derived from InventoryItem class (minimum implementation specified below).

Private member data: name (string), quantity (integer) and price (double).

Public static data:

const string (name): "No Product".

const int (quantity): 0

const double (price): 0.99

Constructors (use member initializer syntax)

Default constructor: set member data to static data's default values above. Must explicitly invoke the base class' default constructor.

Non-default constructor: take five parameters (id, restocking, name, quantity and price). Must explicitly invoke the base class' non-default constructor.

Destructor: output "Product: , Name, quantity, price , restocking destroyed ...".

Public member functions:

accessors/mutators for name, quantity, price.

Display: invoke Display from base class, then display its own data. NOTE: If the product restocking is true somehow indicate it using "special effects" such as ***** or whatever effect you'd like.

Cost: take an integer as its only parameter representing the quantity (how many product to be sold) and return the total cost (price * quantity parameter).

class InventorySystem: (minimum implementation specified below). This class maintains an Inventory which is an array of pointers to InventoryItem which "point" to Product objects (Product class is derived from the base class InventoryItem) as shown below:

Public static data

constant integer denoting array size (initialized to 512).

constant string as default value for store name ("My Store").

constant int as default value for product count ( 0 ).

constant string for Input file name.

constant string for Output file name.

Private member data

Store name

Product list (array of pointers to InventoryItem object whose size is the static data of value 512).

Product count (tracking how many items are currently stored in the array (or the inventory). This information should be used to control the loop whenever the Product list array is processed.

Constructors

Default constructor: set member data to the static default values as appropriate (must use member initializer syntax). Use a loop to explicitly initialize all pointers in the array to nullptr.

Non-default constructor: taking a string for store name. Do similar initialization as specified in default constructor.

Destructor: Finally our destructor has something to work for: de-allocate dynamic memory for individual Product objects in the array of pointers (up to product count elements).

Private member function:

FindInventoryItem: take an integer as item id and search through the array of pointers for a match. If found return the InventoryItem pointer (InventoryItem * is the return type of the function) to the found Product. Otherwise return nullptr.

Public member functions:

BuildInventory: read a text file (its name is the static data) containing Product records (one Product per line), dynamically allocate Product objects (by using Product's non-default constructor) and store the objects in the array product_list (the array of InventoryItem pointers). It should update product count member data accordingly to keep track of the number of inventory items in the system.

ShowInventory: display all Products in the inventory. Output must be properly formatted and aligned (using field width and floating data with 2 digits after decimal point). Hint: A loop to go thru the array of product list may display only InventoryItem information. Extra work is needed to properly display both InventoryItem (base) and Products (derived objects) information.

UpdateInventory: ask for item id and quantity. Invoke the FindInventoryItem function. If such a Product is found display total cost and update Product object (reduce Product's quantity. If quantity becomes 0 update restocking to true and display a message asking for restocking).

Terminate: iterate through the array of pointers to write Product objects information to a text file (its name is the static data) in the same format as the input file's.

mutators/accessors for store name and product count.

Implementation Requirements

Must use static_cast to downcast the InventoryItem base pointers to Product derived pointers in order to access Product objects' functions as needed. Without the casting you only have Item * pointer which can only access Item's member functions, not Product's member functions even though the Item * pointers do point to Product objects.

If you are accessing member data in member functions do not use getters or accessors. The member functions should have direct access to member data (even if they're declared as private) and base class' protected member data.

Your text file must contain at least 8 products (you may come up with your own product data).

Here is how your main program should be implemented:

Declare a pointer to InventorySystem object and properly initialize it to nullptr (last time that I will remind you about initializing variables at declarations in C++)

Dynamically allocate an InventorySystem object using the non-default constructor (making up the data as needed).

Invoke BuildInventory

Invoke ShowInventory

Invoke UpdateInventory

Invoke Terminate

De-allocate InventorySystem object

In this assignment you're allowed to use array notation syntax such as product_list [ i ] as this is a pointer to an InventoryItem object (InventoryItem *). If you wish (my preference) you may try to use double pointer syntax InventoryItem ** to iterate through the array and de-reference it to get a pointer to the Product object. Try to get your program crash and scream or curse :-) That's the best way to learn C++ pointers.

Starting with this assignment you're on your way to implement non-trivial programs. One suggestion is to divide the implementation into several phases:

Phase 1: implement the classes, one class at a time with an empty main function. Sometimes it's a good idea to just implement one member function and go to phase 2 to verify it. Then come back here to implement the next member function. For example you should implement BuildInventory ( ) function first (as it reads a text file). In the function try to output the first, middle and last elements in the array and check it against your text file. That will help to tell if you've loaded the text file correctly into the array of pointers. I can help you with some code here:

product_list [ 0 ]->Display ( ); // first element

product_list [ 3 ]->Display ( ); // middle element

product_list [ 7 ]->Display ( ); // last element assuming your text file has only 8 products

if ( product_list [ 8 ] == nullptr ) {

cout << "Yes my array only loads that much data! Hooray!" << endl;

}

If your program crashes due to one of those statements I love it! You know how to get help I assume.

Phase 2: test your implemented classes by trying to create/instantiate the objects from the classes in phase 1 in the main function and see if you can use the accessor, mutator and member functions correctly. You may want to add cout output statements to those functions to verify the results as needed. Remove the output statements after you feel your classes are robust. Comeback to phase 1 as needed.

Phase 3: start implementing what the program is trying to solve using objects.

Phase 4: testing your program thoroughly.

Text file format

One Product per line. Each Product data is separated by semi-colon ;

id1;Name1;Quantity1;Price1

id2;Name2;Quantity2;Price2

id3;Name3;Quantity3;Price3

For example:

901;Panasonic DVD Player;45;128.99

36789;iPhone Battery;120;35.99

784;Sony Camcoder;125;395.99

1231;Samsung TV;0;298.99

7734;Apple iPhone 8;1200;599.98

Note: you can figure out the restocking value (true of false) based on quantity value in the text file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions