Skip to content

This project focuses on inheritance and polymorphism, using classes like ClapTrap, ScavTrap, FragTrap, and DiamondTrap to demonstrate single and multiple inheritance, including handling the diamond problem with virtual inheritance. It also covers function overriding to specialize behaviors in derived classes.

Notifications You must be signed in to change notification settings

lai-jia-jing/cpp-module-03

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

cpp-module-03

This project focuses on inheritance and polymorphism, using classes like ClapTrap, ScavTrap, FragTrap, and DiamondTrap to demonstrate single and multiple inheritance, including handling the diamond problem with virtual inheritance. It also covers function overriding to specialize behaviors in derived classes.

Final score

100%

ex00 - ClapTrap

In the first exercise, we are required to create a basic class called ClapTrap, which can perform actions like attacking, taking damage, and repairing itself. The class also contains private attributes such as a name, hit points, energy points, and attack damage.

ex01 - ScavTrap

The second exercise builds upon the first by creating a new class, ScavTrap, which inherits from the ClapTrap class and introduces additional functionality, such as the guardGate method. ScavTrap also has different default values for its hit points, energy points, and attack damage attributes.

ex02 - FragTrap

The third exercise introduces another class, FragTrap, which inherits from ClapTrap and adds its own functionality, such as the highFivesGuys method. FragTrap also has unique default values for its hit points, energy points, and attack damage attributes, differing from both ClapTrap and ScavTrap.

ex03 - DiamondTrap

The fourth and final exercise introduces the DiamondTrap class, which inherits from both ScavTrap and FragTrap, combining attributes from each. Despite inheriting from two classes, it only has one grandparent class, ClapTrap, ensuring that only one instance of ClapTrap is created upon instantiation. Additionally, DiamondTrap uniquely updates the name of its grandparent class during construction.


About

This project focuses on inheritance and polymorphism, using classes like ClapTrap, ScavTrap, FragTrap, and DiamondTrap to demonstrate single and multiple inheritance, including handling the diamond problem with virtual inheritance. It also covers function overriding to specialize behaviors in derived classes.

Topics

Resources

Stars

Watchers

Forks