Các lượt nộp
    Danh sách bài
    Trang chủ
    Báo lỗi
    solution

    Đề bài: Multiple Inheritance & Combining "Is-A" with "Has-A"

    Multiple Inheritance & Combining "Is-A" with "Has-A"

    Focus: Multiple inheritance (class Derived : public Base1, public Base2), scope resolution for disambiguation, composition ("Has-A") inside an inheritance hierarchy ("Is-A"), and constructor execution sequencing.

    Scenario & Requirements:

    An academic department needs to model a senior faculty member who serves both as a lecturer (GiangVien) and an administrative manager (CanBoQuanLy), while being assigned an office room (PhongLamViec).

    1. Base Class 1 GiangVien:
      • Attributes: maGV (std::string), luongGiangDay (double).
      • Methods: Constructor, nhap_gv(), xuat_gv().
    2. Base Class 2 CanBoQuanLy:
      • Attributes: chucVu (std::string), phuCapChucVu (double).
      • Methods: Constructor, nhap_ql(), xuat_ql().
    3. Composed Class PhongLamViec ("Has-A" component):
      • Attributes: soPhong (std::string), toaNha (std::string).
      • Methods: Constructor, nhap_phong(), xuat_phong().
    4. Derived Class GiangVienQuanLy (inherits public GiangVien, public CanBoQuanLy):
      • Composed Member: PhongLamViec phong (Embedded object).
      • Methods:
        • Constructor demonstrating the explicit call order: GiangVien -> CanBoQuanLy -> phong -> GiangVienQuanLy.
        • tinhTongThuNhap(): Returns luongGiangDay + phuCapChucVu.
        • nhap() and xuat() combining base methods and component methods.
    5. main() Program:
      • Instantiate a GiangVienQuanLy object to verify that constructors and destructors execute in the correct, predictable sequence.
    • Định dạng đầu vào:

      The program accepts data for a combined academic manager (GiangVienQuanLy) across three distinct sub-sections:

      • Teaching Credentials (GiangVien attributes):
        • maGV (Lecturer ID): A non-empty string token or line (e.g., "GV001").
        • luongGiangDay (Teaching Base Salary): A non-negative floating-point number (double >= 0.0).
      • Management Role (CanBoQuanLy attributes):
        • chucVu (Management Position): A string describing the title (e.g., "Head of Department", "Vice Dean").
        • phuCapChucVu (Position Allowance): A non-negative floating-point number (double >= 0.0).
      • Office Location (PhongLamViec component attributes):
        • soPhong (Office Room Number): A string token (e.g., "P1310", "Room 402").
        • toaNha (Building Name): A string token (e.g., "Building A1").
    • Ràng buộc đầu vào:
      • Class Architecture & Relationships:
        • Multiple Inheritance ("Is-A"): GiangVienQuanLy must inherit publicly from both GiangVien and CanBoQuanLy (class GiangVienQuanLy : public GiangVien, public CanBoQuanLy).
        • Composition ("Has-A"): GiangVienQuanLy must contain a private member object instance of PhongLamViec (PhongLamViec phong;).
      • Encapsulation & Scope:
        • All member attributes across all four classes (GiangVien, CanBoQuanLy, PhongLamViec, and GiangVienQuanLy) must be declared private.
        • Modification of member variables outside class boundaries is prohibited; access must go through getters or constructors.
      • Constructor Initialization Order:
        • The constructor of GiangVienQuanLy must use a member initializer list to pass parameters in explicit execution order:
          1. Base class 1: GiangVien(id, teachingSalary)
          2. Base class 2: CanBoQuanLy(position, allowance)
          3. Composed object: phong(room, building)
      • Scope Resolution Rule:
        • Overridden or aggregated methods inside GiangVienQuanLy must invoke base and component methods using scope resolution (GiangVien::xuat_gv(), CanBoQuanLy::xuat_ql(), and phong.xuat_phong()).
    • Định dạng đầu ra:
      • Calculated Values:
        • Total Income (tinhTongThuNhap()): Dynamically calculated as luongGiangDay + phuCapChucVu and formatted to 2 decimal places.
      • Console Formatting:
        • Output must be aligned in a formatted table using <iomanip> stream manipulators (std::left, std::setw, std::fixed, std::setprecision(2)).

    Chủ đề

    🧩 Lập trình hướng đối tượng🔷 C++C++OOPTất cả môn học

    Đang tải editor...