Directions:Please complete the following assignment to signify your completion of Unit 17. All programming projects need to be completed and submitted electronically, following the Electronic Submission Guidelines discussed in class. Please cherry-pick from your solution folder and submit just the .cpp and .h files you created or modified as well as .exe file that Visual Studio built from your code.
Background:This assignment deals with inheritance. Inheritance is one of the major principles of object-oriented programming. In C++, one of the biggest goals is code reuse. Inheritance accomplishes this. 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..
part_a: flashdrive 4.0 (inheritance)
The purpose of this assignment is to work with exceptions and inheritance. As you may recall, I have provided you with a sample class named FlashDrive which has been diagrammed below. You will reuse code from previous assignments and further extend it. Id 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. 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 with it.
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.
|
|
![]()
|
![]()
|
part_b: Gambler
Id like you to make two inherited gambler classes as described below. A Gambler is a casino player. A SlotPlayer is a kind of Gambler who plays casino slot machines. The relationship between these two classes is shown in the diagram shown below.
![]()
|
Please remember that subclasses really MUST call their parent class constructors by using an initialization list.
Gambler |
Driver Code |
|
Gambler( std::string name );virtual void win( );virtual void lose( ); | Gambler g( Tom );SlotPlayer sp( Toms Mother );g.win( );sp.lose( );g.lose( );sp.win( ); | |
std::string myName; // protected | ||
SlotPlayer |
||
Sample Output |
||
SlotPlayer( std::string name );virtual void win( );virtual void lose( ); | ||
The Great Gambler Tom wins!The SlotPlayer Toms Mother loses 🙁The Great Gambler Tom loses!The SlotPlayer Toms Mother wins 🙂 | ||
- Your submission should follow this organization, all of which have been provided:
- part_a
- main.cpp
- flashdrive_4_0.h
- flashdrive_4_0.cpp
- part_b
- Gambler.cpp
- Gambler.h
- SlotPlayer.cpp
- SlotPlayer.h
- main.cpp
- part_a
Reviews
There are no reviews yet.