Question: You will create a C++ program calculate the time needed when organizing the library bookshelf and find the order of book on the shelf after
You will create a C++ program calculate the time needed when organizing the library bookshelf and find the order of book on the shelf after organizing. When organizing, the library manager decides to put the books into two queues and select one book from each queue to fill the shelf in sequence. These books are mixed with different topic. However, the manager wants to fill the shelf with Comp Sci book first before adding the rest into the shelf. If a book is not a Comp Sci book, it will be discarded into a third queue, waiting to be added to the shelf. Compute the time it takes to organize all the books, assuming that putting a book into the shelf take 20 sec and discarding a book take 10 sec. Example of Operation (input 1): Queue 1: math,compsci A,compsci B Queue 2: art,novel,compsci C Begin with queue 1, the first book is math so it will be discarded into a third queue (since it took 10 sec to discard, total time = 10) Queue 3: math Then following the sequence, the manager takes a book from queue 2, which is art so it will also be discarded into the third queue (total time = 20) Queue 3: math,art The next book will be taken from queue 1, this time its a comp sci book so it will took 20 sec to organize it into the shelf (total time = 40) ... This operation will take total of 150 sec And the order of book is: compsci A,compsci B,compsci C,math,art,novel *Note: queue 1 and 2 must be empty before you can proceed with queue 3. You must use queue to implement this operation
2. Input and Output a. Input file The first line of input will contain the list of books in queue 1. The second line will contain the list of books in queue 2. Each book will be separated by a comma. Book name can have spaces between the string. There will be no duplicate book name. No empty input will be given. b. Output file The first line of output should display the total time. The second line should display the order of book after organizing, with each book separated by a comma.
3. Example of Input and Answer input1.txt math,compsci A,compsci B art,novel,compsci C ans1.txt 150 compsci A,compsci B,compsci C,math,art,novel input2.txt chemistry,compsci A,bio A,english B compsci B,compsci D,compsci C ans2.txt 170 compsci B,compsci A,compsci D,compsci C,chemistry,bio A,english B input3.txt novel,magazine,science math,physic,english ans3.txt 180 novel,math,magazine,physic,science,english
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
