Background:The purpose of this assignment is to practice dealing with exception handling. Exception handling is a very important part of being an object-oriented programming. Rather returning some kind of int return value every time you tickle an object, C++ programmers expect methods to focus on their task at hand. If something bad happens, C++ programmers expect methods to throw exceptions. When caught, exceptions can be processed. When uncaught, they cause a program to terminate dead in its tracks. The typical pattern in this course is to have class code throw exceptions and driver code catch them. Because of exceptions, when writing client driver code, our try blocks will not be polluted with error processing statements.
part_a: flashdrive 3.0 (exceptions)
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. You can acquire the source to the FlashDrive class by clicking here. Id 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 <stdexcept> to begin working with logic_error, but Visual Studio (being a badly behaved child) lets 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.
Id also like you to get operator << and operator >> working for the class FlashDrive.
|
|
![]()
|
![]()
|
Overall
- Your submission should follow this organization:
- part_a
- main.cpp
- flashdrive_3_0.h
- flashdrive_3_0.cpp
- part_a
Reviews
There are no reviews yet.