Instructions: There is one problem worth 20 points. | Cheap Nursing Papers

Instructions: There is one problem worth 20 points.

Instructions: This is an individual homework assignment. There is one problem worth 20 points. Solve

the problem by yourself (unlike the labs, where you can work collaboratively), and submit the solution

as a C++ source code file. Here are a few more important details:

• You submit the correct file through Canvas by the due deadline.

• You should follow the example input and output formats given in each problem description.

(match the input and output format exactly)

• Regardless of how or where you develop your solutions, your programs compile and execute on

cselabs computers running the Linux operating system.

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 homework, 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. See later in this file for an example input file.

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.

See example stub below.

6. All methods must be public.

To assist you to get started with this, a stub (that is, incomplete code) is provided on the next page for

the class declaration. It is missing important function declarations and other elements, which you have

to complete. The sorting function should be a non-member function of the Book class (hint: have

friends!).

// Complete this below and write a main driver program.

class Book {

 string book_id;

 // an 6-digit numeric ID. Can begin with 0, so we need a string to store.

 …

public:

 Book();

 …

 // Getters and setters for each of the private fields.

 int getYear() const;

 void setYear( int yr );

 …

};

void Sort( Book bookList[], int size );

To sort, one possible (albeit inefficient) approach is :

 for i=0 to size-2

for j=i+1 to size-1

if array[i] > array[j] then swap array[i] with array[j]

Please note, this example shown is pseudocode, not actual C++. Also, this requires you to compare

element i with element j of the array, and also swap them. For this homework, you have to compare the

title of the book record at index i with the title of the book record at index j, and swap entire records,

not just the title.

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

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp