C++.how to write a selection sort to sort it. read_book_data() This member function takes one parameter, a...

60.1K

Verified Solution

Question

Programming

C++.how to write a selection sort to sort it.

read_book_data()

This member function takes one parameter, a string that containsthe name of a file. This string parameter can be a C++ string or aC string (your choice). The function returns nothing.

This constructor should do the following:

  1. Declare and open an input file stream variable using the filename string passed in as a parameter.

  2. Check to make sure the file was opened successfully. If not,print an error message and exit the program.

  3. Read the file into your book_store object using theifstream::read() member function for binary input.

  4. Close the file stream variable.

  5. Sort the book objects in the array in ascending order by ISBNnumber using a sorting algorithm of your choice. Note that theISBNs are C strings, which means that you will not be able tocompare them using the standard relational operators. The ISBN isalso private data of the book class, so code in the book_storeclass will need to call get_isbn() for book object rather thanaccessing the object's ISBN directly.

Note that the code described above will read data intoall of the book data members. That includes boththe array of 30 book objects, and the number of array elementsfilled with valid data. No further initialization of the datamembers will be needed

void book_store::read_book_data(string data)
{
ifstream inFile;

inFile.open(data, ios::binary);
if( inFile.fail() )
{
cout << \"input file did not open\";
exit(-1);
}

inFile.read((char*)this, sizeof(book_store));

inFile.close();
}

C++.how to write a selection sort to sort it.

Answer & Explanation Solved by verified expert
4.0 Ratings (574 Votes)
SELECTIONSORTThe selection sort algorithm is a sorting technique to sort anarray by repeatedly finding the minimum element from unsorted partand putting it at the beginning of the array The algorithmmaintains two subarrays in a given array1 Sorted Subarray2 Unsorted SubarrayIn every iteration of selection sort the minimum    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students