Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

C++ Assignment

Program Specifications

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 store them in an array of pointers

ShowInventory: display all inventory items

ShowDefectInventory: display inventory items that are defective

Terminate: to 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

Class Design

You need at least three classes.

class InventorySystem: (minimum implementation specified below). This class stores InventoryItem objects (which are in fact InventoryItem base class pointers to derived Product objects) and member functions to manipulate those Product objects as shown below:

image text in transcribed

Private data members

Store Name

Store ID

Item List (array of pointers to InventoryItem objects, max of 512)

Item Count (tracking how many items are currently stored in the array)

Constructors (initialize all pointers in the array to NULL in addition to what's described below)

Default constructor: set data members to 0 (for integers), 0.0 (for float/double), or NULL (for pointers) as appropriate. Also invoke this function to initialize a seed for the random generator: srand (time (NULL)); (to be used later by Product class to genearte random values for Product ID. See Code Helper section at the end of the lab specs.).

Non-default constructor: taking a string for store name, an integer for store ID. Call srand as shown above

Destructor: de-allocate dynamic memory in the array of pointers (up to Item Count elements).

Public member functions:

BuildInventory: read a text file containing Product records (one Product per line), dynamically allocate Product objects and store the objects in the array ItemList (an array of InventoryItem pointers). It should also update Item Count as needed

ShowInventory: display all Products in the inventory. Output must be properly formatted and aligned (using field with and floating data with 2 digits after decimal point). Note that if you invoke the Display function using the pointers from the array only InventoryItem (base object) information will be displayed. Extra work is needed to properly display Products (derived objects) information

ShowDefectInventory: display only defective Products

Terminate: iterate thru the array of pointers to write Product objects in the array to a text file in the same format as they were read in. You may use a different file name for writing.

mutators/accessors for store name, store id, and item count

class InventoryItem (minimum implementation specified below)

Protected data members: Name, Quantity

Constructors

Default constructor

Non-default constructor

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

Public member functions:

mutators/accessors for name and quantity

Display: to show InventoryItem name and quantity

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

Private data members: Product ID (to be generated randomly and initialized in constructors. See helper code below), Price, and Condition

Note: Condition is an enum variable describing the Product objects current condition. Possible Product objects conditions are: pcNew, pcUsed, pcRefurbished, pcDefective. See code helper at the end of the specs

Constructors

Default constructor (set Product ID to 0, Price to 0.0, Condition to pcNew)

Non-default constructor (randomly generate Product ID, set Price, and set Condition via arguments passed to it)

Destructor: output "Product , price =, Condition= destroyed ..."

Public member functions:

accessors/mutators for Product ID, Price, and Condition.

Display (invoke Display from base class, then display its own data)

Implementation Requirements

Use member initializer syntax in constructors (can't do it for the array of pointers so for this case you must use a loop in the constructors' body)

Member functions that do not modify member data must be defined as const

class InventoryItem {

public:

void Display ( ) const ;

} ;

Must use static_cast to downcast the InventoryItem base pointers to Product derived pointers before accessing Product objects' functions if needed

Your text file must contain at least 16 inventory product items

Here is how your main program should be coded

Declare a pointer to InventorySystem object

Dynamically allocate an InventorySystem object using non-default constructor

Invoke BuildInventory

Invoke ShowInventory

Invoke ShowDefectInventory

Invoke Terminate

De-allocate InventorySystem object

Testing

Run the program and make sure the two reports showing Product items are properly formatted and aligned

Verify if the output text file is correct (the same as the input text file)

Assignment submission and late policy

Same as assignment #1

Examples of Products: camcorder, dvd player, blueray player, tv, camera, xbox 360, ps4, Wii, laptops, battery, smart phones, computer desktop, printer, usb, mouse, etc

Extra Credit (10 points):

Add a SearchItem member function in InventorySystem class that takes a product Id and return a pointer (InventoryItem * ) to the found Product in the array of pointers or NULL pointer if the product ID does not exist.

Add a Discontinue member function in InventorySystem class to discontinue a Product from Inventory. The function will first ask which product to be discontinued via product ID. It will then invoke SearchItem (described above). If product is not found display an error message. Otherwise

properly de-allocate the memory of the Product object

update ItemCount

Shift all Product pointers below the deleted Product up if the deleted Product is not the last Product in the array

In the main function using a while loop to keep invoking Discontinue until users selects quit. this loop must occur before Terminate function invocation. You must show testing that tries:

discontinue the first product

discontinue the last product

discontinue some product in the middle

discontinue a non-existing product

the output text file should show the right inventory after some product discontinuation

Text file format: one Product per line. Each Product data is separated by semi-colon ;.

Name1;Quantity1;Price1;Condition1

Name2;Quantity2;Price2;Condition2

Name3;Quantity3;Price3;Condition3

..........................................................

Condition

Value

N

pcNew

R

pcRefurbished

U

pcUsed

D

pcDefective

NOTE: Your text file may contain multiple entries of the same Product but they're in different conditions

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Panasonic DVD Player;5;125.99;D

Panasonic DVD Player;43;125.99;N

Sony Camcoder;125;395.99;U

Samsung TV;15;298.99;R

Apple iPhone 6;1200;399;N

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

CODE HELPER SECTION

The below code shows how to randomly generate a Product ID:

#include

#include

int generateProductID ( ) {

int id = 0;

id = rand ( ) % 10000; // generate a number between 0-9999

return id;

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The below section is about how to declare enum type for Product condition. enum is mostly used for enhancing program readability.

For a full description of what enum is all about please consult the following page from cplusplus.com: http://www.cplusplus.com/forum/beginner/44859/ (Links to an external site.)Links to an external site.

Here I simply give you a helping hand:

Define the following enum at global scope:

typedef enum { pcNew, pcUsed, pcRefurbished, pcDefective } T_ProductCondition;

// Note how I name different product conditions in enum starting with pc (stands for Product Condition)

Now in Product class you may define the condition member data as follows:

class Product : .................. {

private:

T_ProductCondition condition_;

};

// Examples of how to use enum variable condition_

// to assign value to condition:

condition_ = pcNew ;

condition_ = pcDefective;

// to verify a product condition:

if (condition_ == pcDefective) {

}

// In a switch statement:

switch ( condition_ ) {

case pcNew:

break;

case pcUsed:

break; case pcRefurbished:

break;

case pcDefective:

break;

}

Inventoryltem* Product Inventoryltem* Product Product Inventoryltem * Invehtoryltem Product Inventoryltem * roduct 1l

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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