USE C++ and comment all lines of code!!! Create all header and .cpp files needed
ID: 3801159 • Letter: U
Question
USE C++ and comment all lines of code!!! Create all header and .cpp files needed
Using queues, design a system that allows the circulation of books to employees.
Technical Requirements
• (Weight: 10%) The system should keep track of two lists: (1) Books to be circulated: these are the books that will be circulated to employees. (2) Archived books: when the last employee on the queue returns the book to the library, the book gets added to the list of archived books.
• (Weight: 5%) The system should keep track of employees: these are the employees that will get the books later on.
• (Weight: 25%) Circulate a book to the employees in the system. The circulation starts on a given date. Further, the system makes a queue of employees that should receive the book. The queue should be prioritized based on two factors: (1) the total waiting time for the employee: How many days the employee waited to get a book since the beginning of the circulation. (2) The total retaining time: How many days the employee retained books.
• (Weight: 20%) Make a data structure (priority queue) that allows the pushing and popping of items. The popped item is the item with the highest priority. The queue should also be updatable whenever an item’s priority changes. • The more the employee waited, the higher the priority. The more she retained a book, the lower the priority. To put it simply, the priority is: waiting_time – retaining_time. The employee in front of the queue gets the book.
• (Weight: 40%) The system should allow the employee to pass the book on to the next employee on the queue on a given date. Use parallel programming to speed up the performance. Passing on the book has the following outcome: If the employee who is passing on the book is the last in the queue, the book gets archived. The total retaining time for the employee who passed on the book gets adjusted. The total waiting time for the employee who got the book gets adjusted. If there are other queues for other books, and these queues contain the employee who passed on the book and the employee who got the book, then adjust these queues (because the priorities have changed). See Figure 1 for an illustration.
Waiting line for the Software Engineering book Ann After 3 days After 1 day Sam Sam Adam Adam Ann passes the book on to Sam Queue Sam passes the book on to Adam Queue Employee Retaining time Waiting time Employee Retaining time Waiting time Ann Ann Sam Sam Adam Adam After 5 days Queue is empty, and the book is archived Adam Queue Sam passes the book on to the Queue library so that they archive it Employee Retaining time waiting time Employee Retaining time Waiting time Ann Ann Sam Sam Adam Adam Figure 1: An illustration of circulating the software engineering book.Explanation / Answer
Indentation and Wrapping
Wrap lines at 150 columns. If a line needs to be split, then the split should occur at some functional location (e.g., before/after the operator) and not just after the 150th character.
Indentation level/tab character is two spaces as follows:
Functions declarations and definitions:
Function Overloading
Except for constructors, function overloading should be reserved for functions in which the meaning of the overload is clear. Overloading and calling overloaded functions can decrease readability because it may not be clear to the reader which version of the function is being called. Functions should not be overloaded on the const-ness of the input arguments unless absolutely necessary and thoroughly documented.
Passing Arguments
Return Values
For getter functions that may fail we prefer to return unset optionals rather than throw exceptions:
For setter functions that may fail we return a bool, if the setter always succeeds then we return void:
When returning multiple values from functions we prefer to return an object or struct. Alternatively, pair or tuple types may be returned provided that the meaning of each member of return type is well documented. We do not suggest returning multiple values by passing in reference arguments:
Consider returning a const reference to a vector or large data member stored in a class:
Const-Correctness
Use const whenever possible (Meyers 2005; Sutter and Alexandrescu 2004).
Details
Effective C++ suggests using const for any value that should never be modified, to provide compile-time guarantees against logic errors. Example:
Similarly, any methods that should not modify object data, such as "getter" methods should be declared const:
Getter methods on custom containers that return references to internal data need to provide both const and non-const versions to ensure that the container can be used in as many contexts as possible.
Standard containers such as std::vector are implemented in this way.
Exceptions
Do not provide both const and non-const overloads for parameters. The subtleties for when one version would be chosen over another are nuanced, and the meaning of the function is likely unclear:
Similarly, do not implement both const and non-const versions of templated types, unless the design specifically needs it. The danger is that the number of permutations would grow too quickly and the meaning of the code being called is likely lost and the implementation is probably duplicated:
Also:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.