Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is based on the World Wide Widget Works code listed in the Budd Boo

ID: 3801201 • Letter: T

Question

This program is based on the World Wide Widget Works code listed in the Budd Book in the PPT slides for the list class. Both have the same code. The current program is an inventory management system for WWW. Your job is to enhance the program with the following features:

1. Use inheritance, and create classes for WidgetA, WidgetB, and WidgetC. The Widget class will be the base class. Update the Widget class as needed.

2. Use the factory design pattern to create Widgets with one common interface

3. Instead of list of Widget objects for on_hand, you will have a list of Widget*. This list will be able to hold pointers to WidgetA, WidgetB, and WidgetC objects. The id numbers 0, 1, 2 should be matched to WidgetA, WidgetB, and WidgetC types respectively.

4. Write a function that is called at start up to populate the on_hand inventory with least 5 widgets of different types.

3. Create a menu system with the five options:

process an order,

receive a shipment,

show on hand,

show on order, and

exit.

NOTE: The code that is in the book and slides is C++-like Pseudocode for the purposes of this assignment. This means that you can not just type the code in and expect it to work. You still need to type the code and build it one class at a time. This will help you identify errors early and it will also help you better understand the code. You may add code to get rid of compiler errors or runtime errors in the logic. You may use STL algorithms wherever you would like if it will reduce the code size. You may not change the structure of the classes and the data STL container must remain a STL list.

Explanation / Answer

Here is the code that will work .

using namespace std;

class Widget {
  
public:
Widget ()
{
id =0; // widget identification number
}

Widget (int a)
{
id =a;
}

// operations
int id ()
{
return id;
}

void operator = (Widget &w)
{
id = w.id;
}

bool operator == (Widget & w)
{
return id == w.id;
}

bool operator < (Widget & w)
{
return id < w.id;
}

protected:
int id;
};

ostream & operator << (ostream & out, Widget & w)
// output printable representation of widget
{
return out << "Widget " << w.id();
}

class WidgetTester
{
public:
WidgetTester (int id)
{
test_id = id;
}
int test_id;

bool operator () (int id)
{
Widget w;
id=test_id;

bool a;

if (w.id() == id)
a=true;
else
a=false;

return a;
}
};


class inventory
{
public:
void order (int widType); // process order for widget type widType
void receive (Widget widType); // receive widget of type widType in shipment
void displayonhand();
void displayonorder();

protected:
std::list on_hand;
std::list on_order;
};

void inventory::displayonhand()
{ list::const_iterator it;
for(it=on_hand.begin(); it!=on_hand.end(); ++it)
{
cout <<"On Hand"<< *it << endl; // each element on a separate line
}
}

void inventory::displayonorder()
{ list::const_iterator it;
for(it=on_order.begin(); it!=on_order.end(); ++it)
{
cout <<"On Order"<< *it << endl; // each element on a separate line
}
}


void inventory::receive (Widget widType)
// process a widget received in shipment
{
cout << "Received shipment of widget " << widType << endl;
std::list::iterator we_need =
std::find(on_order.begin(), on_order.end(), widType.id());
if (we_need != on_order.end()) {
cout << "Ship " << widType << " to fill back order" << endl;
on_order.erase(we_need);
}
else
on_hand.push_front(widType.id());
}

void inventory::order (int widType)
// process an order for a widget with given id number
{
cout << "Received order for widget type " << widType << endl;
WidgetTester wtest(widType); // create the tester object
std::list::iterator we_have =
find_if(on_hand.begin(), on_hand.end(), wtest);
if (we_have != on_hand.end()) {
cout << "Ship " << *we_have << endl;
on_hand.erase(we_have);
}
else {
cout << "Back order widget of type " << widType << endl;
on_order.push_front(widType);
}
}


void main()
{
int menu=0;
inventory wworks;
do
{
cout<<"1) process an order"< cout<<"2) receive a shipment"< cout<<"3) show on hand"< cout<<"4) show on order"< cout<<"5) exit"< cout<<"Enter a option:";
cin>>menu;

switch(menu)
{
case 1:
{
int num;
cout<<"Enter the Widget No from 0 to 2:"< cin>>num;
wworks.order(num);
}
break;

case 2:
{
int widType;

cout<<"Enter the Wiget No to receive Shipment:"< cin>>widType;

wworks.receive(Widget(widType));
}
break;

case 3:
{
wworks.displayonhand();

}
break;

case 4:
{
wworks.displayonorder();

}
break;

default:
cout<<"Proper Option"< break;
}
}
while(menu!=5);


//wworks.receive (Widget(1));
//wworks.receive (Widget(2));
//wworks.receive (Widget(3));
//wworks.order (2);
//wworks.order (2);
//wworks.receive (Widget(3));
//wworks.receive (Widget(2));
//wworks.order (1);
system ("Pause");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote