└── Inheritance /Inheritance: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity 0.8.17; 4 | 5 | /** 6 | * @title Employee 7 | * @dev Abstract contract defining common properties and behavior for employees. 8 | */ 9 | abstract contract Employee { 10 | uint public idNumber; // Unique identifier for the employee 11 | uint public managerId; // Identifier of the manager overseeing the employee 12 | 13 | /** 14 | * @dev Constructor to initialize idNumber and managerId. 15 | * @param _idNumber The unique identifier for the employee. 16 | * @param _managerId The identifier of the manager overseeing the employee. 17 | */ 18 | constructor(uint _idNumber, uint _managerId) { 19 | idNumber = _idNumber; 20 | managerId = _managerId; 21 | } 22 | 23 | /** 24 | * @dev Abstract function to be implemented by derived contracts to get the annual cost of the employee. 25 | * @return The annual cost of the employee. 26 | */ 27 | function getAnnualCost() public virtual returns (uint); 28 | } 29 | 30 | /** 31 | * @title Salaried 32 | * @dev Contract representing employees who are paid an annual salary. 33 | */ 34 | contract Salaried is Employee { 35 | uint public annualSalary; // The annual salary of the employee 36 | 37 | /** 38 | * @dev Constructor to initialize the Salaried contract. 39 | * @param _idNumber The unique identifier for the employee. 40 | * @param _managerId The identifier of the manager overseeing the employee. 41 | * @param _annualSalary The annual salary of the employee. 42 | */ 43 | constructor(uint _idNumber, uint _managerId, uint _annualSalary) Employee(_idNumber, _managerId) { 44 | annualSalary = _annualSalary; 45 | } 46 | 47 | /** 48 | * @dev Overrides the getAnnualCost function to return the annual salary of the employee. 49 | * @return The annual salary of the employee. 50 | */ 51 | function getAnnualCost() public override view returns (uint) { 52 | return annualSalary; 53 | } 54 | } 55 | 56 | /** 57 | * @title Hourly 58 | * @dev Contract representing employees who are paid an hourly rate. 59 | */ 60 | contract Hourly is Employee { 61 | uint public hourlyRate; // The hourly rate of the employee 62 | 63 | /** 64 | * @dev Constructor to initialize the Hourly contract. 65 | * @param _idNumber The unique identifier for the employee. 66 | * @param _managerId The identifier of the manager overseeing the employee. 67 | * @param _hourlyRate The hourly rate of the employee. 68 | */ 69 | constructor(uint _idNumber, uint _managerId, uint _hourlyRate) Employee(_idNumber, _managerId) { 70 | hourlyRate = _hourlyRate; 71 | } 72 | 73 | /** 74 | * @dev Overrides the getAnnualCost function to calculate the annual cost based on the hourly rate. 75 | * Assuming a full-time workload of 2080 hours per year. 76 | * @return The annual cost of the employee. 77 | */ 78 | function getAnnualCost() public override view returns (uint) { 79 | return hourlyRate * 2080; 80 | } 81 | } 82 | 83 | /** 84 | * @title Manager 85 | * @dev Contract managing a list of employee IDs. 86 | */ 87 | contract Manager { 88 | uint[] public employeeIds; // List of employee IDs 89 | 90 | /** 91 | * @dev Function to add a new employee ID to the list. 92 | * @param _reportId The ID of the employee to be added. 93 | */ 94 | function addReport(uint _reportId) public { 95 | employeeIds.push(_reportId); 96 | } 97 | 98 | /** 99 | * @dev Function to reset the list of employee IDs. 100 | */ 101 | function resetReports() public { 102 | delete employeeIds; 103 | } 104 | } 105 | 106 | /** 107 | * @title Salesperson 108 | * @dev Contract representing salespeople who are paid hourly. 109 | */ 110 | contract Salesperson is Hourly { 111 | /** 112 | * @dev Constructor to initialize the Salesperson contract. 113 | * @param _idNumber The unique identifier for the employee. 114 | * @param _managerId The identifier of the manager overseeing the employee. 115 | * @param _hourlyRate The hourly rate of the employee. 116 | */ 117 | constructor(uint _idNumber, uint _managerId, uint _hourlyRate) 118 | Hourly(_idNumber, _managerId, _hourlyRate) {} 119 | } 120 | 121 | /** 122 | * @title EngineeringManager 123 | * @dev Contract representing engineering managers who are paid an annual salary and have managerial responsibilities. 124 | */ 125 | contract EngineeringManager is Salaried, Manager { 126 | /** 127 | * @dev Constructor to initialize the EngineeringManager contract. 128 | * @param _idNumber The unique identifier for the employee. 129 | * @param _managerId The identifier of the manager overseeing the employee. 130 | * @param _annualSalary The annual salary of the employee. 131 | */ 132 | constructor(uint _idNumber, uint _managerId, uint _annualSalary) 133 | Salaried(_idNumber, _managerId, _annualSalary) {} 134 | } 135 | 136 | /** 137 | * @title InheritanceSubmission 138 | * @dev Contract for deploying instances of Salesperson and EngineeringManager. 139 | */ 140 | contract InheritanceSubmission { 141 | address public salesPerson; // Address of the deployed Salesperson instance 142 | address public engineeringManager; // Address of the deployed EngineeringManager instance 143 | 144 | /** 145 | * @dev Constructor to initialize the InheritanceSubmission contract. 146 | * @param _salesPerson Address of the deployed Salesperson instance. 147 | * @param _engineeringManager Address of the deployed EngineeringManager instance. 148 | */ 149 | constructor(address _salesPerson, address _engineeringManager) { 150 | salesPerson = _salesPerson; 151 | engineeringManager = _engineeringManager; 152 | } 153 | } 154 | --------------------------------------------------------------------------------