Prerequisites
The code must compile with c++ and the flags -Wall -Wextra -Werror
Don't forget this project has to follow the C++98 standard. Thus,
C++11 (and later) functions or containers are NOT expected.
Any of these means you must not grade the exercise in question:
- A function is implemented in a header file (except for template
functions).
- A Makefile compiles without the required flags and/or another
compiler than c++.
Any of these means that you must flag the project with "Forbidden
Function":
- Use of a "C" function (*alloc, *printf, free).
- Use of a function not allowed in the exercise guidelines.
- Use of "using namespace <ns_name>" or the "friend" keyword.
- Use of an external library, or features from versions other than
C++98.
Class and Attributes
There is a ClapTrap class. It has all the following private attributes:
- name
- hit points
- energy points
- attack damage
These attributes are initialized to the requested values.
Member Functions
The following member functions are present and function as specified:
- attack()
- takeDamage()
- beRepaired()
Class and Attributes
There is a ScavTrap class. ScavTrap publicly inherits from the Claptrap class. It does not redeclare
the attributes. The attributes of the ClapTrap class are now protected instead of private. The
attributes are initialized to the requested values.
Member Functions
The following member functions are present and functional:
- attack()
- takeDamage() (inherited)
- beRepaired() (inherited)
The messages from the constructor, destructor, and attack() function must be different from those of
the ClapTrap.
Construction and Destruction
ScavTrap must have a constructor and destructor with specific messages. Their proper implementation
must be demonstrated by a sequence of calls in the expected order: if you create a ScavTrap, the message
from the ClapTrap constructor should be displayed first, followed by that of the ScavTrap. Conversely,
if you delete a ScavTrap, the message from the ScavTrap destructor should be displayed first, followed
by that of the ClapTrap.
Special Feature
ScavTrap has a guardGate() function that displays a message on the standard output. ScavTrap also has
an attack() function that displays a message different from that of the ClapTrap on the standard output.
Class and Attributes
There is a FragTrap class that publicly inherits from ClapTrap. Attributes should not be redeclared
without reason.
Construction and Destruction
FragTrap must have a constructor and destructor with specific messages. Their proper implementation
must be demonstrated by a sequence of calls in the expected order: if you create a FragTrap, the message
from the ClapTrap constructor should be displayed first, followed by that of the FragTrap. Conversely,
if you delete a FragTrap, the message from the FragTrap destructor should be displayed first, followed
by that of the ClapTrap.
Special Feature
FragTrap has a highFivesGuys() function that displays a message on the standard output.
The Ultimate Weirdness of C++
There is a DiamondTrap class. It inherits from both FragTrap and ScavTrap. It defines attributes with
the requested values. It uses virtual inheritance to avoid the pitfalls of diamond inheritance.
Choose Wisely...
The DiamondTrap class uses the attack() function of Scavtrap. It has the special functions of both its
parents. DiamondTrap has a private member std::string name. The whoAmI() function has access to both
name and ClapTrap::name.