MIDTERM EXAM LECTURE
FOR SOFTWARE AND COMPUTER ENGINEERS
EMIRHAN AR
, 16.1 Object-Oriented Programming (OOP)
Classes are used. Within a class, there are data members and member functions.
- Data Members: Information belonging to the object (e.g., name, age)
- Member Functions: Operations like print, calculate
- Object: An instance of a class. It occupies memory.
!!!!
In C++, OOP increases code reusability.
The code becomes modular: each object carries its own responsibility.
Main principles of OOP:
1. Encapsulation: Preventing direct access to data, using setters/getters instead
2. Inheritance: A class inherits properties and methods from another class, reducing code repetition
3. Polymorphism: The same method name can function differently in various classes 4. Abstraction:
Highlighting only essential features of a complex system/object, ignoring other details
- Function declaration: class Car { void start(); }; (Does not include a body since the result is not defined yet!)
- Definition: void write() { cout << "Hello"; } (Includes a body - result is "Hello")
To include a body: You need curly braces + a defined outcome