Class 12 Computer Science Practice Assignments: CBSE Class 12 Computer Science Object Oriented Programming Concepts
Explore structured practice materials through the CBSE Class 12 Computer Science Object Oriented Programming Concepts. Tailored for Class 12 learners, utilizing these Computer Science assignments ensures thorough preparation and strengthens foundational knowledge before final CBSE evaluations.
Download Object Oriented Programming Concepts Assignment PDF with Solutions
Navigate directly to the solved Computer Science assignments using the digital viewer below. Each practice set includes detailed step-by-step solutions, allowing students to instantly cross-check their work and identify areas requiring further revision.
OBJECT ORIENTED PROGRAMMING CONCEPTS
OBJECT ORIENTED PROGRAMMING CONCEPTS
Object Oriented Programming follows bottom up approach in program design and emphasizes on safety and security of data.
FEATURES OF OBJECT ORIENTED PROGRAMMING:
Inheritance:
- Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class.
- Derived class is also known as a child class or sub class. Inheritance helps in reusability of code, thus reducing the overall size of the program.
Data Abstraction:
- It refers to the act of representing essential features without including the background details. Example: For driving, only accelerator, clutch and brake controls need to be learnt rather than working of engine and other details.
Data Encapsulation:
- It means wrapping up data and associated functions into one single unit called class.
- A class groups its members into three sections: public, private and protected, where private and protected members remain hidden from outside world and thereby helps in implementing data hiding.
Modularity:
- The act of partitioning a complex program into simpler fragments called modules is called as modularity.
- It reduces the complexity to some degree and creates a number of well defined boundaries within the program.
Polymorphism:
- Poly means many and morphs mean form, so polymorphism means one name multiple forms.
- It is the ability for a message or data to be processed in more than one form.
- C++ implements Polymorphism through Function Overloading, Operator overloading and Virtual functions.
Objects and Classes:
The major components of Object Oriented Programming are Classes & Objects.
A Class is a group of similar objects. Objects share two characteristics: They all have state and behavior. For example: Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming. These real-world observations all translate into the world of object-oriented programming.
Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through functions.
Classes in Programming:
- It is a collection of variables, often of different types and its associated functions.
- Class just binds data and its associated functions under one unit there by enforcing encapsulation.
- Classes define types of data structures and the functions that operate on those data structures.
- A class defines a blueprint for a data type.
Declaration/Definition:
A class definition starts with the keyword class followed by the class name; and the class body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon or a list of declarations.class class_name { access_specifier_1: member1; access_specifier_2: member2; ... } object_names;
Where class_name is a valid identifier for the class, object_names is an optional list of names for objects of this class. The body of the declaration can contain members that can either be data or function declarations, and optionally access specifiers.
[Note: the default access specifier is private.]
Example:class Box { int a; public: double length; double breadth; double height; };
Access specifiers in Classes:
Access specifiers are used to identify access rights for the data and member functions of the class. There are three main types of access specifiers in C++ programming language:
- private
- public
- protected
| Type of Access | Meaning |
|---|---|
| Private | Class members declared as private can be used only by member functions and friends (classes or functions) of the class. |
| Protected | Class members declared as protected can be used by member functions and friends (classes or functions) of the class. Additionally, they can be used by classes derived from the class. |
| Public | Class members declared as public can be used by any function. |
Importance of Access Specifiers:
Access control helps prevent you from using objects in ways they were not intended to be used. Thus it helps in implementing data hiding and data abstraction.
OBJECTS in C++:
Objects represent instances of a class. Objects are basic run time entities in an object oriented system.
Creating object / defining the object of a class:
The general syntax of defining the object of a class is:Class_name object_name;
In C++, a class variable is known as an object. The declaration of an object is similar to that of a variable of any data type. The members of a class are accessed or referenced using object of a class.Box Box1; // Declare Box1 of type BoxBox Box2; // Declare Box2 of type Box
Both of the objects Box1 and Box2 will have their own copy of data members.
Accessing / calling members of a class:
All members of a class are private by default. Private members can be accessed only by the member functions of the class itself. Public members of a class can be accessed through any object of the class. They are accessed or called using the object of that class with the help of dot operator (.).
The general syntax for accessing data member of a class is:Object_name.Data_member = value;
The general syntax for accessing member function of a class is:Object_name.Function_name(actual arguments);
The dot (.) used above is called the dot operator or class member access operator. The dot operator is used to connect the object and the member function.
Class methods definitions (Defining the member functions):
Member functions can be defined in two places:
1. Outside the class definition:
The member functions of a class can be defined outside the class definitions. It is only declared inside the class but defined outside the class. The general form of member function definition outside the class definition is:Return_type Class_name::function_name(argument list) { Function body }
Where symbol :: is a scope resolution operator. The scope resolution operator specifies the class to which the member being declared belongs, granting exactly the same scope properties as if this function definition was directly included within the class definition.
Example (Outside Definition):class sum { int A, B, Total; public: void getdata(); void display(); };void sum::getdata() { cout<<"\n enter the value of A and B"; cin>>A>>B; }void sum::display() { Total = A + B; cout<<"\n the sum of A and B="<<Total; }
2. Inside the class definition:
The member function of a class can be declared and defined inside the class definition.
Example (Inside Definition):class sum { int A, B, Total; public: void getdata() { cout<<"\n enter the value of A and B"; cin>>A>>B; } void display() { Total = A + B; cout<<"\n the sum of A and B="<<Total; } };
Differences between struct and classes in C++:
In C++, a structure is a class defined with the struct keyword. Its members and base classes are public by default. A class defined with the class keyword has private members and base classes by default. This is the only difference between structs and classes in C++.
INLINE FUNCTIONS:
- Inline functions definition starts with keyword inline.
- The compiler replaces the function call statement with the function code itself (expansion) and then compiles the entire code.
- They run a little faster than normal functions as function calling overheads are saved.
- A function can be declared inline by placing the keyword inline before it.
Example:inline void Square(int a) { cout<<a*a; }void main() { Square(4); // expands to { cout<<4*4; } Square(8); // expands to { cout<<8*8; } }
Pass Object As An Argument (Program):#include<iostream.h>#include<conio.h>class height { int feet, inches; public: void getht(int f, int i) { feet = f; inches = i; } void putheight() { cout<<"\nHeight is:"<<feet<<"feet\t"<<inches<<"inches<<endl; } void sum(height a, height b) { height n; n.feet = a.feet + b.feet; n.inches = a.inches + b.inches; if(n.inches == 12) { n.feet++; n.inches = n.inches - 12; } cout<<endl<<"Height is "<<n.feet<<" feet and "<<n.inches<<endl; } };void main() { height h, d, a; clrscr(); h.getht(6, 5); a.getht(2, 7); h.putheight(); a.putheight(); d.sum(h, a); getch(); }
Output:
Height is: 6feet 5inches
Height is: 2feet 7inches
Height is 9 feet and 0
4 Marks Solved Problems:
Question 1. Define a class TAXPAYER in C++ with following description : Private members : Name of type string, PanNo of type string, Taxabincm (Taxable income) of type float, TotTax of type double, A function CompTax() to calculate tax according to the following slab (Up to 160000: 0%, >160000 and <=300000: 5%, >300000 and <=500000: 10%, >500000: 15%). Public members : A parameterized constructor to initialize all the members, A function INTAX() to enter data for the tax payer and call function CompTax() to assign TotTax, A function OUTAX() to allow user to view the content of all the data members.
Answer:class TAXPAYER { char Name[30], PanNo[30]; float Taxabincm; double TotTax; void CompTax() { if(Taxabincm > 500000) TotTax = Taxabincm * 0.15; else if(Taxabincm > 300000) TotTax = Taxabincm * 0.1; else if(Taxabincm > 160000) TotTax = Taxabincm * 0.05; else TotTax = 0.0; } public: TAXPAYER(char nm[], char pan[], float tax, double ttax) { strcpy(Name, nm); strcpy(PanNo, pan); Taxabincm = tax; TotTax = ttax; } void INTAX() { gets(Name); cin>>PanNo>>Taxabincm; CompTax(); } void OUTAX() { cout<<Name<<"\n"<<PanNo<<"\n"<<Taxabincm<<"\n"<<TotTax<<endl; } };
In simple words: The class TAXPAYER stores personal tax details and computes income tax automatically based on government tax slabs using member functions.
Exam Tip: Always make calculation functions private so they cannot be invoked directly from outside the class, maintaining data security.
Question 2. Define a class HOTEL in C++ with the following description: Private Members: Rno (Room No), Name (Customer Name), Tariff (Per day charge), NOD (Number of days), CALC (A function to calculate and return amount as NOD*Tariff and if the value of NOD*Tariff is more than 10000 then as 1.05*NOD*Tariff). Public Members: Checkin() (A function to enter Rno, Name, Tariff and NOD), Checkout() (A function to display Rno, Name, Tariff, NOD and Amount by calling CALC()).
Answer:#include<iostream.h>class HOTEL { unsigned int Rno; char Name[25]; unsigned int Tariff; unsigned int NOD; int CALC() { int x; x = NOD * Tariff; if(x > 10000) return(1.05 * NOD * Tariff); else return(NOD * Tariff); } public: void Checkin() { cin>>Rno>>Name>>Tariff>>NOD; } void Checkout() { cout<<Rno<<Name<<Tariff<<NOD<<CALC(); } };
In simple words: The HOTEL class manages room bookings, applies a 5 percent surcharge if the total bill exceeds 10,000, and displays final billing details.
Exam Tip: Ensure that return types of helper functions match the required calculations and that conditional checks handle boundary values accurately.
Question 3. Define a class Applicant in C++ with following description: Private Members: ANo (Admission Number) of type long, Name of type string, Agg (Aggregate Marks) of type float, Grade of type char, GradeMe() (Member function to find Grade: >=80: A, <80 and >=65: B, <65 and >=50: C, <50: D). Public Members: Enter() (To enter values for ANo, Name, Agg & call GradeMe()), Result() (To view all data members).
Answer:class Applicant { long ANo; char Name[25]; float Agg; char Grade; void GradeMe() { if (Agg >= 80) Grade = 'A'; else if (Agg >= 65 && Agg < 80) Grade = 'B'; else if (Agg >= 50 && Agg < 65) Grade = 'C'; else Grade = 'D'; } public: void Enter() { cout<<"\n Enter Admission No. "; cin>>ANo; cout<<"\n Enter Name of the Applicant "; cin.getline(Name, 25); cout<<"\n Enter Aggregate Marks obtained by the Candidate :"; cin>>Agg; GradeMe(); } void Result() { cout<<"\n Admission No. "<<ANo; cout<<"\n Name of the Applicant "<<Name; cout<<"\n Aggregate Marks obtained by the Candidate. "<<Agg; cout<<"\n Grade Obtained is "<<Grade; } };
In simple words: The Applicant class accepts student scores, evaluates their grades based on specific cutoffs, and displays the complete report.
Question 4. Define a class ITEM in C++ with following description: Private members: Icode (Item Code), Item (Item Name), Price (Price of each item), Qty (Quantity in stock), Discount (Discount percentage on item), finddisc() (Calculate discount: Qty <=50: 0%, 50 < Qty <=100: 5%, Qty > 100: 10% of price). Public members: Buy() (To enter values and call finddisc()), showall() (To view all data members).
Answer:class ITEM { int Icode, Qty; char item[20]; float price, discount; void finddisc() { if(Qty <= 50) discount = 0; else if(Qty > 50 && Qty <= 100) discount = 0.05 * price; else if(Qty > 100) discount = 0.10 * price; } public: void buy() { cout<<"Item Code :"; cin>>Icode; cout<<"Name :"; gets(item); cout<<"Price :"; cin>>price; cout<<"Quantity :"; cin>>Qty; finddisc(); } void showall() { cout<<"Item Code :"<<Icode; cout<<"Name :"<<item; cout<<"Price :"<<price; cout<<"Quantity :"<<Qty; cout<<"Discount :"<<discount; } };
In simple words: The ITEM class handles inventory pricing and calculates tiered discounts based on stock quantity.
Exam Tip: Check variable name consistency across function definitions to avoid compilation errors.
4 marks Practice Problems:
Question 1. Define a class employee with the following specifications: Private members: empno (integer), ename (20 characters), basic, hra, da, netpay (float), calculate() (A function to calculate basic + hra + da with float return type). Public member functions: havedata() (To accept values and invoke calculate()), dispdata() (To display all data members).
Answer:class employee { int empno; char ename[20]; float basic, hra, da, netpay; float calculate() { return (basic + hra + da); } public: void havedata() { cout<<"Enter Employee Number: "; cin>>empno; cout<<"Enter Employee Name: "; gets(ename); cout<<"Enter Basic, HRA, DA: "; cin>>basic>>hra>>da; netpay = calculate(); } void dispdata() { cout<<"\nEmp No: "<<empno<<"\nName: "<<ename<<"\nNet Pay: "<<netpay; } };
In simple words: This class computes an employee's total salary by summing basic pay, house rent allowance, and dearness allowance.
Exam Tip: Ensure return-type functions like calculate() properly return computed float values back to calling variables.
Question 2. Define a class Student with the following specifications: Private members: roll_no (integer), name (20 characters), class (8 characters), marks[5] (integer), percentage (float), Calculate() (Calculates overall percentage of marks and returns it). Public members: Readmarks() (Reads marks and invokes Calculate()), Displaymarks() (Prints the marks).
Answer:class Student { int roll_no; char name[20]; char student_class[8]; int marks[5]; float percentage; float Calculate() { int sum = 0; for(int i = 0; i < 5; i++) sum += marks[i]; return ((float)sum / 500.0) * 100; } public: void Readmarks() { cout<<"Enter Roll No: "; cin>>roll_no; cout<<"Enter Name: "; gets(name); cout<<"Enter Class: "; cin>>student_class; cout<<"Enter marks for 5 subjects: "; for(int i = 0; i < 5; i++) cin>>marks[i]; percentage = Calculate(); } void Displaymarks() { cout<<"\nRoll No: "<<roll_no<<"\nName: "<<name<<"\nPercentage: "<<percentage<<"%"; } };
In simple words: The Student class stores student details and arrays of marks to compute their overall academic percentage.
Exam Tip: When using arrays in classes, loop through indices carefully during input and calculation routines.
Question 3. Define a class report with the following specification: Private members: adno (4 digit admission number), name (20 characters), marks (array of 5 floating point values), average (average marks obtained), getavg() (to compute average obtained in five subjects). Public members: readinfo() (accepts values and invokes getavg()), displayinfo() (displays all data members). Give function definitions.
Answer:class report { int adno; char name[20]; float marks[5]; float average; void getavg() { float sum = 0; for(int i = 0; i < 5; i++) sum += marks[i]; average = sum / 5.0; } public: void readinfo() { cout<<"Enter Admission Number: "; cin>>adno; cout<<"Enter Name: "; gets(name); cout<<"Enter 5 subject marks: "; for(int i = 0; i < 5; i++) cin>>marks[i]; getavg(); } void displayinfo() { cout<<"\nAdmission No: "<<adno<<"\nName: "<<name<<"\nAverage Marks: "<<average; } };
In simple words: The report class collects student marks in floating-point format and computes their subject average.
Exam Tip: Always initialize or compute summary fields like average immediately after reading input arrays.
Question 4. Declare a class myfolder with the following specification: Private members: Filenames (array of strings of size [10][25]), Availspace (long), Usedspace (long). Public members: Newfileentry() (Accepts values from user), Retavailspace() (Returns total Kilobytes available, where 1 Kilobyte = 1024 bytes), Showfiles() (Displays names of all files).
Answer:class myfolder { char Filenames[10][25]; long Availspace; long Usedspace; public: void Newfileentry() { cout<<"Enter available space (bytes): "; cin>>Availspace; cout<<"Enter used space (bytes): "; cin>>Usedspace; cout<<"Enter 10 file names:\n"; for(int i = 0; i < 10; i++) cin>>Filenames[i]; } long Retavailspace() { return (Availspace / 1024); } void Showfiles() { cout<<"\nFiles in folder:\n"; for(int i = 0; i < 10; i++) cout<<Filenames[i]<<endl; } };
In simple words: The myfolder class manages file collections and memory allocations, converting byte spaces into kilobytes.
Exam Tip: Double-check unit conversions (bytes to KB by dividing by 1024) in return functions.
2 Marks Practice Problems
Question 1. What is relation between class and object?
Answer: A class is a user-defined blueprint or template from which objects are created. An object is an instance of a class that represents a runtime entity with specific states and behaviors.
In simple words: A class is like a house blueprint, while an object is the actual physical house built from that blueprint.
Exam Tip: Remember that a class consumes no memory until an object of that class is instantiated.
Question 2. What are inline functions? Give example.
Answer: An inline function is a function whose code is inserted directly at every point where the function is called, eliminating function-calling overhead.
Example:inline int cube(int s) { return s * s * s; }
In simple words: Inline functions save execution time by replacing function calls with the actual function body during compilation.
Exam Tip: Inline functions are recommended for small, frequently used functions.
Question 3. Difference between private & public access specifiers.
Answer: Private members can be accessed only within the same class by member functions and friends. Public members can be accessed by any function or object outside the class.
In simple words: Private members are hidden from the outside world, whereas public members are globally accessible.
Exam Tip: By default, class members in C++ are private.
Question 4. How class implements data-hiding & encapsulation?
Answer: Encapsulation binds data and functions into a single unit (class). Data hiding is implemented by declaring data members as private, restricting direct external access and allowing modification only through public member functions.
In simple words: Encapsulation wraps data together, and access specifiers hide sensitive variables from unauthorized external access.
Exam Tip: Highlight that data hiding is achieved specifically through private and protected access specifiers.
Question 5. What is the difference between structure and a class?
Answer: In C++, the primary difference is that members and base classes of a structure (struct) are public by default, whereas members and base classes of a class are private by default.
In simple words: Struct members are public by default, while class members are private by default.
Exam Tip: Structs in C++ can also have member functions just like classes.
Question 6. How is inline function different from a normal function?
Answer: A normal function involves control transfer overhead (pushing/popping stack frames) during execution calls. An inline function's code is directly substituted at the call site by the compiler, saving execution time.
In simple words: Normal functions jump to separate code locations, while inline functions expand code directly in place.
Exam Tip: Large functions declared inline are typically treated as normal functions by the compiler.
Object Oriented Programming follows bottom up approach in program design and emphasizes on safety and security of data..
FEATURES OF OBJECT ORIENTED PROGRAMMING:
Inheritance:
¶ Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class.
¶ Derived class is also known as a child class or sub class. Inheritance helps in reusability of code , thus reducing the overall size of the program
Data Abstraction:
¶ It refers to the act of representing essential features without including the background details .Example : For driving , only accelerator, clutch and brake controls need to be learnt rather than working of engine and other details.
Data Encapsulation:
¶ It means wrapping up data and associated functions into one single unit called class..
¶ A class groups its members into three sections :public, private and protected, where private and protected members remain hidden from outside world and thereby helps in implementing data hiding.
Modularity :
¶ The act of partitioning a complex program into simpler fragments called modules is called as modularity.
¶ It reduces the complexity to some degree and
¶ It creates a number of well defined boundaries within the program .
Objects and Classes :
The major components of Object Oriented Programming are . Classes & Objects
A Class is a group of similar objects . Objects share two characteristics: They all have state and behavior. For example : Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, applying brakes). Identifying the state and behavior for realworld objects is a great way to begin thinking in terms of object-oriented programming.These real-world observations all translate into the world of object-oriented programming.
Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through functions
Classes in Programming :
• It is a collection of variables, often of different types and its associated functions.
• Class just binds data and its associated functions under one unit there by enforcing encapsulation.
• Classes define types of data structures and the functions that operate on those data structures.
• A class defines a blueprint for a data type. Declaration/Definition :A class definition starts with the keyword class followed by the class name; and the class body,
enclosed by a pair of curly braces. A class definition must be followed either by a semicolon or a list of declarations.
Free study material for Computer Science
CBSE Class 12 Computer Science Assignments for Object Oriented Programming Concepts
Class 12 Computer Science Object Oriented Programming Concepts Printable Assignments
Review targeted chapter assignments for Class 12 Computer Science Object Oriented Programming Concepts. Built according to official CBSE guidelines, these downloadable problem sets help students build accuracy and prepare effectively for school tests.
Why Practice Class 12 Computer Science Assignments?
- Curriculum Standards: Assignments match modern CBSE sample formats to ensure relevant preparation.
- Thorough Revision: Detailed problem sets reinforce core concepts and eliminate conceptual weak spots.
- Execution Speed: Timed practice with assignment sets sharpens overall response timing.
How to Approach Computer Science Object Oriented Programming Concepts Assignments
- Initial Reading: Begin by reading the NCERT book for Class 12 Computer Science to build a baseline understanding.
- Independent Testing: Attempt assignment questions unassisted, then verify work using provided answer keys.
- Supplementary Aids: Leverage revision notes and worksheets whenever you encounter difficult topics.
FAQs
You can download free PDF assignments for Class 12 Computer Science Object Oriented Programming Concepts from StudiesToday.com. These practice sheets have been updated for the 2026-27 session covering all concepts from latest NCERT textbook.
Yes, our teachers have given solutions for all questions in the Class 12 Computer Science Object Oriented Programming Concepts assignments. This will help you to understand step-by-step methodology to get full marks in school tests and exams.
Yes. These assignments are designed as per the latest CBSE syllabus for 2026. We have included huge variety of question formats such as MCQs, Case-study based questions and important diagram-based problems found in Object Oriented Programming Concepts.
Practicing topicw wise assignments will help Class 12 students understand every sub-topic of Object Oriented Programming Concepts. Daily practice will improve speed, accuracy and answering competency-based questions.
Yes, all printable assignments for Class 12 Computer Science Object Oriented Programming Concepts are available for free download in mobile-friendly PDF format.