Page 311 - Computer_Science_F5
P. 311

Computer Science  Output:   Figure 4.74: Output of abstraction program






          FOR ONLINE READING ONLY
            In this program example, the  variables  a and b cannot be accessed  directly,
            however, you can call the function set() to set the values in a and b and the function
            display() to display the values of a and b.



             Activity 4.13:                           (b)   Implement  a Student class that
                                                           inherits  from  SchoolMember
             Implementing a simple school                  with  specific  attributes  like
             management system                             grade.

            Aim:                                      (c)   Ensure  both derived classes

            To understand and implement the                provide their own implementation
                                                           of the introduce() and getRole()
            concept of abstraction in C++ by               methods.
            creating a simple school management
            system with different types of members
                                                      Step 3: Implement main function
            Materials:                                 (a)  Instantiate  objects of  Teacher

            Computer     installed   with   C++            and Student.
            compilers, or online IDEs                 (b)  Call  their respective methods
                                                           to demonstrate polymorphic
            Instructions:                                  behavior.
            Step 1: Implement base class:             (c)  Print  out  the  introductions  and
            (a)   Create  an abstract base class           roles of the school members.
                  SchoolMember  with  common
                  attributes like name, age, and id.
            (b)   Define  pure  virtual  functions       Exercise 4.18
                  for actions like introduce() and   1.  Create a C++ program that simulates
                  getRole().                             a bank account system. Define a base
                                                         class BankAccount with private
            Step 2: Implement derived class:             attributes like accountNumber,
            (a)  Implement a Teacher class that          balance, and ownerName. Provide
                  inherits  from  SchoolMember           public methods to deposit and
                  with  specific  attributes  like       withdraw money, and to display
                  subject.                               account details.  Then, derive a


                                                 302
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   302                                                     23/07/2024   12:34
   306   307   308   309   310   311   312   313   314   315   316