Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ please and I want the out put for this program.. please try to use a program

ID: 3729335 • Letter: C

Question

C++ please and I want the out put for this program.. please try to use a programming code not a paper
eUsing queues, design a system that allows the circulation of books to employees. Technical Requirements (Weight: 1096) 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: 596) 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: 2096) 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: 4096) The system should allow the employee to pass the book on to the next employee on the queue on a given date . . . . * . .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.

Explanation / Answer

Hi,

Save all the files in same directory.

//main.cpp file

#include <iostream>

#include <queue>

#include <list>

#include "book.hpp"

#include "library.hpp"

void main(){

Library library;

library.add_book("Software Engineering");

library.add_book("Chemistry");

library.add_employee("Adam");

library.add_employee("Sam");

library.add_employee("Ann");

library.circulate_book("Chemistry", Date(2015, 3, 1, DateFormat::US));

library.circulate_book("Software Engineering", Date(2015, 4, 1, DateFormat::US));

library.pass_on("Chemistry", Date(2015, 3, 5, DateFormat::US)); //tell the next employee to pass the book on March 5, 2015

library.pass_on("Chemistry", Date(2015, 3, 7, DateFormat::US));

library.pass_on("Chemistry", Date(2015, 3, 15, DateFormat::US)); //at this point in time, the system will archive the chemistry book

library.pass_on("Software Engineering", Date(2015, 4, 5, DateFormat::US));

library.pass_on("Software Engineering", Date(2015, 4, 10, DateFormat::US));

library.pass_on("Software Engineering", Date(2015, 4, 15, DateFormat::US));

system("pause");

}

//book.cpp file

#include "book.hpp"

Book::Book(){

}

Book::Book(string bookName){

name = bookName;

}

Book::Book(string bookName,Date start){

name = bookName;

startDate = start;

}

Book::Book(const Book& other){

name = other.name;

startDate = other.startDate;

endDate = other.endDate;

archived = other.archived;

waiting = other.waiting;

}

string Book::getname(){

return name;

}

Date Book:: getstartDate(){

return startDate;

}

Date Book::getendDate(){

return endDate;

}

bool Book::getarchived(){

return archived;

}

Date Book::getHeld(){

return lastHeld;

}

void Book::setname(string newName){

name = newName;

}

void Book::setstartDate(Date newDate){ // start date is also lastHeld for first pass_on()

startDate = lastHeld = newDate;

}

void Book::setendDate(Date newDate){

endDate = newDate;

}

void Book::setarchived(bool newBool){

archived = newBool;

}

void Book::setHeld(Date date){

lastHeld = date;

}

void Book::populate_queue(const list<Employee*> empList ){

list<Employee*>::const_iterator it;

for (it = empList.begin(); it != empList.end(); it++){ // add all current employees to queue

waiting.addEmployee(*it);

}

}

Employee* Book::pop_max(){

return waiting.pop_max();

}

Employee* Book::top(){

return waiting.top();

}

bool Book::isEmpty(){

return waiting.empty();

}

//library.cpp file

#include "library.hpp"

Library::Library(){

}

Library::~Library(){

list<Employee*>::iterator it;

for (it = employeeList.begin(); it != employeeList.end(); it++){

delete *it;

}

}

void Library::add_book(string newBook){

Book tempBook(newBook);

toBeCirculated.push_back(tempBook);

}

void Library::add_employee(string name){

Employee *temp;

temp = new Employee(name);

employeeList.push_front(temp);

}

void Library::circulate_book(string bookToMove, Date dayOfMove){

list<Book>::iterator it;

for (it = toBeCirculated.begin(); it != toBeCirculated.end(); it++){ // find book : O(n)

if (it->getname() == bookToMove){ // this is the book

it->populate_queue(employeeList); // create queue

it->setstartDate(dayOfMove); // save start date

break;

}

}

cerr << "Book not found" << endl;

}

void Library::pass_on(string bookToMove, Date date){

Employee *next, *prev; // prev is employee that is popped

list<Book>::iterator it;

for (it = toBeCirculated.begin(); it != toBeCirculated.end(); it++){ // find book : O(n)

if (it->getname() == bookToMove){

prev = it->pop_max(); // pop max, save to prev

prev->retain(date - it->getHeld()); // retain = current date - last pass of book

if (!it->isEmpty()){

next = it->top(); // next is now max

next->wait(date - it->getstartDate()); // wait = current date - book start date

it->setHeld(date); // save pass date for next employee

}

else{ // circulation complete

it->setarchived(true);

it->setendDate(date);

archived.push_back(*it); // archive

toBeCirculated.erase(it); // erase

}

break;

}

}

cerr << "Book not found" << endl;

}

//book.hpp file

#ifndef book_hpp

#define book_hpp

#include <stdio.h>

#include <string>

#include "pQueue.hpp"

#include <list>

#include "Date.h"

#include "employee.hpp"

using namespace std;

class Book{

private:

string name;

Date startDate;

Date endDate;

bool archived;

pQueue waiting;

Date lastHeld;

public:

Book();

Book(string bookName);

Book(string bookName, Date start);

Book(const Book& other);

string getname();

Date getstartDate();

Date getendDate();

bool getarchived();

Date getHeld();

void setname(string newName);

void setstartDate(Date newDate);

void setendDate(Date newDate);

void setarchived(bool newBool);

void setHeld(Date date);

void populate_queue(list<Employee*> empList);

Employee* pop_max();

Employee* top();

bool isEmpty();

};

#endif /* book_hpp */

//library.hpp file

#ifndef library_hpp

#define library_hpp

#include <stdio.h>

#include <string>

#include <queue>

#include <list>

#include "Date.h"

#include "book.hpp"

class Library{

private:

list<Book> toBeCirculated;

list<Book> archived;

list<Employee*> employeeList; // list of pointers to employees

public:

Library();

~Library();

void add_book(string newBook);

void add_employee(string newPerson);

void circulate_book(string bookToMove, Date dayOfMove);

void pass_on(string bookToMove, Date date);

};

#endif

//pQueue.cpp file

#include "pQueue.hpp"

pQueue::pQueue(){}

void pQueue::addEmployee(Employee* temp){

WorkQueue.push_back(temp);

}

Employee* pQueue::pop_max(){ // pulls highest priority from queue : O(n)

Employee *max = *WorkQueue.begin(); // assume max is first element

vector<Employee*>::iterator it, toErase;

it = toErase = WorkQueue.begin();

it++; // start at second element so we don't compare max to itself

for (it; it != WorkQueue.end(); it++){

if ((max->getWait() - max->getRetain()) < ((*it)->getWait() - (*it)->getRetain())){ // if new max is found, update pointers

max = *it;

toErase = it;

}

}

WorkQueue.erase(toErase);

return max;

}

Employee* pQueue::top(){ // O(n)

Employee *max = *WorkQueue.begin(); // assume max is first element

vector<Employee*>::iterator it = WorkQueue.begin();

it++; // start at second element so we don't compare max to itself

for (it; it != WorkQueue.end(); it++){

if ((max->getWait() - max->getRetain()) < ((*it)->getWait() - (*it)->getRetain())){ // if new max is found, update pointer

max = *it;

}

}

return max;

}

bool pQueue::empty(){

return WorkQueue.size() < 1;

}

//pQueue.hpp file

#ifndef pQueue_hpp

#define pQueue_hpp

#include <stdio.h>

#include <list>

#include "employee.hpp"

#include <vector>

#include <algorithm>

#include <iostream>

using namespace std;

class pQueue{

private:

vector<Employee*> WorkQueue;

public:

pQueue();

void addEmployee(Employee* temp);

Employee* pop_max();

Employee* top();

bool empty();

};

#endif /* pQueue_hpp */

//Date.h file

#ifndef _DATE_H_

#define _DATE_H_

#include <stdexcept>

#include <algorithm>

#include <functional>

#include <cctype>

#include <locale>

#include "StringTokenizer.h"

#include <sstream>

#include <iomanip>

#include <string>

using namespace std;

/* class Date wirtten by Mohammad Kuhail

e-mail: kuhailm@Umkc.edu

*/

const int DAYS[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; //number of days in the 12 months

enum DateFormat{ Standard, US }; //Standard format is year, month, day , US format is month, day, year

class Date {

public:

Date(DateFormat format = DateFormat::US) :format(format){}

Date(string date, DateFormat format = DateFormat::US) :format(format){

year = 1; month = 1; day = 1;

*this = parseDate(date, format);

}

Date(int year, int month, int day, DateFormat format = DateFormat::US) : year(year), month(month), day(day), format(format){

if (!valid_date(year, month, day))

throw std::runtime_error(" The date is not valid");

}

void set_format(DateFormat format){

this->format = format;

}

/* return a string that represents the date*/

string toString() const {

switch (format){

case DateFormat::US:

return to_string(month) + "/" + to_string(day) + "/" + to_string(year);

case DateFormat::Standard:

return to_string(year) + "/" + to_string(month) + "/" + to_string(day);

}

}

/* parse a date according to a given format*/

static Date parseDate(const string& date, DateFormat format){

String_Tokenizer st(date, "-/,");

int year = 0, month = 0, day = 0;

int index = 0;

while (st.has_more_tokens()){

switch (format){

case DateFormat::Standard: //standard format: year month day

switch (index){

case 0:

std::istringstream(st.next_token()) >> year;

break;

case 1:

std::istringstream(st.next_token()) >> month;

break;

case 2:

std::istringstream(st.next_token()) >> day;

break;

}

break;

case DateFormat::US: //US format: month day year

switch (index){

case 0:

std::istringstream(st.next_token()) >> month;

break;

case 1:

std::istringstream(st.next_token()) >> day;

break;

case 2:

std::istringstream(st.next_token()) >> year;

break;

}

}

++index;

}

if (!valid_date(year, month, day))

throw std::runtime_error(" The date is not valid");

return Date(year, month, day, format);

}

//this function allows the user to get a date from the user

friend istream& operator >> (istream& in, Date& d) {

std::string date;

in >> date;

d = parseDate(date, d.format);

return in;

}

friend ostream& operator <<(ostream& out, Date& d){

return out << d.month << "-" << d.day << "-" << d.year;

}

//checks whether this date < another date

bool operator <(const Date& other) const{

if (year != other.year)

return year < other.year;

if (month != other.month)

return month < other.month;

return day < other.day;

}

//checks if this date is valid

void check_valid(){

if (!valid_date(year, month, day))

throw std::runtime_error("The date is invalid");

}

//checks if a date is valid

static bool valid_date(int year, int month, int day){

if (year >= 0 && month >= 1 && month <= 12 && day >= 1 && day <= 31){

if (is_leap_year(year) && month == 2) // check for the leap year case

return day <= 29;

return day <= DAYS[month - 1];

}

return false;

}

//checks if a year is a leap year

static bool is_leap_year(int year){

//Algorithm is taken from Wikipedia: http://en.wikipedia.org/wiki/Leap_year

if (year % 4 != 0)

return false;

else if (year % 100 != 0)

return true;

else if (year % 400 != 0)

return false;

else

return true;

}

//returns the number of days in the month of this year

int days_of_month(int month){

return is_leap_year(year) && month == 2 ? 29 : DAYS[month - 1];

}

//returns the number of days in given month and year

static int days_of_month(int month, int year){

return is_leap_year(year) && month == 2 ? 29 : DAYS[month - 1];

}

//how many days are in this year?

int days_of_year(){

return is_leap_year(year) ? 366 : 365;

}

//how many days are in a given year?

static int days_of_year(int year){

return is_leap_year(year) ? 366 : 365;

}

//subtract a number of days from a date

void subtract_days(int days){

int reminder = days;

while (reminder > 0){

if (day - reminder >= 1){ // applies to all months

day -= reminder;

reminder = 0;

}

else if (month == 1){ //treat December differently

year--;

month = 12;

reminder -= day;

day = days_of_month(month);

}

else { //applies to all other months

month--;

reminder -= day;

day = days_of_month(month);

}

}

check_valid(); //check the date is valid. Maybe the year has become negative for instance

}

//add a number of days to this date

void add_days(int days){

if (days<0)

subtract_days(-1 * days);

int reminder = days;

while (reminder > 0){

int limit = days_of_month(month);

if (reminder + day <= limit){ // applies to all months

day += reminder;

reminder = 0;

}

else if (month == 12){ //treat December differently

year++;

month = 1;

reminder -= limit - day;

day = 0;

}

else { //applies to all other months

month++;

reminder -= limit - day;

day = 0;

}

}

check_valid(); //check the date is valid. Maybe the year has become negative for instance

}

//difference between two dates in number of days.

int operator - (const Date& other) const{

int year_r = 0, month_r = 0, day_r = 0;

if (this->operator<(other))

throw std::invalid_argument("This date is < the given data");

int year1 = year, year2 = other.year;

while (year2 - year1 < 0){

year_r += days_of_year(year2);

year2++;

}

//year_r = (year - other.year) * 365;

Date larger_month_date = month>other.month ? Date(year, month, day) : other;

Date smaller_month_date = month<other.month ? Date(year, month, day) : other;

int smaller_month = smaller_month_date.month;

int larger_month = larger_month_date.month;

while (smaller_month - larger_month < 0){

month_r += days_of_month(smaller_month, smaller_month_date.year);

smaller_month++;

}

if (other.month > month)

month_r *= -1;

day_r = day - other.day;

return day_r + month_r + year_r;

}

//checks if this date is > another date

bool operator >(const Date& other) const{

if (year != other.year)

return year > other.year;

if (month != other.month)

return month > other.month;

return day > other.day;

}

//checks if this date is == another date

bool operator ==(const Date& other) const{

return year == other.year && month == other.month && day == other.day;

}

//checks if this date is != another date

bool operator !=(const Date& other) const{

return !(*this == other);

}

//checks if this date is <= another date

bool operator <=(const Date& other) const{

return this->operator<(other) || this->operator==(other);

}

//checks if this date is >= another date

bool operator >=(const Date other) const{

return this->operator>(other) || this->operator==(other);

}

int getYear() { return year; }

int getMonth() { return month; }

int getDay() { return day; }

void setYear(int theYear) { year = theYear; check_valid(); }

void setMonth(int theMonth) { month = theMonth; check_valid(); }

void setDay(int theDay) { day = theDay; check_valid(); }

const Date& operator=(const Date& rhs){

year = rhs.year;

month = rhs.month;

day = rhs.day;

format = rhs.format;

return *this;

}

private:

int year = 0;

int month = 0;

int day = 0;

DateFormat format;

};

#endif

//StringTokenizer.h file

#ifndef STRINGTOKENIZER_H

#define STRINGTOKENIZER_H

#include <string>

int getNumber(int low, int high, std::string message);

/** The string_tokenizer class splits a string into a sequence of subtrings,

called tokens, separated by delimeters.

*/

class String_Tokenizer

{

public:

/** Construct a String_Tokenizer

@param source The string to be split into tokens

@param delim The string containing the delimeters. If

this parameter is omitted, a space character is assumed.

*/

String_Tokenizer(std::string source, std::string delim = " ") :

the_source(source), the_delim(delim), start(0), end(0) {

find_next();

}

/** Determine if there are more tokens

@return true if there are more tokens

*/

bool has_more_tokens() {

return start != std::string::npos;

}

/** Retrieve the next token

@return the next token. If there are no more

tokens, an empty string is returned

*/

std::string next_token() {

// Make sure there is a next token

if (!has_more_tokens())

return "";

// Save the next token in return_value

/*<snippet id="3" omit="false">*/

std::string token = the_source.substr(start, end - start);

/*</snippet>*/

// Find the following token

find_next();

// Return the next token

return token;

}

private:

/** Position start and end so that start is the index of the start

of the next token and end is the end.

*/

void find_next() {

// Find the first character that is not a delimeter

/*<snippet id="1" omit="false">*/

start = the_source.find_first_not_of(the_delim, end);

/*</snippet>*/

// Find the next delimeter

/*<snippet id="2" omit="false">*/

end = the_source.find_first_of(the_delim, start);

/*</snippet>*/

}

/** The string to be split into tokens */

std::string the_source;

/** The string of delimeters */

std::string the_delim;

/** The index of the start of the next token */

size_t start;

/** The index of the end of the next token*/

size_t end;

};

#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote