The purpose of this project is to put C++ Object Oriented skills to practice by developing a simulation of an assembly line with any number of stations. A line with 3 Stations is illustrated in the figure below.
The assembly line in your solution consists of a set of workstations each of which holds a set of stock items, which are specific to the station. A line manager moves customer orders along the line filling the orders at each station, as requested. Each customer order consists of a list of items that need to be filled. Each station processes a queue of orders by filling the next order in the queue if that order requests the station's item and that item is in stock. The line manager keeps moving the customer orders from station to station until all orders have been processed. Any station that has used all the items in stock cannot fill any more orders. At the end of the line orders are either completed or incomplete due to a lack of inventory at one or more stations. The simulator lists the completed orders and those that are incomplete once the line manager has finished processing all orders.
The project is divided into 3 milestones.
Milestone 1 implements and tests the Utilities and Station modules.
- The
Utilitiesmodule supports the parsing of input files, which contain information used to setup and configure the assembly line. - The
Stationmodule manages information about a station on the assembly line, which holds a specific item and fills customer orders.
The specifications of these two modules are defined below.
Parsing string data from input files into tokens is performed uniformly for all objects within the simulation system. The Utilities type provides the basic functionality required for all objects in the system.
The Utilities class has the following structure:
Instance Variable
m_widthField-- specifies the length of the token extracted; used for display purposes; default value is1.
Class Variable
m_delimiter-- separates the tokens in any givenstd::stringobject. AllUtilitiesobjects in the system share the same delimiter.
Member Functions
-
void setFieldWidth(size_t newWidth)-- sets the field width of the current object to the value of parameternewWidth -
size_t getFieldWidth() const-- returns the field width of the current object -
std::string extractToken(const std::string& str, size_t& next_pos, bool& more)-- extracts a token from stringstrreferred to by the first parameter.This function:
- uses the delimiter to extract the next token from
strstarting at positionnext_pos.- If successful, return a copy of the extracted token found (without spaces at the beginning/end), update
next_poswith the position of the next token, and setmoretotrue(falseotherwise).
- If successful, return a copy of the extracted token found (without spaces at the beginning/end), update
- reports an exception if a delimiter is found at
next_pos. - updates the current object's
m_widthFielddata member if its current value is less than the size of the token extracted.
Note: in this application,
strrepresents a single line that has been read from an input file. - uses the delimiter to extract the next token from
Class Functions
static void setDelimiter(char newDelimiter)-- sets the delimiter for this class to the character receivedstatic char getDelimiter()-- returns the delimiter for this class.
A Station object manages a single station on the assembly line. Each station handles a specific item for filling customer orders.
The Station class has the following structure:
Instance Variables
- the id of the station (integer)
- the name of the item handled by the station (string)
- the description of the station (string)
- the next serial number to be assigned to an item at this station (non-negative integer)
- the number of items currently in stock (non-negative integer)
Class Variables
m_widthField-- the maximum number of characters required to print to the screen the item name for any object of typeStation. Initial value is 0.id_generator-- a variable used to generate IDs for new instances of typeStation. Every time a new instance is created, the current value of theid_generatoris stored in that instance, andid_generatoris incremented. Initial value is 0.
Public Functions
-
custom 1-argument constructor
- upon instantiation, a
Stationobject receives a reference to an unmodifiablestd::string. This string contains a single record (one line) that has been retrieved from the input file specified by the user. - this constructor uses a
Utilitiesobject (defined locally) to extract each token from the record and populates theStationobject accordingly. - this constructor assumes that the string contains 4 fields separated by the delimiter, in the following order:
- name of the item
- starting serial number
- quantity in stock
- description
- the token delimiter is a single character, specified by the client and previously stored into the
Utilitiesclass of objects. - this constructor extracts name, starting serial number, and quantity from the string first
- before extracting description, it updates
Station::m_widthFieldto the maximum value ofStation::m_widthFieldandUtilities::m_widthField.- Note: the
display(...)member function uses this field width to align the output across all the records retrieved from the file.
- Note: the
- upon instantiation, a
-
const std::string& getItemName() const- returns the name of the currentStationobject -
size_t getNextSerialNumber()– returns the next serial number to be used on the assembly line and incrementsm_serialNumber -
size_t getQuantity() const– returns the remaining quantity of items in theStationobject -
void updateQuantity()– subtracts 1 from the available quantity; should not drop below 0. -
void display(std::ostream& os, bool full) const-- inserts information about the current object into streamos.- if the second parameter is
false, this function inserts only the ID, name, and serial number in the format:ID | NAME | SERIAL | - if the second parameter if
true, this function inserts the information in the following format:ID | NAME | SERIAL | QUANTITY | DESCRIPTION - the
IDfield uses 3 characters, theNAMEfield usesm_widthFieldcharacters, theQUANTITYfield uses 4 characters, theSERIALfield uses 6 characters; theDESCRIPTIONhas no formatting options (see the sample output for other formatting options) - this function terminates the printed message with an endline
- if the second parameter is
The tester module and the input files are included in the repository. Do not modify any of them.
Look in the file ms1_output.txt for the command line necessary to start the application and the expected output.
Milestone 2 implements and tests the CustomerOrder module.
The CustomerOrder module contains all the functionality for processing customer orders as they move from Station to Station along the assembly line. The Station where a given order currently rests fills a request for one item of that station, if there is any such request.
A CustomerOrder object manages a single order on the assembly line and contains the following information:
The CustomerOrder class has the following structure:
Item Definition
struct Item
{
std::string m_itemName;
size_t m_serialNumber{0};
bool m_isFilled{false};
Item(const std::string& src) : m_itemName(src) {};
};Instance Variables
std::string m_name– the name of the customer (e.g., John, Sara, etc)std::string m_product– the name of the product being assembled (e.g., Desktop, Laptop, etc)size_t m_cntItem– a count of the number of items in the customer's orderItem** m_lstItem– a dynamically allocated array of pointers. Each element of the array points to a dynamically allocated object of typeItem(see below). This is the resource that your class must manage.
Class Variable
static size_t m_widthField– the maximum width of a field, used for display purposes
Member Functions
-
default constructor
-
a custom 1-argument constructor that takes a reference to an unmodifiable string. This constructor uses a local
Utilitiesobject to extract the tokens from the string and populate the current instance. The fields in the string are (separated by a delimiter):- Customer Name
- Order Name
- the list of items making up the order (at least one item)
After finishing extraction, this constructor updates
CustomerOrder::m_widthFieldif the current value is smaller than the value stored inUtilities::m_widthField. -
a
CustomerOrderobject should not allow copy operations. The copy constructor should throw an exception if called and the copyoperator=should be deleted. -
a move constructor. This constructor should "promise" that it doesn't throw exceptions. Use the
noexceptkeyword in the declaration and the definition. -
a move assignment operator. This operator should "promise" that it doesn't throw exceptions. Use the
noexceptkeyword in the declaration and the definition. -
a destructor
-
bool isOrderFilled() const– returnstrueif all the items in the order have been filled;falseotherwise -
bool isItemFilled(const std::string& itemName) const– returnstrueif all items specified byitemNamehave been filled. If the item doesn't exist in the order, this query returnstrue. -
void fillItem(Station& station, std::ostream& os)– this modifier fills one item in the current order that theStationspecified in the first parameter handles.- if the order doesn't contain the item handled, this function does nothing
- if the order contains items handled, and the
Station's inventory contains at least one item, this function fills the order with one single item. It subtracts 1 from the inventory and updatesItem::m_serialNumberandItem::m_isFilled. It also prints the messageFilled NAME, PRODUCT [ITEM_NAME]. - if the order contains items handled but unfilled, and the inventory is empty, this function prints the message
Unable to fill NAME, PRODUCT [ITEM_NAME]. - all messages printed are terminated by an endline
-
void display(std::ostream& os) const– this query displays the state of the current object in the format (see the sample output for details)CUSTOMER_NAME - PRODUCT [SERIAL] ITEM_NAME - STATUS [SERIAL] ITEM_NAME - STATUS ...SERIAL- a field of width 6ITEM_NAME- a field of sizem_widthFieldSTATUSis eitherFILLEDorTO BE FILLED- you must use IO manipulators to format this output.
The tester module and input files are included in the repository. Do not modify any of them.
Look in the file ms2_output.txt for the command line necessary to start the application and the expected output.
Milestone 3 implements and tests the Workstation and LineManager modules.
The LineManager module first configures the assembly line and then moves CustomerOrders along it (from start to finish). The LineManager object configures the Workstation objects identified by the user, and moves orders along the line one step at a time. A Workstation is a Station that the LineManager has activated on the user's request. At each step, every Workstation fills one item in a Customer Order, if possible. The manager moves orders from station to station. Once an order has reached the end of the line, it is either complete or incomplete. An order is incomplete if one or more stations had an insufficient number of items in stock to cover that order's requests.
The Workstation module consists of three double-ended queues of CustomerOrder and the Workstation class. The queues (global variables) hold the orders at either end of the assembly line:
g_pendingholds the orders to be placed onto the assembly line at the first station.g_completedholds the orders that have been removed from the last station and have been completely filled.g_incompleteholds the orders that have been removed from the last station and could not be filled completely.
Each queue is accessible outside this module's translation unit.
The Workstation class defines the structure of an active station on the assembly line and contains all the functionality for filling customer orders with station items. Each Workstation is-a-kind-of Station. A Workstation object manages order processing for a single Item on the assembly line. Since a Workstation object represents a single location on the assembly line for filling customer orders with items, the object cannot be copied or moved. Make sure that this capability is deleted in your definition of the Workstation class.
The Workstation class includes the following additional information:
Instance Variables
m_orders– is a double-ended-queue withCustomerOrdersentering the back and exiting the front. These are orders that have been placed on this station to receive service (or already received service).m_pNextStation– a pointer to the nextWorkstationon the assembly line.
Member Functions
-
a custom 1-argument constructor -- receives a reference to an unmodifiable reference to
std::stringand passes it to theStationbase class. -
void fill(std::ostream& os)– this modifier fills the order at the front of the queue if there areCustomerOrdersin the queue; otherwise, does nothing. -
bool attemptToMoveOrder()– attempts to move the order order at the front of the queue to the next station in the assembly line:- if the order requires no more service at this station or cannot be filled (not enough inventory), move it to the next station; otherwise do nothing
- if there is no next station in the assembly line, then the order is moved into
g_completedorg_incompletequeue
- if there is no next station in the assembly line, then the order is moved into
- if an order has been moved, return
true;falseotherwise.
- if the order requires no more service at this station or cannot be filled (not enough inventory), move it to the next station; otherwise do nothing
-
void setNextStation(Workstation* station)– this modifier stores the address of the referencedWorkstationobject in the pointer to them_pNextStation. Parameter defaults tonullptr. -
Workstation* getNextStation() const– this query returns the address of nextWorkstation -
void display(std::ostream& os) const– this query inserts the name of theItemfor which the current object is responsible into streamosfollowing the format:ITEM_NAME --> NEXT_ITEM_NAME- if the current object is the last
Workstationin the assembly line this query inserts:ITEM_NAME --> End of Line. - in either case, the message is terminated with
\n
- if the current object is the last
-
Workstation& operator+=(CustomerOrder&& newOrder)– moves theCustomerOrderreferenced in parameternewOrderto the back of the queue.
The LineManager class manages an assembly line of active stations and contains the following information:
Instance Variables
std::vector<Workstation*> m_activeLine– the collection of workstations for the current assembly line.size_t m_cntCustomerOrder– the total number ofCustomerOrderobjectsWorkstation* m_firstStation- points to the first active station on the current line
Member Functions
-
LineManager(const std::string& file, const std::vector<Workstation*>& stations)- this constructor receives the name of the file that identifies the active stations on the assembly line (example:AssemblyLine.txt) and the collection of workstations available for configuring the assembly line.The file contains the linkage between workstation pairs. The format of each record in the file is
WORKSTATION|NEXT_WORKSTATION. The records themselves are not in any particular order.This function stores the workstations in the order received from the file in the
m_activeLineinstance variable. It loads the contents of the file, stores the address of the next workstation in each element of the collection, identifies the first station in the assembly line and stores its address in them_firstStationattribute. This function also updates the attribute that holds the total number of orders in theg_pendingqueue. If something goes wrong, this constructor reports an error.Note: to receive full marks, use STL algorithms throughout this function, except for iterating through the file records (one
whileloop); marks will be deducted if you use any offor,whileordo-whileloops except for iterating through the file records. -
void reorderStations()- this modifier reorders the workstations present in the instance variablem_activeLine(loaded by the constructor) and stores the reordered collection in the same instance variable. The elements in the reordered collection start with the first station, proceeds to the next, and so forth until the end of the line. -
bool run(std::ostream& os)– this modifier performs one iteration of operations on all of the workstations in the current assembly line by doing the following:- keeps track of the current iteration number (use a local variable)
- inserts into stream
osthe iteration number (how many times this function has been called by the client) in the formatLine Manager Iteration: COUNT<endl> - moves the order at the front of the
g_pendingqueue to them_firstStationand remove it from the queue. This function moves only one order to the line on a single iteration. - for each station on the line, executes one fill operation
- for each station on the line, attempts to move an order down the line
- return
trueif all customer orders have been filled or cannot be filled, otherwise returnsfalse.
-
void display(std::ostream& os) const-- this query displays all active stations on the assembly line in their current order
The tester module and input files are included in the repository. Do not modify any of them.
Look in the file ms3_output.txt for the command line necessary to start the application and the expected output.
