Unit 1 of 4 · BCA Sem 2

Unit 1: Principles of OOP

Object Oriented Programming using C++ notes · PTU syllabus (UGSEC2503)

3 min read5 topics9 exam questions
On this page
  1. Unit summary
  2. Introduction to OOP
  3. Benefits of OOP
  4. Structure of a C++ program
  5. Compiling and executing a C++ program
  6. Procedural vs object-oriented languages
  7. Key terms
  8. Quick revision
  9. Important questions

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
FrameworkThe four pillars of OOP
  • Encapsulation

    Bundle data and functions; hide internals

  • Abstraction

    Show only what users need

  • Inheritance

    Reuse and extend existing classes

  • Polymorphism

    One interface, many behaviours

1

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.

ClassificationBasic features of OOP
OOP
  • 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

2

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.
3

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.
  • endl or "\n" ends a line.
  • A typical program has: include files, class declarations, member function definitions, and the main function.
4

Topic 4

Compiling and executing a C++ program

ProcessFrom source to output
  1. 1Write source

    prog.cpp

  2. 2Compile

    g++ prog.cpp -o prog

  3. 3Link

    Libraries joined to make an executable

  4. 4Run

    ./prog

  5. 5Debug

    Fix compile-time and run-time errors

5

Topic 5

Procedural vs object-oriented languages

ComparisonProcedural vs object-oriented
Procedural (C)
Object-oriented (C++)

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

  1. Q1.Define object-oriented programming.
  2. Q2.Differentiate between a class and an object.
  3. Q3.What is encapsulation?
  4. Q4.What are cin and cout?
  5. Q5.Differentiate between procedural and object-oriented programming.
  6. Q6.List three benefits of OOP.

Long-answer questions

  1. Q1.Explain the basic features of object-oriented programming with examples.
  2. Q2.Explain the structure of a C++ program with a sample program.
  3. 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.

WhatsApp us