Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need c++ format here is start code class CampsiteDB { public : CampsiteDB( std::string filename ); int get_record_count( ); int get_current_index( bool write=false ); Campsite

need c++ format here is start code class CampsiteDB { public: CampsiteDB( std::string filename ); int get_record_count( ); int get_current_index( bool write=false ); Campsite get_next_sequential( ); Campsite get_at_index( int index ); void write_next_sequential( const Campsite& site ); void write_at_index( int index, const Campsite& site ); void print_record( int index, std::ostream& strm = std::cout ); void list_records( std::ostream& strm = std::cout ); // This object is non-copyable CampsiteDB(const CampsiteDB&) = delete; CampsiteDB& operator=(const CampsiteDB&) = delete; private: // private methods: void _create_file( ); bool _open_file( ); // attributes std::string _filename; std::fstream _file; };

image text in transcribedimage text in transcribed

Implement the constructor for the campsite storage database. The constructor will always open the file (if possible). If the file doesn't exist, it must be created. We will detect this by trying to open it the way we want first, then detecting a failure, trying to create, then trying again to open. If all of that fails (we can't create the file), we have no choice but to throw an exception. The algorithm follows; make use of the _open file and create file helper methods when you implement. try to open the file - if we fail to open the file: try to create the file try to open the file -- if we still fail, throw a std:iruntime_error exception saying "Unable to create the database. Now we must immediately implement the two private helper methods _open file and _create file. The operate on the_file attribute as follows: _open_file) should open the file whose name is _filename with input, output, and binary mode flags. Then, use the stream seekp) method to seek the "putt position to the end of the file (seek to 0 bytes from std: :ios: :end). This will allow immediate appending of new values at the end, if desired. The result of testing whether the file is indeed open after this operation should be returned ( true if the file is open false otherwise). create file) should open the file whose name is_filename in output mode (this will create the file, if you have permission). The file stream should then be immediately closed. Create method stubs for all of the other methods in CampsiteDB so that you can compile. Add the following to your main program and check that it compiles. CampsiteDB db( campsites.db" Run the program and verify that the file "campsites.db" is being created. It is currently empty (size zero); you may delete it and re-test as needed Implement the constructor for the campsite storage database. The constructor will always open the file (if possible). If the file doesn't exist, it must be created. We will detect this by trying to open it the way we want first, then detecting a failure, trying to create, then trying again to open. If all of that fails (we can't create the file), we have no choice but to throw an exception. The algorithm follows; make use of the _open file and create file helper methods when you implement. try to open the file - if we fail to open the file: try to create the file try to open the file -- if we still fail, throw a std:iruntime_error exception saying "Unable to create the database. Now we must immediately implement the two private helper methods _open file and _create file. The operate on the_file attribute as follows: _open_file) should open the file whose name is _filename with input, output, and binary mode flags. Then, use the stream seekp) method to seek the "putt position to the end of the file (seek to 0 bytes from std: :ios: :end). This will allow immediate appending of new values at the end, if desired. The result of testing whether the file is indeed open after this operation should be returned ( true if the file is open false otherwise). create file) should open the file whose name is_filename in output mode (this will create the file, if you have permission). The file stream should then be immediately closed. Create method stubs for all of the other methods in CampsiteDB so that you can compile. Add the following to your main program and check that it compiles. CampsiteDB db( campsites.db" Run the program and verify that the file "campsites.db" is being created. It is currently empty (size zero); you may delete it and re-test as needed

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

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago