Question
In C++ code Problem : A Book Database Databases are an essential part of most computing systems, and has become an indispensable part of our
In C++ code
Problem : A Book Database Databases are an essential part of most computing systems, and has become an indispensable part of our lives as a whole. We encounter many databases on a daily basis, even though we may not realize it (student records, social security, health/medical to just name a few). This homework will look at a mini-database for a library to store book records, and will use a plain text file to store and retrieve information for multiple books. In database terms, this is referred to as a flat-file storage. In a flat-file storage, each line represents one unique record. So if you were to store the information of every book in a collection (for example, the Minneapolis Central Library) in a flat file, this would take up exactly one line per book. You have seen an example of a flat-file database in the lab on earthquake data where you used a comma-separated value (CSV) file.
In this, you will create an object-oriented program with classes, to 1. read in records for all books available from an input file into C++ objects representing book records, 2. sort those records alphabetically based on their title (more on that later), 3. write the sorted records into a different file.
Input/output specifications: 1. The input file will be called bookinput.dat (without the quotes). 2. The output file will be called bookoutput.dat (without the quotes). 3. Each line in the input file will contain entry for exactly one book, and the same needs to happen for the output file. 4. Number of records in a file shall not be known upfront. 5. The book records will be made up of the following fields (with data types in parenthesis):
1. 6-digit book ID (string) 2. Author (string) 3. Title (string) 4. Edition (int) 5. Year published (int) 6. A 10-digit alphanumeric ISBN (International Standard Book Number) (string) The data types must be as shown.
Program Operation: 1. When run, the program will read the file bookinput.dat. If the file does not exist or is empty, it will report that and then exit the program. 2. No book data will be input from the keyboard. All data shall be read from the input file. 3. You can safely assume the input file will contain no errors. 4. If the file exists and is not empty, the program shall sort all book records on their title, in increasing lexicographic order. 5. No data shall be output to the screen. Every input/output operation will happen within the two files. To handle the tasks as explained above, you have to create a class to represent a book record. Each book will thus become an object (remember: class==blueprint, object==actual instance).
Specifically, 1. As you read each line from bookinput.dat, create an object of type Book 2. Store that Book object into an array, keeping a track of how many Book objects have been added to the array. You can assume the maximum number of Books will be 2000. 3. Sort this array in increasing order by title. 4. Write each object of this array to the output file in the same format as the input file, of course, in the same sorted order in increasing title.
Book Class Specification: 1. The class will be called Book (without the quotes); 2. All data members (variables) will be private; 3. Each data member thus will need one method to read from it, and one method to write to it. Remember, these methods are called getters and setters, respectively. 4. The class also needs to have two constructors; one default, and the other with six arguments, to set the values of the data members at once during construction. 5. Methods that only have read-only access to data members must be defined as const methods. 6. All methods must be public.
The sorting function should be a non-member function of the Book class (hint: have friends!).
Example Output (must be only in the file, do not show on the screen): For the input shown here: 000001, Bjarne Stroustrup, The C++ Programming Language, 4, 2013, 0321563840 000002, Stephen Colbert, Stephen Colbert's Midnight Confessions, 1, 2017, 1501169009 000003, Tom Clancy, The Hunt for Red October, 2, 1984, 0425240339 000004, Gregory Dudek, Computational Principles of Mobile Robotics, 2, 2010, 0521692121
the output file would contain: 000004, Gregory Dudek, Computational Principles of Mobile Robotics, 2, 2010, 0521692121 000002, Stephen Colbert, Stephen Colbert's Midnight Confessions, 1, 2017, 1501169009 000001, Bjarne Stroustrup, The C++ Programming Language, 4, 2013, 0321563840 000003, Tom Clancy, The Hunt for Red October, 2, 1984, 0425240339 For this problem, you can just create one CPP file that includes everything. No need to separate into different files
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started