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: 25/07/2019
Object Oriented Programming in C++
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.
Rewrite the following program after removing the syntactical errors (if any). Underline each correction.
#include [iostream.h]
class MEMBER
{
int Mno;float Fees;
PUBLIC:
void Register(){cin>>Mno>>Fees;}
void Display{cout<<Mno<<":"<<Fees<<endl;}
};
void main()
{
|MEMBER M;
Register ( );
M.Display ( );
}
2.
Rewrite the following program after removing the error(s), if any. Underline each correction
#include< iostream.h >
void main( )
{
int x,sum=0;
cin>>n;
for(x=1;x<100,x+2=2)
ifx%2=0
sum+=x;
cout<<"sum="sum;
}
3.
How does a class enforce data hiding, abstraction, and encapsulation?
4.
Why do you think function overloading must be a part of an OOP?
5.
Answer the questions (i) to (iv) based on the following code :
class CUSTOMER
{ int Cust_no;
char Cust_Name[20];
protected:
void Register();
public: CUSTOMER();
void Status(); };
class SALESMAN
{
int Salesman_no;
char Salesman_Name[20];
protected: float Salary;
public: SALESMAN();
void Enter( );
void Show( );
};
class SHOP :
private CUSTOMER , public SALESMAN
{
char Voucher_No[10];
char Sales_Date[8];
public:
SHOP();
void Sales_Entry();
void Sales_Detail();
}
(iii) Write the names of data members which are accessible from objects belonging to class CUSTOMER.
(iv) Write the names of all the member functions which are accessible from objects belonging to class SALESMAN.
(v) Write the names of all the members which are accessible from member functions of class SHOP. (iv) How many bytes will be required by an object belonging to SHOP?
6.
Define a class in C++ with following description:
Private Members
• A data member Flight number of type integer
• A data member Destination of type string
• A data member Distance of type float
• A data member Fuel of type float
• A member function CALFUEL() to calculate the value of Fuel as per the following criteria:
| Distamce | Fuel |
| <=1000 | 500 |
| more than 1000 and <=2000 | 1100 |
| More than 2000 | 2200 |
Public Members
" A function FEEDINFO( ) to allow user to enter values Flight Number,
Destination, Distance & call function CALFUEL ( ) to calculate the quantity of Fuel
" A function SHOWINFO ( ) to allow user to view the contebt of all the data members.
7.
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).
8.
Write the output of the following C++ code.Also, write the name of feature of object-oriented programming used in the following program jointly illustrated by the functions [I] to [IV].
9.
Find the output of the following program : 2
#include< iostream.h >
void main()
{
int Numbers[ ] = {2,4,8,10};
int *ptr = Numbers;
for (int C = 0; C<3; C++)
{ cout<< *ptr << “@”; ptr++;
}
cout<< &ptr<<"@";
ptr++;
cout<<end1;
fof(C=0;C<4;C++)
{
(*ptr)*=2;
-ptr;
}
for(C=0;C<4;C++)
cout<< Number[ C]<<"#";
cout<< end1;
}
10.
Write the output of the following program:
#include< iostream.h >
#include
int a =3;
void demo(int &x, int y, int *z)
{
a+= x; y*=a; *z = a+y;
cout<< a << “”<< x << “”<< y << ""<< z << end1;
}
void main( )
{
clscr( )
{
int a=2, b=5;
demo (::a,a,&b);
cout << ::a <<""<, a << "" << b << end1;
}
11.
To show the use of static variables.
12.
To illustrate the use of friend keyword.
13.
Observe the program segment carefully and answer the question that follows:
class student
{
int student name[20];
int mark;
public:
void enterDetail( );
void showDetail( );
void change_mark( ); //Function to change the mark
int getStudent_no( ){ return student_no;}
};
void modify( int y )
{
fstream File;
File.open( “student.dat”, ios::binary|ios::in|ios::out) ;
student i;
int recordsRead = 0, found = 0;
while(!found && File .read((char*) & i , sizeof (i)))
{
recordsRead++;
if(i . getStudent_no( ) = = y )
{
i . change_mark( );
____________//Missing statement 1
___________//Missing statement 2
found = 1;
}
}
if( found = = 1)
cout<<”Record modified” ;
File.close() ;
}
If the function modify( ) is supposed to change the mark of a student having student_no y in the file “student.dat”, write the missing statements to modify the student record.
14.
Observe the program segment carefully and answer the question that follows: class member
{
int member_no;
char member_name[20];
public:
void enterDetail( );
void showDetail( );
int getMember_no( ){ return member_no;}
};
void update(member NEW )
{
fstream File;
File.open( “member.dat”, ios::binary|ios::in|ios::out) ;
member i;
while(File .read((char*) & i , sizeof (i)))
{
if(NEW . getMember_no( ) = = i . getMember_no( ))
{
___________//missing statement
File.write((char*) &NEW , sizeof (NEW));
}
}
File.close() ;
}
If the function update( ) is supposed to modify the member_name field of a record in the file “ member.dat” with the values of member NEW passed as argument, write the appropriate statement for the missing statement using seekp( ) or seekg( ), whichever is needed, in the above code that would write the modified record at its proper place.
15.
Inheritance allows code reusability in OOp.Explain how?
16.
How are abstraction and encapulation interrelated?
17.
Why function overloading is used?
18.
How are the object's behaviour and object's characteristics represented in OOP?
1.
#include < iostream.h >
class MEMBER
{
int Mno;float Fees;
public:
void Register(){cin>>Mno>>Fees;}
void Display(){cout<<Mno<<:; <<Fees<<endl;}
};
void main()
{
MEMBER M;
M.Register( )
M.Display( )
}
2.
Corrected code:
#include
void main( )
{
int x, sum =0;
cin >> x ; // x in place of n
for (x=1; x<100 ; x+=2) //semicolon
if x%2= = 0 // double =due to assignment
sum+=x;
cout<< “sum=” << sum; //<<
}
3.
A class binds data and its associated functions together under one unit, which enforcing encapsulation that means wrapping up data and associated functions together into a single unit.
Member of the class can be group into three parts: public, private, and protected.The private and protected functions remain hidden from outside world.Thus, through private and protected members a class enforce the data hiding.The public member can be used outside the world, that is important and necessary information, rest of the thing remain hidden which is nothing but abstraction.We can say that an abstraction means representing only essential features without expressing background details.
4.
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.
5.
(i) None of data members are accessible from objects belonging to class AUTHOR.
(ii) Enter(), Show()
(iii) Data members: Voucher_No, Sales_Date, Salary Member function:Sales_Entry(),Sales_Detail(),Enter(),Show(),Register(), Status()
(iv) 66
6.
class FLIGHT
{
int Fno;
char Destination[20];
float Distance, Fuel;
void CALFUEL();
public: void FEEDINFO( );
void FEEDINFO( );
void SHOWINFO( );
};
void FLIGHT::CALFUEL( )
{
if (Distance<=1000)
Fuel=500;
else
if Distance<=2000)
Fuel=1100;
else
Fuel=2200;
}
void FLIGHT::FEEDINFO( )
{
cout << " Flight No:";cin>> FNO;
cout << " Desinatiion :";getsDestnation);
cout << "Distance:"cin>> Distance;
CALFUEL ( );
}
void FLIGHT::SHOWINFO( )
{
cout << "Flight No:" << Fno << endl;
cout << " Destination :"<< Destination << end1;
cout << " Distance :"<< Distance << endl;;
cout << "Fuel:" << Fuel << end1;;;
}
7.
(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.
8.
#include<iostream.h>
void Print() //Function[I]
{
for(int K=1; K<=60; K++)
cout<<"-"; cout<<end1;
}
void Print(int N) //Function[II]
{
for(K=1; K<=N; K++)
cout<<"*"; cout<<end1;
}
void Print(int A, int B) //Function[III]
{
for(K=1; K<=B; K++)
cout<<A*K; cout<<end1;
}
void Print(char T, int N) //Function[IV]
{
for(K=1;K<=N;K++)
cout<<T; cout<<end1;
}
void main()
{
int U=9, V=4, W=3;
char C='@';
Print(C,V);
Print(U,W);
}
Ans Output
@@@@
91827
In the above example, the function overloading concept is used from function [I] to [IV].
9.
2@4@8@
4#8#16#20#
10.
In function definition, 1 variable by reference, 1 normal variable and 1 pointer variable is used.
In calling for a pointer variable, always use & symbol.
Calling : demo(3,2,Address of b);
::a and x are having same address ( due to by reference)
a =a+x
=3+3=6
y = y * a
= 2*6=12
*z = a + y
= 6+12 = 18
First output : 6(value of a),
6 ( value of x), 12, z will be any valid address 0xfff4
Second output: 6,2,18( value stored at the address pointed by z i.e. value of b)
11.
#include<iostream.h>
#include<conio.h>
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number = a;
count++;
}
void getcount(void)
{
cout<<"count " ;
cout<<count<<"\n";
}
} ;
int item :: count;
void main()
{
item a,b,c; //count is initialised to zero
a.getcount();
b.getcount();
c.getcount();
a.getdata(100);
b.getdata(200);
c.getdata(300);
cout<<"After reading data\n";
a.getcount();
b.getcount();
c.getcount();
getch();
}
Output
count 0
count 0
count 0
After reading data
count 3
count 3
count 3
12.
#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
13.
( )
Stetement 1:
File.seekp(Record*size of(A)); //object name
OR
file.seekp(Reord*sizeof(Appliciant); // class name
File,seekp(File,tellg(g)-size of(A);
OR
File.seekp(File.tellg() - sizeof(Applicant));
OR
File.seekp(-sizeof(A), ios::cur);
File.seekg(Record * sizeof(A));
OR
File.seekg(Record * sizeof(Applicant));
OR
File.seekg(-sizeof(A), ios::cur);
Statement 2:
File.write((char*)&A, sizeof(A));
OR
File.write((char*)&A, sizeof(Applicant));
14.
( )
File.seekp( -sizeof(i), ios::cur );
15.
( )
Inheritance allows us to add additional features to an existing class without modifying it.Thus,
the class can be raised by inheriting it.We look for a class that can be reused in our program.
If such a class exists,we simple use it or inherit it.Thus , inheritance allows code reusability.
16.
( )
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.
17.
( )
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.
18.
( )
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