Вы находитесь на странице: 1из 30

QUESTION BANK OF COMPUTER SCIENCE

COMPUTER SCIENCE (THEORY) 083


CBSE QUESTIONS OF LAST 10 YEARS
Note: In Computer Science CBSE Exam, the pattern of Questions is same, but all questions are distinct.

Chapter : 1 Review of C++ covered in class XI


ONE (01) Marks Questions:
1.Observe the following program very carefully and write the names of those header file(s), which are
essentially needed to compile and execute the following program successfully :
[2015, outside delhi]
typedef char STRING[80];
void main()
{
STRING Txt[] = We love Peace;
int Count=0;
while (Txt[Count]!=\0)
if (isalpha(Txt[Count]))
Txt[Count++]=@;
else
Txt[Count++]=#;
puts(Txt);
}
2. Observe the following program very carefully and write the names of those header
file(s), which are essentially needed to compile and execute the following program
successfully :
[2015, Delhi ]
typedef char TEXT[80];
void main()
{
TEXT Str[] = Peace is supreme;
int Index=0;
while (Str[Index]!=\0)
if (isupper(Str[Index]))
Str[Index++]=#;
else
Str[Index++]=*;
puts(Str);
}
3. Name the header files that shall be needed for successful compilation of the following C++ code :
[2014, outside Delhi]
void main()
{char str[20], str1[20];
gets(str);
strcpy(str1,str);
1

strrev(str);
puts(str);
puts(str1); }
4. Observe the following C++ code and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler :
[2014, outside Delhi]
void main()
{
char CH, STR[20];
cin>>STR;
CH=toupper(STR[0]);
cout<<STR<< starts with <<CH<<endl;
}
5. Observe the following C++ code and write the name(s) of the header fiIe(s), which will be essentially
required to run it in a C++ compiler :
[2014, Delhi]
void main ( )
{
char Text[20] , C;
cin>>Text;
C = tolower (Text [0]);
cout<<C<<" is the first char of " <<Text<<end1;
}
6. Observe the following C++ code and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler:
[CBSE,2013]
void main ( )
{
int number;
cin >> number;
if (abs (number) = = number);
cout << Positive <<endl;
}
7. Write the names of the header files, which is/are essentially required to run/execute the following C++
code:
[CBSE, 2011]
void main ( )
{
char C, String [ ] = "Excellence Overload";
for (int I=0; String [ I ] ! = '\ 0'; I ++ )
if (String [I] ==' ')
cout<<end1;
else
{
C=toupper(String[I]);
cout<<C ;
}
}

8. Which C++ header file(s) will be essentially required to be included to run/execute the following C++
code?
[CBSE, 2010]
void main( )
{
int Eno=123, char Ename[ ]=Rehan Swamp;
cout<<setw(5)<<Eno<<setw(25)<<EName<<endl;
}
9. Name the header files that shall be needed for the following code:
void main ( )

[CBSE, 2008]

{
char word [ ]= Exam;
Cout << setw (20) << word ;
}
10. Name the header file(s) that shall be needed for successful compilation of the following C++ code :
[CBSE, 2007]
void main( )
{
char Text[40];
strcpy(Text,AISSCE);
puts(Text);
}
11. Name the header file(s) that shall be needed for successful compilation of the following C++ code:
[CBSE, 2006]
void main ( )
{
char String [20];
gets (String);
strcat (String, CBSE);
puts (String);
}
12. Name the header file to which the following belong:
i. pow ( )
ii. random ( )

[CBSE, 2006-SET1]

13. Name the header file to which the following belong


i. abs ( )
ii. isupper ( )

[CBSE, 2006-SET2]

TWO MARKS QUESTIONS: ( Correct identifiers and Error Detection and


Correction)
1.Find the correct identifiers out of the following, which can be used for naming Variable, Constants or
Functions in a C++ program :
[CBSE, outside delhi, 2015]
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
2. Find the correct identifiers out of the following, which can be used for naming variable, constants or
functions in a C++ program :
[CBSE, 2015, Delhi]
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
3. Observe the following C++ code very carefully and rewrite it after removing any/all syntactical errors
with each correction underlined.
Note : Assume all required header files are already being included in the program.
[CBSE, 2014, Outside Delhi set-I]
#define float MaxSpeed=60.5;
void main()
{
int MySpeed
char Alert=N;
cinMySpeed;
if MySpeed>MaxSpeed
Alert=Y;
cout<<Alert<<endline;
}
Q4. Observe the following C++ code very carefully and rewrite it after removing
any/all syntactical errors with each correction underlined.
Note : Assume all required header files are already being included in the program.
[CBSE outside delhi, 2014]
#Define float Max=70.0;
Void main()
{
int Speed
char Stop=N;
cin>>Speed;
if Speed>Max
Stop=Y;
cout<<Stop<<end;
}
Q 5. Deepa has just started working as a programmer in STAR SOFTWARE company. In the company she
has got her first assignment to be done using a C++ function to find the smallest number out of a given set of
numbers stored in a one-dimensional array. But she has committed some logical mistakes while writing the
code and is not getting the desired result. Rewrite the correct code underlining the corrections done. Do not
add any additional statements in the corrected code.
[CBSE, 2013]
int find(int a[],int n)
4

{ int s=a[0];
for(int x=1;x<n;x++)
if(a[x]>s)
a[x]=s;
return(s);
}
Q 6. Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make sure
that you underline each correction done by you in the code.
[CBSE 2012]
Important Note :
Assume that all the required header files are already included, which are essential to run this code.
The corrections made by you do not change the logic of the program.
typedef char[80] STR;
void main()
{
Txt STR;
gets(Txt);
cout<<Txt[0]<<\t<<Txt[2];
cout<<Txt<<endline;
}
Q 7. Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make
sure that you underline each correction done by you in the code.
Important Note :
[CBSE, 2011]
- Assume that all the required header files are already included, which are essential to run this code.
- The corrections made by you do not change the logic of the program.
typedef char [50] STRTNG;
void main ( )
{
City STRING;
gets (City) ;
cout<<City [0] << \t<<City [2] ;
cout << City << endline ;
}
Q 8. Rewrite the following program after removing the syntactical errors (if any).
Underline each correction.
[CBSE, 2010]
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{
Text T= "Indian";
int Count=strlen(T) ;
cout<<T<<'has'<<Count<< 'characters' <<end1;
}

Q 9. Rewrite the following c++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2009]
include <iostream.h>
class TRAIN
{
long TrainNo;
char Description[25];
public
void Entry ( )
{
cin >>TrainNo; gets(Description);
}
Void Display ( )
{
cout<<TrainNo<<:<<Description<<endl;
}
};
void main( )
{
TRAIN T;
Entry. T( ); Display. T( );
}
Q 10. Rewrite the following C++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2008]
include <iostream.h>
class FLIGHT
{
long FlightCode;
char Description [25];
public
void AddInfo ( )
{
cin >> FlightCode;
}

gets(Description);

void ShowInfo ( )
{
cout << FlightCode << : << Description << endl;
}
};
void main ( )
{
FLIGHT F;
AddInfo. F ( );
ShowInfo ( );

}
6

Q 11. Rewrite the following c++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2007]
include <iostream.h>
class TRAIN
{
long TrainNo;
char Description[25];
public
void Entry ( )
{
cin >>TrainNo; gets(Description);
}
Void Display ( )
{
cout<<TrainNo<<:<<Description<<endl;
}
};
void main( )
{
TRAIN T;
Entry. T( ); Display. T( );
}
Q 12. Rewrite the following program after removing the syntax error(s), if any. Underline each correction.
[CBSE, 2006, SET-III]
# include <iostream.h>
void main ( )
{
One=10, Two = 20;
Callme (One; Two);
Callme (Two);
}
void Callme ( int Arg1, int Arg2 = 20)
{
Arg1 = Arg1 + Arg2;
cout << Arg1 >> Arg2;
}
Q 13. Rewrite the following program after removing the syntactical error(s), if any. [CBSE, 2006, SET-II]
Underline each correction.
#include <iostream.h>
const int Size 5;
void main()
{
int Array[Size];
Array = {50,40,30,20,10};
for(Ctr=0; Ctr<Size; Ctr++)
cout>>Array[Ctr];
}
Q 14. Rewrite the following program after removing the syntactical error(s) if any.
[CBSE, 2006, SET-I]
7

Underline each correction.


# include <iostream.h>
const int Max 10;
void main ( )
{
int Numbers [Max];
Numbers = { 20, 50,10, 30,40 } ;
for (Loc= Max-1 ; Loc > = 0 ; Loc - -)
cout>>Numbers [Loc];
}
Q 15. Rewrite the following program after removing the syntactical error(s), if any Underline each
correction,
#include <iostream.h>
void main( )
{ struct TV
{ char Manu_name[20];
char Tv_Type;
int Price = 17000;
} New Tv;
gets(Manu_name);
gets(Tv_Type);
}
Q 16. Rewrite the following program after removing the syntactical error(s), if any. Underline each
correction.
#include <iostream.h>
void main( )
{ struct movie
{ char movie_name [20];
char movie type;
int ticket cost = 100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}
Q 17. Rewrite the following program after removing the syntactical error(s), if any. Underline each
correction.
[CBSE, 2006]
# include <iostream.h>
void main()
{ struct STUDENT
{ char stu_name [20];
char stu_sex;
int stu_age=17;
} student;
gets(stu_name);
gets(stu_sex);
}

CHAPTER-2 :Object Oriented Programming in C++:


8

Output Questions 02 Marks each (Combination of chapter 1 and chapter 2)


Q 1. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
[CBSE, 2015, Outside Delhi]
void Location(int &X, int Y=4)
{
Y+=2;
X+=Y;
}
void main()
{
int PX=10,PY=2;
Location(PY);
cout<<PX<<,PY<<endl;
Location(PX,PY);
cout<<PX<<,PY<<endl;
}
Q 2. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program. [CBSE, 2015, Delhi]
void Position(int &C1,int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<,<<P2<<end1;
Position(P2,P1);
cout<<P1<<,<<P2<<end1;
}
Q 3. Find output of the following program segment :
[CBSE, 2014, Outside Delhi-I]
#include<iostream.h>
#include<ctype.h>
void Mycode(char Msg[],char CH)
{
for(int cnt=0;Msg[cnt]!=\0;cnt++)
{ if(Msg[cnt]>=B&& Msg[cnt]<=G)
Msg[cnt]=tolower(Msg[cnt]);
else
if(Msg[cnt]==N||Msg[cnt]==n || Msg[cnt]==)
Msg[cnt]=CH;
else
if(cnt%2==0)
Msg[cnt]=toupper(Msg[cnt]);
9

else
Msg[cnt]=Msg[cnt1];
}}
void main( )
{ char MyText[]="Input Raw";
Mycode(MyText,@);
cout<<"NEW TEXT:"<<MyText<<endl; }
Q 4. Obtain the output from the following C++ program as expected to appear on the screen after its
execution. [CBSE, 2014, Outside Delhi]
Important Note :
- All the desired header files are already included in the code, which are required to run the code.
void main()
{
char *Text= AJANTA;
int *P, Num[ ]={1,5,7,9};
P=Num;
cout<<*P<<Text<<endl;
Text++;
P++;
cout<<*P<<Text<<endl;
}
Q 5. Obtain the output from the following c++ program as expected to appear on the screen after its
execution.
Important Note :
- All the desired header files are already included in the code, which are required to run the code.
void main ( )
[CBSE, 2014, Delhi]
{
char *String = SARGAM ;
int *ptr, A [ ] = { 1,5,7,9 };
Ptr = A;
cout << * ptr << String<< end1 ;
String++;
Ptr+=3;
cout<< * Ptr << String<<endI;
}
Q 6. Find the output of the following program:
[CBSE, 2013]
#include<iostream.h>
void main ( )
{
int Track [ ] = {10, 20, 30, 40}, *Striker ;
Stxiker=Track :
Track [1] += 30 ;
cout<<"Striker>"<<*Striker<<end1 ;
Striker =10 ;
Striker++ ;
cout<<"Next@"<<*Striker<<end1 ;
Striker+=2 ;
cout<<"Last@"<<*Striker<<end1 ;
10

cout<< "Reset To" <<Track[0] <<end1 ;


}
Q 7. Find the output of the following program :
#include <iostream.h>
#include <ctype.h>
void ChangeIt(char Text[ ], char C)
{
for (int K=0;Text[K]!='\0';K++)
{
if (Text[K]>=F && Text[K]<=L)
Text[K]=tolower(Text[K]);
else
if (Text[K]=E || Text[K]==e)
Text[K]= =C;
else
if (K%2==O)
Text[K]=toupper(Text[K]);
else
Text[K]=Text[K-l];
}
}
void main ( )
{
char OldText[ ]=pOwERALone;
ChangeIt(OldText,%);
cout<<New TEXT:<<OldText<<endl;
}

[CBSE, 2011]

Q 8. Find the output of the following program :


[CBSE, 2010]
# include <iostream.h>
void main ( )
{
int A=5, B=10;
for (int I= 1; I <= 2; I+ +)
{
cout << Line1= <<A++ << & << B-2 <<endl;
cout << Line2= << ++B << & <<A+3 <<endl;
}
}
Q 9. Find the output of the following program :
#include<iostream.h>
void main()
{
int Numbers[] = {2,4,8,10};
int *ptr = Numbers;
for (int C = 0; C<3; C++)
{
cout<< *ptr << @;
ptr++;

[CBSE,2010-setI]

11

}
cout<<endl;
for(C = 0; C<4; C++)
{
(*ptr)*=2;
--ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< #;
cout<<endl;
}
Q 10. Find the output of the following program :
# include < iostream.h>
void main ( )
{
intArray[] = {4,6,10,12};
int *pointer = Array ;
for (int I=1 ; I<=3 ; I++)
{
cout<<*pointer<<#;
pointer ++;
}
cout<<endl;
for (I=1 ; I<=4 ; I++)
{
(*pointer)*=3 ;
-- pointer;
}
for(I=l; I<5; I + + )
cout << Array [I-1] << @;
cout << endl;
}

[CBSE,2008]

Q 11. Find the output of the following program:


#include < iostream.h>
void main( )
{ int *Pointer Array [10];
int marks [ ]= {75, 68, 90, 34, 0, 10, 90, 65};
for (int I = 0; marks [ I]!=0; I++)
{
PointerArray [I]=&marks[I];
* (PointerArray [I] ) += 5;
}
int index = 0;
while(index < I )
{
int p=*(PointerArray[index] );
if(p >=60) cout <<p<<,;
index ++;
}
}

[CBSE, 2007-II]

Q 12. Find the output of the following program: [CBSE, 2007]


#include<iostream.h>
12

void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{
int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}
Q 13. Find the output of the following program:
#include<iostream.h>
[CBSE, 2006]
void main( )
{ long NUM = 1234543;
int F = 0, S = 0;
do
{ int Rem = NUM% 10;
if (Rem % 2 !=0)
F+ =R;
else
S+ = R;
NUM/=10;
} while(NUM>0);
cout<<F-S;
}

OUTPUT QUESTIONS OF (03 Marks each):


Q 1. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
[CBSE, 2015, Outside Delhi]
class Eval
{
char Level;
int Point;
public:
Eval(){Level=E;Point=0;}
void Sink(int L)
{
Level-=L;
}
void Float(int L)
{
Level+=L;
Point++;
}
void Show()
13

{
cout<<Level<<#<<Point<<endl;
}
};
void main()
{
Eval E;
E.Sink(3);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
Q 2. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
[CBSE, 2015, Delhi]
class Calc
{
char Grade;
int Bonus;
public:
Calc() {Grade=E;Bonus=0;}
void Down(int G)
{
Grade=G;
}
Void Up(int G)
{
Grade+=G;
Bonus++;
}
void Show()
{
cout<<Grade<<#<<Bonus<<end1;
}
};
void main()
{
Calc c;
C.Down(2);
C.Show();
C.Up(7);
C.Show();
C.Down(2);
C.Show();
}
Q 3. Find the output of the following program :
[CBSE, 2014,Outside Delhi-I]
14

#include<iostream.h>
void in(int x,int y, int &z)
{
x+=y;
y ;
z*=(xy);
}
void out(int z,int y, int &x)
{
x*=y;
y++;
z/=(x+y);
}
void main()
{
int a=20, b=30, c=10;
out(a,c,b);
cout<<a<<"#"<<b<<"#"<<c<<"#"<<endl;
in(b,c,a);
cout<<a<<"@"<<b<<"@"<<c<<"@"<<endl;
out(a,b,c);
cout<<a<<"$"<<b<<"$"<<c<<"$"<<endl;
}
Q 4. Obtain the output of the following C++ program, which will appear on the screen after its execution.
Important Note :
[CBSE, 2014,Outside Delhi]
All the desired header files are already included in the code, which are required to run the code.
class Game
{
int Level, Score;
char Type;
public:
Game(char GType=P)
{Level=1;Score=0;Type=GType;}
void Play(int GS);
void Change();
void Show()
{
cout<<Type<<@<<Level<<endl;
cout<<Score<<endl;
}
};
void main()
{
Game A(G),B;
B.Show();
A.Play(11);
A.Change();
B.Play(25);
A.Show();
B.Show();
}
void Game::Change()
{
Type=(Type==P)?G:P;
15

}
void Game::Play(int GS)
{
Score+=GS;
if(Score>=30)
Level=3;
else if(Score>=20)
Level=2;
else
Level=1;
}
Q 5. Observe the following C++ code carefully and obtain the output, which will appear on the screen after
execution of it.
[cbse, 2014, delhi]
# include <iostream.h>
class Aroundus
{
int Place, Humidity, Temp;
public :
Aroundus (int p=2) { Place=P; Humidity = 60; Temp = 20;}
void Hot (int T) { Temp += T;}
void Humid (int H) { Humidity + = H;}
void JustSee ( )
{
cout << Place << : <<Temp << & << Humidity
<< % <<endl;
}
};
void main ( )
{
Aroundus A, B(5);
A. Hot (10);
A.JustSee( );
B.Humid (15);
B.Hot (2);
B.JustSee ( );
A.Humid (5);
A.justSee( );
}
Q 6. Find the output of the following program:
#include<iostream.h>
[cbse, 2013]
void ChangeArray(int Number, int ARR[ ], int Size)
{
for (int L =0; L<Size; L++)
if (L<Number)
ARR [L] +=L;
e1se
ARR [L] *=L;
}
16

void Show (int ARR [ ], int Size)


{
for (int L=0; L<Size; L++)
(L%2!=0) ?cout<<ARR[L] <<"#": cout<<ARR[L]<<end1 ;
}
void main ( )
{
int Array [ ] = {30, 20, 40, 10, 60, 50};
ChangeArray (3, Array, 6) ;
Show (Array, 6) ;
}
Q 7. Find the output of the following program :
#inc1ude <iostream.h>
struct POINT
{int X, Y, Z;};
void StepIn(POINT & P, int Step=1)
{
P.X+=Step;
P.Y -=Step;
P.Z+=Step;
}
void StepOut(POINT & P, int Step=1)
{
P.X-=Step;
P.Y+=Step;
P.Z=Step;
}
void main ( )
{
POINT P1={15, 25, 5}, P2={10, 30, 20};
StepIn(P1);
StepOut(P2,4);
cout<<P1.X<<,<<P1.Y<<,<<P1.Z<<endl;
cout<<P2.X<<,<<P2.Y<<,<<P2.Z<<endl;
StepIn(P2,12);
cout<<P2.X<<,<<P2.Y<<,<<P2.Z<<endl;
}

[cbse, 2011]

Q 8. Find the output of the following program:


[CBSE, 2008]
#include<iostream.h>
#include <ctype.h>
void main ()
{
Char Mystring[] = What@OUTPUT!;
for (int I = 0; Mystring [ I ] = \0 ; I++)
17

{
if ( isalpha (Mystring [ I ] ) )
Mystring [ I ] = * ;
else

if

( isupper (Mystring [ I ]) )

Mystring [ I ] = Mystring [ I ] + 1;
else
Mystring [ I ] = Mystring [ I + 1];
}
cout<< Mystring;
}
Q 9. Find the output of the following program :
[CBSE-2007-II]
#include<iostream.h>
void Indirect(int Temp=20)
{
for (int I=10; I<=Temp; I+=5)
cout << I <<, ;
cout << endl ;
}
void Direct (int &Num)
{
Num + = 10;
Indirect (Num) ;
}
void main()
{
int Number=20;
Direct(Number);
Indirect();
cout<< Number= <<Number<<endl ;
}
Q 10. Find the output of the following program :
# include < iostream.h>
void Withdef (int HisNum = 30)
{
for (int 1=20 ; I<*= HisNum; I+=5)
cout<<I<<;
cout<<endl;
}
void Control (int &MyNum)
{
MyNum+=10;
Withdef(MyNum);

[CBSE, 2007-I]

18

}
void main ()
{
int YourNum=20;
Control (YourNum);
Withdef();
cout<<Number=<<YourNum<<endl;
}
Q 11. Find the output of the following program
# include<iostream.h>
[CBSE, 2006]
#include<string.h>
class state
{
char * state_name;
int size;
public;
state( ); { size=0; state_name=new char[size+1]; }
state(char *s)
{ size = strlen(s) ; state_name = new char[size+1];}
strcpy(state_name,s);
}
void display() {cout<<state name<<endl; }
void Replace (state &a, state &b)
{ size = a.size + b.size;
delete state_name;
state_name = new char[size+1] ;
strcpy(state_name, a.state_name);
strcat(state_name, b.state_name);
}
};
void main( )
{ char *temp = Delhi;
state state1(temp), state2(Mumbai), state3(Nagpur), SI, S2;
SI .Replace(state1, state2);
S2.Replace(S1, state3);
S1.display( );
S2.display( );
}

RANDOMIZE ( ) FUNCTIONS: 02 Marks each


Q 1. Study the following program and select the possible output(s) from the options (i) to (iv) following it.
Also, write the maximum and the minimum values that can be assigned to the variable VAL.
[CBSE, 2015, Outside Delhi]
Note :
Assume all required header files are already being included in the program.
19

random(n) function generates an integer between 0 and n-1.


void main()
{
randomize();
int VAL;
VAL=random(3)+2;
char GUESS[]=ABCDEFGHIJK;
for (int I=1;I<=VAL; I++)
{
for(int J=VAL; J<=7;J++)
coutGUESS[J];
cout<<endl;
}
}
(i)
BCDEFGH
BCDEFGH

(ii)
CDEFGH
CDEFGH

(iii)
EFGH
EFGH
EFGH
EFGH

(iv)
FGHI
FGHI
FGHI
FGHI

Q 2. Study the following program and select the possible output(s) from the options (i)
to (iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable NUM.
Note :
[CBSE, 2015, DELHI]
Assume all required header files are already being included in the program.
random(n) function generates an integer between 0 and n 1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]=ABCDEFGHIJK;
for (int I=1;I<=NUM; I++)
{
for(int J=NUM; J<=7;J++)
cout<<TEXT[J];
cout<<end1;
}
}
(i) FGHI
(ii) BCDEFGH
FGHI
BCDEFGH
FGHI
FGHI

(iii) EFGH
EFGH
EFGH
EFGH

(iv) CDEFGH
CDEFGH

Q 3. Read the following C++ code carefully and find out, which out of
the given options (i) to (iv) are the expected correct output(s) of it.
Also, write the maximum and minimum value that can be assigned to the variable Taker used in the code :
[CBSE, 2014, Outside Delhi]
20

void main( )
{
int GuessMe[4]={100,50,200,20};
int Taker=random(2)+2;
for (int Chance=0;Chance<Taker;Chance++)
cout<<GuessMe[Chance]<<#;
}
(i) 100#
(ii) 50# 200#
(iii) 100# 50# 200#
(iv) 100# 50
Q 4. Based on the following C++ code, find out the expected correct output(s) from the option (i) to (iv).
Also, find out the minimum and the maximum value that can be assigned to the variable Trick used in the
code at the time when value of Count is 3: [cbse, 2013]
void main ( )
char Status [ ]

[10] = { EXCEL, GOOD, OK };

int Turn = 10, Trick;


for

(int

Count = 1; Count < 4; Count ++ )

{
Trick = random ( Count ) ;
cout << Turn Trick << Status [ Trick ] << # ;
}
}
(i)
(ii)

10 EXCEL # 10 EXCEL # 80 K #
10 EXCEL # 80 K # 9GOOD#
(iii)
10 EXCEL # 9GOOD # 10 EXCEL #
(iv)

10 EXCEL# 10 GOOD # 80 K #

Q 5. Go through the C++ code shown below, and find out the possible output or
outputs from the suggested Output Options (i) to (iv). Also, write the least
value and highest value, which can be assigned to the variable Guess.
#include <iostream.h>
[CBSE 2011]
#include <stdlib.h>
void main ( )
{
randomize ( ) ;
int Guess, High=4;
Guess=random{High)+ 50 ;
for{int C=Guess ; C<=55 ; C++)
cout<<C<<"#" ;
}
21

(i) 50 # 51 # 52 # 53 # 54 # 55 #
(ii) 52 # 53 # 54 # 55
(iii) 53 # 54 #
(iv) 51 # 52 # 53 # 54 # 55
Q 6. The following code is from a game, which generates a set of 4 random numbers. Yallav is playing this
game, help him to identify the correct option(s) out of the four choices given below as the possible set of
such numbers generated from the program code so that he wins the game. Justify your answer.
[CBSE 2010]
#include <iostream.h>
#include <stdlib.h>
const int LOW=15;
void main ( )
{
randomize( ) ;
int POINT=5, Number;
for (int 1=1;I<=4;I++)
{
Number=LOW+random(POINT) ;
cout<<Number<<: ;
POINT--;
}
}
(i) 19:16:15:18:
(ii) 14:18:15:16:
(iii) 19:16:14:18:
(iv) 19:16:15:16:

Q 7. In the following program, find the correct possible output(s) from the options:[CBSE 2008]
#include <stdlib.h>
#include <iostream.h>
void main ( )
{
randomize ( );
char Area [ ] [ 10 ] = { NORTH , SOUTH , EAST, WEST);
int ToGo;
22

for

( int I = 0 ; I<3; I++ )

{
To Go = random (2) + 1;
cout<< Area [ToGo ]<< :;
}
}
Outputs:
(i)

SOUTH:EAST:SOUTH:

(ii)

NORTH: SOUTH: EAST:

(iii)

SOUTH: EAST: WEST:

(iv)

SOUTH: EAST: EAST:

Q 8. In the following C++ program what is the expected value of MyMarks from Options (i) to (iv) given
below. Justify answer.
[CBSE, 2007]
#include<stdlib.h >
# include<iostream.h>
void main ()
{
randomize ();
int Marks [ ]= {99, 92, 94, 96, 93, 95}, MyMarks;
MyMarks = Marks [1 + random (2) ];
cout<<MyMarks<<endl;
}
(i) 99
(ii) 94
(iii) 96
(iv) None of the above

Q 9. In the following C++ program what is the expected value of Myscore from Options (i) to (iv) given
below. Justify your answer.
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize();
int Score[] = {25,20,34,56, 72, 63}, Myscore;
Myscore = Score[2 + random(2)];
cout<<Myscore<<endl; }
(i) 25
(ii) 34
(iii) 20
(iv) None of the above
23

Implementation of OOP Concepts:


CHAPTER (01, 02, 03, 04)
OOP CONCEPTS (02 MARKS EACH)
Q1.Explain in brief the purpose of function prototype with the help of a suitable example.
[CBSE, 2014, Outside Delhi]
Q2. Explain data hiding with an example.

[CBSE, 2014, Outside Delhi]

Q3. What is the difference between call by reference and call by value
with respect to memory allocation ? Give a suitable example to
illustrate using C++ code.
[CBSE, 2014, Outside Delhi set -II]
[CBSE, 2010]
Q4. What is the difference between actual and formal parameter ? Give a suitable example to illustrate using
a C++ code.
[CBSE, 2014, Delhi]
Q5. What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code to
illustrate both.
[CBSE, 2011]
Q6. Differentiate between members, which are present within the private visibility mode with those which
are present within the public visibility modes.
[CBSE, 2011]
Q7. What is the purpose of using a typedef command in C++. Explain with suitable example.
[CBSE, 2008]
Q8. Differentiate between private and public visibility modes in context of Object Oriented Programming
giving a suitable example illustrating each.
[CBSE, 2008]
Q9. Differentiate between a Run Time Error and Syntax Error. Also give suitable examples of each in C++.
[CBSE, 2007]
Q 10. Illustrate the use of inline function in C++ with the help of an example.
[CBSE, 2006, SET-II]
Q. 11. Illustrate the use of #define in C++ to define a macro.
[CBSE, 2006, SET-I]
Q12. What are Nested Structures? Give an example.
[CBSE, 2006, SET-I]

CHAPTER -04
CLASSES AND OBJECTS (04 MARKS EACH)
Q 1.Write the definition of a class Photo in C++ with following description:
[CBSE, 2015, Outside Delhi]
24

Private Members
Pno
//Data member for Photo Number (an integer)
Category
//Data member for Photo Category (a string)
Exhibit
//Data member for Exhibition Gallery (a string)
FixExhibit //A member function to assign
//Exhibition Gallery as per Category
//as shown in the following table
Category

Exhibit

Antique

Zaveri

Modern

Johnsen

Classic

Terenida

Public Members
Register()
ViewAll()

//A function to allow user to enter values


//Pno, Category and call FixExhibit() function
//A function to display all the data members

Q 2. Write the definition of a class PIC in C++ with following description :


[CBSE, 2015, DELHI]
Private Members
Pno
//Data member for Picture Number (an integer)
Category
//Data member for Picture Category (a string)
Location
//Data member for Exhibition Location (a string)
FixLocation //A member function to assign
//Exhibition Location as per category
//as shown in the following table
Category

Location

Classic

Amina

Modern

Jim Plaq

Antique

Ustad Khan

Public Members
Enter()
SeeAll()

//A function to allow user to enter values


//Pno, category and call FixLocation() function
//A function to display all the data members

Q 3. Define a class CONTEST in C++ with the following description :


Private Data Members
[CBSE, 2014, Outside Delhi]
Eventno
integer
25

Description
Score
qualified

char(30)
integer
char

Public Member functions


A constructor to assign initial values Eventno as 11, Description as School level, Score as 100, qualified
as N.
Input() To take the input for Eventno, description and score.
Award (int cutoffscore) To assign qualified as Y, if score is more than the cutoffscore that is passed as
argument to the function, else assign qualified as N.
Displaydata() to display all data members.
Q 4. Define a class Tourist in C++ with the following specification :
[CBSE, 2014, Delhi]
Data Members
CNo - to store Cab No
CType - to store a character A, B, or C as City Type
PerKM - to store per Kilo Meter charges
Distance - to store Distance travelled (in KM) Member Functions
A constructor function to initialize CType as A and CNo as 0000
A function CityCharges( ) to assign PerKM as per the following table :
CType

PerKM

A
B
C

20
18
15

A function RegisterCab() to allow administrator to enter the values for CNo and CType. Also, this
function should call CityCharges() to assign PerKM Charges.
A function Display() to allow user to enter the value of Distance and display CNo, CType, PerKM,
PerKM*Distance (as Amount) on screen.
Q 5. Define a class Tourist in C++ with the following specification.
[ CBSE 2013]

Data Members :

Carno
- To store Bus No
Origin - To store Place Name
Destination - To store Place Name
Type - To store Car Type such as E for Economy
26

Distance - To store Distance as Kilometers


Charge - To store the Car Fare.

Member Functions :

A constructor function to initialize Type as E and Freight as 250


A function CalcCharge ( ) to calculate the fare as per the following criteria :
Type

Charge

E
16* Distance
A
22 * Distance
L
30 * Distance
A function Enter ( ) to allow the user to enter the values of Carno, Origin, Destination, Type and
Distance. Also, this function should call CalcCharge ( ) to calculate Fare.
A function Show ( ) to display the content of all the data members on screen.

Q 6. Define a class Candidate in C++ with following description:


[CBSE, 2011]
Private Members
_ A data member RNo (Registration Number) of type long
_ A data member Name of type string
_ A data member Score of type float
_ A data member Remarks of type string
_ A member function AssignRem( ) to assign Remarks as per the Score obtained by a candidate. Score range
and the respective Remarks are shown as follows:
Score
Remarks
>=50
Selected
less than 50
Not selected
Public Members
_ A function ENTER ( ) to allow user to enter values for RNo, Name, Score & call function AssignRem( ) to
assign the remarks.
_ A function DISPLAY ( ) to allow user to view the content of all the data members.
Q 7. Define a class ITEM in C++ with following description:
Private Members
[CBSE, 2010]
Code of type integer (Item Code)
Iname of type string (Item Name)
Price of type float (Price of each item)
Qty of type integer (Quantity of item in stock)
Offer of type float (Offer percentage on the item)
A member function GetOffer() to calculate Offer percentage as per the following rule:
If Qty<=50
If 50<Qty<=100
If Qty>100

Offer is 0
Offer is 5
Offer is 10
27

Public Members
A function GetStock() to allow user to enter values for Code, Iname, Price, Qty and call function
GetOffer() to calculate the offer
A function ShowItem() to allow user to view the content of all the data members.
Q 8. Define a class Clothing in C++ with the following descriptions :
Private Members :
Code

of type string

Type

of type string

Size

of type integer

Material

of type string

Price

of type float

A function Calc_Price ( ) which calculates and assigns the value of Price as follows :
For the value of Material as COTTON :
TYPE

Price (Rs)

TROUSER

1500

SHIRT

1200

For Material other than COTTON the above mentioned Price gets reduced by 25%.

Public Members :

A constructor to assign initial value of Code, Type and Material with the words NOT ASSIGNED
and Size and Price with 0.

A function Enter ( ) to input the values of data members Code, Type, Size and Material and invoke
the Calc_Price ( ) function.

A function Show ( ) which displays the content of all the members for a Clothing.

Q 9. Define a class Tour in C++ with the description given below :


[CBSE, 2007]
Private Members :
TCode of type string
28

NoofAdults of type integer


NoofKids of type integer
Kilometres of type integer
TotalFare of type float
Public Members :
A constructor to assign initial values as follows :
TCode with the word NULL
NoofAdults as 0
NoofKids as 0
Kilometres as 0
TotalFare as 0
A function AssignFare ( ) which calculates and assigns the value of
the data member TotalFare as follows
For each Adult
Fare(Rs)

For Kilometres

500

>=1000

300

< 1000 & > =500

200

< 500

For each Kid the above Fare will be 50% of the Fare mentioned in
the above table
For example :
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3
Then TotalFare should be calculated as
NumofAdults * 300 + NoofKids * 150
i.e. 2*300 + 3*150=1050
A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and
Kilometres; and invoke the Assign Fare( ) function.
A function ShowTour( ) which displays the content of all the data members for a Tour.
Q 10. Define a class named ADMISSION in C++ with the following descriptions:
[CBSE, 2006]
Private members:
AD_NO integer (Ranges 10 - 2000)
NAME Array of characters (String)
CLASS Character
FEES Float
Public Members:
Function Read_Data ( ) to read an object of ADMISSION type
Function Display() to display the details of an object
Function Draw-Nos ( ) to choose 2 students randomly. And display the details. Use random function
to generate admission nos. to match with AD_NO.
29

Q 11. Define a class named HOUSING in C++ with the following descriptions:
[CBSE, 2006, SET-II]
Private members
REG_NO integer(Ranges 10 1000)
NAME Array of characters(String)
TYPE Character
COST Float
Public Members
Function Read_Data( ) to read an object of HOUSING type
Function Display() to display the details of an object
Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array
of 10 objects of type HOUSING Use random function to generate the registration nos. to match with
REGNO from the array.

30

Вам также может понравиться