Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Seneca Library Application To complete your project for this semester, create a project called ms5. Then go back to all your milestones, and add

The Seneca Library Application

To complete your project for this semester, create a project called ms5. Then go back to all your milestones, and add all the latest versions of your modules (developed throughout the first 4 milestones) to ms5.

Get the PublicationSelector module (fully developed by another developer) from the project repository and add it to your project. Use pubSel_Tester.cpp to test the module and understand its usage.

PublicationSelector Module

The PublicationSelector module holds the addresses of a selection of the Publications in an array and lets the user select one of them. Upon user's selection, the Library Reference number of the selected publication is returned to the caller module for further actions.

For example, the array of Publications can be searched for a match to a specific title, and the matches found in the array can be inserted into the PublicationSelector. Then the PublicationSelector can be run to display the search results and ask the user to select one of them.

The logic below (in pubSel_Tester.cpp) is searching all the publications in "LibRecs.txt", displaying the matches to "Harry" and "MoneySense" and letting the user select one.

// Final Project // PublicationSelector Usage demonstration // File pubSel_Tester.cpp // Version 1.0 // Author Fardad Soleimanloo // Revision History // ----------------------------------------------------------- // Name Date Reason // 2021-11-27 Initial release ///////////////////////////////////////////////////////////////// #define _CRT_SECURE_NO_WARNINGS #include #include #include #include "Publication.h" #include "Book.h" #include "PublicationSelector.h" using namespace std; using namespace sdds; // prints the publication with the library reference number "ref: void prnPub(Publication* p[], int size, int ref) { int i; for (i = 0; i < size; i++) { if (ref == p[i]->getRef()) { cout << *p[i] << endl; i = size; // Exit the loop. } } } int main() { ifstream infile("LibRecs.txt"); Publication* p[1000]{}; PublicationSelector ps("Publications with Harry and MoneySencse", 5); char type{}; int i; for (i = 0; infile; i++) { infile >> type; infile.ignore(); if (infile) { if (type == 'P') p[i] = new Publication; else if (type == 'B') p[i] = new Book; if (p[i]) { infile >> *p[i]; // find publications with Harry or MoneySence in the title if (strstr(*p[i], "Harry") || strstr(*p[i], "MoneySense")) ps << p[i]; // insert into PublicationSelector if there is match } } } if (ps) { ps.sort(); // sort them based on date and title int ref = ps.run(); // display the publications and select one if (ref) { cout << "Selected Library Reference Number: " << ref << endl; prnPub(p, 100, ref); } else { cout << "Aborted by user!"; } } else { cout << "No matches to \"Harry\" and \"MoneySense\" found" << endl; } for (i = 0; p[i]; i++) { //free the allocated memory delete p[i]; } return 0; }

LibApp Module

Complete the LibApp module as follows

Add the following attributes to the LibApp Module.

File name

Add an array of 256 characters to hold the publication data file name.

Publication Pointers Array

Create and add an array of Publication pointers to the size of SDDS_LIBRARY_CAPACITY. This array will be populated with all the records of the publication data file when the LibApp is instantiated.

We will call Publication Pointers Array "PPA" for short, from now on.

Number Of Loaded Publications

Add an integer to hold the number of Publications loaded into the PPA.

We will call this attribute "NOLP" for short, from now on.

Last Library Reference Number

Add an integer to hold the last library reference number read from the data file. This number will be used to assign new library reference numbers to new publications added to the library. When a new publication is added to the library, this number will be added by one and then assigned to the new publication. Doing this; each publication in the library will have a unique library reference number.

We will call this attribute "LLRN" for short, from now on.

Publication Type Menu

Add a Menu to the LibApp for selection of publication type. The title of this menu is: "Choose the type of publication:"

The publication type menu should also provide two selections: "Book" and "Publication".

Setup the publication type menu in the constructor as you did for the main and exit menus.

Method Implementations

Create new methods or Modify MS2 methods for the following

The load method

First print "Loading Data" and then open the data file for reading and read all the publications in dynamic instances pointed by the PPA Array.

Do this by first reading a single character for the type of publication and then dynamically instantiating the corresponding object into the next available PPA element. Then extract the object from the file stream and add one to the NOLP. Since the extraction operator calls the proper read function virtually, the object will be properly read from the file.

Continue this until the ifstream reading fails.

At the end set the LLRN to the reference number of the last publication read.

See the pubSel_Tester.cpp that uses a similar logic to load the publications for example...

The save method

First print "Saving Data" and then open the data file stream for overwriting. (ofstream) Go through the elements of PPA up to the N0LP. Insert all elements into the ofstream object except those with 0 (zero) as Library Reference Number. (return value of getRef() method)

Publications that have the reference number of 0 (zero) are deleted by the user (removed from the library) and therefore should not be saved back into the data file. We refer to these publications as deleted ones.

search

Add needed arguments so the search function can be called in three different modes:

  1. Search all
  2. Search Checkout Items Search only those publications which are on loan by library members
  3. Search Available Items Search only those publications which are not on loan

Search will use an instance of PublicationSelector class to collect the search matches and user selection. The prompt of the PublicSelector should be: "Select one of the following found matches:" The page size for the selector menu should be 15 (the default value)

First, get the type of publication to search for from the user. (user the type selection Menu of the class)

Then print "Publication Title: " and get the title to search the PPA for. (up to 256 characters)

Go through all the publications in the PPA and base on the method of search (all the items, on loan items or available ones) check each element and if the publication (pointed by the PPA element) is not deleted and type matches the selection of the user and the title contains the title the user entered, insert it into the PublicationSelector object.

MS5 V1.1

If matches are found, sort the result and get the user's selectionand return the library reference number. If not print "No matches found!"

If the user aborts at any stage print "Aborted!"

Abort Scenarios (searching all)

Choose the type of publication: 1- Book 2- Publication 0- Exit > 0 Aborted! ------------------------------------------------------- Choose the type of publication: 1- Book 2- Publication 0- Exit > 1 Publication Title: Harry Select one of the following found matches: Row |LocID | Title |Mem ID | Date | Author | ------+------+--------------------------------+-------+------------+-----------------| 1- | T343 | Harry Potter.................. | 65205 | 2021/11/19 | J. K. Rowling | 2- | F861 | Harry Potter and the Chamber o | N/A | 2021/11/24 | J. K. Rowling | 3- | C872 | Harry Potter and the Deathly H | 64984 | 2021/11/17 | J. K. Rowling | 4- | C945 | Harry Potter and the Goblet of | N/A | 2021/11/14 | J. K. Rowling | 5- | C332 | Harry Potter and the Half/Bloo | 85952 | 2021/11/22 | J. K. Rowling | 6- | L290 | Harry Potter and the Order of | N/A | 2021/11/11 | J. K. Rowling | 7- | D208 | Harry Potter and the Philosoph | 72685 | 2021/11/19 | J. K. Rowling | 8- | R856 | Harry Potter and the Prisoner | N/A | 2021/11/10 | J. K. Rowling | > X (to Exit) > Row Number(select publication) > x Aborted! 

Search on loan

Choose the type of publication: 1- Book 2- Publication 0- Exit > 1 Publication Title: Harry Select one of the following found matches: Row |LocID | Title |Mem ID | Date | Author | ------+------+--------------------------------+-------+------------+-----------------| 1- | T343 | Harry Potter.................. | 65205 | 2021/11/19 | J. K. Rowling | 2- | C872 | Harry Potter and the Deathly H | 64984 | 2021/11/17 | J. K. Rowling | 3- | C332 | Harry Potter and the Half/Bloo | 85952 | 2021/11/22 | J. K. Rowling | 4- | D208 | Harry Potter and the Philosoph | 72685 | 2021/11/19 | J. K. Rowling | > X (to Exit) > Row Number(select publication) > 

Search available publications

Choose the type of publication: 1- Book 2- Publication 0- Exit > 1 Publication Title: Harry Select one of the following found matches: Row |LocID | Title |Mem ID | Date | Author | ------+------+--------------------------------+-------+------------+-----------------| 1- | F861 | Harry Potter and the Chamber o | N/A | 2021/11/24 | J. K. Rowling | 2- | C945 | Harry Potter and the Goblet of | N/A | 2021/11/14 | J. K. Rowling | 3- | L290 | Harry Potter and the Order of | N/A | 2021/11/11 | J. K. Rowling | 4- | R856 | Harry Potter and the Prisoner | N/A | 2021/11/10 | J. K. Rowling | > X (to Exit) > Row Number(select publication) > 

Publication* getPub(int libRef) method

Create a method to return the address of a Publication object in the PPA that has the library reference number matching the "libRef" argument.

the newPublication() method

If the NOLP is equal to the SDDS_LIBRARY_CAPACITY, print: "Library is at its maximum capacity!" and exit.

Otherwise,

  • print: "Adding new publication to the library"
  • get the publication type from the user.
  • in a publication pointer, instantiate a dynamic "Publication" or "Book" based on the user's choice.
  • Read the instantiated object from the cin object.
  • If the cin fails, flush the keyboard, print "Aborted!" and exit.
  • If the cin is ok, then confirm that the user wants to add the publication to the library using this prompt: "Add this publication to the library?". If the user did not confirm, print "Aborted!" and exit.
  • After the user confirms, if the publication object is valid
    • Add one to the LLRN and set the library reference number to the value
    • Add the publication object's address to the end of the PPA and add one to the NOLP.
    • set the "changed" flag to true
    • print: "Publication added"
  • If the publication object is not valid print: "Failed to add publication!" and delete the allocated memory.

Adding a new publication to the library:

Seneca Library Application 1- Add New Publication 2- Remove Publication 3- Checkout publication from library 4- Return publication to library 0- Exit > 1 Adding new publication to the library Choose the type of publication: 1- Book 2- Publication 0- Exit > 2 Shelf No: S001 Title: Seneca Student Handbook Date: 2022/1/5 Add this publication to the library? 1- Yes 0- Exit > 1 Publication added 

The removePublication Method

  • print: "Removing publication from the library"
  • Search all the publications
  • If the user selects a publication and confirms to remove the publication using the prompt: "Remove this publication from the library?"
    • Set the library reference of the selected publication to 0 (zero)
    • set the "changed" flag to true
    • print: "Publication removed"

removing a publication from the library

Seneca Library Application 1- Add New Publication 2- Remove Publication 3- Checkout publication from library 4- Return publication to library 0- Exit > 2 Removing publication from the library Choose the type of publication: 1- Book 2- Publication 0- Exit > 2 Publication Title: Sen Select one of the following found matches: Row |LocID | Title |Mem ID | Date | Author | ------+------+--------------------------------+-------+------------+-----------------| 1- | P008 | MoneySense Magazine........... | N/A | 2021/11/11 | 2- | P008 | MoneySense Magazine........... | 72614 | 2021/11/16 | 3- | P008 | MoneySense Magazine........... | 48096 | 2021/11/17 | 4- | P008 | MoneySense Magazine........... | 89325 | 2021/11/17 | 5- | P008 | MoneySense Magazine........... | 33074 | 2021/11/17 | 6- | P008 | MoneySense Magazine........... | N/A | 2021/11/18 | 7- | P008 | MoneySense Magazine........... | 70451 | 2021/11/24 | 8- | S001 | Seneca Student Handbook....... | N/A | 2022/01/05 | > X (to Exit) > Row Number(select publication) > 8 | S001 | Seneca Student Handbook....... | N/A | 2022/01/05 | Remove this publication from the library? 1- Yes 0- Exit > 1 Publication removed 

The checkOutPub method

  • print: "Checkout publication from the library"
  • Search in available publications only
  • If the user selects a publication and confirms to checkout using the prompt: "Check out publication?"
    • read a 5 digit number from the console, if invalid print: "Invalid membership number, try again: " and read again
    • set the membership number of the selected publication the integer value.
    • set the changed flag to true
    • print: "Publication checked out"

Checking out a publication

Seneca Library Application 1- Add New Publication 2- Remove Publication 3- Checkout publication from library 4- Return publication to library 0- Exit > 3 Checkout publication from the library Choose the type of publication: 1- Book 2- Publication 0- Exit > 2 Publication Title: Sen Select one of the following found matches: Row |LocID | Title |Mem ID | Date | Author | ------+------+--------------------------------+-------+------------+-----------------| 1- | P008 | MoneySense Magazine........... | N/A | 2021/11/11 | 2- | P008 | MoneySense Magazine........... | N/A | 2021/11/18 | 3- | S001 | Seneca Student Handbook....... | N/A | 2022/01/05 | > X (to Exit) > Row Number(select publication) > 3 | S001 | Seneca Student Handbook....... | N/A | 2022/01/05 | Check out publication? 1- Yes 0- Exit > 1 Enter Membership number: 12345 Publication checked out 

The returnPub() Method

  • Print: "Return publication to the library"
  • Search for "on loan" publications only
  • If the user selects a publication and confirms the return using the prompt: "Return Publication?"
    • If the publication is more than 15 days on loan, a 50 cents per day penalty will be calculated for the number of days exceeding the 15 days.
      • Following message is printed: Please pay $9.99 penalty for being X days late!, 9.99 is replaced with the penalty value and X is replaced with the number of late days.
    • set the membership number of the publication to 0 (zero)
    • set the "changed" flag to true
    • print: "Publication returned"

Returning publication to library

Seneca Library Application 1- Add New Publication 2- Remove Publication 3- Checkout publication from library 4- Return publication to library 0- Exit > 4 Return publication to the library Choose the type of publication: 1- Book 2- Publication 0- Exit > 1 Publication Title: Harry Select one of the following found matches: Row |LocID | Title |Mem ID | Date | Author | ------+------+--------------------------------+-------+------------+-----------------| 1- | T343 | Harry Potter.................. | 65205 | 2021/11/19 | J. K. Rowling | 2- | C872 | Harry Potter and the Deathly H | 64984 | 2021/11/17 | J. K. Rowling | 3- | C332 | Harry Potter and the Half/Bloo | 85952 | 2021/11/22 | J. K. Rowling | 4- | D208 | Harry Potter and the Philosoph | 72685 | 2021/11/19 | J. K. Rowling | > X (to Exit) > Row Number(select publication) > 2 | C872 | Harry Potter and the Deathly H | 64984 | 2021/11/17 | J. K. Rowling | Return Publication? 1- Yes 0- Exit > 1 Please pay $4.00 penalty for being 8 days late! Publication returned 

The constructor

Add the following to the constructor:

  • Initialize and set the Publication Type Menu as described in the attributes section.
  • Add an argument to the constructor to receive the file name. Set the file name attribute to the incoming argument.

MS5 Sample executionMilestone 5 Test One (m51)

Data file: LibRecsSmall.txt

  • load
  • Book and Publication entry
  • setting the library reference number
  • save

Data Entry:

1 1 S001 Book one 2020/10/10 John Doe 1 1 2 S002 Daily one 2020/10/10 1 0 1 

Correct Output

Milestone 5 Test Two (m52)

Data file: LibRecsSmall.txt

  • load
  • Removing Publication and Book
  • save

Data Entry:

2 1 e 3 1 2 2 e 3 1 0 1 

Correct Output

Milestone 5 Test Three (m53)

Data file: LibRecsSmall.txt

  • load
  • Checking out and no match found
  • Checking out with success
  • save

Data Entry:

3 1 Harry 3 1 Web 1 1 12345 0 1 

Correct Output

Milestone 5 Test Four (m54)

Data file: LibRecsSmall.txt

  • load
  • Returning a Book with no penalty
  • Returning a Book with penalty
  • Returning a Publication
  • save

Data Entry:

4 1 Harry 1 1 4 1 Hobbit 1 1 4 2 e 2 1 0 1 

Correct Output

Milestone 5 Test Five (m55)

Data file: LibRecs.txt

Before starting this this test make sure that in "Lib.h" The maximum capacity of the library is set to 333. >> const int SDDS_LIBRARY_CAPACITY = 333; <<

  • load
  • Adding a publication
  • Add another publication unsuccessfully
  • save

Data Entry:

1 2 S003 News Daily 2021/11/30 1 1 0 1 

Correct Output

Milestone 5 Test Six (m56)

Data file: LibRecs.txt

  • load
  • Aborting and error handling
  • exit without saving

Data Entry:

1 0 2 2  x 3 1  1 1 123456 12345 4 2  x 0 0 1 

Correct Output

date.cpp-1.jpg

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

5. What recommendations would you make to Coach?

Answered: 1 week ago