Question: Im supposed to have a flashdrive_3_0.cpp file aswell please it has to be a total of 3 files . Thank You. The purpose of this

Im supposed to have a flashdrive_3_0.cpp file aswell please it has to be a total of 3 files . Thank You.

The purpose of this assignment is to work with exceptions. As you may recall, I have provided you with a sample class named FlashDrive which has been diagrammed below. I'd like you to enhance this class so that invoking its methods or operators potentially throw exceptions, rather than just printing error messages to cout. Currently, our favorite exception class is std::logic_error. You can create a logic_error by passing a string value to its constructor. Officially, you should also say #include to begin working with logic_error, but Visual Studio (being a badly behaved child...) let's you get away without it. Once you get it all working correctly, the driver code should run as described in class.

Although the sample driver code might not code for all these circumstances, I would like you to throw exceptions when:

more stuff has been put onto the drive than it can safely hold (due to writeData)

a negative number is potentially used as a my_StorageUsed value (due to operator or bad values being sent to the constructor call)

a negative number is potentially used as a my_StorageCapacity value (due to operator or bad values being sent to the constructor call)

So carefully wind your way thru all the operators and methods of the class ensuring that logic_error gets thrown in each of these circumstances.

I'd also like you to get operator << and operator >> working for the class FlashDrive.

FlashDrive

// constructors 
FlashDrive( ); 
FlashDrive( int capacity, int used, bool pluggedIn ); 
void plugIn( ); 
void pullOut( ); 
void writeData( int amount ); 
void eraseData( int amount ); 
void formatDrive( ); 
// basic accessors and modifiers 
int getCapacity( ); 
void setCapacity( int amount ); 
int getUsed( ); 
void setUsed( int amount ); 
bool isPluggedIn( ); 
// overloaded +, -, >, <, >>, << 
friend FlashDrive operator+(const FlashDrive& fd1, const FlashDrive& fd2); 
friend FlashDrive operator-(const FlashDrive& fd1, const FlashDrive& fd2); 
friend bool operator>(const FlashDrive& fd1, const FlashDrive& fd2); 
friend bool operator<(const FlashDrive& fd1, const FlashDrive& fd2); 
friend ostream &operator<<( ostream &stream, const FlashDrive &fd ); 
friend istream &operator>>( istream &stream, FlashDrive &fd ); 
friend ostream &operator<<( ostream &stream, const FlashDrive fd ); 
friend istream &operator>>( istream &stream, FlashDrive fd ); 
int my_StorageCapacity; 
int my_StorageUsed; 
bool my_IsPluggedIn 

main.cpp

#include #include "flashdrive_3_0.h" void main( ) { FlashDrive empty; FlashDrive drive1( 10, 0, false ); FlashDrive drive2( 20, 0, false ); drive1.plugIn( ); drive1.formatDrive( ); drive1.writeData( 5 ); drive1.pullOut( ); drive2.plugIn( ); drive2.formatDrive( ); drive2.writeData( 1 ); drive2.pullOut( ); // read in a FlashDrive... // the class designer for FlashDrive (that's you!) // gets to decide which fields matter and should be read in FlashDrive sample; cin >> sample; // print out a FlashDrive... // the class designer for FlashDrive (that's you!) // gets to decide which fields matter and should be printed cout << sample << endl; FlashDrive combined = drive1 + drive2; cout << "this drive's filled to " << combined.getUsed( ) << endl; FlashDrive other = combined drive1; cout << "the other cup's filled to " << other.getUsed( ) << endl; if (combined > other) { cout << "looks like combined is bigger..." << endl; } else { cout << "looks like other is bigger..." << endl; } if (drive2 > other) { cout << "looks like drive2 is bigger..." << endl; } else { cout << "looks like other is bigger..." << endl; } if (drive2 < drive1) { cout << "looks like drive2 is smaller..." << endl; } else { cout << "looks like drive1 is smaller..." << endl; } // let's throw some exceptions... try { empty = empty combined; cout << "something not right here..." << endl; } catch( std::logic_error ) { // an exception should get thrown... // so the lines of code here should // be run, not the cout statement... } try { drive2.writeData( 10000 ); cout << "something not right here..." << endl; } catch( std::logic_error ) { // an exception should get thrown... // so the lines of code here should // be run, not the cout statement... } try { FlashDrive f( -1, -1, false ); cout << "something not right here..." << endl; } catch( std::logic_error ) { // an exception should get thrown... // so the lines of code here should // be run, not the cout statement... } }

flashdrive_3_0.h

// constructors FlashDrive( ); FlashDrive( int capacity, int used, bool pluggedIn );

void plugIn( ); void pullOut( ); void writeData( int amount ); void eraseData( int amount ); void formatDrive( );

// basic accessors and modifiers int getCapacity( ); void setCapacity( int amount ); int getUsed( ); void setUsed( int amount ); bool isPluggedIn( );

// overloaded +, -, >, <, >>, << friend FlashDrive operator+(const FlashDrive& fd1, const FlashDrive& fd2); friend FlashDrive operator-(const FlashDrive& fd1, const FlashDrive& fd2); friend bool operator>(const FlashDrive& fd1, const FlashDrive& fd2); friend bool operator<(const FlashDrive& fd1, const FlashDrive& fd2); friend ostream &operator<<( ostream &stream, const FlashDrive &fd ); friend istream &operator>>( istream &stream, FlashDrive &fd ); friend ostream &operator<<( ostream &stream, const FlashDrive fd ); friend istream &operator>>( istream &stream, FlashDrive fd );

int my_StorageCapacity; int my_StorageUsed; bool my_IsPluggedIn

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!