Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to use classes when structuring a program. You will doing an app for library administrators who will need add

The purpose of this assignment is to use classes when structuring a program. You will doing an app for library administrators who will need add and delete book information in the catalog for a library. You will also be creating a file to store the book catalog information in.

Book Class

Make a Book class with private member variables for the following information: ID (this can be a number or an ISBN if you want something more real), title, author, copies available, copies checked out. Each member variable must have a corresponding 'getter' and 'setter' in the Book class. You can also have an optional print member function to print out a book's information.

Please do not use any structs in your code. All book info should be in a class as private variable members only.

You can make an OPTIONAL catalog class to hold the array of Book objects but you can also just have an array in the main function like in project 2. In project 4 you will be creating the Catalog class.

File IO

Before going into the loop to display the menu, the program will open a file that contains the book catalog information. The program will read in each book entry and put them in the array of Book objects (the catolog). If no file exists or is empty (no entries in it), it should just continue with an empty catalog (count is set to zero). When the user quits the program, the same file should be opened for output and the entire catalog including any changes should be written out to the file.

Since I will not be using a pre-existing file, I will leave it up to the student to come up with a format. To grade your program, I will run your program twice. The first time I run it, I will be adding several books to the catalog. Your program should write these out to your file when the program ends. Then I will run your program again and see if the book entries are read in correctly from the file.

You can name this file what you want to but don't use path names (directories) with your file; just give it a simple name, such as 'catalog.txt' or books.txt'. This way it will be created in the same directory as the program and easy for me to find it.

NOTE: The C-string members (title, author, etc) will have spaces in them. So don't use the >> operator to read these in; use iostream function 'getline' to read in all C-strings from either a file or the keyboard. See Week 3 activities for how to use 'getline'.

WARNING: Please don't try to do random access file IO as the fields vary in length and it is very difficult to find the beginning of a field to write data out to. Just open the file for input/reading at the beginning of the program, read everything into the array and close the file. Do all changes to the array; not the file. Then before quitting the program, re-open the file for output/writing and write everything back out to the file.

Library Admin Tasks

The program should start by reading in the catalog from a file. The format is up to you as I will not be using any files when grading. However, for the benefit of project 4, you may want to make the first line of the file be the number of books in the file. This will make doing dynamic arrays much easier.

To grade your program, I will run your program twice. The first time I run it, I will be adding several entries to the catalog. Your program should write these out to your file when the program ends. Then I will run your program again and see if the entries are read in correctly from the file.

The administration program allows the administrator to do the following to the catalog:

Add a new book. Ask for all the information and make sure it is valid (number of copies should be 1 or larger). Set the number of checkouts to 0. Make sure the ID (or ISBN number if you want use them) is unique by looking for it in the catalog.

Print catalog - print all books in the catalog. Don't print any blank entries.

Modify Book Information - Ask for an ID. If not found, print an error message and return to main menu. Else, print another menu of possible fields to change. Let the user pick a field to change. Check for the same valid input as in add book; ID must be unique and no negative counts. Also, check to make sure the number of checkouts is between the number of copies and 0.

NOTE: You will get points off if you force me to enter info for all the fields even if I only want to change one field. This is not very user-friendly way to do this :(

Delete a book. Ask for an ID. If not found, print an error message and return to main menu. Else, delete the book with that ID. You can optionally re-print the book info and ask the user if this is the book they want to delete but just deleting the book is fine too.

Requirements

You must create and use a Book class; the Catalog class is optional. All member variables in any classes must be private. The member variables will be changed or read via a set of public member functions.

You will need more than one file for this project. Each class needs two files: a implementation (.cpp) file and a header (.h) file. There will still be one main.cpp file. So you need to turn in at least 3 source code files for this project. Please see d2l week 4 "Using Multiple Files" for how to structure your code.

You need to use C-strings, no 'string' type in your entire code. All functions, including main, must be less than 30 lines long (this count does not include comments, blank lines and { } on separate lines).

No global variables are allowed in this program. Whether you are using a Catalog class or any array of Book objects, create the Catalog object or array of Book objects in the main function. Pass it into functions in main.cpp if this is needed. Remember to pass the Catalog object (if you created one) into functions by reference (ie. use the & in front of the catalog name); an array doesnt need the & to be passed by reference.

The program should read and write information correctly to a file. The program should not crash if this file is not present. In this case, set count to zero and return to the main menu. This allows the admin to create a new catalog.

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

Students also viewed these Databases questions

Question

What is liability of newness?

Answered: 1 week ago