Question: class Campsite { public : Campsite( ) = default ; Campsite( int number, std::string description, bool has_electric, double rate ); Campsite( const CampsiteRecord& r );

class Campsite { public: Campsite( ) = default; Campsite( int number, std::string description, bool has_electric, double rate ); Campsite( const CampsiteRecord& r ); CampsiteRecord get_record() const; int get_number( ) const; std::string get_description( ) const; bool has_electric( ) const; bool get_rate( ) const; void set_number( int number ); void set_description( std::string description ); void set_has_electric( bool flag ); void set_rate( double rate ); std::ostream& write(std::ostream& strm) const; std::istream& from_ascii_file(std::istream& strm); private: CampsiteRecord _rec; }; std::ostream& operatorconst Campsite& site); 

*******************************************************************************

class Campsite { public: Campsite( ) = default; Campsite( int number, std::stringdescription, bool has_electric, double rate ); Campsite( const CampsiteRecord& r ); CampsiteRecord

Implementing print record () The print record) method should perform the following steps retrieve the Campsite at the specified index print the record to the stream parameter using the Campsite object's write) method Adding Additional Functionality The following methods will add "nice to have" features to the class. Add prototypes to the class definition (CampsiteDB.h) and implement them in the in CampsiteDB.cpp. void move to index ( int index ) This method should move both the "get" and "put" markers on the underlying file stream to the logical index supplied in the index parameter. void swap_records ( int index_1, int index 2) This method should swap the record at index 1 with the record at index _2 in the file. std: :vector get range( int first_index, int last_index ) This method should retrieve all campsites between first_index and last_index (inclusive on the left end of the range, but exclusive on the right: first index, last index): campsite objects representing the records should be added to a vector in the same order they were in the file, and the vector should be returned. Campsite get _random ) This method should choose a record at random from within the file, retrieve the record, and return a Campsite object representing the record. See note on random number generation below. Index Validation If the random access file represents an "array in secondary storage", then this array has a serious issue: It does no bounds checking! We need to add protection against reading/writing beyond the ends of the file. Adjust your implementation to take into account these considerations: Sequentially writing when the put" location is already exactly at the end is OK the user likely expects this to append a new record to the file. It should be allowed. (But you must check the "put" position; if it is o bytes from the end, OK, but if it is beyond the end, an exception should be thrown.) Sequentially reading when the "get marker is at the end should not succeed. Currently, this will cause the internal file stream to detect end- of-file and fail, but a Campsite record is returned anyway the contents of that Campsite are invalid. An exception should be thrown in this case instead. A random access write to any index not in the range where N is the number o records in the e is an error. Note that writing to the index T should be allowed; this is ust appending one record to the end see the discussion of sequential writes). This can be checked before seeking to the target destination; attempts to move to a negative index or an index greater than N should result in an exception being thrown A random-access read to any index not in the range [0, N) where N is the number of records, must throw an exception. Note that reading at index N is illegal, even though writing at index N is allowed (writing there is appending, reading there is invalid). Be sure that every method that deals with indices has been updated to throw exceptions when given an index that is invalid, based on the behaviors defined in the points above. Use std: :length error as the exception type in all cases where the index is invalid, with the message "Index out of bounds. specifically relies on You will need to modify your previous code (i.e. in the main program, list_records).and perhaps elsewhere) to handle the exceptions that may occur. The algorithm in list_records behavior that will now throw an exception. You must adjust its code to behave properly with the new behavior of get_next sequential ) Implementing print record () The print record) method should perform the following steps retrieve the Campsite at the specified index print the record to the stream parameter using the Campsite object's write) method Adding Additional Functionality The following methods will add "nice to have" features to the class. Add prototypes to the class definition (CampsiteDB.h) and implement them in the in CampsiteDB.cpp. void move to index ( int index ) This method should move both the "get" and "put" markers on the underlying file stream to the logical index supplied in the index parameter. void swap_records ( int index_1, int index 2) This method should swap the record at index 1 with the record at index _2 in the file. std: :vector get range( int first_index, int last_index ) This method should retrieve all campsites between first_index and last_index (inclusive on the left end of the range, but exclusive on the right: first index, last index): campsite objects representing the records should be added to a vector in the same order they were in the file, and the vector should be returned. Campsite get _random ) This method should choose a record at random from within the file, retrieve the record, and return a Campsite object representing the record. See note on random number generation below. Index Validation If the random access file represents an "array in secondary storage", then this array has a serious issue: It does no bounds checking! We need to add protection against reading/writing beyond the ends of the file. Adjust your implementation to take into account these considerations: Sequentially writing when the put" location is already exactly at the end is OK the user likely expects this to append a new record to the file. It should be allowed. (But you must check the "put" position; if it is o bytes from the end, OK, but if it is beyond the end, an exception should be thrown.) Sequentially reading when the "get marker is at the end should not succeed. Currently, this will cause the internal file stream to detect end- of-file and fail, but a Campsite record is returned anyway the contents of that Campsite are invalid. An exception should be thrown in this case instead. A random access write to any index not in the range where N is the number o records in the e is an error. Note that writing to the index T should be allowed; this is ust appending one record to the end see the discussion of sequential writes). This can be checked before seeking to the target destination; attempts to move to a negative index or an index greater than N should result in an exception being thrown A random-access read to any index not in the range [0, N) where N is the number of records, must throw an exception. Note that reading at index N is illegal, even though writing at index N is allowed (writing there is appending, reading there is invalid). Be sure that every method that deals with indices has been updated to throw exceptions when given an index that is invalid, based on the behaviors defined in the points above. Use std: :length error as the exception type in all cases where the index is invalid, with the message "Index out of bounds. specifically relies on You will need to modify your previous code (i.e. in the main program, list_records).and perhaps elsewhere) to handle the exceptions that may occur. The algorithm in list_records behavior that will now throw an exception. You must adjust its code to behave properly with the new behavior of get_next sequential )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!