Question: c++ inheritance project Background This assignment deals with inheritance. Inheritance is one of the major principles of object-oriented programming. In programming one of the biggest
c++ inheritance project
Background
This assignment deals with inheritance. Inheritance is one of the major principles of object-oriented programming. In programming one of the biggest goals is "code reuse". Inheritance accomplishes this in C++. In order to get inheritance working in C++, you must get both the structure of your .h files as well as the implementation of your constructor correct. Constructor implementations must use an initialization list. Please review the book and the online content on these issues so you know how it works before you begin.
Flashdrive 4.0 (inheritance)
The purpose of this assignment is to work with exceptions and inheritance. You will reuse code from previous assignments and further extend it. 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. Officially, you should also say #include to begin working with logic_error, but Visual Studio let's you get away with it, repl.it does not.
For this assignment, you will want to focus on subclassing std::logic_error. In each exceptional situation, rather than writing errors to cout or throwing std::logic_error, please create and throw a custom subclass as shown below:


Please remember that subclasses really MUST call their parent class constructors by using an initialization list.
// 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 +, -, >, >, (const FlashDrive& fd1, const FlashDrive& fd2); friend bool operator>( istream &stream, FlashDrive &fd ); friend ostream &operatorfd ); friend istream &operator>>( istream &stream, FlashDrive fd );
int my_StorageCapacity;
int my_StorageUsed;
bool my_IsPluggedIn
sample code:
| main.cpp : #include #include "flashdrive_4_0.h" #include "test.h" using namespace std; int main() { // let's throw some exceptions... cout > test_num; switch (stoi(test_num)) { case 1: exception_test_1(); break; case 2: exception_test_2(); break; case 3: exception_test_3(); break; case 4: personal_tests(); break; } } | test.h: #ifndef TEST_H #define TEST_H using namespace std; void personal_tests(); void exception_test_1(); void exception_test_2(); void exception_test_3(); #endif |
| test.cpp: #include void personal_tests(){ cout void exception_test_1() { FlashDrive empty(0,0, false); FlashDrive drive2(20, 1, false); try { empty = empty - drive2; cout void exception_test_2() { FlashDrive drive2(20, 0, false); try { drive2.writeData(10000); cout void exception_test_3() { try { FlashDrive f(-1, -1, false); cout | |
std: logic_error UnderflowingFlashDriveException OverflowingFlashDriveException
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
