CBSE Guess > Papers > Important Questions > Class XII > 2009 > Computer Science > Computer Science By Mr. Bibhuti Bhusan Patra
CBSE CLASS XII
Q. 1. a. Name the header files to which the following belong:
- isalnum ( )
- strcat( )
- random ( )
- setw( )
b. In the following C++ program what is expected value of myscore from options
(i) to (iv) given below.
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize( );
int score[]={ 25, 20,34,56, 72, 63};
int myscore=score[2+random(2)]; cout<<myscore<<endl;
}
- 25
- 34
- 20
- None of these
c. Predict the output:
for( int i=1;i<4;i++)
{
cout<< “\n”;
for( int j=1; j<=I;j++)
cout<< “*”;
}
d. Rewrite the following program after removing the syntactical error , if any. Under line each correction.
#include<iostream.h>
const int Devidor 5;
void amin( )
{
Number=15; for(int count=1;
count<=5;count++) if( Number/ Devidor= = 0)
cout<<Number/Devidor; cout<<endl;
Else
cout<< Number+Devidor<<endl;
e. Find the output of the following program:
#include<string.h>
#include<iostream.h>
#include<ctype.h>
void change(char msg[ ], int len)
{
for( int count=0;count< len;count++)
{
if(islower(msg[ count]))
msg[count]=toupper(msg[count]);
else if(isupper(msg[ count]))
msg[count]=tolower(msg[count]);
else if(isdigit(msg[ count]))
msg[count]=msg[count]+1;
else
msg[count]= ‘*’;
}
}
void main( )
{
char message[ ]= “ 15th AugusT CelebratED”;
int size= strlen( message);
change(message,size);
cout<<message<<endl;
for( int c=0;,r=size-1;c<=size/2; c++,r--)
{
char temp=message[c];
message[c]=message[r];
message[r]=temp;
}
cout<<message<<endl;
}
f. What is the difference between call by value and call by reference? Give example?
Q. 2. a. What is inline function? Write two advantages of using inline functions?
b. Define copy constructor? Mention the condition where a copy constructor is invoked?
c. Encapsulation is one of the major properties of OOP? How is it implemented in C++?
d. What is the difference between global and local variables ? Give an example to illustrate the same?
e. Write the output of the following code:
#include<iostream.h>
int func( int &x,int y=10)
{
if(x%y==0) return ++X; else return y- -;
}
void main( )
{
int p=20, q=23;
q= func(p,q);
cout<<p<<q<<endl;
p= func(q);
cout<<p<<q<<endl;
q= func(p);
cout<<p<<q<<endl;
}
f. Predict the output:
for(int i=0; i<=10;i++);
cout<<I;
Q. 3. a. Define and declare a class MYFOLDER with the following specifications:s
Private Members:
Filename: An array of string of size [10][25]
Availspace: long
Usedspace: long
Public members:
newfileEntry( ): Function to read value
Retavailspace( ): Function that returns the value of total kilobytes available
Showfile(): Function to display details.
b. Define a class teacher with the following specifications: ( No need to define the functions)
Private members:
name: 20 characters
sub: 10 characters
basic,da,hra: integers
salary: float
calculate(): that returns salary
public members:
readdata(): read data values
showdata(): display details
Q. 4. a. Find syntax errors, if any ( giving reasons for errors):
class ABC
{
int x=10;
float y;
ABC( ) {y=5;}
~( ) { }
}
void main( )
{
ABC a1,a2;
}
b. Consider the following code:
class ci
{
int l;
public: ci(int j){ l=j}
ci(ci &v) { l=v.l}
void initialize( ) { l=0;}
};
void main( )
{
ci orig(1);
ci x(orig);
ci a=orig;
}
Referring to the sample code above, What initializes the object x.
- initialize( ) function
- default constructor
- copy constructor
- default copy constructor Justify your answer.
Justify your answer.
c. Define a class play with the following specifications:
Private Members:
Playcode integer
Playtitle 25 character
Duration float
Noofscenes integer
Public members:
A constructor function to initialize duration as 45 seconds and noofscene as 5.
Newplay( ) to accept values for play code and play title
Moreinfo( ) to assign values duration and noofscenes with the help of corresponding values passed as parameters as functions.
Showplay( ) function to display all the data members on each scene.
d. What will be the output of following code:
#include< iostream.h>
class MAIN( )
{
public:
MAIN( )
{
calculate()
cout<<”\t”<< “constructor.\n”;
}
void calculate( )
{
show();
cout<< “calculating”;
}
void show( )
{
cout<< “ I am displaying”;
}
};
void main( )
{
MAIN one;
}
e. Following object declaration is producing an error:
Test T1; What could be the possible reasons for it?
f. Write construction and destructor definition for a class that should display the object numbers being created or destroyed of this type?
Q. 5. a. Write the output of the following program:
void x( int & a, int & b)
{
a=a+b;
b=a-b;
a=a-b;
}
void main( )
{
int a=4, b=14;
x(a,b);cout<<a<<”,”<<b;
}
b. What will be the output of the following code:
#include<iostream.h>
class sample
{
int I;
public:
void get(int a)
{
i=a;
}
void display( )
{
cout<<++i<< “,”<<i<< “,”<<i++;
}
};
void main( )
{
sample obj;
obj.get(6);
obj.display();
}
c. What is wrong with the following code:
class c {public: int x=10;};
d. What do you mean by static data members of a class ? Explain the characteristics of a static data member.
e. Rewrite the following code after removing syntactical errors if any:
#include<iostream.h>
CLASS STUDENT
{
int admno;
float marks;
public:
STUDENT( )
{
admno=0;
marks=0.0;
}
void input( )
{cin>>admno;
cin>>marks;
}
void output()
{
cout<<admno;
cout<<marks;
}
}
void main()
{
STUDENT s;
Input(s);
}
Q. 6. a. Distinguish between the following two statements:
time T1(11,20,12);
time T1= time(11,20,12);
b. Write the output of the following program:
#include<iostream.h>
class counter
{
private:
unsigned int count;
public:
counter( ) { count =0;}
void inc_count( ) { count ++}
int get_count( ) {return count;}
};
void main( )
{
counter C1,C2;
cout<<”\nC1=”<<C1.get_count( );
cout<<”\nC2=”<<C2.get_count( );
C1.inc_count( );
C2.inc_count( );
C2.inc_count( );
cout<<”\nC1=”<<C1.get_count( );
cout<<”\nC2=”<<C2.get_count( );
}
c. Answer the following questions after going through the following class:
class Exam
{
int year;
public:
Exam(int y) { year=y;} //constructor 1
Exam( Exam &t); //constructor 2
};
- Create an object , such that it invokes constructor 1.
- Write complete definition for constructor 2
d. In what order will the constructors be invoked in the
following program segment:
class distance
{
};
class time
{
};
class figure
{
int plane();
distance dist;
time t;
:
};
main( )
{
time t1;
distance d1;
figure f1;
:
}
Q. 7. a. What is wrong with the following program segment:
class sample
{
double a, b ,c;
public:
double sample( );
};
b. Given the following C++ code , answer the questions i and ii.
Class readbook
{
public:
readbook( ) //function 1
{
cout<< “open the book”<< endl;
}
void readchapter( ) //function 2
{
cout<< “ reading chapter 1” <<endl;
}
~readbook( ) //function 3
{
cout<< “close the book”<< endl;
}
- In oop , What is function 1 reffered to as when does it get invoked?
- In oop , What is function 3 reffered to as when does it get invoked?
c. What are the difference between constructors and destructors?
d. What is the purpose mem-initialisation list. Give example?
e. Define Encapsulation.
Paper By Mr. Bibhuti Bhusan Patra |