Unit 1: Principles of OOP
Object Oriented Programming using C++ notes · PTU syllabus (UGSEC2503)
On this page
Unit summary
Object-oriented programming (OOP) organises a program around objects — bundles of data and the functions that work on that data — instead of around a sequence of procedures. C++ adds OOP features to C. This unit introduces the principles of OOP, the structure of a C++ program and how it differs from procedural programming.
After this unit you can
- Explain the basic features of OOP
- Write, compile and run a simple C++ program
- Use cin, cout and namespaces
- Compare procedural and object-oriented programming
PTU syllabus topics
- Introduction to OOP and its basic features
- C++ program structure
- compiling and executing a C++ program
- procedural vs object-oriented languages
Encapsulation
Bundle data and functions; hide internals
Abstraction
Show only what users need
Inheritance
Reuse and extend existing classes
Polymorphism
One interface, many behaviours
Topic 1
Introduction to OOP
In procedural programming (C), a program is a list of functions working on shared data. As programs grow, any function can change any data, which makes them hard to maintain. OOP solves this by combining data and functions into objects and controlling access to the data.
Class and object
A class is a blueprint; an object is an instance
Encapsulation
Data and functions wrapped in one unit
Abstraction
Showing only essential details
Inheritance
A new class reuses an existing class
Polymorphism
One name, many forms
Dynamic binding and message passing
Call resolved at run time; objects communicate by calling functions
Topic 2
Benefits of OOP
- Reusability through inheritance — write once, extend many times.
- Data security through encapsulation and data hiding.
- Easier maintenance and modelling of real-world entities (Student, Account, Car).
- Extensibility — new features can be added with little change to existing code.
Topic 3
Structure of a C++ program
cpp#include <iostream> // header for input/output
using namespace std; // use names like cout directly
class Greeting { // class definition
public:
void show() { cout << "Welcome to SBS" << endl; }
};
int main() { // execution starts here
Greeting g; // object
g.show();
return 0;
}cout <<(insertion operator) prints;cin >>(extraction operator) reads input.endlor"\n"ends a line.- A typical program has: include files, class declarations, member function definitions, and the main function.
Topic 4
Compiling and executing a C++ program
- 1Write source
prog.cpp
- 2Compile
g++ prog.cpp -o prog
- 3Link
Libraries joined to make an executable
- 4Run
./prog
- 5Debug
Fix compile-time and run-time errors
Topic 5
Procedural vs object-oriented languages
Focus
Functions and steps
Objects: data plus behaviour
Data
Often global and shared freely
Hidden inside classes
Approach
Top-down
Bottom-up
Reuse
Copying functions
Inheritance
Security
Less
More through access specifiers
Examples
C, Pascal
C++, Java, Python
Key terms
- Object
- An instance of a class with its own data
- Class
- A user-defined blueprint describing data and functions
- Encapsulation
- Binding data and functions into one unit
- Abstraction
- Exposing only essential details
- Polymorphism
- The ability of one name to take many forms
Quick revision
- OOP features: class/object, encapsulation, abstraction, inheritance, polymorphism, dynamic binding.
- cout << prints; cin >> reads.
- Procedural is top-down; OOP is bottom-up.
- C++ = C + classes and OOP features.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.Define object-oriented programming.
- Q2.Differentiate between a class and an object.
- Q3.What is encapsulation?
- Q4.What are cin and cout?
- Q5.Differentiate between procedural and object-oriented programming.
- Q6.List three benefits of OOP.
Long-answer questions
- Q1.Explain the basic features of object-oriented programming with examples.
- Q2.Explain the structure of a C++ program with a sample program.
- Q3.Compare procedural and object-oriented programming languages in detail.
Stuck on this unit?
Message SBS on WhatsApp for help with Object Oriented Programming using C++, or to ask about studying BCA at Synetic.
