Page 309 - Computer_Science_F5
P. 309

Computer Science  Developing program using    Abstraction in C++
               Activity 4.12:
                                                     Abstraction is the process of hiding the
                                                     complex  implementation  details  and
             encapsulation to manage student’s
                                                     showing only important  features  of
             examination
          FOR ONLINE READING ONLY
                                                     does rather than how it does it. The way
            Imagine you are an examination officer at   an object. It focuses on what an object
            Mpemba High school. Create a program     abstraction relates with encapsulation is
            to manage students’ examinations,        when encapsulation  is used to  achieve
            including their names, admission         abstraction.  In encapsulation, this is
            numbers, and scores for some subjects.
            The program  should calculate total and   done by hiding the internal details of an
            average scores of students.              object leaving only essential features.



           Public and Private Members in Abstraction

           Public Members
           Members declared as public are accessible  from outside the class, forming part
           of the class interface. These members, sometimes referred to as access specifiers,
           define the accessibility of class elements.

           For example, following part of code shows public member:
               class Library {
               public:

                   void addBook() {
                       // The code to add books of class Library will be written here
                    }
               };



           Private members
           Members declared as private cannot be accessed directly from outside the class.
           They can only be accessed by the class’s own methods. This helps in hiding the
           implementation details.

           For example, following part of code shows private member:
           class Car {

            private:
                int mileage;


                                                 300
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   300                                                     23/07/2024   12:34
   304   305   306   307   308   309   310   311   312   313   314