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
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started