Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program SearchNewBooks.cc that given as command line input newbooks.dat and request.dat and a method of search either binary or linear, creates a file

Create a program SearchNewBooks.cc that given as command line input newbooks.dat and request.dat and a method of search either binary or linear, creates a file of the number of books found from the request list.

program should receive two filenames as command line arguments, the new books file and request file, which the program should read in. The list of new books and list of requested books should should be stored in only two std::vector containers. Because some code to open these two files will probably be equivalent, you are encourage to write generic functions in order to avoid code duplication.

You should write a class for representing book as a combination of both the ISNB number and type, so that each vector is an object of that class. For debugging purposes, you can overload the << operator to print positional vectors in a pretty way.

$ cat newbooks.dat

58,new

92,used

82,digital

114,used

26,new

$ cat request.dat

8,new 1,new 95,new

you will need to implement two search strategies in order to find the given requested books in the list of new arrivals: a linear search and a binary search. The user will choose between using one of these two strategies every time the program is run. If the user input is invalid, they should be asked again, as shown in the example below. The error message should be printed to std::cerr.

For the binary search, the vector of new books should be sorted by their ISNB number beforehand. For the sorting, you should use std::sort. If you overload the < operator of your positional vector class, this function can easily be applied for sorting all of objects contained in a vector container:

please help me to write code as a class. please write in C++ language.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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