Question: Project 16: Inherited FlashDrive Please provide the code for the .h file. .cpp file. and main file all in c++ PLEASE COMMENT OUT TITLES IN

Project 16: Inherited FlashDrive

Please provide the code for the .h file. .cpp file. and main file all in c++

PLEASE COMMENT OUT TITLES IN CODE

thanks

Project 16: Inherited FlashDrive Using the FlashDrive class provided in this link - https://pastebin.com/fVZ4TZjq , upgrade the class so that it throws subclasses of the exception class std::logic_error when the user does silly things. In the past, about all you could do when the user demanded silly operations was use cout to state your displeasure over making an overflowing FlashDrive (one where its contents exceeded its size) or an underflowing FlashDrive (one with a negative contents values). In the past, you blindly used std::logic_error. However now that you have seen inheritance, Id like you to make your FlashDrive class throw more specific exceptions at various times. For example, if while using operator-, you end up with a FlashDrive with a negative contents, throw a UnderflowingFlashDriveException back at the user. If while using operator+, you end up with a FlashDrive with more contents than its size allows, throw a OverflowingFlashDriveException at the user. A revised sample driver is shown below. Throw the right kind of subclasses exception anytime your user makes silly demands on you.

I'd like you to enhance this class so that invoking its methods or operators potentially throw a custom exception, rather than just a std::logic_error. As you may recall, you can create a logic_error by passing a string value to its constructor. You say #include to begin working with logic_error.

HINT: Recall that you can create a logic_error by passing a string message. For example,

std::logic_error error( "Bad News" );

While not required with Visual Studio, please #include when working with this class. Linux fans will require this include; its optional for Windows users but wont hurt anything if you do it.

Project 16: Inherited FlashDrive Please provide the code for the .h file.

Following the diagrams show below, create the class UnderflowingFlashDriveException and OverflowingFlashDriveException. Like other exception subclasses seen in class, these classes don't need any methods or members at all - just a public constructor and to inherit from std::logic_error.

FURTHER HINT: Please scroll down to the end to see the changes to the driver code made for Unit 17 purposes...

Driver Code

#include  
#include "OverflowingFlashDriveException.h" 
#include "UnderflowingFlashDriveException.h" 
#include "FlashDrive.h" 
void main( ) { using namespace cs52; cs52::FlashDrive empty; cs52::FlashDrive drive1( 10, 0, false ); cs52::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 cs52::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  
if (combined > other) { cout  other) { cout  
if (drive2  
// let's throw some exceptions... 
try { empty = empty  combined; cout  
try { drive2.writeData( 10000 ); cout  
// work with the new stuff added for Unit 16!!! 
cs52::FlashDrive * drive3 = NULL; // careful... cout  
drive3 = &drive2; cout  
drive3 = new FlashDrive(); cin >> drive3; cout  
delete( drive3 ); 
} 

Sample Output

----some tests follow---- A can with a size of 200 containing 8 items A can with a size of 10 containing 0 items > is working...

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!