In: Computer Science
Write a menu-driven program to handle the flow of widgets into and out of a warehouse.
The warehouse will have numerous deliveries of new widgets and orders for widgets
The widgets in a filled order are billed at a profit of 50 percent over their cost
Each delivery of new widgets may have a different cost associated with it
The accountants for the firm have instituted a last-in, first-out system for filling orders
the newest widgets are the first ones sent out to fill an order and the most recent orders are filled first
partial shipments allowed
10 widgets were ordered and warehouse has only 4 available, ship 4, the remainder 6 will be shipped later
Assign unique numbers to each order and each delivery
This function of inventory can be represented using two stacks: orders-to-be-filled and widgets-on-hand. When delivery of new widgets is received, any unfilled orders (on the orders-to-be-filled stack) are processed and filled. After all orders are filled, if there are widgets remaining in the new delivery, a new element is pushed onto the widgets-on- hand stack. When an order for new widgets is received, one or more objects are popped from the widgets-on-hand stack until the order has been filled.
If the order is completely filled and there are widgets left over in the last object popped, a modified object with the quantity updated is pushed onto the widgets-on-hand stack.
If the order is not completely filled, the order is pushed onto the orders-to-be-filled stack with an updated quantity of widgets to be sent out later.
After an order is fully or a partially filled display the following in the format shown below:
order number
quantity ordered
quantity shipped
price per widget and the total cost for all widgets in the order
indicate whether there are any widgets remaining to be sent out at a later time.
After delivery is processed, display information about each order that was filled with this delivery.
Keep track of the number of widgets in stock and the number of widgets shipped.
Make sure each function definition is preceded by a description, post/preconditions
Create menu options to display the details of the inventory on hand ( delivery stack) and the details of the outstanding orders (shipment/order stack)
You may implement the stack as an array or a linked list
Well format the output: all numbers should be right-aligned; see the sample below
Create a test plan ( hand-written or typed); the test plan has to be approved for the instructor before you can submit the lab.
Order Number 123
Qty to Ordered 25
Qty Shipped this Shipment 10
Qty to be Shipped 5
Total Cost to the Warehouse 28.25
Total Cost to the Customer 42.38
Profit this Shipment 14.13
Shipment details
Delivery # Qty Shipped Unit Price Cost to the Warehouse Cost to the Customer
621 5 2.5 12.5 18.75
620 3 1.75 5.25 7.88
619 2 5.25 10.5 15.75
Modify lab #5 Backwards Warehouse to work on first come first serve basis, first in - first out. The newest widgets are the last ones sent out to fill an order and the oldest and back orders are filled first. Use queue data structure implemented as a linked list..
The programming language will be in c++,but i need assistance in in the written code as well as having a test plan ( hand-written or typed); the test plan has to be approved for the instructor before you can submit the lab and for this program we will have the user one have one item and not multiple items and my professor claried that i use arrays for this lab and not linked list. the ouput need to match exactly what is displayed
Order Number 123
Qty to Ordered 25
Qty Shipped this Shipment 10
Qty to be Shipped 5
Total Cost to the Warehouse 28.25
Total Cost to the Customer 42.38
Profit this Shipment 14.13
Shipment details
Delivery # Qty Shipped Unit Price Cost to the Warehouse Cost to the Customer
621 5 2.5 12.5 18.75
620 3 1.75 5.25 7.88
619 2 5.25 10.5 15.75
#ifndef _WIDGET_H
#define _WIDGET_H
#include <iostream>
#include <cstddef>
using namespace std;
class Widget
{
private:
double cost; // A widget has a cost.
public:
Widget(double c); // Default Constructor.
Widget(const Widget & aWidget); // Copy Constructor.
~Widget(); // Destructor.
void setCost(); // Setting the cost of the widget.
double getCost()const; // Getting the cost of the widget.
};// end class Widget
#endif
#include "Widget.h"
// Default Constructor.
Widget::Widget(double c)
: cost(c){}
// Copy Constructor.
Widget::Widget(const Widget & aWidget)
: cost(aWidget.cost){}
// Destructor
Widget::~Widget(){}
// Set the cost of the widget.
void Widget::setCost()
{
if (cost < 0.00)
cerr << "ERROR: Invalid cost.\n";
else
this->cost = cost;
}
// Get the cost of the widget.
double Widget::getCost()const
{
return this->cost;
}
#ifndef _Order_H
#define _Order_H
#include <iostream>
#include <cstddef>
#include "Widget.h"
using namespace std;
class Order
{
private:
int RemainingQty; // Storing the remaining qty of the widgets.
int TotalQty; // Storing the total qty of the widgets.
double TotalPrice; // Storing the total price of the widgets.
int OrderNo; // Storing the value of number of order.
public:
Order(int q, int on); // Default Constructor.
Order(const Order & aOrder); // Copy Constructor.
~Order(); // Destructor.
bool IsSatisfied(); // Return true is this order has been satisfied.
void Fulfill(double c); // Full this order by decreasing the amount of widgets it still requires @param cost of the widget.
void setTotalPrice(); // Setting the TotalPrice.
void setRemainingQty(); // Setting the RemainingQty.
void setTotalQty(); // Setting the TotalQty.
void setOrderNo(); // Setting the OrderNo.
double getTotalPrice()const; // Getting the TotalPrice.
int getRemainingQty()const; // Getting the RemainingQty.
int getTotalQty()const; // Getting the RemainingQty.
int getOrderNo()const; // Getting the RemainingQty.
};// end class Order
#endif
#include "Order.h"
// Default Constructor.
Order::Order(int q, int on)
:TotalQty(q), TotalPrice(0), RemainingQty(q), OrderNo(on) {}
// Copy Constructor.
Order::Order(const Order & aOrder)
: TotalQty(aOrder.TotalQty), TotalPrice(aOrder.TotalPrice), RemainingQty(aOrder.RemainingQty), OrderNo(aOrder.OrderNo) {}
// Destructor
Order::~Order(){}
// Return true is this order has been satisfied.
bool Order::IsSatisfied()
{
return RemainingQty == 0;
}
// Full this order by decreasing the amount of widgets it still requires @param cost of the widget.
void Order::Fulfill(double c)
{
RemainingQty--;
TotalPrice += c;
}
// Setting the TotalPrice.
void Order::setTotalPrice()
{
this->TotalPrice = TotalPrice;
}
// Setting the RemainingQty.
void Order::setRemainingQty()
{
this->RemainingQty = RemainingQty;
}
// Setting the TotalQty.
void Order::setTotalQty()
{
this->TotalQty = TotalQty;
}
// Setting the OrderNo.
void Order::setOrderNo()
{
this->OrderNo = OrderNo;
}
// Return the price of this order Acumulated over time.
double Order::getTotalPrice()const
{
return this->TotalPrice;
}
// Return the Remaining Qty of widgets this order still requires.
int Order::getRemainingQty()const
{
return this->RemainingQty;
}
// Return the total qty of the order.
int Order::getTotalQty()const
{
return this->TotalQty;
}
// Return Order No.
int Order::getOrderNo()const
{
return this->OrderNo;
}
//MAIN
#include <iostream>
#include "LinkedStack.h"
#include "Widget.h"
#include "Order.h"
using namespace std;
int main()
{
LinkedStack <Widget> Widgets_On_Hand;
LinkedStack <Order> Orders_To_Be_Filled;
int choice, num, qty, sv, i = 1;
bool flag = false, pful = false;
int oct = 1;
while (1)
{
cout << "*******************************************\n"
<< "\t 1.Add New Widgets To Inventory\n"
<< "\t 2.Place Order\n"
<< "\t 3.Quit\n"
<< "\t\tENTER YOUR SELECTION: \n";
cout << "*******************************************" << endl;
cout << "Please Enter You Choice:";
cin >> choice;
switch (choice)
{
case 1:
cout << "Enter the number of widgets arrived: ";
cin >> num;
sv = num;
while (num > 0)
{
double c;
cout << "Enter cost of widget:" << i << " :";
cin >> c;
Widget neww(c);
Widgets_On_Hand.push(neww);
i++;
num--;
}
i = 1;
while (!Orders_To_Be_Filled.isEmpty())
{
// Store the address of top value into the object of the class Order.
Order &o = Orders_To_Be_Filled.top();
while (!Widgets_On_Hand.pop())
{
// Store the address of top value into the object of the class Order.
Widget &w = Widgets_On_Hand.top();
o.Fulfill(1.5*w.getCost());
Widgets_On_Hand.pop();
sv--;
if (o.IsSatisfied())
{
flag = true;
break;
}
if (Widgets_On_Hand.isEmpty())
pful = true;
}
if (flag)
{
cout << endl << "\t\t Order No. \t" << o.getOrderNo() << " Fulfilled By This Delivery\n";
cout << "\t\t Total Quantity of Order:" << o.getTotalQty() << endl;
cout << "\t\t Total Cost of Order:" << o.getTotalPrice() << endl;
Orders_To_Be_Filled.pop();
flag = false;
}
else
{
if (pful)
{
cout << endl << "\t\t Order No.\t" << o.getOrderNo() << "Partially Fulfilled By This Delivery\n";
cout << "\t\t Total Quantity of Order:" << o.getTotalQty() << endl;
cout << "\t\t Remaining Quantity of Order:" << o.getRemainingQty() << endl;
cout << "\t\t Total Cost of Order:" << o.getTotalPrice() << endl;
}
pful = false;
break;
}
}
if (!Widgets_On_Hand.isEmpty())
cout << "\n\n\t\t Total Number of widgets stored in Wharehouse:" << sv << endl;
break;
case 2:
cout << "\n\t\t Enter the Quantity:";
cin >> qty;
if (qty > 0)
{
Order o(qty, oct++);
while (!Widgets_On_Hand.isEmpty())
{
if (o.IsSatisfied())
{
flag = true;
break;
}
Widget &w = Widgets_On_Hand.front();
o.Fulfill(1.5*w.getCost());
Widgets_On_Hand.pop();
}
if (flag)
{
cout << endl << "\t\t Order No.\t" << o.getOrderNo() << " Fulfilled \n";
cout << "\t\t Total Quantity of Order:" << o.getTotalQty() << endl;
cout << "\t\t Total Cost of Order:" << o.getTotalPrice() << endl;
flag = false;
}
else
{
cout << endl << "\t\t Order No.\t" << o.getOrderNo() << "Is Not Fulfilled\n";
cout << "\t\t Total Quantity of Order:" << o.getTotalQty() << endl;
cout << "\t\t Remaining Quantity of Order:" << o.getRemainingQty() << endl;
cout << "\t\t Total Cost of Order:" << o.getTotalPrice() << endl;
Orders_To_Be_Filled.push(o);
}
}
break;
case 3:
exit(1);
default:
cout << endl << "Wrong Choice\n";
}
}
system("pause");
return 0;
}