CBSE Class 12 Computer Science Chapter 3: Implementation of OOP Concepts in C++ NCERT Solutions

NCERT Solutions PDF Class 12 PDF

This resource provides comprehensive NCERT Solutions for CBSE Class 12 Computer Science, focusing on Chapter 3: Implementation of OOP Concepts in C++. It covers fundamental Object-Oriented Programming (OOP) principles as applied in C++, including the definition and usage of classes, data members, member functions, constructors, and destructors. The solutions explain how to create objects, invoke member functions, and manage object lifecycles. Detailed explanations and code snippets are provided for each question, ensuring students grasp the practical application of OOP concepts. These solutions are designed to aid students in understanding complex topics, reinforcing learning, and preparing effectively for their board examinations by offering clear, step-by-step guidance on implementing OOP features in C++.

Quick info

BoardCBSE
ClassClass 12
SubjectComputer Science
Session2026
LanguageEnglish
TypeNCERT Solutions
Chapter3. Implementation of OOP Concepts in C++

Chapter summary

Chapter 3 of the CBSE Class 12 Computer Science syllabus focuses on the practical implementation of Object-Oriented Programming (OOP) concepts in C++. This NCERT Solutions set breaks down key topics such as defining classes, declaring private and public members, creating constructors and destructors, and using member functions for data manipulation and display. It addresses questions related to object instantiation and method invocation, providing clear explanations and code examples for each.

Learning outcomes

  • Understand the structure and syntax of a C++ class.
  • Differentiate between private and public members of a class.
  • Identify and explain the purpose of constructors and destructors.
  • Implement member functions to manipulate class data.
  • Write C++ code to create objects and call their member functions.
  • Apply OOP concepts to solve programming problems.

Topics covered

Paper topics

  • Class Definition
  • Data Members
  • Member Functions
  • Constructors
  • Destructors
  • Object Instantiation
  • Function Invocation
  • String Manipulation in C++
  • OOP Concepts in C++

Important topics

  • Class Definition and Members
  • Constructors and Destructors
  • Member Function Implementation
  • Object Creation and Usage
  • OOP Principles in C++

PDF preview

Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.

Loading document …
Page of
Loading page …

Questions and Solutions

Question 1

Observe the following C++ code and answer the questions (i) and (ii):

class Traveller {

long PNR;

char TName [20];

public:

Traveller ( ) // Function 1 { cout << "Ready" << endl; } void Book (long P, char N [ ]) // Function 2 { PNR = P;

strcpy (TName, N); } void print ( ) // Function 3 { cout << PNR << " " << TName << endl; } ~Traveller ( ) // Function 4 { cout << "Booking cancelled!" << endl; } };

  1. Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3 respectively in the following code:

void main ( ) { Traveller T;

//Line 1

//Line 2 } //Stops here

Solution:

To execute Function 2 (Book) and Function 3 (print) respectively, the following statements should be used:

  1. Line 1: To call Function 2, which is the Book function, we need to provide a long integer for PNR and a character array for TName. The statement would be:

    T.Book(1234567890, "Amit Kumar");

  2. Line 2: To call Function 3, which is the print function, we simply need to call it on the object T. The statement would be:

    T.print();

These statements ensure that the object T calls its Book function to set the PNR and name, and then calls its print function to display these details.

Question 2

Write the definition of a class PIC in C++ with the following description:

Private Members

  • Pno // Data member for Picture Number (an integer)
  • Category // Data member for picture category (a string)
  • Location // Data member for Exhibition Location (a string)
  • FixLocation // A member function to assign Exhibition Location as per category

The assignment logic for Location based on Category is:

Category Location
Classic Amina
Antique Ustad Khan

Public Members

  • Enter() // A function to allow user to enter values for Pno, Category and call FixLocation() function
  • SeeAll() // A function to display all the data members.
Solution:

Here is the C++ definition for the PIC class as per the description:

class PIC {

int Pno;

char Category[20];

char Location[20];

void FixLocation();

public:

void Enter();

void SeeAll(); }; Now, let's define the member functions:

// Definition for FixLocation()

void PIC::FixLocation() {

// Using strucmpi for case-insensitive comparison

if (strucmpi(Category, "Classic") == 0)

strcpy(Location, "Amina");

else if (strucmpi(Category, "Antique") == 0)

strcpy(Location, "Ustad Khan");

// Add other categories and locations as needed } // Definition for Enter()

void PIC::Enter() {

cout << "Enter Picture Number: ";

cin >> Pno;

cout << "Enter Category (e.g., Classic, Antique): ";

cin >> Category;

FixLocation(); // Call FixLocation to set the location based on category } // Definition for SeeAll()

void PIC::SeeAll() {

cout << "Picture Number: " << Pno << endl;

cout << "Category: " << Category << endl;

cout << "Location: " << Location << endl; }

Common mistakes

  • Incorrectly calling member functions or constructors.
  • Confusing the roles of constructors and destructors.
  • Errors in string manipulation functions like strcpy or strucmpi.
  • Forgetting to define or implement necessary member functions.

Revision tips

  • Review the syntax for class definition and member access.
  • Practice writing constructors and destructors for different scenarios.
  • Trace the execution flow for object creation and function calls.
  • Pay close attention to string handling in member functions.
  • Re-implement the provided code examples to solidify understanding.

Practice MCQs

Q1. In C++, what is the primary purpose of a constructor?

Q2. Which special member function is automatically called when an object goes out of scope or is explicitly deleted?

Q3. What does the `strucmpi` function do?

Q4. In the context of a class, what are data members?

Q5. What is the significance of the `public` keyword in a C++ class definition?

Frequently asked questions

What are the key OOP concepts covered in Chapter 3 of CBSE Class 12 Computer Science?

Chapter 3 focuses on the practical implementation of OOP concepts in C++, including defining classes, using data members and member functions, and understanding the roles of constructors and destructors.

How do these NCERT Solutions help in understanding C++ classes?

The solutions provide step-by-step explanations and code examples for creating and using classes, demonstrating how to define members, write member functions, and instantiate objects.

What is the difference between a constructor and a destructor in C++?

A constructor is used to initialize an object when it is created, while a destructor is used to clean up resources and destroy an object when it is no longer needed.

Are the code examples in the solutions runnable?

Yes, the code examples provided in the solutions are standard C++ code that can be compiled and run in a C++ environment to observe the behavior of OOP concepts.

How can I use these solutions for exam preparation?

You can use these solutions to understand the theoretical concepts, practice implementing them in C++, and review common question patterns related to OOP in C++ for your exams.

Content reviewed by the NCERT Help team. Editorial Team and update policy

NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.