C++ Exam Cheat Sheet (1-Page)

OOP C++ Exam Prep

Subject: Object-Oriented Programming with C++

For: Diploma in Computer Engineering (2nd Year)

Based on: Official Question Bank (Units 1–3)

UNIT 1: Principles of OOP

OOP Definition (2 marks)

Key Concept

OOP = Object-Oriented Programming. It uses objects (instances of classes) to model real-world entities. Focuses on data security, reusability, and modularity.

Core Concepts (Remember A PIE):

Abstracton → Hide internal details
Polymorphism → One name, many forms
Inheritance → Reuse parent class
Encapsulation → Bind data + functions

OOP vs POP (3 marks)

Feature OOP POP
Approach Bottom-up Top-down
Data & Functions Combined (in objects) Separate
Inheritance Yes No
Access Control (public/private) No
Examples C++, Java C, BASIC

Access Specifiers (3–4 marks)

Specifier Access
public Anywhere
private Only in class
protected In class & derived classes

private members cannot be accessed in main().

Scope Resolution Operator (::) (3 marks)

Used to:

  1. Access global variable when local has same name
  2. Define member functions outside class
int x = 10;
int main() {
    int x = 20;
    cout << ::x; // prints 10
}

UNIT 2: Functions, Classes & Objects

Inline Function (3–4 marks)

Function expanded at compile time for speed. Use inline keyword.

inline int cube(int a) {
    return a * a * a;
}

Use for short, frequently called functions.

Function Overloading (3–4 marks)

Same name, different parameters (number or type). Not by return type.

class Cal {
public:
    int add(int a, int b) { return a+b; }
    int add(int a, int b, int c) { return a+b+c; }
};

Friend Function (3 marks)

Non-member function that can access private members using friend.

class Test {
    int a;
public:
    friend void show(Test t);
};

void show(Test t) {
    cout << t.a; // OK!
}

Class & Object (2 marks)

Class

Blueprint (class Student {};)

Object

Instance (Student s1;)

An instance of a class = object created at runtime.

UNIT 3: Constructor & Destructor

Constructor (3 marks)

Special function with same name as class, called automatically when object is created. No return type.

Types:

1
Default → No parameters
2
Parameterized → Takes parameters
3
Copy → Initializes using another object

Parameterized Constructor (3–4 marks)

class Student {
public:
    int id;
    string name;
    Student(int i, string n) {
        id = i;
        name = n;
    }
};

// Usage: Student s(101, "Rahul");

Program: Student Details (3 marks)

#include <iostream>
using namespace std;

class Student {
public:
    int id;
    string name;
    float salary;
    Student(int i, string n, float s) {
        id = i;
        name = n;
        salary = s;
    }
    void display() {
        cout << id << " " << name << " " << salary << endl;
    }
};

int main() {
    Student s1(101, "Rahul", 50000);
    s1.display();
    return 0;
}

Write this in exam — covers Q25, Q27, and constructor use.

Quick Tips for Exam

Write Neatly & Underline

Underline keywords: private, friend, inline, ::

Draw Tables

For comparisons (OOP vs POP, access specifiers) to organize information clearly.

Write Small Code

Even 4 lines with comments = full marks. Focus on key concepts.

Time Management

Spend 1 min per 2 marks — don't over-write answers.

Don't Leave Blanks

If blank, write something — definition, syntax, or example.

Review Core Concepts

Focus on A PIE (Abstraction, Polymorphism, Inheritance, Encapsulation).