Saturday

PREVIOUS YEAR COMPUTER SCIENCE CBSE BOARD QUESTION ANSWERS OF CHAPTER 1 - CLASS XII

1. C++ REVISION TOUR
2012 Delhi:
1.a) Give the difference between the type
casting and automatic type conversion. Also,
give a suitable C++ code to illustrate both. 2
Ans. Automatic Type Conversion: It is an
implicit process of conversion of a data from
one data type to another. It is performed by the
compiler. It is also called as type promotion.
For example:
int N = 65;
char C = N; // Automatic type conversion
cout<Output:
A
Type Casting: It is an explicit process of
conversion of a data from one type to another.
(It is performed by the programmer.)
For example
int A=1, B=2;
float C = (float)A/B; //Type Casting
cout<Output:
0.5
b) Which C++ header file(s) are essentially
required to be included to run/execute the
following C++ source code (Note: Do not
include any header file, which is/are not
required): 1
void main( )
{ char TEXT[ ]=”SomeThing”;
cout<<”Remaining SMS Chars:”<<
160-strlen(TEXT)<}
Ans: iostream.h (for cout)
string.h (for strlen( ));
(f) Observe the following program and find out,
which output(s) out of (i) to (iv) will not be
expected from the program? What will be the
minimum and the maximum value assigned to
the variable Chance?
#include
#include
void main( )
{ randomize( );
int Arr[ ] ={9,6},N;
int Chance=random(2)+10;
for(int C=0;C<2 br="">{ N=random(2);
cout<}
}
(i) 9#6#
(ii) 19#17#
(iii) 19#16#
(iv) 20#16#
Ans: (i) 9#6#
Minimum Value: 10
Maximum Value: 11
2011 Delhi:
1. (a) What is the difference between Local
Variable and Global Variable? Also, give a
suitable C++ code to illustrate both. 2
Ans:
Local Variables: Local variables are those
variables which are declared within a function
or a compound statement and these variables
can only be used within that function/scope.
Global Variables: Global variables are those
variables which are not declared within any
function or scope. So, these variables can be
accessed by any function of the program.
Example:
#include
#include
int G; // Global variable declared
void Fun ( )
{i
nt L=25;// Local variable of function Fun ( ) assigned value 25
G=5; // Global Variable is accessed and assigned value 5
cout<cout<}
void main ( )
{
Fun ( ) ; // Function call
G = G + 5; // Global variable is incremented by 5
cout<}
(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<else
{
C=toupper(String[I]);
cout<}
}
Ans: iostream.h ctype.h

(c)Rewrite the following program after
removing the syntactical errors (if any).
Underline each correction. 2
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{
Text T= "Indian";
int Count=strlen(T) ;
cout<}
Ans:
#include
#include
typedef char Text [80];
void main ( )
{
Text T= "Indian";
int Count=str1en(T);
cout<}
(d)Find the output of the following program: 3
#inc1ude
void ChangeArray(int Number, int ARR[ ], int Size)
{f
or (int L =0; Lif (LARR [L] +=L;
e1se
ARR [L] *=L;
}
void Show (int ARR [ ], int Size)
{f
or (int L=0; L(L%2!=0)?cout<cout<}
void main ( )
{ int Array [
]
=
{
30, 20, 40, 10, 60, 50};
ChangeArray (3, Array, 6) ;
Show (Array, 6) ;
}
Ans: 30
21#42
30#240
250#
(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
#include
void main ( )
{r
andomize ( ) ;
int Guess, High=4;
Guess=random{High)+ 50 ;
for{int C=Guess ; C<=55 ; C++)
cout<}(
i) 50 # 51 # 52 # 53 # 54 # 55 #
(ii) 52 # 53 # 54 # 55
(iii) 53 # 54 #
(iv) 51 # 52 # 53 # 54 # 55
Ans: (i) 50 # 51 # 52 # 53 # 54 # 55 #
Least value 50
Highest value 53


2011 Outside Delhi:
1. (a) What is the difference between Type
Casting and Automatic Type conversion? Also,
give a suitable C++ code to illustrate both.
Ans: Refer 2012 Delhi
(b) Write the names of the header files, which
is/are essentially required to run/execute the
following c++ code:
void main ( )
{ char CH,Text[ ] ="+ve Attitude";
for (int I=0 ; Text[I] ! ='\0' ;I++)
if (Text[I]== ' ')
cout<else
{ CH=toupper (Text [I]) ;
cout<}
}
Ans: iostream.h, ctype.h
(c) Rewrite the following program after
removing the syntactical errors (if any).
Underline each correction. 2
include
typedef char [80] String;
void main ( )
{ String S= "Peace";
int L=strlen(S) ;
cout<}
Ans:
#include
#include
typedef char String [80];
void main ( )
{
String S = "Peace";
int L= strlen(S) ;
cout<}

(d) Find the output of the following program:3
#include
void SwitchOver(int A [ ], int N, int Split)
{f
or (int K=0 ; Kif (KA(K]+ =K;
else
A [K]*=K;
}
void Display (int A [ ], int N)
{f
or (int K=0 ; K(K%2==0)?
cout<}
void main ( )
{ int H[ ]= {
30,40,50,20,10,5};
SwitchOver (H, 6, 3);
Display (H, 6);
}
Ans:
30%41
52%60
40%25
(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 minimum and maximum values, which can
be assigned to the variable MyNum. 2
#include
#include
void main ( )
{ randomize (
)
;
int MyNum, Max=5;
MyNum = 20 + random (Max) ;
for (int N=MyNum; N<=25;N++)
cout} (
i) 20*21*22*23*24*25
(ii) 22*23*24*25*
(iii) 23*24*
(iv) 21*22*23*24*25
Ans (ii) 22*23*24*25*
Minimum value 20
Maximum value 24
2010 Delhi:
1. (a) What is the difference between automatic
type conversion and type casting? Also, give a
suitable C++ code to illustrate both. 2
Ans: Refer 2012 Outside Delhi
(b) Which C++ header file(s) will be essentially
required to be included to run/ execute the
following C++ code? 1
void main( )
{
int Eno=123, char Ename[ ]=”Rehan Swamp”;
cout<}
Ans. (i) iostream.h (ii) iomanip.h
(d) Find the output of the following program : 3
#inc1ude
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<;
cout<;
StepIn(P2,12);
cout<;
}
Ans.
16, 24, 6
6, 34, 16
18, 22, 28
(e) Find the output of the following program : 2
#include
#include
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==0)
Text[K]=toupper(Text[K]);
else
Text[K]=Text[K-1];

}
}
void main ( )
{
char OldText[ ]="pOwERALone";
ChangeIt(OldText,'%');
cout<<"New
TEXT:"<}
Ans.
New TEXT : PPW % RRllN%
(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
#include
const int LOW=15;
void main ( )
{ randomize( ) ;
int POINT=5, Number;
for (int 1=1;I<=4;I++)
{ Number=LOW+random(POINT) ;
cout<POINT--;
}
} (
i) 19:16:15:18:
(ii) 14:18:15:16:
(iii) 19:16:14:18
(iv) 19:16:15:16:
Ans.
(iv) 19:16:15:16:
Justification is as follows:
I POINT random Minimum Maximum
(POINT) Number Number
1 5 0 to 4 15 19
2 4 0 to 3 15 18
3 3 0 to 2 15 17
4 2 0 to 1 15 16
The only option that satisfies these values is option (iv).
2010 Outside Delhi:
1. (a) What is the difference between call by
value and call by reference? Also, give a
suitable C++ code to illustrate both. 2
Ans.
Call by value: The formal parameter makes a
copy of actual parameter. It does not make the
changes In actual parameter If the changes are
done In formal parameters.
Call by reference: The formal parameter Is an
alias of actual parameter. Thechanges made In
the formal parameter are reflected In actual
parameter. It is preceded by &.
void Calculator(int A,int & B )
{
A++;
a+=A;
}
Here A is called by value and B is called by
reference.
(b) Which C++ header file(s) will be essentially
required to be included to run/execute the
following C++ code: 1
void main()
{i
nt Rno=24; char Name [] =” Amen Singhania”;
cout<}
Ans.
iostream.h, iomanip.h
(d) Find the output of the following program: 3
#include
struct THREE_D
{ int X,Y,Z;
};
void MoveIn(THREE_D &T, int Step=l)
{ T.X+=Step;
T.Y-=Step;
T.Z+=Step;
}
void MoveOut(THREE_D &T, int Step=l)
{ T.X-=Step;
T.Y+=Step;
T.Z-=Step;
}
void main ()
{ THREE_D Tl={lO,20,5},T2={30,lO,40};
MoveIn(T1);
MoveOut(T2,5) ;
cout<cout<l;
MoveIn(T2,l0);
cout<;
}
Ans. 11, 19, 6
25, 15, 35
35, 5, 45
(e) Find. the output of the following program: 2
#include
#include
void MyCode (char Msg [], char CH)
{ for (int (Cnt=O;Msg[Cnt]!=’\0';Cnt++)

{ if (Msg[Cnt]>=’B’ && Msg[Cnt]<=’G’)
Msg[Cnt]=tolower(Msg[Cnt]);
else
if (Msg[Cnt]==’A’|| Msg[Cnt]==’a’)
Msg[Cnt]=CH;
else
if (Cnt%2==0)
Msg[Cnt]=toupper(Msg[Cnt]);
else
Msg[Cnt]=Msg[Cnt-l];
}
}
void main ()
{ char MyText [] =” ApEACeDriVE”;
MyCode(MyText,’@’);
cout<<“NEW TEXT:”<}
Ans.
NEW TEXT :@@e@ccddIIe
(f) The following code is from a game, which
generates a set of 4 random numbers. Praful 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
#include
const int LOW=25;
void main ()
{
randomize() ;
int P01NT=5,Number;
for (int I=1;I<=4;I++)
{
Number=LOW+random(POINT);
cout<P0INT--;
}
} (
i) 29:26:25:28:
(ii) 24:28:25:26:
(iii) 29:26:24:28:
(iv) 29:26:25:26:
Ans.
(iv) 29:26:25:26:
Justification is as follows:
I POINT Number
Minimum Maximum
1 5 25 29
2 4 25 28
3 3 25 27
4 2 25 26
The only option that satisfies these values is option (iv).
2009 Delhi:
1. (a) What is the difference between call by
value and call by reference? Give an example in
C++ to illustrate both. 2
Ans:
Call by value is used to create a temporary
copy of the data coming from the actual
parameter into the formal parameter. The
changes done in the function in formal
parameter are not reflected back in the calling
environment. It does
not use ‘&’ sign.
Call by reference is used to share the same
memory location for actual and formal
parameters and so changes done in the function
are reflected back in the calling environment. It
uses ‘&’ sign.
void Compute(int A, int &B)
{ A++;
B++;
cout<<”In the function”<cout<<”A=”<
}
void main ()
{ int I=50,J=25;
cout<<”Before function call “<cout<<”I=”<Compute (I,J) ;
cout<<”After function call “<cout<}
OUTPUT
Before function call
I=50&J=25
In the function
A=51&B=26
After function call
I=50&J=26
1(b) Write the names of the header files to
which the following belong: 1
(i) puts ( ) (ii) sin ( )
Ans (i) stdio.h (ii) math. h
1.(e) Find the output of the following program:2
#include
#include
void Encode (char Info [ ], int N) ;
void main ( )
{ char Memo [ ] = “Justnow” ;
Encode (Memo, 2) ;
cout<}
void Encode (char Info [ ], int N)
{ for (int I = 0 ; Info[I] !=‘\0’ ; 1++)
if (1%2= =0)
Info[I] = Info[I] –N ;
else if (islower(Info[I]))
Info[I] = toupper(Info[I]) ;

else
Info[I] = Info[I] +N ;
}
Ans
HuqTlOu
(f) Study the following program and select the
possible output from it : 2
#include
#include
const int LIMIT = 4 ;
void main ( )
{ randomize( ) ;
int Points;
Points = 100 + random(LIMIT) ;
for (int P=Points ; P>=100 ; P– –)
cout<
cout<} (
i) 103#102#101#100#
(ii) 100#101#102#103#
(iii) 100#101#102#103#104#
(iv) 104#103#102#101#100#
Ans
(i) 103#102#101#100#
2009 Outside Delhi:
1. (a) What is the difference between Actual
Parameter and Formal Parameter? Give an
example in C++ to illustrate both types of
parameters. 2
Ans A parameter used in the function call is
known as Actual Parameter. It is used to send
the data to function. A parameter used in the
function definition is known as Formal
Parameter, It is used to accept the data from
actual parameter.
void Seventimes(int A) //A is formal parameter
{ cout<<7 br="">}
void main ()
{ int P=6;
Seventimes(P); //p is actual parameter
}
Other answer for the same question:
Ans)The parameters in the function call
statement (or calling function) are called as
Actual Parameters.
The parameters in the function
definition (or called function) are called as
Formal Parameters.
Eg:
void manip(int x, int y)
{ ---
---
}
void main( )
{
int a,b;
----
manip(a,b);
}
Here a,b are Actual Parameters and
x,y are Formal Parameters.
1.(b) Write the names of the header files to
which the following belong: 1
(i) setw( ) (ii) sqrt( )
Ans
(i) iomanip.h (ii) math.h
1.(e) Find the output of the following program:2
#include
#include
void Secret (char Mig[ ], int N);
void main ( )
{ char SMS[ ] = “rEPorTmE” ;
Secret{SMS,2);
cout<}
void Secret(char Msg[ ], int N)
{ for (int C=0; Msg[C] !=’ \0' ;C++)
if (C%2==0)
Msg[C] = Msg[C]+N;
else if (isupper(Msg[C]))
Msg[C] = tolower(Msg[C]);
else
Msg[C] = Msg[C]-N;
}
Ans
teRmttoe
(f) Study the following program and select the
possible output from it : 2
#include
#include
const int MAX=3 ;
void main ( )
{ randomize( ) ;
int Number ;
Number = 50 + random{MAX) ;
for (int P=Number; P>=50; P– –)
cout<
cout<}(
i) 53#52#51#50#
(ii) 50#51#52#
(iii) 50#51#
(iv) 51#50#
Ans
(iv) 51#50#
(Solution: MAX value is 3. That’s why
random(MAX) can produce 0 or 1 or 2.
(random(N)will produce no.between 1 to n-1). The
Number value may be 50 or 51 or 52. The P value
starts from Number, upto 50,each time decreases by
1.
So Possible outputs are as follows:
52#51#50#

51#50#
50#.
As the output 51#50# is available in given
answers, so 51#50# is the answer.)
2008 Delhi:
1.b)Name the header files that shall be needed
for the following code: 1
void main( )
{ char String[ ] = “Peace”;
cout << setw(2)<}
Ans) iomanip.h, iostream.h
1. c)Rewrite the following program after
removing the syntactical error(s) if any.
Underline each correction. 2
#include
void main( )
{ First = 10, Second = 20;
Jumpto(First;Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
count<>N2;
}
Ans)
#include
void Jumpto(int N1,int N2=20); //Prototype missing
void main( )
{ int First = 10, Second = 20; //Data type missing
Jumpto(First,Second); //Comma to come instead of ;
Jumpto(Second);
}
void Jumpto(int N1, int N2)
{ N1=N1+N2;
cout<}
d)Find the output of the following program;3
#include
#include
void main( )
{ char Text[ ] = “Mind@work!”;
for(int I=0; Text[I]!=’\0’;I++)
{ if(!isalpha(Text[I]))
Text[I]=’*’;
else if(isupper(Text[I]))
Text[I]=Text[I]+1;
else
Text[I] = Text[I+1];
}
cout<}
Ans: Text[ ] =
When I=0
Since Text[0] is ‘M’, Upper Case Letter,
(isupper(Text[I]) will becomes true.
So Text[I] =Text[I]+1
So Text[0]=Text[0]+1
Text[0] =77(ASCII Value of M) + 1 = 78
=N(78 is ASCII Value of N)
Now the String Text[ ] =
When I=1
Since Text[1] is ‘i’, Which is a character, but
which is not Upper case,
else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[1]=Text[1+1]
=Text[2]
Ie ‘n’ will be stored in place of ‘i’
Now the String Text[ ] =
When I=2
Since Text[2] is ‘n’, Which is a character, but
which is not Upper case, else part will be
executed.
Ie Text[I]=Text[I+1]
Here Text[2]=Text[2+1]
=Text[3]
Ie ‘d’ will be stored in place of ‘n’
Now the String Text[ ] =
When I=3
Since Text[3] is ‘d’, Which is a character, but
which is not Upper case, else part will be
executed.
Ie Text[I]=Text[I+1]
Here Text[3]=Text[3+1]
=Text[4]
Ie ‘@’ will be stored in place of ‘d’
Now the String Text[ ] =
When I=4
Since Text[4] is ‘@’, Since which is not an
alphabet,
(!isalpha(Text[I])) will becomes true.
Ie if(!isalpha(Text[I]))
Text[I]=’*’;

Ie Text[4]=’*’
Ie ‘*’ will be stored in place of ‘@’
Now the String Text[ ] =
When I=5
Since Text[5] is ‘W’, Upper Case Letter,
(isupper(Text[I]) will becomes true.
So Text[I] =Text[I]+1
So Text[5]=Text[5]+1
Text[5] =87(ASCII Value of W) + 1 = 88
=X(88 is ASCII Value of X)
Now the String Text[ ] =
When I=6
Since Text[6] is ‘o’, Which is a character, but
which is not Upper case, else part will be
executed.
Ie Text[I]=Text[I+1]
Here Text[6]=Text[6+1]
=Text[7]
Ie ‘r’ will be stored in place of ‘o’
Now the String Text[ ] =
When I=7
Since Text[7] is ‘r’, Which is a character, but
which is not Upper case, else part will be
executed.
Ie Text[I]=Text[I+1]
Here Text[7]=Text[7+1]=Text[8]
Ie ‘k’ will be stored in place of ‘r’
Now the String Text[ ] =
When I=8
Since Text[8] is ‘k’, Which is a character, but
which is not Upper case, else part will be
executed. Ie Text[I]=Text[I+1]
Here Text[8]=Text[8+1]
=Text[9]
Ie ‘!’ will be stored in place of ‘k’
Now the String Text[ ] =
When I=9
Since Text[9] is ‘!’, Since which is not an
alphabet, (!isalpha(Text[I])) will becomes true.
Ie if(!isalpha(Text[I]))
Text[I]=’*’;
Ie Text[9]=’*’
Ie ‘*’ will be stored in place of ‘!’
Now the String Text[ ] =
Output: Nnd@*Xrk!*
e) Find the output of the following program:
2
#include
void main( )
{ int U=10,V=20;
for(int I=1;I<=2;I++)
{ cout<<”[1]”<cout<<”[2]”<<++V<<”&”<}
}
Ans: Output:
[1]10&15
[2]21&13
[1]11&16
[2]22&14
f) In the following program, find the correct
possible output(s) from the options:
2
#include
#include
void main( )
{ randomize( );
char City[][10]=
{“DEL”,”CHN”,”KOL”,”BOM”,”BNG”};
int Fly;
for(int I=0; I<3 br="">{ Fly=random(2) + 1;
cout<}
}
Outputs:
(i) DEL : CHN : KOL:
(i) CHN: KOL : CHN:
(ii) KOL : BOM : BNG:
(iii) KOL : CHN : KOL:
Ans)Since random(2) gives either 0 or 1, Fly value
will be either 1 or 2. (random(n) gives you any
number between 0 to n-1)
City[1] is “CHN”. City[2] is “KOL”.
Since I value from 0 to 2 (ie<3 3="" br="" iterations="" will="">takes place. So the possible output consists 3 strings
separated by :, each of them may be either “CHN” or
“KOL”.
So the possible output will be
(ii) CHN : KOL : CHN:
(iv) KOL :CHN : KOL:
1.a) What is the difference between #define and
const? Explain with suitable example. 2

Ans: While they both serve a similar purpose,
#define and const act differently. When using
#define the identifier gets replaced by the
specified value by the compiler, before the code
is turned into binary. This means that the
compiler makes the substitution when you
compile the application.
Eg: #define number 100
In this case every instance of “number” will be
replaced by the actual number 100 in your code,
and this means the final compiled program will
have the number 100 (in binary).
#define with different types of data:
*The #define preprocessor allows u s to define
symbolic names and constants.
Eg: #define PI 3.14159
*The #define allows you to make text
substitutions before compiling the program.
Eg: #define MAX 70
* Before compilation, if the C++ preprocessor
finds MAX as one word, in the source code, it
replaces it with the number 70.
* The #define preprocessor can be used in the
creation of macros (code substitution).
Eg: #define SQUARE(x) x*x
Before compilation, if the C++
preprocessor finds SQUARE(x), where x is any
value in the source code, it replaces it with its
square (ie x*x). Here a macro substitutes text
only; It does not check for data types.
On the other hand, when we use const
and the application runs, memory is allocated
for the constant and the value gets replaced
when the application is run.
Syntax: const type variable_name=value;
Eg: const int a=10;
The value of a constant is fixed
and in the above example, the value for a in
entire program is 10 only. You cannot change
the value of a, since it is declared as constant.
Difference between #define and const in
declaration:.
1.#define: #define symbolic_constant value.
Eg: #define number 100 //No semicolon ,no
equal to symbol.
2.const: const type variable_name=value;
Eg: const number=100; //Semicolon, equal to
symbol.
2008 Outside Delhi:
1.b) Name the header files that shall be needed
for the following code:
1
void main( )
{ char word[]=”Exam”;
cout<}
Ans: iostream.h, iomanip.h
1.c) Rewrite the following program after
removing the syntax error(s) if any. Underline
each correction. 2
#include
void main( )
{ One=10,Two=20;
Callme(One;Two);
Callme(Two);
}
void Callme(int Arg1,int Arg2)
{ Arg1=Arg1+Arg2;
Count<>Arg2;
}
Ans:
void Callme(int Arg1,int Arg2=20);
#include
void main( )
{ int One=10,Two=20;
Callme(One,Two); //Given ; instead of ,
Callme(Two);
}
void Callme(int Arg1,int Arg2)
{
Arg1=Arg1+Arg2;
cout<}
1.d)Find the output of the following program:3
#include
#include
void main( )
{ char Mystring[ ] = "what@OUTPUT!";
for(int I=0; Mystring[I]!='\0';I++)
{ if(!isalpha(Mystring[I]))
Mystring[I]='*';
else if(isupper(Mystring[I]))
Mystring[I]=Mystring[I]+1;
else
Mystring[I] =Mystring[I+1];
}
cout<Ans:
Output: hat@*PVUQVU*
e) Find the output of the following program: 2
#include
void main( )
{ int A=5,B=10;
for(int I=1;I<=2;I++)
{ cout<<”Line1”<
cout<<”Line2”<<++B<<”&”<}
}
Ans: Output:

Line15&8
Line211&9
Line16&9
Line212&10
f) In the following program, find the correct
possible output(s) from the options: 2
#include
#include
void main( )
{ randomize( );
char Area[ ][10]={“NORTH”,”SOUTH”,”EAST”,”WEST”};
int ToGo;
for(int I=0; I<3 br="">{ ToGo=random(2) + 1;
cout<}
}
Ans: Outputs:
(i) SOUTH : EAST : SOUTH :
(ii) NORTH : SOUTH : EAST :
(iii) SOUTH : EAST : WEST :
(iv) SOUTH : EAST : EAST :
Ans)Since random(2) gives either 0 or 1, ToGo
value will be either 1 or 2. (random(n) gives you any
number between 0 to n-1)Area[1] is
“SOUTH”.Area[2] is “EAST”. Since I value from 0
to 2 (ie<3 3="" br="" iterations="" place.="" so="" takes="" the="" will="">possible output consists 3 strings separated by :, each
of them may be either “SOUTH” or “EAST”.
So the possible output will be
(i) SOUTH : EAST : SOUTH :
(iv) SOUTH : EAST : EAST :
1.a) What is the purpose of using a typedef
command in C++?Explain with suitable
example 2
Ans: C++ allows you to define explicitly new
data type names by using the keyword typedef.
Using typedef does not actually create a new
data class, rather it defines a new name for an
existing type. This can increase the portability
of a program as only the typedef statements
would have to be changed. Typedef makes your
code easier to read and understand. Using
typedef can also aid in self documenting your
code by allowing descriptive names for the
standard data types.
The syntax of the typedef statement is
typedef type name;
Where type is any C++ data type and name is
the new name for this type. This defines
another name for the standard type of C++. For
example, you could create a new name for float
values by using the following statement:
typedef float amount;
This statement tells the compiler to recognize
amount as an alternative name for float. Now
you could create float variables using amount.
amount loan, saving, installment;
Using typedef does not replace the standard C+
+ data type name with the new name, rather the
new name is in addition to the existing name.
You still can create float variables using float.
Once a new name has been defined by typedef,
it can be used as a type for another typedef also.
Eg: typedef amount money;
Now, this statement tells the compiler to
recognize money as another name for amount,
which itself is another name for float. Typedef
does not create any new data types rather
provides an alternative name for standard types.
Reference provides an alias name for a variable
and typedef provides an alias name for a data
type.
2007 Delhi :
1.a) Differenctiate between a Run Time Error
and Syntax Error. Also give suitable examples
of each in c++. 2
Ans: Run Time Errors: Errors that occur
during the execution of a program are called as
run time errors. It is caused of some illegal
operation taking place or inavailability of
desired or required conditions for the execution
of the program. For instance, if a program is
trying to open a file which does not exist or it
could not be opened, it results into an execution
error. Similarly, if enough memory is not
available or an expression is trying to divide a
number by zero are run-time errors.
Eg: Division by zero. c=a/b ;
User will give the values of a and b at the time
of program execution. If he give the value of b
as ‘0’ , then division by zero, ie a run time error
occurs.
Syntax Errors:Syntax errors occur when rules
of a programming languages (syntax) is
misused. Ie when a grammatical rule of C++ is
violated.
Eg (i) c=a+b In this statement,
since there is no semicolon at the end of the
statement, there will occurs a syntax error.
(ii) cin<
stream insertion operator (<<) has given instead
of stream extraction operation(>>), there will
occurs a syntax error.
1.b) Name the header file(s) that shall be needed
for successful compilation of the following C++
code. 1
void main( )
{ char String[20];
gets(String);
strcat(String,”CBSE”);
puts(String);
}
Ans) stdio.h string.h

1. c) Rewrite the following program after
removing the syntactical error(s) if any.
Underline each correction. 2
#include
const int Max 10;
void main()
{ int Numbers[Max];
Numbers = {20,50,10,30,40};
for(Loc=Max-1;Loc>=10;Loc--)
cout>>Numbers[Loc];
}
Ans)
#include
const int Max = 10 ;/ /Constant Variable ‘Max’ must be
// initialized.Declaration Syntax Error
void main( )
{ int Numbers[Max]={20,50,10,30,40};
for(Loc=Max-1;Loc>=0;Loc--)
cout>>Numbers[Loc];
}
e)Find the output of the following program. 3
#include
void Withdef(int HisNum=30)
{ for(int I=20;I<=HisNum;I+=5)
cout<cout<}
void Control(int &MyNum)
{ MyNum+=10;
Withdef(MyNum);
}
void main()
{ int YourNum=20;
Control(YourNum);
Withdef();
cout<<”Number=”<}
Ans:
Output:
20,25,30,
20,25,30,
Number=30
f)In the following C++ program what is the
expected value of MyMarks from options (i) to
(iv)given below. Justify answer.
2 #
include
#include
void main( )
{ randomize( );
int Marks[]={99,92,94,96,93,95},MyMarks;
MyMarks = Marks [1+random(2)];
cout<} (i)99 (ii)94 (iii)96 (iv) None of the above.
Ans: Output:
(ii) 94
2007 Outside Delhi:
1.a) Differentiate between a Logical Error and
Syntax Error. Also give suitable examples of
each in C++. 2
Ans: Logical Error: A logical error is that
error which causes a program to produce
incorrect or undesired output.
An incorrectly implemented algorithm
or use of a variable before its initialization, or
unmarked end for a loop, or wrong parameters
passed are causes logical errors. These must be
handled carefully.
For instance, if we are trying to print the
table of a number 5 and if we say
counter=1;
while(counter>8)
{ cout<counter=counter+1;
}
Here the loop would not be executed even once
as the condition (counter>8) is not fulfilled at
all. Therefore, no output will be produced.
Such an error is logical error.
Syntax Error: Syntax errors occur when rules
of a programming languages (syntax) is
misused. Ie when a grammatical rule of C++ is
violated.
Eg (i) c=a+b
In this statement, since there is no semicolon at
the end of the statement, there will occurs a
syntax error.
(ii)cin<
insertion operator (<<) has given instead of
stream extraction operation(>>), there will
occurs a syntax error.
1.b) Name the header file(s) that shall be needed
for successful compilation of the following C++
code. 1
void main( )
{ char Text[40];
strcpy(Text,”AISSCE”);
puts(Text);
}
Ans:
string.h, stdio.h
1.c) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. 2
#include
const int Size 5;
void main( )
{ int Array[Size];
Array={50,40,30,20,10};
for(Ctr=0;Ctrcout>>Array[Ctr];

}
Ans)
#include
const int Size=5;
void main( )
{ int Array[Size];
Array={50,40,30,20,10};
for(Ctr=0;Ctrcout<}
1.e)Find the output of the following program3
#include
void Indirect(int Temp=20)
{ for(int I=10;I<=Temp;I+=5)
cout<cout<}
void Direct(int &Num)
{ Num+=10;
Indirect(Num);
}
void main( )
{ int Number=20;
Direct(Number);
Indirect( );
cout<<”Number =”<}
Ans: Output:
10,15,20,25,30,
10,15,20,
Number =30
f) In the following C++ program what is the
expected value of Mysore from options (i) to
(iv) given below.Justify your answer. 2
#include
#include
void main( )
{ randomize( );
int Score[ ] = {25,20,34,56,72,63},Myscore;
cout<}
(i) 25 (ii) 34 (iii) 20 (iv) None of the above.
Ans: Expected Output:
(i) None of the above.
2006 Delhi:
1.a) Name the header file to which the
following below: (i) abs( ) (ii)
isupper( ) 1
Ans) (i) abs( ) - math.h, stdlib.h, complex.h
(ii)isupper( ) - ctype.h
1.e) Find the output of the following program 2
#include
void main( )
{ long NUM=1234543;
int F=0,S=0;
do
{ int R=NUM % 10;
if (R %2 != 0)
F += R;
else
S += R;
NUM / = 10;
} while (NUM>0);
cout<} Ans: Output: 2
1.b) Illustrate the use of #define in C++ to
define a macro. 2
Ans: The #define preprocessor can be used in
the creation of macros (code substitution).
Eg: #define SQUARE(x) x*x
Before compilation, if the C++ preprocessor
finds SQUARE(x), where x is any value in the
source code, it replaces it with its square (ie
x*x). Here a macro substitutes text only; It does
not check for data types.
1.C) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. 2
#include
void main( )
{ struct STUDENT
{
char stu_name[20];
char stu_sex;
int stu_age=17;
}student;
gets(stu_name);
gets(stu_sex);
}
Ans:
#include
#include
void main( )
{ struct STUDENT
{ char stu_name[20];
char stu_sex;
int stu_age;
//Initialization of variables inside a structure is not allowed.
}student;
gets(student.stu_name);
cin>>student.stu_sex);
//A single character cannot be read using gets
}
1.f) What are Nested Structures? Give an
example. 2

Ans: Nested structures are structures as
member of another structure. For example, the
date of birth is astructure within the structure of
a student as shown below. These types of
structures are known as nested structures.
Eg1:
struct date
{ int dd;
int mm;
int yy;
};
struct student
{ char name[20];
int roll;
date dob;
int marks;
};
The member of a nested structure is referenced
from the outermost to innermost with the help
of dot operators.
student stud;
Then the members of the nested structure can be
accessed as stud.dob.mm=10;
Eg2:
struct addr
{ int houseno;
char area[26];
char city[26];
char state[26];
};
struct emp
{ int empno;
char name[26];
char design[16];
addr address;
float basic;
}worker;
2006 Outside Delhi:
1.a) Name the header file to which the
following belong:
(i) pow ( ) (ii)random( ) 1
Ans:
(i) abs( ) - math.h, stdlib.h, complex.h
(ii)random( ) - stdlib.h
1.e)Find the output of the following program 2
#includevoid 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 > 0);
cout<}
Ans: Output -2
1.C) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. 2
#include
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost=100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}
Ans:
#include
#include
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost;
//Initialization of variables inside a structure is not allowed.
}MOVIE;
gets(MOVIE.movie_name);
cin>>MOVIE.movie_type;
//A single character cannot be read using gets
}
2005 Delhi:
1.a) Differentiate between a Call by Value and
Call by Reference, giving suitable examples of
each. 2
Ans: Call by value: In call by value method,
the called function creates a new set of variables
and copies the values of arguments into them.
The function does not have access to the
original variables (actual parameters) and can
only work on the copies of values it created.
Passing arguments by value is useful when the
original values are not to be modified.
In call by reference method, a
reference to the actual argument (original
variable) is passed to the called function.
(Reference is an alias for a predefined variable.
Ie the same variable value can be accessed by
any of the two names: the original variable’s
name and the reference name.) Thus, in call by
reference method, the changes are reflected
back to the original values. The call by
reference method is useful in situations where
the values of the original variables are to be
changed using a function.
Example:

void Calculator(int A,int & B )
{
A++;
a+=A;
}
Here A is called by value and B is called by
reference.
1. b) Name the header files to which the
following belong: (i) abs( ) (ii) strcmp( ) 1
Ans) (i) abs( ) - stdlib.h, math.h, complex.h
(ii) strcmp( ) - string.h
1. c) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. 2
#include
const int Multiple 3;
void main( )
{ value = 15;
for(int Counter = 1;Counter = <5 -="2)<br" ounter="" value="">if(Value%Multiple = = 0)
cout<cout<else
cout<}
Answer:
#include
const int Multiple=3;
void main( )
{ int Value = 15;
for(int Counter = 1;Counter <=5;Counter ++, Value -=
2)
if(Value%Multiple == 0)
{ cout<cout<}
else
cout<}
1.e) Find the output of the following program 2
#include
#include
#include
void Convert(char Str[ ],int Len)
{ for(int Count=0;Count{ if(isupper(Str[Count]))
Str[Count]=tolower(Str[Count]);
else if (islower(Str[Count]))
Str[Count]=toupper(Str[Count]);
else if(isdigit(Str[Count]))
Str[Count]=Str[Count]+1;
else Str[Count]=’*’;
}
}
void main( )
{
char Text[ ]=”CBSE Exam 2005”;
int Size = strlen(Text);
Convert(Text,Size);
cout<for(int C=0,R=Size – 1;C<=Size/2;C++,R--)
{
char Temp=Text[C];
Text[C]=Text[R];
Text[R]=Temp;
}
cout<}
Ans:
Output:
cbse*eXAM*3116
6113*MXAe*esbc
1. f) Observe the following program
SCORE.CPP carefully, if the value of Num
entered by the user is 5, choose the correct
possible output(s) from the options from (i) to
(iv), and justify your option. 2
//Program: SCORE.CPP
#include
#include
void main( )
{ randomize( );
int Num,Rndnum;
cin>>Num;
Rndnum = random(Num) + 5;
for(int N = 1;N<=Rndnum;N++)
cout<}
Output Options:
(i) 1 2 3 4 (ii) 1 2
(iii) 1 2 3 4 5 6 7 8 9
(iv) 1 2 3
Ans: Expected Output:
(iii) 1 2 3 4 5 6 7 8 9
1.d) Find the output of the following program:
#include
struct MyBox
{ int Length,Breadth,Height;
};
void Dimension(MyBox M)
{ cout<cout<}
void main( )
{ MyBox B1={10,15,5},B2,B3;
++B1.Height;
Dimension(B1);
B3=B1;
++B3.Length;
B3.Breadth++;

Dimension(B3);
B2=B3;
B2.Height+=5;
B2.Length--;
Dimension(B2);
}
2005 Outside Delhi :
1.b) Name the header files to which the
following belong: (i) puts( )
(ii)isalnum( ) 1
Ans)(i) puts( ) - stdio.h
(isalnum( ) - ctype.h
1.c) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. 2
#include
const int dividor 5;
void main( )
{ Number = 15;
for(int Count=1;Count=<5 -="3)<br" ount="" umber="">if(Number % dividor = = 0)
cout<cout<else
cout<Ans:
#include
const int dividor= 5;
void main( )
{ int Number = 15;
for(int Count=1;Count<=5;Count++,Number -= 3)
if(Number % dividor = = 0)
{ cout<cout<}
else
cout<}
1.e) Find the output of the following program 2
#include
#include
#include
void Change(char Msg[],int Len)
{
for(int Count=0;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[ ]=”2005 Tests ahead”;
int Size=strlen(Message);
Change(Message,Size);
cout<for(int C=0,R=Size – 1; C<=Size/2;C++,R--)
{ char Temp=Message[C];
Message[C]=Message[R];
Message[R]=Temp;
}
cout<}
Ans: Output:
3116*tESTS*AHEAD
DAEHA*SSTEt*6113
1.f) Observe the following program
GAME.CPP carefully, if the value of Num
entered by the user is 14, choose the correct
possible output(s) from the options from (i) to
(iv), and justify your option. 2
//Program:GAME.CPP
#include
#include
void main( )
{ randomize( );
int Num,Rndnum;
cin>>Num;
Rndnum=random(Num)+7;
for(int N=1;N<=Rndnum;N++)
cout<}
Output Options:
(i) 1 2 3 (ii) 1 2 3 4 5 6 7 8 9 10 11
(iii) 1 2 3 4 5 (iv) 1 2 3 4
Ans: Expected Output
(ii) 1 2 3 4 5 6 7 8 9 10 11
1.d) Find the output of the following program:
#include
struct Package
{ int Length,Breadth,Height;
};
void Occupies(Package M)
{ cout<cout<}
void main( )
{ Package P1={100,150,50},P2,P3;
++P1.Height;
Occupies(P1);
P3=P1;
++P3.Lengh;
P3.Breadth++;
Occupies(P3);
P2=P3;

P2.Height+=50;
P2.Length--;
Occupies(P2);
}
2004:
1.b) Write the names of the header files to
which the following belong:
(i) gets( ) (ii) strcmp( ) (iii)abs( ) (iv)isalnum( )
Ans: (i)gets( ) - stdio.h
(ii)strcmp( ) - string.h
(iii)abs( ) - math.h,
stdlib.h,complex.h
(iv)isalnum( ) - ctype.h
1.e) What will be the output of the following
program
#include
void main( )
{ int var1=5,var2=10;
for(int i=1,i<=2;i++)
{ cout<cout<}
}
Ans: Output:
5 9
9 7
7 7
7 9
f)Write definition for a function
SumSequence( ) in C++ with two arguments/
parameters – double X and int n. The function
should return a value of type double and it
should perform sum of the following series.
1/x- 3!/x2 + 5!/x3 – 7!/x4 + 9!/x5 - ------upto n terms.
Note: The symbol ! represents Factorial of a
number ie 5!= 1 X 2 X 3 X 4 X 5.
#include
#include
#include
double SumSequence(int x1,int n1);
void main()
{ int x;
int n;
clrscr();
cout<<"Enter the vaue of X and N";
cin>>x>>n;
cout<<”\nThe sum of the series =
“<getch();
}
double SumSequence(int x1,int n1)
{
double sum=0;
int c=0;
for(int i=1;i<=(2*n1);i=i+2)
{ int f=1;
for(int j=1;j<=i;j++)
{ f=f*j;
}
c=c+1;
if(c%2==1)
{ sum=sum+f/(pow(x1,c));
}
else
{ sum=sum-f/(pow(x1,c));
}
}
return sum;
}
1.c) Rewrite the corrected code for the
following program. Underline each correction
if any.
#include
structure Supergym
{ int member number;
char membername[20];
char membertype[]=”HIG”;
};
void main( )
{ Supergym person1,person2;
cin>>”Member Number: “;
cin>>person1.membhernumber;
cout<<”Member Name: “;
cin>>person1.membername;
person1.member type = “MIG”;
person2=person1;
cin>>”Member Number;“
<cin<<”Member Name”
<cin<<”Member Number:”
<}
Ans:
#include
#include
struct Supergym
{ int membernumber;
char membername[20];
char membertype[4];
};
void main( )
{ Supergym person1,person2;
cin>>"Member Number: ";
cin>>person1.membernumber;
cout<<"Member Name: ";
cin>>person1.membername;
strcpy(person1.membertype,"MIG");
person2=person1;
cin>>"Member Number;"

>>person2.membernumber;
cin>>"Member Name"
>>person2.membername;
cin>>"Member Number:"
>>person2.membertype;
}
2003:
1.a) What is the difference between global
variables and local variables? Give an example
to illustrate the same .2
Ans: The local variables are the variables
defined within any function (or block) and are
hence accessible only within the block in which
they are declared. In contrast to local variables,
variables declared outside of all the functions in
a program are called global variables. These
variables are defined outside of any function, so
they are accessible to all functions. These
functions perform various operations on the
data. They are also known as External
Variables.
Eg: #include
int a,b;
void main()
{ float f;
---;
---;
}
In the above program segment, a and b are
global variables, we can access a and b from
any function. f is local variable to function
main( ), we can access f from main( ) only.
1.b) Name the header file, to which the
following built-in function belongs:
(i) strcmp( ) (ii)getc( ) 1
Ans: (i) strcmp( ) - string.h
(ii) getc( ) - stdio.h
1.c) Rewrite the following program after
removing all the syntax error(s) if any.2
#include
void main( )
{ int P[ ]={90,10,24,15};Q,Number=4;
Q=9;
for[int I=Number-1;I>=0,I--]
switch(I)
{ case 0;
case 3:cout>>P[I]*Q<case 1:
case 2: cout<
}
}
Ans:
#include
void main( )
{ int P[ ]={90,10,24,15},Q,Number=4;
Q=9;
for(int I=Number-1;I>=0;I--)
switch(I)
{ case 0:
case 3:cout<
case 1:
case 2: cout<
}
}
1.e) Write the output of the following program:
#include
int Execute(int M)
{ if(M%3==0)
return M*3;
else
return M+10;
}
void Output(int B=2)
{ for(int T=0;Tcout<cout<}
void main( )
{ Output(4);
Output( );
Output(3);
}
f) Write a C++ function SUMFUN( ) having
two parameters Y(of type double) and m(of type
integer) with a result type as double to find the
sum of the series given below:
Y + Y3 / 2! + Y5 /3! + ------ + Y 2m-1 / m!
#include
#include
#include
double SUMFUN(int y1,int m1);
void main()
{ int y;
int m;
clrscr();
cout<<"Enter the vaue of Y and M";
cin>>y>>m;
cout<<”\nThe sum of the series =
“<getch();
}
double SUMFUN(int y1,int m1)
{ double sum=0;
double upper;
for(int i=1;i<=m1;i++)
{ int f=1;
for(int j=1;j<=i;j++)
{ f=f*j;
}
upper=pow(y1,(i*2-1));
sum=sum+upper/f;
}
return sum;
}

1.d) Give the output of the following program:
#include
struct Pixel
{ int C,R;
};
void Display(Pixel P)
{
cout<<”col”<
}
void main( )
{
Pixel X={40,50},Y,Z;
Z=X;
X.C+=10;
Y=X;
Y.R+=20;
Z.C-=15;
Display(X);
Display(Y);
Display(Z);
}
2002:
1.b)Name the header files of C++ to which the
following functions belong: 2
(i)get( ) (ii)open( )
(iii)abs( ) (iv)strcat( )
Ans: (i)get( ) - iostream.h
(ii)open( ) - fstream.h
(iii)abs( ) - math.h, stdlib.h
(iv)strcat( ) - string.h
1.c)Find the syntax error(s), if any, in the
following program. 2
#include
void main( )
{ int x;
cin>>x;
for( int y=0,y<10 br="" y="">cout<}
Ans:
#include
void main( )
{ int x;
cin>>x;
for( int y=0;y<10 br="" y="">cout<}
1.d)Write the output of the following program2
void main( )
{ int x=5,y=5;
cout<cout<<”,”;
cout<- -="" br="" x="">cout<<”,”;
cout<}
Ans: Output:
5,3,4,4
1.e)Write the output of the following program 3
#include
void X(int &A,int &B)
{ A=A+B;
B=A-B;
A=A-B;
}
void main( )
{ int a=4,b=18;
X(a,b);
cout<
}
Ans: Output:
18,4
f)Write a function called zero_Small() that has
two integer arguments being passed by
reference and sets the smaller of the two
numbers to 0. Write the main program to access
this function.4
#include
#include
void zero_Small(int &A,int &B)
{ if(AA=0;
else
B=0;
}
void main( )
{ clrscr();
int a,b;
cout<<”Enter any two values…”;
cin>>a>>b;
cout<<"Initial values of a and b are ";
cout<
zero_Small(a,b);
cout<";
cout<
cout<cout<<"\nPress any key to continue...";
getch();
}
2001:
1.b) Name the header file to be included for the
use of the following built in functions:
(i)getc( ) (ii)strcat() 1
Ans: (i) getc( ) - stdio.h
(ii)strcat( ) - string.h
1.e) Give the output of the following program:
#include

#include
int g=20;
void func(int &x,int y)
{ x=x-y;
y=x*10;
cout<}
void main( )
{ int g=7;
func(g,::g);
cout<func(::g,g);
cout<}
Ans: Output:
-13,-130
-13,20
33,330
-13,33
1.f) Write a function named SUMFIN( ), with
arguments x, N, which returns the sum of N
terms of the following series.: 4
x – x^3/3 + x^5/5 – x^7/7 + x^9/9
#include
#include
#include
double SUMFIN(int x1,int n1);
void main()
{ int x;
int n;
clrscr();
cout<<"Enter the vaue of X and N";
cin>>x>>n;
cout<<”\nThe sum of Series = “<getch();
}
double SUMFIN(int x1,int n1)
{ double sum=0;
int c=0;
for(int i=1;i<=(2*n1);i=i+2)
{ c=c+1;
if(c%2==1)
{ sum=sum+(pow(x1,i))/i;
} else
{ sum=sum-(pow(x1,i))/i;
}
}
return sum;
}
1.e)Give the output of the following program. 3
#include
#include
int g=20;
void func(int &x,int y)
{ x=x-y;
y=x*10;
cout<}
void main( )
{ int g=7;
func(g,::g);
cout<func(::g,g);
cout<}
2000:
1.b) Name the header file, to which following
built in function belong: 2
(i) isupper( ) ( ii)setw()
(iii)exp( ) (iv)strcmp( )
Ans) (i) isupper( ) - ctype.h
(ii)setw( ) - iomanip.h
(iii)exp( ) - math.h
(iv)strcmp( ) - string.h
1.c)Will the following program execute
successfully?If not, state the eason(s) 2
#include
void main( )
{ int s1,s2,num;
s1=s2=0;
for(x=0;x<11 br="" x="">{ cin<if(num>0)s1+=num;else s2=/num;
}
cout<}
Ans: The program will not execute successfully.
Because some syntax errors are there in the
program. They are
(i)cin and cout, stream objects used but
iostream.h header file is not included in the
program.
(ii)x is not declared, it should be declared as int.
(iii)With cin, we should use >> instead of <<.
(iv)The shorthand operator /=, is given wrongly
as =/.
So the corrected program is as follows:
#include
void main( )
{ int s1,s2,num;
s1=s2=0;
for(int x=0;x<11 br="" x="">{ cin>>num;
if(num>0)s1+=num;else s2/=num;
}
cout<}
d)Give the output of the following program
segment(Assuming all required header files are
included in the program): 2
char *NAME=”a ProFiLe”;
for(int x=0;xif(islower(NAME[x]))
NAME[x]=toupper(NAME[x]);

else if(isupper(NAME[x]))
if(x%2!=0)
NAME[x]=tolower(NAME[x-1]);
else
NAME[x]--;
cout<Ans: Output: AOROoIiE
1.e)Write the output of the following program3
#include
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=func(q);
cout<
q=func(p);
cout<
}
Ans: Output: 2023
1023
1111
f) Write a function seqsum( ) in C++ with two
arguments, double x and int n. The function
should return a value of type double and it
should find the sum of the following series. 4
1+ x/2! + x2/4! + x3/6! + x4/8! + x5/10! + ----+ xn/
(2n)!
#include
#include
#include
double seqsum(int x1,int m1);
void main()
{ int x;
int m;
clrscr();
cout<<"Enter the vaue of X and M";
cin>>x>>m;
cout<<"\nThe sum of the series =
"<getch();
}
double seqsum(int x1,int m1)
{ double sum=1;
for(int i=1;i<=m1;i++)
{ int f=1;
for(int j=1;j<=2*i;j++)
{ f=f*j;
}
sum=sum+pow(x1,i)/f;
}
return sum;
}
1999:
1.a) Why main( ) function is so special. Give
two reasons? 1
Ans: Execution of the program starts and ends
at main( ). The main( ) is the driver function of
the program. If it is not present in a program,
no execution can take place.
1.b) Name the header file of C++ to which
following functions belong. (i)strcat( )
(ii) scanf( ) (iii) getchar( ) (iv)clrscr( )
Ans: (i)strcat( ) - string.h
(ii)scanf( ) - stdio.h
(iii)getchar( ) - stdio.h
(iv)clrscr( ) - conio.h
1.c) Find the syntax error(s), if any, in the
following program:
#include
main( )
{ int x[5],*y,z[5];
for(i=0;i<5 br="" i="">{ x[i]=i;
z[i]=i+3;
y=z;
x=y;
}
}
Ans (i) Line No 5: Undefined symbol ‘i’.
The variable ‘i’ is not declared in the program.
(ii)Line No 10:Assign the value of a pointer to
an integer variable. Ie error in x=y.
1.e) Write the output of the following program.
#include
static int i=100;
void abc( )
{ static int i=8;
cout<<”first =”<}
main( )
{ static int i=2;
abc( );
cout<<”second =”<}
Ans: Output:
First =8second =2
1.f) Write a C++ function that converts a 2-
digit octal number into binary number and prints
the binary equivalent.
#include
#include
void binary(int a)
//member function for conversion
{ int i,b[5]; //integer array 6
for(i=3;i>=1;i--)
{ b[i]=a%2;
a=a/2;
}
for(i=1;i<=3;i++)

cout<}
void main()
{ int n,x,y;
clrscr( );
cout<<"Enter a two digit octal number: ";
cin>>n;
x=n/10;
y=n%10;
binary(x);
binary(y);
getch( );
}
1998 :
1.b)Name the header files, to which the
following built in functions belongs to:
(i)cos( ) (ii)setw( )
(iii)toupper( ) (iv)strcpy( )
Ans: (i) cos( ) - math.h
(ii) setw( ) - iomanip.h
(iii) toupper( ) - ctype.h
(iv) strcpy( ) - string.h
1.c)Find the syntax error(s), if any, in the
following program:
include
void main( )
{ int R; W=90;
while W>60
{ R=W-50;
switch(W)
{ 20:cout<<”Lower Range”<30:cout<<”Middle Range “<40:cout<<”Higher Range”<}
}
}
Ans:
(i) Line 1: It should be,
#include
(ii) Line 4:Variables should be
separated using commas.
It should be int R,W=90;
(iii) Line 5:Test expression should be
in braces. It should be while
(W>60)
(iv) Line 10:It should be case 20;
(v) Line 11:It should be case 30;
(vi) Line 13:It should be case 40;
So the corrected version of the program is as
follows:
#include
void main( )
{ int R, W=90;
while (W>60)
{R=W-50;
switch(W)
{ case 20:cout<<”Lower Range”<case 30:cout<<”Middle Range “<case 40:cout<<”Higher Range”<}
}
}
1.d) Give the output of the following program
segment: char *NAME=”IntRAneT”;
for(int x=0;xif(islower(NAME[x])
NAME[x]=toupper(NAME[x]));
else if(isupper(NAME[x]))
if(x%2==0)
NAME[x]=tolower(NAME[x]);
else
NAME[x]=NAME[x-1];
puts(NAME);
Ans: Output: INTTaNEE
1.f) Write the output of the following program:
#include
void Execute(int &X,int Y=200)
{ int TEMP=X+Y;
X+=TEMP;
if(Y!=200)
cout<}
void main( )
{ int A=50,B=20;
Execute(B);
cout<
Execute(A,B);
cout<
}
1.f) Write a C++ function having two value
parameters X and N with result type float to find
the sum of series given below:
1 + x1/2! + x2/3! + x3/4! + x4/5! + - - - - - - xn/(n+1)!
#include
#include
#include
float sum_series(float X,int N) //function being
declared
{ float sum=0,term;
int fact,f;
sum+=1;
for(int i=1;i<=N;i++)
{ fact=1;
for(f=1;f<=(i+1);f++)
fact*=f;
term=pow(X,i)/fact;
sum+=term;
}
return(sum);
}
void main( )

{ clrscr( );
float x1;
int n1;
cout<<"\nEnter the value of X and N";
cin>>x1>>n1;
cout<<"\nThe Sum of the Series
..."<getch( );
}
Model Paper 1 for 2008-09 Batch:
Q1. (a) What is the difference between Global
Variable and Local Variable? 2
Answer:
Global Variable Local Variable
· It is a variable,
which is declared
outside all the
functions
· It is accessible
throughout the
program
· It is a variable,
which is declared
with in a function
or with in a
compound
statement
· It is accessible only
within a
function/compound
statement in which
it is declared
#include
float NUM=900; //NUM is a global variable
void LOCAL(int T)
{ int Total=0; //Total is a local variable
for (int I=0;ITotal+=I;
cout<}
void main()
{ LOCAL(45);
}
1.b)Write the names of the header files to which
the following belong: 1
(i) strcmp() (ii) fabs()
Answer: (i)string.h (ii) math.h
1(d) Find the output of the following
program: 3
#include
struct PLAY
{ int Score, Bonus;
};
void Calculate(PLAY &P, int N=10)
{ P.Score++;
P.Bonus+=N;
}
void main()
{ PLAY PL={10,15};
Calculate(PL,5);
cout<Calculate(PL);
cout<Calculate(PL,15);
cout<}
Answer:
11:20
12:30
13:45
1.e)Find the output of the following program 2
#include
#include
void Encrypt(char T[])
{ for (int i=0;T[i]!='\0';i+=2)
if (T[i]=='A' || T[i]=='E')
T[i]='#';
else if (islower(T[i]))
T[i]=toupper(T[i]);
else
T[i]='@';
}
void main()
{ char Text[]="SaVE EArtH";
//The two words in the string Textare separated
by single space
Encrypt(Text);
cout<}
Answer: @a@E@E#rTH
1.f)In the following program, if the value of N
given by the user is 15, what maximum and
minimum values the program could possibly
display? 2
#include
#include
void main()
{ int N,Guessme;
randomize();
cin>>N;
Guessme=random(N)+10;
cout<}
Answer:M aximum Value:24 Minimum
Value:10
Model Paper 2 for 2008-09 Batch:
1.b)Write the names of the header files to which
the following belong: 1
(i) frexp() (ii) isalnum()
Answer:
(i) math.h (ii) ctype.h
1.d)Find the output of the following program3
#include

void Changethecontent(int Arr[], int Count)
{
for (int C=1;CArr[C-1]+=Arr[C];
}
void main()
{
int A[ ]={3,4,5},B[ ]={10,20,30,40},C[ ]={900,1200};
Changethecontent(A,3);
Changethecontent(B,4);
Changethecontent(C,2);
for (int L=0;L<3 br="">cout<
cout<for (L=0;L<4 br="">cout<cout<for (L=0;L<2 br="">cout<}
Answer:
7#9#5#
30#50#70#40#
2100#1200#
1.(e)Find the output of the following program:2
#include
struct Game
{ char Magic[20];int Score;
};
void main()
{ Game M={“Tiger”,500};
char *Choice;
Choice=M.Magic;
Choice[4]=’P’;
Choice[2]=’L’;
M.Score+=50;
cout<Game N=M;
N.Magic[0]=’A’;N.Magic[3]=’J’;
N.Score-=120;
cout<}
Answer:
TiLeP550
AiLJP430
1.f)In the following program, if the value of N
given by the user is 20, what maximum and
minimum values the program could possibly
display? 2
#include
#include
void main()
{ int N,Guessnum;
randomize();
cin>>N;
Guessnum=random(N-10)+10;
cout<}
Answer:M aximum Value:19 Minimum
Value:10
Sample Paper 1 for 2009-10:
1.a) What is the difference between Global
Variable and Local Variable? Also, give
a suitable C++ code to illustrate both. 2
Ans) Global Variable:
* It is a variable which is declared outside all
the functions
* It is accessible throughout the program
Local Variable:
* It is a variable which is declared with in a
function or with in a compound statement
* It is accessible only within a function/
compound statement in which it is declared
#include
float NUM=900; //NUM is a global variable
void LOCAL(int T)
{
int Total=0; //Total is a local variable
for (int I=0;ITotal+=I;
cout<}
void main()
{
LOCAL(45);
}
1.b) Which C++ header file(s) will be
essentially required to be included to run
/execute the following C++ code: 1
void main()
{
char Msg[ ]="Sunset Gardens";
for (int I=5;Iputs(Msg);
}
A) (i) string.h (ii) stdio.h
1. d) Find the output of the following program:3
#include
struct GAME
{ int Score, Bonus;
};
void Play(GAME &g, int N=10)
{
g.Score++;
g.Bonus+=N;
}
void main()
{

GAME G={110,50};
Play(G,10);
cout<Play(G);
cout<Play(G,15);
cout<}
A) 111:60 3
112:70
113:85
e) Find the output of the following program: 2
#include
void Secret(char Str[ ])
{
for (int L=0;Str[L]!='\0';L++);
for (int C=0;Cif (Str[C]=='A' || Str[C]=='E')
Str[C]='#';
else
{
char Temp=Str[C];
Str[C]=Str[L-C-1];
Str[L-C-1]=Temp;
}
}
void main()
{
char Message[ ]="ArabSagar";
Secret(Message);
cout<}
A) #agaSbarr
f) In the following program, if the value of
Guess entered by the user is 65, what will be the
expected output(s) from the following options
(i), (ii), (iii) and (iv)? 2
#include
#include
void main()
{
int Guess;
randomize();
cin>>Guess;
for (int I=1;I<=4;I++)
{
New=Guess+random(I);
cout<<(char)New;
}
} (
i) ABBC
(ii) ACBA
(iii) BCDA
(iv) CABD
A)
(i) ABBC
Sample Paper 2 for 2009-10 Batch:
1.(a) What is the difference between Actual
Parameter and Formal Parameters? Also, give a
suitable C++ code to illustrate both. 2
A) Actual Parameter Formal Parameter 2
* It is a parameter, which is used in function
call to send the value from calling environment
* It is a parameter, which is used in function
header, to receive the value
from actual parameter
#include
void Calc(int T) //T is formal parameter
{
cout<<5 br="">}
void main()
{ int A=45;
Calc(A);//A is actual parameter
}
(b) Write the names of the header files to which
the following belong: 1
(i) frexp() (ii) isalnum()
A) (i) math.h (ii) ctype.h
(c) Rewrite the following program after
removing the syntactical errors (if any).
Underline each correction. 2
#include
struct Pixels
{ int Color,Style;}
void ShowPoint(Pixels P)
{ cout<
void main()
{
Pixels Point1=(5,3);
ShowPoint(Point1);
Pixels Point2=Point1;
Color.Point1+=2;
ShowPoint(Point2);
}
Ans:
#include 2
struct Pixels
{
int Color,Style;
};
void ShowPoint(Pixels P)
{
cout<
}
void main()
{
Pixels Point1={5,3};
ShowPoint(Point1);
Pixels Point2=Point1;

Point1.Color+=2;
ShowPoint(Point2);
}
(d) Find the output of the following program: 3
#include
void Changethecontent(int Arr[ ], int Count)
{
for (int C=1;CArr[C-1]+=Arr[C];
}
void main()
{
int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};
Changethecontent(A,3);
Changethecontent(B,4);
Changethecontent(C,2);
for (int L=0;L<3 br="" cout="">cout<for (L=0;L<4 br="" cout="">cout<for (L=0;L<2 br="" cout="">}
Ans:
7#9#5#
30#50#70#40#
2100#1200#
(e) Find the output of the following program: 2
#include
struct Game
{c
har Magic[20];int Score;
};
void main()
{
Game M={"Tiger",500};
char *Choice;
Choice=M.Magic;
Choice[4]='P';
Choice[2]='L';
M.Score+=50;
cout<Game N=M;
N.Magic[0]='A';N.Magic[3]='J';
N.Score-=120;
cout<}
A)
TiLeP550
AiLJP430
(f) In the following program, if the value of N
given by the user is 20, what maximum and
minimum values the program could possibly
display? 2
#include
#include
void main()
{i
nt N,Guessnum;
randomize();
cin>>N;
Guessnum=random(N-10)+10;
cout<}
A)
Maximum Value: 19 Minimum Value: 10
Sample Paper 1 for 2011-12:
1.a)Differentiate between the post increment
and pre increment operators. Also, give a
suitable C++ code to illustrate both. 2
Post Increment: ++ is an increment operator to
increment the value of a variable by one. When
used after the operand it is known as post
increment operator.
Pre Increment: When ++ is used before an
operand to increment its value by one, it is
called a pre-increment operator.
Example:
#include
void main( )
{
int NUM=9;
cout<<++NUM; //10 will be displayed
cout<cout<}
b) Which C++ header file(s) will be essentially
required to be included to run/execute the
following C++ code: 1
void main( )
{
int Last=25;
for(int C=9;C<=Last;C++)
cout<}
Ans:
(i)iostream.h (for cout)
(ii) math.h (for sqrt( ))
c) Find the output of the following program:
#include
struct STOCK
{
Int Ino,Qty;
};
void Buy(STOCK &I,int TQ=2)
{I
.Qty+=TQ;
}
void main( )
{
STOCK i[2]

Header files – Important Functions.
From Old Papers
Name the header files that shall be needed for
the following
2009 Outside Delhi:
(i) setw( ) – iomanip.h
(ii) sqrt( ) – math.h
2008 Delhi & OD:
Due to cout, include iostream.h
Due to setw( ), include iomanip.h
2007 Delhi & OD:
Due to strcat( ), include string.h
Due to gets( ), include stdio.h
2006 Delhi:
(i) abs( ) - math.h, stdlib.h
(ii) isupper( ) – ctype.h
2006 Outside Delhi
(i) abs( ) - math.h, stdlib.h
(ii) random( ) - stdlib.h
2005 Delhi:
(i) abs( ) - stdlib.h, math.h
(ii) strcmp( ) - string.h
2005 OD:
(i) puts( ) - stdio.h
(ii) isalnum( ) - ctype.h
2004 :
(i) gets( ) - stdio.h
(ii) strcmp( ) - string.h
(iii) abs( ) - math.h, stdlib.h
(iv) isalnum( ) - ctype.h
2003:
(i) strcmp( ) - string.h
(ii) getc( ) - stdio.h
2002:
(i) get( ) - iostream.h
(ii) open( ) - fstream.h
(iii) abs( ) - math.h, stdlib.h
(iv) strcat( ) - string.h
2001:
(i) getc( ) - stdio.h
(ii) strcat( ) - string.h
2000:
(i) isupper( ) - ctype.h
(ii) setw( ) - iomanip.h
(iii) exp( ) - math.h
(iv) strcmp( ) - string.h
1999:
(i) strcat( ) - string.h
(ii) scanf( ) - stdio.h
(iii) getchar( ) - stdio.h
(iv) clrscr( ) - conio.h
1998:
(i) cos( ) - math.h
(ii) setw( ) - iomanip.h
(iii) toupper( ) - ctype.h
(iv) strcpy( ) - string.h
Model Paper 1:
(i) strcmp( ) – string.h
(ii) fabs( ) – math.h
Model Paper 2:
(i) frexp( ) – math.h
(ii) isalnum( ) – ctype.h
ctype.h (Character functions)
isalnum( ), isalpha( ), isdigit( ), islower( ),
isupper( ), tolower( ), toupper( )
string.h (Generally starts with str)
strcat( ), strcmp( ), strcpy( ), strlent( ), strchr( ),
stricmp( ), strlwr( ), strew( ), strupr( )
iomanip.h
setw( ), setprecision( ), endl, flush( ).
stdlib.h
abs( ), labs( ), free( ), random( ), atof( ), atoi( ),
atol( ),strtol( ), strtod( ), calloc( ),malloc(),
realloc( )
iostream.h
(cout,cin – these are streams available in
iostream.h)
get( ) getline( ) read( ) write( ) put( )
open( ) close( ) flush( )
seekg( ) seekp( ) tellg( ) tellp( )
bad( ) eof( ) fail( ) good( )
clear( )
stdio.h (Many of the functions starting with f)
printf( ) scanf( )
fflush( ) fgetc( ) fgetchar( ) fgets( ) fopen( )
fprintf( ) fputc( ) fputchar( )
fputs( ) fread( ) freopen( ) fscanf( ) fseek( )
fsetpos( ) fwrite( ) ftell( )
fwrite( ) getc( ) getchar( ) gets( ) getw( )
putc( ) putchar( ) puts( ) putw( )
remove( ) rename( )
conio.h
clrscr( ) getch( ) gotoxy( ) cprintf( )
dos.h
sound( ) nosound( ) delay( )
process.h
exit(0)
math.h
acos( ) acosl( ), etc, etc div( ) exp( ) ceil( )
ceill( ) fabs( ) floor( ) fmod( ) log( )
pow( ) modf( ) poly( ) sqrt( )

” If WEALTH is lost, nothing is lost.
If HEALTH is lost, something is lost.
If CHARACTER is lost, everything is lost.”
XII Computer Science
Chapter: C++ Revision Tour
Important Models
1.a) Name the header file to which the
following below: (i) abs( ) (ii)
isupper( ) 1
Ans) (i) abs( ) - math.h, stdlib.h, complex.h
(ii)isupper( ) - ctype.h
2) Name the header file(s) that shall be needed
for successful compilation of the following C++
code. 1
void main( )
{ char String[20];
gets(String);
strcat(String,”CBSE”);
puts(String);
}
Ans) stdio.h string.h
3) In the following program, find the correct
possible output(s) from the options: 2
#include
#include
void main( )
{ randomize( );
char Area[ ][10]
={“NORTH”,”SOUTH”,”EAST”,”WEST”};
int ToGo;
for(int I=0; I<3 br="">{
ToGo=random(2) + 1;
cout<}
}
Ans: Outputs:
(i) SOUTH : EAST : SOUTH :
(ii) NORTH : SOUTH : EAST :
(iii) SOUTH : EAST : WEST :
(iv) SOUTH : EAST : EAST :
4) Find the output of the following program.2
#include
#include
#include
void Change(char Msg[],int Len)
{ for(int Count=0;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[ ]=”2005 Tests ahead”;
int Size=strlen(Message);
Change(Message,Size);
cout<for(int C=0,R=Size – 1; C<=Size/2;C++,R--)
{ char Temp=Message[C];
Message[C]=Message[R];
Message[R]=Temp; }
cout<}
Ans: Output:
3116*tESTS*AHEAD
DAEHA*SSTEt*6113
5) Find the output of the following program 2
#include
void main( )
{ long NUM=1234543;
int F=0,S=0;
do
{ int R=NUM % 10;
if (R %2 != 0)
F += R;
else
S += R;
NUM / = 10;
} while (NUM>0);
cout<}
Ans: Output: 2
6)Write the output of the following program 3
#include
void X(int &A,int &B)
{ A=A+B;
B=A-B;
A=A-B;
}
void main( )
{ int a=4,b=18;
X(a,b);
cout<
}
Ans: Output:
18,4
7) Give the output of the following program:
#include
struct Pixel
{ int C,R;

};
void Display(Pixel P)
{
cout<<”col”<
dl;
}
void main( )
{
Pixel X={40,50},Y,Z;
Z=X;
X.C+=10;
Y=X;
Y.R+=20;
Z.C-=15;
Display(X);
Display(Y);
Display(Z);
}
8) Find the output of the following program: 2
#include
void main( )
{ int U=10,V=20;
for(int I=1;I<=2;I++)
{ cout<<”[1]”<cout<<”[2]”<<++V<<”&”<}
} Ans: Output:
[1]10&15
[2]21&13
[1]11&16
[2]22&14
9) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. 2
#include
const int dividor 5;
void main( )
{ Number = 15;
for(int Count=1;Count=<5 -="3)<br" ount="" umber="">if(Number % dividor = = 0)
cout<cout<else
cout<Ans:
#include
const int dividor= 5;
void main( )
{ int Number = 15;
for(int Count=1;Count<=5;Count++,Number -= 3)
if(Number % dividor = = 0)
{ cout<cout<}
else
cout<}
10) Find the syntax error(s), if any, in the
following program:
#include
main( )
{ int x[5],*y,z[5];
for(i=0;i<5 br="" i="">{ x[i]=i;
z[i]=i+3;
y=z;
x=y;
}
}
Ans (i) Line No 5: Undefined symbol ‘i’.
The variable ‘i’ is not declared in the program.
(ii)Line No 10:Assign the value of a pointer to
an integer variable. Ie error in x=y.
11)Rewrite the following program after
removing the syntactical error(s)if any.
Underline each correction. 2
#include
void main( )
{ First = 10, Second = 20;
Jumpto(First;Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
count<>N2;
}
Ans)#include
void Jumpto(int N1,int N2=20);
//Prototype missing
void main( )
{ int First = 10, Second = 20;
//Data type missing
Jumpto(First,Second);
//Comma to come instead of ;
Jumpto(Second);
}
void Jumpto(int N1, int N2)
{ N1=N1+N2;
cout<//Output operator << required
}
12) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction. 2
#include
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost=100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}

Ans:#include
#include
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost;
//Initialization of variables inside a structure is not allowed.
}MOVIE;
gets(MOVIE.movie_name);
cin>>MOVIE.movie_type;
//A single character cannot be read using gets
}
13)Write definition for a function
SumSequence( ) in C++ with two arguments/
parameters – double X and int n. The function
should return a value of type double and it
should perform sum of the following series.
1/x- 3!/x2 + 5!/x3 – 7!/x4 + 9!/x5 - ------upto n
terms.
Note: The symbol ! represents Factorial of a
number
ie 5!= 1 X 2 X 3 X 4 X 5.
#include
#include
#include
double SumSequence(int x1,int n1);
void main()
{ int x;
int n;
clrscr();
cout<<"Enter the vaue of X and N";
cin>>x>>n;
cout<<”\nThe sum of the series =
“<getch();
}
double SumSequence(int x1,int n1)
{ double sum=0;
int c=0;
for(int i=1;i<=(2*n1);i=i+2)
{ int f=1;
for(int j=1;j<=i;j++)
{ f=f*j;
}
c=c+1;
if(c%2==1)
{ sum=sum+f/(pow(x1,c));
}
else
{ sum=sum-f/(pow(x1,c));
}
}
return sum;
}
Some Important Theorey Questions:
1. Differentiate between call by value and call
by reference with example. (whole concept is
imp)
2. Type Convertion.
3. Diff between various types of errors.
4. Diff between #define and const
5. Typedef keyword
6. Nested Structures.
7. Global variables and local variables.
8. Importance of main().
(Theory question we cannot guess. It can be
on any of the topic covered in XI C++
Revision Tour)
XII Computer Science
TEST - C++ Revision Tour
1. Name the header file to which the following
below: (i) isupper( ) (ii) setw( )
2) Name the header file(s) that shall be needed
for successful compilation of the following C++
code.
void main( )
{ char<< word[ ]=”Exam”;
cout<}
3) In the following program, find the correct
possible output(s) from the options:
#include
#include
const int MAX=20;
void main( )
{ randomize( );
int SCORE=8,Num;
for(int i=2;i<=5;i++)
{ Num=MAX+random(SCORE);
cout<SCORE--;
}
}
(i) 24:24:25:25:
(ii) 24:24:25:24:
(iii) 26:25:24:23:
(iv) 24:24:25:24:23
4) Find the output of the following program
#include
#include
#include
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]=='A'|| Msg[Cnt]=='a')
Msg[Cnt]=CH;
else
if (Cnt%2==0)
Msg[Cnt]=toupper(Msg[Cnt]);
else
Msg[Cnt]=Msg[Cnt+2];
}

}
void main ()
{ clrscr();
cout<char MyText[] ="Jawahar Navodaya Vidyalaya";
MyCode(MyText,'@');
cout<<"MY TEXT:"<}
5)Write the output of the following program
#include
void Withdef(int HisNum=22)
{ for(int I=20;I<=HisNum;I+=7)
cout<cout<}
void Control(int &MyNum)
{ MyNum+=8;
Withdef(MyNum);
}
void main()
{ int YourNum=20;
Control(YourNum);
Withdef( );
cout<<”Number=”<}
6) Give the output of the following program:
#include
struct Package
{ int Length,Breadth,Height;
};
void Occupies(Package M)
{ cout<x”;
cout<}
void main( )
{ Package P1={5,10,15},P2,P3;
++P1.Height;
Occupies(P1);
P3=P1;
++P3.Breadth;
P3.Height++;
Occupies(P3);
P2=P3;
P2.Length+=25;
--P2.Length;
Occupies(P2);
}
7. Find the output of the following program
#include
struct Game
{char Magic[20];int Score;
};
void main()
{ Game M={"Tiger",500};
char *Choice;
Choice=M.Magic;
Choice[4]='P';
Choice[2]='L';
M.Score+=50;
cout<Game N=M;
N.Magic[0]='A';N.Magic[3]='J';
N.Score-=120;
cout<}
8) Find the output of the following program:
#include
void main( )
{ int A=7,B=9;
for(int I=10;I<=11;I++)
{ cout<<”Line1”<<++A<<”&”<cout<<”Line2”<}
}
9)Rewrite the following program after removing
the syntactical error(s) if any. Underline each
correction.
include
void main( )
{ First = 10; Second = 20;
Jumpto(First;Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{ N1=N1+N2;
count<>N2;
}
10) Rewrite the following program after
removing the syntactical error(s), if any.
Underline each correction.
#include
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost=100;
}MOVIE;
gets(movie_name);
gets(movie_type); }
11) Write the output for the following program.
#include
#include
int g=20;
void func(int &x,int y)
{ x=x-y;
y=x*10;
cout<}
void main( )
{ int g=7;
func(g,::g);
cout<func(::g,g);
cout<}
12) Write the output of the following program.
#include
static int i=100;

void abc( )
{ static int i=8;
cout<<”first =”<}
main( )
{ static int i=2;
abc( );
cout<<”second =”<}
13.What are Nested Structures? Give an example.
14.Differentiate between call by value and call
by reference.
15. Explain type convertion.

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.