NAME: KWADWO WIAFE AKENTENG OKYERE
INDEX NUMBER: 2425403957
QUESTION
1. State and explain any five advantages of using object-
oriented programming over procedural programming.
ANSWER:
Modularity for easier troubleshooting: OOP groups
data and functions into self-contained objects. This
makes it easier to isolate and fix errors without
crashing the entire system.
Code reusability through inheritance: You can create a
new class that inherits properties from an existing one.
This eliminates the need to rewrite common code,
saving time and reducing bugs.
Data redundancy: Inheritance and polymorphism
allow developers to maintain a single repository of
code, which helps in reducing duplicate code
throughout the project.
Security through encapsulation: By using access
specifiers, OOP hides sensitive data from outside
interference, ensuring that internal object logic is not
accidentally modified.
Better productivity: OOPsystems can be easily
upgraded from small to large systems, and the
modular nature allows different team members to
work on different objects simultaneously.
QUESTION
2. Why is C++ considered an object-oriented
programming language? Explain your answer by
discussing any five object-oriented features supported by
C++ with simple examples.
ANSWER:
C++ is considered an OOP language because it supports
the creation and manipulation of objects-units that
combine data and methods that operates on them.
Classes and objects
A Class is a blueprint, while an Object is an instance of
that blueprint.
EXAMPLE: A class Car defines properties like speed,
while an object myTesla is a specific car with a speed of
100mph.
Encapsulation
This involves wrapping data and functions into a single
unit and restricting direct access to some component.
EXAMPLES: Using a private variable for a bank balance
so it can only be changed via a deposit() funtion.
INHERITANCE
Inheritance allows a “child” class to acquire the
properties of a “parent” class.
EXAMPLE: A class Dog can inherit from a class
Animal, gaining the eat() function automatically.
POLYMORPHISM
This allows one interface to be used for a general class of
actions. The most common form is “Function
Overloading”
EXAMPLE: A function draw() could behave differently
if you are drawing a Circle verses a Square.
ABSTACTION
Abstraction means showing only the essential features of
an object and hiding the complex background details.
EXAMPLE: When you use a pow(x, y) function, you
know it calculates power,but you do not need to see the
complex mathematical algorithm running inside.