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: 27/07/2018
Based on the chapter Object Oriented Programming in C++, some of the important questions are prepared in this question paper. It covers one mark, two and five marks questions from the book back and PTA question.
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.
Locate the error in the following program and write the correct program.
#include
#idefine 1000 MAX_SIZE;
typedef BYTE unsigned char
class MyClass
{
int m,n;
public:
void MyClass();
void get();
}
void MyClass:Myclass()
{
m=n=0;
}
void main()
{
MyClass MyObject;
int n=10;
int Arr[n];
for (i=0, i<=n, i++)
cin>>Arr[i];
}
2.
Discuss the benefits of constructor overloading. Can other member function of a class be also overload? What is your opinion?
3.
What do you understand by an array of objects? Explain with a suitable example.
4.
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 ( );
5.
Rewrite the following C++ program code after removing the syntax error(s) (if any).Underlining each correction.
include
class FLIGHT
{
long FlightCode;
char Description {25};
public:
void AddInfo( )
{
cin>>FlightCode;
gets(Description);
}
void ShowInfo( )
{
cout<
};
void main( )
{
Flight F;
AddInfo.F( );
ShowInfo.F( );
}
6.
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( )
}
7.
Rewrite the following program after removing the syntactical errors(if any).Underline each correction.
#include<iostream.h>
class Product
{
long PId, Qty;
public:
void Purchase
{
cin>>PId>>Qty;
}
void sale()
{
cout<<setw(5)<<PId<<"Old:"<<Qty<<end1;
cout<<"New:"<<--Qty<<end1;
}
} ;
void main()
{
Product P;
Purchase( );
P.Sale( );
P.Sale( );
}
8.
What is the difference between a struct and a class in C++?
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.
Write a program using overloaded function to compute the area of rectangle and area of triangle using hero's formula.
11.
With the multiple definition of single function name, what makes them significantly different?
12.
How does OOP overcome the shortcoming of traditional programming approach?
13.
How does a compiler decide as to which function should be invoked when there are many functions with the same name?
14.
Name the features by which classes acquier the properties of other classes.
15.
Does the return type of a function also help in finding the best match in function overloading?
16.
Write declaration for two overloadded functions named bar().They both return float type.the first takes one argument of type char and second takes two argument of type char.If this impossible,explain why?
17.
In function overloading how is matching done?
18.
How are abstraction and encapulation interrelated?
19.
Is this possible to declare two functions with same name and same argument but different return type in C++?
20.
When do you think function overloading be used?
21.
Why function overloading is used?
22.
How are the object's behaviour and object's characteristics represented in OOP?
23.
Consider the following C++ declaration and answer the question given below:
class Alpha
{
int x, y;
protected:
void PutValA()
public:
void GetValA();
};
class Beta : private Alpha
{
int m, n;
protected:
void PutValB()
public:
void GetValB();
};
class Gamma : protected Beta
{
int a:
public:
void GetData();
void ShowData();
};
(i) Write name of member function, wgich are accessible from the objects of class Gamma.
(ii) Write the name of the data members, which are accessible from the member function of class Beta.
(iii) Name the base class and the derived class of class Beta
(iv) Name the base class and derived class of class Gamma
24.
identify the syntax error(),if any
class ABC
{
int x = 100;
float y;
ABC()
{
y = 5;
}
~()
{ }
void main()
{
ABC a1,a2;
}
1.
#include
#idefine 1000 MAX_SIZE 100;
typedef BYTE unsigned char BYTE;
class MyClass
{
int m,n;
public:
void MyClass();
void get();
};
MyClass:Myclass()
{
m=n=0;
}
void main()
{
MyClass MyObject;|
int n=10;
int Arr[n];
for (int i=0, i<=n, i++)
cin>>Arr[i];
}
2.
Constructor overloading facilitates multiple ways of object creation. That is, with constructor overloading one can create objects without passing any value; by passing certain value; or as replica of an existing object. Yes, any member function of a class can be overloaded.
3.
An array of object is the collection of same type of object having the same properties and behaviors.An array of object can be defined in the same manner as we define array for build in type.
If we want to define an array of object of student type, we use the following syntax:
classname ArrayofObjectName[size];
consider a class student
class student
{
int rollNo;
char name[10];
void setdata( );
void getdata( );
}
student S[10];
where, S is an array of objects.
4.
5:1:20
1:1:50
5:2:50
5.
#include
//# is required before include
#include
class FLIGHT
{
long FlightCode;
char Description [25];
public:
void AddInfo( )
{
cin>>FlightCode;
gets(Description);
}
void ShowInfo( )
{
cout<
};
void main( )
{
Flight F;
F.AddInfo( );
//syntax is object.member_function
F.ShowInfo( );
}
6.
#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( );
}
7.
#include<iostream.h>
#include<iomanip.h>
class Product
{
long PId, Qty;
public:
void Purchase ( )
{
cin>>PId>>Qty;
}
void Sale ( )
{
cout<<setw(5)<<PId<<"Old:"<<Qty<<end1;
cout<<"New:"<<- -Qty<<end1;
}
} ;
void main( )
{
Product P;
P.Purchase( );
P.Sale( );
P.Sale( );
}
8.
The struct default access type is public.A struct should typically be used for grouping data.The class-default access type is private and the default mode for inheritance is private.
A class should be used for grouping data and methods that operate on that data.
In short, the convention is to use struct when the purpose is to group data and use classes when we require data abstraction and perhaps inheritance.
In C++, structures and classes are passed by value, unless explicitly dereferenced.In other languages, classes and structures may have distinct semantics, i.e. objects (instances of classes) may be passed by reference and structures may be passed by value.
Technically, there are only two differences between classes and structures:
(i) classes are declared using the keyword 'class' while structures are declared using the keyword 'struct'.
(ii) structures are entirely public, while classes are private by default.
9.
25
6
27
10.
A program using overloaded function to compute the area of rectangle and area of triangle using hero's formula.
#include<iostream.h>
#include<conio.h>
#include<math.h>
double area(int x, int y);
double area(int x, int y, int z);
void main()
{
int A,B,a,b,c;
double AREA;
clrscr();
cout<<"Enter the side of rectangle";
cin>>A>>B;
AREA=area(A,B);
cout<<"\nArea of rectangle="<<AREA;
cout<<"\nEnter the side of triangle";
cin>>a>>b>>c;
AREA=area(a,b,c);
cout<<"\nArea of triangle="<<AREA;
getch();
}
double area(int X, int Y)
{
return(x*y);
}
double area(int x, int y, int z)
{
float s=((x+y+z)/2);
return(sqrt(s*(s-x)*(s-y)*(s-z)));
}
Output
Enter the side of rectangle 10 20
Area of rectangle=200
Enter the side of triangle 70 45 45
Area of triangle=989.949494
11.
With the multiple definitions of single function name, the function
signature makes them significantly different.The function signature can be recognized by the list of argument.Either number of argument may differ or types of argument may differ in function declaration.Another difference is that the sequence of argument type may differ.So in short, we can say that function's signature makes them significantly different in making function with same name with multiple definitions
12.
An OOP overcome the shortcoming of traditional programming approach by implementing a real world problem into objects.An OOP provides an easy way to add new data and function while in traditional programming, it is very difficult to add new data and function.
For the security purpose, in OOP data cannot move easily from functions to functions.It can be kept public or private, so we can control the access of data but in POP, most function uses the global data for sharing, that can be accessed freely from function to function in the system that is the reason of security failed.
In traditional programming, the code reusability is not possible that is very important feature of a programming.While in OOP, through inheritance, the code reusability is possible.
13.
( )
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.
14.
( )
Inheritance is the feature by which classes acquire the properties of other classes.
15.
( )
No,compiler does not have any ceiteria to check function match using return type of a function.
Two functions can have same name and return type in function overloading.If the signatures of two function are same but different return type,it is not allowed by the computer.
16.
( )
Decleration of function is possible with overlading concept:
float bar(char ch)
{
__
__ statements
}
float bar(char ch1,char ch2)
{
__
__ statements
}
17.
( )
In function overloading, the matching is done on the basis of number of argument and types of argument.If two functions have same argument,then matching is done on the basis of sequence
or type of arguments.There is no rule of matching on the basis of return type.
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.
( )
No,it is not possible to declare two functions with same name and same argument but different
return type in C++,because the control will be confused at the time of calling which of these function will be executed first.
20.
( )
Function overloading is used when a function is required to perform for alternatives argument
types and there is a define way of optimising the function for the argument type.In such kind of
case,function overloading should be used.
21.
( )
Function overloading plays very important role to implement polymorphism.It is also used to make the program run faster and reduces the number of comparison in a program.
22.
( )
An object's behaviours and object's characteristics are represented in terms of member functions of a class and data members of a class.
23.
(i) GetData();
Show data().
(ii) m and n
(iii) The base class is alpha and the derived class is gamma .
(iv) There is no private member functionn in the class gamma.
24.
class ABC
{
int x = 100; //Data member cannot
float y; //be initialised within a class ABC
ABC()
{
y = 5;
}
~() //Name of destructor mising
{ }
void main()
{ //Missing semicolon(;) at the class end
ABC a1,a2;
}
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