Question: question 5 Please help me to write code for the following by creating the files mentioned below and creating a project: The purpose is to
question 5
Please help me to write code for the following by creating the files mentioned below and creating a project: The purpose is to put your C++ Object Oriented skills to practice by developing a simulation of an assembly line with any number of stations. 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. Milestone 1 Utilities and Station classes Milestone 1 implements and tests the Utilities and Station modules. The Utilities module supports the parsing of input files, which contain information used to setup and configure the assembly line. The Station module 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. Utilities Module:
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 is 1.
Class Variable
m_delimiter -- separates the tokens in any given std::string object. All Utilities objects 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 parameter newWidth 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 string str referred to by the first parameter
This function uses the delimiter to extract the next token from str starting at position next_pos. If successful, this function returns a copy of the extracted token found, updates next_pos with the position of the next token, and sets more to true (false otherwise0. This function reports an exception if a delimiter is found at next_pos. This function updates the current object's m_widthField data member if its current value is less than the size of the token extracted. Note: in this application, str represents a single line that has been read from an input file Class Functions
static void setDelimiter(char newDelimiter) -- sets the delimiter for this class to the character received static char getDelimiter() -- returns the delimiter for this class. Station Module:
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 of characters) the description of the station (string of characters) 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, serial number and quantity for any object of type Station. Initial value is 0. id_generator -- a variable used to generate IDs for new instances of type Station. Every time a new instance is created, the current value of the id_generator is stored in that instance, and id_generator is incremented. Initial value is 0.
Public Functions
custom 1 argument constructor
upon instantiation, an Station object receives a reference to an unmodifiable std::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 Utilities object (defined locally) to extract each token from the record and populates the Station object 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_widthField to the maximum value of Station::m_widthField and Utilities::m_widthField.
Note: the display(...) member function uses this field width to align the output across all the records retrieved from the file.
const std::string& getItemName() const - returns the name of the current Station object
size_t getNextSerialNumber() - returns the next serial number to be used on the assembly line and increments m_serialNumber
size_t getQuantity() const - returns the remaining quantity of items in the Station object
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 stream os.
if the second parameter is false, this function inserts only the ID, name, and serial number in the format: [ID] Item: NAME [SERIAL] if the second parameter if true, this function inserts the information in the following format: [ID] Item NAME [SERIAL] Quantity: QTY Description: DESCRIPTION the ID field uses 3 characters, the NAME and QTY fields use m_widthField characters, the serial number field uses 6 characters; the DESCRIPTION has no formatting options (see the sample output for other formatting options) this function terminates the printed message with an endline Files to write&submit: Utilities.h Utilities.cpp Station.h Station.cpp ms1.cpp (partially provided) Sample Output file (provided ) Provided Files: 1.) ms1.cpp #include
using namespace std; using namespace sdds;
static bool loadStations(const char*, vector
int main(int argc, char** argv) { cout << "Command Line: " << argv[0]; for (int i = 1; i < argc; i++) cout << " " << argv[i]; cout << endl << endl; if (argc < 3) { cerr << "ERROR: Insufficient number of arguments "; return 1; }
//**************// vector
cout << "========================================" << endl; cout << "= Stations (summary) =" << endl; cout << "========================================" << endl; for (Station& theItem : theStations) theItem.display(cout, false); cout << endl << endl;
cout << "========================================" << endl; cout << "= Stations (full) =" << endl; cout << "========================================" << endl; for (Station& theItem : theStations) theItem.display(cout, true); cout << endl << endl;
//Select an object and verify all the functionality it working cout << "========================================" << endl; cout << "= Manual Validation =" << endl; cout << "========================================" << endl; cout << "getItemName(): " << theStations[0].getItemName() << endl; cout << "getNextSerialNumber(): " << theStations[0].getNextSerialNumber() << endl; cout << "getNextSerialNumber(): " << theStations[0].getNextSerialNumber() << endl; cout << "getQuantity(): " << theStations[0].getQuantity() << endl; theStations[0].updateQuantity(); cout << "getQuantity(): " << theStations[0].getQuantity() << endl; cout << endl;
cout << "========================================" << endl; cout << "= Utilities =" << endl; cout << "========================================" << endl; // create & initialize an array of input data const struct { char delim; std::string data; } input[] { { 'a', "a"}, { 'b', "a" }, { 'l', "Hello"}, { ',', "apple,orange,banana,kiwi,strawberry,yellow watermellon" }, { '|', "Gengar|Arcanine|Bulbasaur|Blaziken|C h a r i z a r d|Umbreon|Lucario|Eevee"} };
for (auto& item : input) { Utilities::setDelimiter(item.delim); Utilities util; bool more = true; // if there are more tokens in the input string size_t pos = 0u; // position of the next token in the input string cout << "Data: [" << item.data << "] Delimiter: [" << item.delim << "] "; while (more) { try { auto token = util.extractToken(item.data, pos, more); cout << " Token: [" << token << "] [" << util.getFieldWidth() << "] "; } catch (...) { cout << " ERROR: No token. "; } } }
return 0; }
bool loadStations(const char* filenameSt, vector
// each line from the file represents an item; // read one at a time and add it to the inventory string theRecord; while (!file.eof()) { std::getline(file, theRecord); Station newItem(theRecord); theStations.push_back(std::move(newItem)); } file.close(); return true; } 2.) Stations1.txt Bed,123456,5,Queen size bed with headboard Armchair,654321,10,Upholstered Wing Chair Dresser,56789,7,6-Drawer Unit Nighttable,887,5,Nightstand with 2 drawers 3.) Stations2.txt Filing Cabinet|987654|5|3-drawer filing cabinet Office Chair|147852|20|High-back carpet-rollers Bookcase|987|5|5-shelf open bookcase Desk|459214|2|6-foot worktable 4.) ms1_output.txt (Use Matrix output) (Our Output should match this sample output) Command Line: ms1 Stations1.txt Stations2.txt
======================================== = Stations (summary) = ======================================== [001] Item: Bed [123456] [002] Item: Armchair [654321] [003] Item: Dresser [056789] [004] Item: Nighttable [000887] [005] Item: Filing Cabinet [987654] [006] Item: Office Chair [147852] [007] Item: Bookcase [000987] [008] Item: Desk [459214]
======================================== = Stations (full) = ======================================== [001] Item: Bed [123456] Quantity: 5 Description: Queen size bed with headboard [002] Item: Armchair [654321] Quantity: 10 Description: Upholstered Wing Chair [003] Item: Dresser [056789] Quantity: 7 Description: 6-Drawer Unit [004] Item: Nighttable [000887] Quantity: 5 Description: Nightstand with 2 drawers [005] Item: Filing Cabinet [987654] Quantity: 5 Description: 3-drawer filing cabinet [006] Item: Office Chair [147852] Quantity: 20 Description: High-back carpet-rollers [007] Item: Bookcase [000987] Quantity: 5 Description: 5-shelf open bookcase [008] Item: Desk [459214] Quantity: 2 Description: 6-foot worktable
======================================== = Manual Validation = ======================================== getItemName(): Bed getNextSerialNumber(): 123456 getNextSerialNumber(): 123457 getQuantity(): 5 getQuantity(): 4
======================================== = Utilities = ======================================== Data: [a] Delimiter: [a] ERROR: No token. Data: [a] Delimiter: [b] Token: [a] [1] Data: [Hello] Delimiter: [l] Token: [He] [2] ERROR: No token. Data: [apple,orange,banana,kiwi,strawberry,yellow watermellon] Delimiter: [,] Token: [apple] [5] Token: [orange] [6] Token: [banana] [6] Token: [kiwi] [6] Token: [strawberry] [10] Token: [yellow watermellon] [18] Data: [Gengar|Arcanine|Bulbasaur|Blaziken|C h a r i z a r d|Umbreon|Lucario|Eevee] Delimiter: [|] Token: [Gengar] [6] Token: [Arcanine] [8] Token: [Bulbasaur] [9] Token: [Blaziken] [9] Token: [C h a r i z a r d] [17] Token: [Umbreon] [17] Token: [Lucario] [17] Token: [Eevee] [17]
Question 26 C programming. Here is the two Menu.cpp and Menu.h ( you can copy paste the content into your file when you downloaded the files from the link) Menu.h // Final Project Milestone 1 // Date Module // File Date.h // Version 1.0 // Author Fardad Soleimanloo // Revision History // ----------------------------------------------------------- // Name Date Reason // Fardad 2021/10/29 Preliminary release ///////////////////////////////////////////////////////////////// #ifndef SDDS_MENU_H #define SDDS_MENU_H #include
class Menu { char* m_menuTitle{}; MenuItem* m_items[MAX_MENU_ITEMS]; int m_noofmenu=0; public: Menu(); Menu(const char* title); ~Menu(); int run(); char* operator[](int i) const; operator bool() const; int operator~(); void display(); std::ostream& write(std::ostream& os = std::cout)const; Menu& operator<<(const char* menuitemConent); // operator int() const; operator unsigned int() const; };
std::ostream& operator<<(std::ostream& os, const Menu& m);
} #endif Menu.cpp #define _CRT_SECURE_NO_WARNINGS #include
MenuItem::MenuItem() { m_menuItem = nullptr; }
MenuItem::MenuItem(const char* item ) { delete[] m_menuItem; m_menuItem = new char[strlen(item) + 1]; strcpy(m_menuItem, item); }
MenuItem::~MenuItem() { delete[] m_menuItem; }
MenuItem::operator bool() const{ if( m_menuItem != nullptr ) return true;
return false; }
void MenuItem::display(){ std::cout << m_menuItem; }
Menu::Menu() { m_menuTitle = nullptr; m_noofmenu = 0; }
Menu::Menu(const char* title) { delete[] m_menuTitle; m_menuTitle = new char[strlen(title) + 1]; strcpy(m_menuTitle, title); }
Menu::~Menu() { delete[] m_menuTitle; for (int i = 0; i < m_noofmenu; i++) delete m_items[i]; }
void Menu::display() { if(m_menuTitle != nullptr) cout< for(int i=0; i } int Menu::run() { display(); char op; cin>>op; int o = op -'0'; while ( o < 0 || o > m_noofmenu ) { cin.clear(); //clear bad input flag cin.ignore(80, ' '); cout<<"Invalid Selection, try again: "; cin>>op; o = op -'0'; } return o; } Menu::operator bool() const { if(m_menuTitle==nullptr) return false; return true; } int Menu::operator~() { display(); char op; cin>>op; int o = op -'0'; while ( o < 0 || o > m_noofmenu ) { cin.clear(); //clear bad input flag cin.ignore(80, ' '); cout<<"Invalid Selection, try again: "; cin>>op; o = op -'0'; } return o; } Menu& Menu::operator<<(const char* menuitemConent) { m_items[m_noofmenu++] = new MenuItem(menuitemConent); return *this; } // Menu::operator int() const { return m_noofmenu; } std::ostream& Menu::write(std::ostream& os )const { if( m_menuTitle != nullptr ) os< std::ostream& operator<<(std::ostream& os, const Menu& m) { return m.write(os); } Menu::operator unsigned int() const { return m_noofmenu; } char* Menu::operator[](int i) const { return m_items[i]->m_menuItem; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
