12th Standard CBSE Syllabus & Materials
12th Standard CBSE
CBSE 12th Economics Government Budget and the Economy Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Interface Python with MySQL - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Database Concept - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Data Communication - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Data Structures - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Computer Science Functions - New Previous year Question Papers Study Material - QB365 Set A

Published on: 02/03/2019
Object Oriented Programming in C++ Important Questions
Download CBSE Class 12th Standard CBSE Computer Science question papers, sample papers, important questions, and previous year solved papers in PDF format. Get free study materials, NCERT solutions, and exam preparation resources for Class 12th Standard CBSE Computer Science
Questions + Answers key
Take MCQ Computer Science Test

1.
Answer the questions (i) and (ii) after going through the following class:
class Interview
{
int Month;
public:
Interview(int y) //Constructor 1
{
Moth = y;
}
Interview(Interview &t);
//Constructor 2
};
(i) create an object, such that it invokes Constructor 1.
(ii) Write the complete definition for Constructor 2.
2.
rewrite the following program after removing the synthetical error (if any). Underline each correction.
#include<iostream.h>
#include<stdio.h>
class AUTO
{
char model[20];
float price;
AUTO()
{
price = 0;
strcpy (Model),"NULL";
}
public
void GetInfo()
{
cin>>price;
gets(model);
}
void PutInfo()
{
cout<<etw(10)<<price<<setw(10);
cout<<Mode<<end1;
}
}
void main()
{
AUTO Car;
Car.GetInfo();
Car.PutInfo();
}
3.
What is the relationship between class and object?Illustrate with a suitable example.
4.
How are objects implemented in C++?
5.
Answer the questions (i) and (ii) after going through the following class:
class Motor
{
int MotorNo , Track;
public
Motor ( ) ; //Function 1
Motor (int MN) ; //Function 2
Motor (Motor &M) ; //Function 3
void Allocate ( ) ; //Function 4
void Move ( ) ; //Function 5
} ;
void main ( )
{
Motar M;
:
:
}
(i) Out of the following, which option is correct for calling Function 2?
Option 1 - Motor N (M) ;
Option 2 - Motor P (10) ;
(ii) Name the feature of object oriented programming, which is illustrated by Function 1, Function 2 and function 3 combined together.
6.
Find The output of the following program:
# include
class METRO
{
int Mno , TripNo , PassengerCount;
public:
METRO (int Tmno = 1)
{
Mno = Tmno;
TripNo=0;
PassengerCount = 0;
void Trip (int PC=20)
{
TripNo++;
PassengerCount += PC;
}
void StatusShow ( )
{
count<<Mno<<<<":"<<TripNo<<":"<<Passengercount<<end1;
};
void main ( )
{
METRO M (5) , T;
M. Trip ( );
T. Trip (50);
M. StatusShow ( );
M. Trip (30) ;
T. StatusShow ( );
M. StatusShow ( );
7.
Rewrite the following program after removing the syntactical errors (if any). Underline each correction.
#include<iostream.h>
class Item
{
long IId, Qty;
public:
void Purchase
{
cin>>IId>>Qty;
}
void Sale( )
{
cout<<setw(5)<<IId<<"old:"<<Qty<<end1;
cout<<"New:"<<- -Qty<<end1;
}
} ;
void main( )
{
Item I;
Purchase( );
I.Sale( );
I.Sale( )
}
8.
What is the significance of (::) scope resolution operator?
9.
What will be the output of the following program?
int area (int s)
{
return (s*s);
}
float area (int b, int h)
{
return (0.5*b*h);
}
void main()
{
cout< cout< cout< getch();
}
10.
Why do you think function overloading must be a part of an OOP?
11.
Given the following c++ code, answer the question (i) and (ii)
class ReadBook
{
public:
Readbook() // Function 1
{
cout<<"open the book"<<end1;
}
void Readchpter() // Function 2
{
cout<<"reading chapter ome"<<end1;
}
~readbook() // Function 3
{
cout<<"close the book"<<end1;
}
};
(i) In object oriented programming, what Function 1 is referred as and when does it get invoked/called?
(ii) In object oriented programming, what Function 3 is referred as and when does it get invoked/called?
12.
Answer the question (i) to (iv) based on the following code:
class Trainer
{
char TNo[5], TName[20];
char Specialisation[10];
int Days;
priotected:
float Remuneration;
void AssignRem(float);
public:
Trainer();
void TEntry();
void TDisplay();
};
class Learner
{
char Regno[10], LName[20], Program[10];
protected:
int Attendance, Grade;
public:
Learner();
void LEntry();
void LDisplay();
};
class Institute : publicLearner, oublic Trainer
{
char ICode[10], IName[20];
public:
Institute();
void IEntry();
void IDisplay();
};
(i) Which type of Inheritance is shown in the above exmple?
(ii) Identify the member function(s) that cannot be called directly from the objects of class Insitute from the following
(a) TEntry()
(b) LDisplay()
(c) IEntry()
(iii) Write name of all the data members accessible from member functions of class Insitute.
(iv) If class Insitute was derived privately from class Learner and privately from class Trainer, then name the member functions that could be accessed through objects of class Insitute.
13.
Answer the questions (i) to (iv) based on the following code:
class FRUIT
{
int FID;
//Identification number
char type[20];
protected:
char Description[20];
float Cost;
public:
FRUIT();
void Set_values();|
void Show_values();
};
class FRESH : public FRUIT
{
char color[10];
protected:
char Agent[20];
public:
FRESH();
void Read-values();
void Display_values();
};
class DECORATIVE : protected FRUIT
{
float Dec_charges;
public:
void input();
void output();
};
(i) Write the names of data members, which are accessible by objects of class type DECORATIVE.
(ii) Write the names of all member functions, which are accessible by the member functions of class FRESH.
(iii) Name the type Inheritance used in the above class?
(iv) How many bytes will be required by an object of class type DECORATiVE?
14.
Consider the following C++ code and answer the questions from (i) to (iv)
class Campus
{
long Id;
char City[20];
protected:
char Country[20];
public:
Campus();
void Resister();
void Display();
};
class Dept : private Campus
{
long DCode[10];
char HOD[20];
protected:
double Budget;
public:
Dept();
void Enter();
void Show();
};
class Applicant : public Dept
{
long RegNo;
char Name[20];
public:
Applicant();
void Enroll();
void View();
};
(i) Which type of inheritance is shown in the above example?
(ii) Write the names of those member functions, which are directly accessed from the objects of class Applicant.
(iii) Write the names of those data members, which can be directly accessed from the member functions of class Applicant.
(iv) Is it possible to directly call function Display()of class University from an object of class Dept?
(Answer as Yes or No).
15.
To illustrate the use of friend keyword.
16.
How does a compiler decide as to which function should be invoked when there are many functions with the same name?
17.
How an object differs from a program module?
18.
How are abstraction and encapulation interrelated?
19.
Which function is called during each function call in the program given below?
int sum(int); //Function[I]
float sum(float); //Function[II]
double sum(double); //Function[III}
void main()
{
int x=20;
int a=sum(x); //call1
float b=sum(x); //call2
double c=sum(x); //call3
getch();
}
20.
How are the object's behaviour and object's characteristics represented in OOP?
1.
(i) Interview objl(7);
(ii) Interview(Interview &t)
{
Month = t.month;
}
2.
#include<iostream.h>
#include<stdio.h>
#include<iomanip.h>
#include<String.h>
class AUTO
{
char model[20];
float price;
public:
AUTO()
{
price = 0;
strcpy (Model),"NULL";
}
public
void GetInfo()
{
cin>>price;
gets(model);
}
void PutInfo()
{
cout<<etw(10)<<price<<setw(10);
cout<<Mode<<end1;
}
};
void main()
{
AUTO Car;
Car.GetInfo();
Car.PutInfo();
}
3.
A class cannot be assigned to memory until the object is created.An object is a class variable, i.e. class is a data type and object is a variable of class type.Without class, object instantiation is not possible.Hence, we can say that an object does not exist without class and a class has no value without object.So, they are related to each other.
e.g. A class Box is given as follows:
class Box
{
int height;
int width;
int length;
public:
double volume (int h, int w, int l)
{
height = h;
width = w;
length = l;
return (height * width * length);
}
} ;
The above class will not assigned memory until the object is instantiated.
The object instantiation is given below:
Box b1;
After the object instantiated it will take place in memory.
Box:b1
| height width length |
| volume() |
4.
Objects are implemented in C++ as follows:
(i) The properties/characteristics are implemented by the data members or member variables.
(ii) Behaviour of an object is determined by its member function or method.
(iii) To identify each object, unique name is given to each of the objects.
5.
(i) Option 2-Motor P (10) is correct
(ii) Constructor overloading.
6.
5:1:20
1:1:50
5:2:50
7.
#include<iostream.h>
#include<iomanip.h>
class Item
{
long IId, Qty;
public:
void Purchase( )
{
cin>>IId>>Qty;
}
void Sale( )
{
cout<<setw(5)<<IId<<"old:"<<Qty<<end1;
cout<<"New:"<<- -Qty<<end1;
}
} ;
void main( )
{
Item I;
I.Purchase( );
I.Sale( );
I.Sale( );
}
8.
Member functions can be defined within the class definition or separately using scope resolution operator(::), Scope resolution operator specifies that the scope of the function is restricted to the class_name.
#include<iostream.h>
class Box
{
double length;
double breadth;
double height;
public:
double getVolume(void);
};
double Box :: getVolume(void)
{
return length*breadth*height;
}
9.
25
6
27
10.
A function overloading must be a part of an OOP because it is a feature that implements the polymorphism in object-oriented programming.i.e. the ability of an object to behave differently in different circumstance can effectively be implemented in programming through overloading.
Also, with the function overloading, the programmer is relieved of the burden of choosing right function for a given set of values.This important responsibility is carried out by the compiler when function is overloaded.
11.
(i) Function 1 is referred to as constructor and it gets invoked when an object gets created.
(ii) Function 3 is referred to as constructor and it gets invoked when an object goes out of scope.
12.
(i) Multiple Inheritance
(ii) None(since, all of these functions can be called from object of class Insitute).
(iii) Remuneration, Attendance, Grade, ICode, IName
(iv) IEntry(), IDisplay()
13.
(i) Data member:
None
(ii) Member functions:
void Read_values()
void Display_values()
void Set_values()
void Show_values()
(iii) Hierarchical Inheritance.
(iv) Number of bytes required by an object of class type DECORTIVE :50 Bytes
14.
(i) Multilevel Inheritance.
(ii) Member functions directly accessible through the objects of class Applicant are:
Enroll(), View(), Enter(), Show().
(iii) Data members directly accessible to the member functions of class Applicant are:
RegNo, Name, Budget.
(iv) No, because in the given program there is no class named University.
15.
#include<iostream.h>
#include<conio.h>
class Box
{
double width;
public:
friend void printWidth(Box box);
void setWidth(double wid);
} ;
void Box :: setWidth(double wid)
{
width = wid;
}
//Note: printWidth() is not a
//member function of any calss.
void printWidth(Box box)
{
/* Because printWidth() is a friend of Box, it
can directly access any number of this class*/
cout<<"Width of box "<<box.width<<end1;
}
void main()
{
Box box;
box.setWidth(10.0);
/* Use friend function to print the width*/
printWidth(box);
getch();
}
When the above code is compiled and excuted, it produces following result:
Width of box 10
16.
( )
The compiler differentiates between functions with same name by the number of arguments and the data type of arguments that are given with function declaration and the function call.
17.
( )
An object is areal world entity that consists of both data and function and this integrated unit
provides the necessary behaviour expected from the object.While a program module is a piece of code,which performs a particular function or set of functions.
18.
( )
Encapsulation means binding of data members and member functions (which operates on the data) into a single unit and ensure that only important features get represented without
background details I.e. called abstraction. Encapsulation is a way to implement data abstraction. Therefore,both are interrelated.
19.
( )
Call 1,2 and 3 will invoke only function [I] because controls with match only function [I] at each
time.It is being called.And each time return value will ba an integer that can be assigned to a
higher data type easily.
20.
( )
An object's behaviours and object's characteristics are represented in terms of member functions of a class and data members of a class.
12th Standard CBSE Syllabus & Materials
12th Standard CBSE
CBSE 12th Computer Science Python Revision Tour I - New Previous year Question Papers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Business Studies Planning Important Questions And Answers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Business Studies Business Environment Important Questions And Answers Study Material - QB365 Set A
NEW12th Standard CBSE
CBSE 12th Business Studies Principles of Management Important Questions And Answers Study Material - QB365 Set A
CBSE 12th Standard CBSE Subjects
CBSE Standards