inventory_system Write a C++ program that calculates the inventory on-hand for W
ID: 3588764 • Letter: I
Question
inventory_system
Write a C++ program that calculates the inventory on-hand for Widget Co, an internationally renowned Widget maker located in Santa Monica. Each month, Widget Co. produces 123 new widgets from its production line during a good month, but only 52 widgets from its production line during a bad month. In addition, each month, its sales team takes orders for some number of widgets. If they are on-hand, Widget Co. reduces its inventory of widgets. If not on-hand, it compiles a back-order for the requested widgets. In order to receive full credit, you must use functions for this calculation and pass parameters and work with return values. The program dialogue should look like this:
Welcome to Widget Co.!
Month: 0 Number of widgets on-hand: 0 Number back-ordered: 0
Was it a good or bad month (g/b)? g
How many did the sales force sell? 15
Continue(y/n)? y
Month: 1 Number of widgets on-hand: 108 Number back-ordered: 0
Was it a good or bad month (g/b)? b
How many did the sales force sell? 150
Continue(y/n)? y
Month: 2 Number of widgets on-hand: 10 Number back-ordered: 0
Was it a good or bad month (g/b)? b
How many did the sales force sell? 100
Continue(y/n)? y
Month: 3 Number of widgets on-hand: 0 Number back-ordered: 38
Was it a good or bad month (g/b)? g
How many did the sales force sell? 200
Continue(y/n)? n
At the end of month 3, you wound up with 0 widgets on-hand and 115 widgets back-ordered
Again, you are expected to create all files.
The main high level method must be named runInvSys(...)
set this with 3 files
main.cpp
my_inventory_system.h
my_inventory_system.cpp
Welcome to Widget Co.!
Month: 0 Number of widgets on-hand: 0 Number back-ordered: 0
Was it a good or bad month (g/b)? g
How many did the sales force sell? 15
Continue(y/n)? y
Month: 1 Number of widgets on-hand: 108 Number back-ordered: 0
Was it a good or bad month (g/b)? b
How many did the sales force sell? 150
Continue(y/n)? y
Month: 2 Number of widgets on-hand: 10 Number back-ordered: 0
Was it a good or bad month (g/b)? b
How many did the sales force sell? 100
Continue(y/n)? y
Month: 3 Number of widgets on-hand: 0 Number back-ordered: 38
Was it a good or bad month (g/b)? g
How many did the sales force sell? 200
Continue(y/n)? n
At the end of month 3, you wound up with 0 widgets on-hand and 115 widgets back-ordered
Explanation / Answer
Here is the .h file:
#ifndef MY_INVENTORY_SYSTEM
#define MY_INVENTORY_SYSTEM
int backOrdered(int atHand, int sellCount);
int totalAtHand(int atHand, char monthType);
#endif
And the .cpp file is:
#include "my_inventory_system.h"
int backOrdered(int atHand, int sellCount)
{
int num = 0;
if(sellCount > atHand)
num = sellCount - atHand;
return num;
}
int totalAtHand(int atHand, char monthType)
{
if(monthType == 'g' || monthType == 'G')
atHand += 123;
if(monthType == 'b' || monthType == 'B')
atHand += 52;
return atHand;
}
Finally the main file is:
#include <iostream>
#include "my_inventory_system.cpp"
using namespace std;
int main()
{
cout << "Welcome to Widget Co.!" << endl;
int month = -1;
int atHand = 0;
char monthType = '-';
char again;
int back_ordered = 0;
int sellCount = 0;
do
{
month++;
cout << "Month: " << month << " Number of widgets on-hand: " << atHand << " Number back-ordered: " << back_ordered << endl;
cout << "Was it a good or bad month (g/b)? ";
cin >> monthType;
atHand = totalAtHand(atHand, monthType);
cout << "How many did the sales force sell? ";
cin >> sellCount;
atHand -= sellCount;
back_ordered = backOrdered(atHand+sellCount, sellCount);
if(atHand < 0)
atHand = 0;
cout << "Continue(y/n)? ";
cin >> again;
}while(again == 'Y' || again == 'y');
cout << "At the end of month " << month << ", you wound up with " << atHand << " widgets on-hand and " << back_ordered << " widgets back-ordered" << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.