You are on page 1of 9

Most Expected Questions for Computer Science Class XII

Q 1. (a) What is the difference between automatic type conversion and type casting? Also, give a
suitable C++ code to illustrate both.
2
(b) Which C++ header file(s) will be essentially required to be included to run/
execute the following C++ code?

void main( ){
int Eno=123, char Ename[ ]=Rehan Swamp;
cout<<setw(5)<<Eno<<setw(25)<<EName<<endl;}

(c) Rewrite the following c++ program code after removing the syntax error(s)
(if any). Underline each correction.

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( );
}

(d) 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;
}

(e) 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;
}

(f) 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.
2
#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:
(iii) 19:16:14:18:

(ii) 14:18:15:16:
(iv) 19:16:15:16:

Q 2. (a) What is the difference between Local Variable and Global Variable? Also, give a suitable
C++ code to illustrate both.
2
(b) Write the names of the header files, which is/are essentially required to run/ execute the following
C++ code:
1
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 ;
}
}
(c) Rewrite the following program after removing the syntactical errors (if any).
Underline each correction.
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{
Text T= "Indian";
int Count=strlen(T) ;
cout<<T<<'has'<<Count<< 'characters' <<end1;
}
(d) Find the output of the following program:
#inc1ude<iostream.h>
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;
}
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) ;
}
(e) Find the output of the following program:
#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 ;
cout<< "Reset To" <<Track[0] <<end1 ;
}

(f) 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.
2
#include <iostream.h>
#include <stdlib.h>
void main ( )
{
randomize ( ) ;
int Guess, High=4;
Guess=random{High)+ 50 ;
for{int C=Guess ; C<=55 ; C++)
cout<<C<<"#" ;
}

(i) 50 # 51 # 52 # 53 # 54 # 55 #
(iii) 53 # 54 #

(ii) 52 # 53 # 54 # 55
(iv) 51 # 52 # 53 # 54 # 55

Q 3. (a) 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.
2
(b) 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 :
1
void main()
{
char CH,STR[20];
cin>>STR;
CH=toupper(STR[0]);
cout<<STR<<starts with<<CH<<endl;
}
(c) 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.
2
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;
}
(d) Obtain the output from the following C++ program as expected to appear on the screen after its
execution.
2
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;
}

(e) Obtain the output of the following C++ program, which will appear on the screen after its
execution.
3
Important Note :
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;
}
void Game::Play(int GS)
{
Score+=GS;
if(Score>=30)
Level=3;
else if(Score>=20)
Level=2;
else
Level=1;
}

(f) 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 :
2
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
Q4.. (a) What is the difference between actual and formal parameter ? Give a suitable
example to illustrate using a C++ code.

b) 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 :
1
void main ( )
{
char Text, [20] = C;
cin>>Text;
C=tolower (Text [0] ) ;
cout<<C<<" is the first char of " <<Text<<end1;
}.
(c) 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 :
- Assume that all the required header files are already included, which are essential to run this code.
2
- 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 ;
}
(d) 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.
2
void main ( )
{
char *String=SARGAM;
int *Ptr, A[ ]={1,5,7,9};
Ptr=A;
cout < < *Ptr<<String< <endl ;
String++;
Ptr+=3;
cout<< * Ptr< < String<<endl ,
}
(e) Obtain the output of the following C++ program, which will appear on the screen after its
execution. Important Note :
o Al1 the desired header files are already included in the code, which are required to run the code.
3
Class Player
{
int Score, Level ;
char Game;
public :
Player (char GGame='A' )
{score=0; Level=1; Game=GGame; }
void Start (int SC) ;
void Next () ;
void Disp ()
{
cout<<Game< < " @" < <Leve1< <end1;
cout<<Score<<endl ;
}};
void main ( )
{
Player P,Q ('B') ;
P.Disp( );
Q. Start (75) ;
Q. next( );
P. Start (120) ,
Q.Disp( );
P.Disp( );
}
void Player::Next ( )
{
Game= (Game==A) ? A : B;
}

void Player: :Start (int SC)


{
Score+=SC;
if (Score >= 100 )
Level=3;
else if (Score>=50 )
Level=2;
else
Level=1;
}
(f) 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 Start used in the code :
2
void main ( )
{
int Guess[4]={200,150,20 ,250};
int Start=random (2 ) +2;
for ( int C=Start ; C<4 ;C++ )
cout<<Guess [C] <<" #;
}
(i) 200#150#
(ii) 150#20#
(iii) 150#20#250#
(iv) 20#250#

You might also like