Professional Documents
Culture Documents
a) Define the term variable. Give example. How is it different from a constant?
c) Rewrite the following program after removing the syntactical error(s), if any.
Underline each correction.
f) 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 [2+1+2+3+2+2=12]
Marks:12
Answer:
a) A variable represent named storage locations whose values can be manipulated during
program run. In C++ a variable is declared as follows -
int a;
float num;
A constant never changes its value during the execution of the program whereas the
value of a variable varies.
b) 1) math.h 2) conio.h
c)
Correct code is:
d) Output:
Name : Pranav
Age : 28
Code : 43
Code : 12
#include<iostream.h>
int area(int side)
{
return (side*side)
}
float area(int length,int breadth)
{
return(length*breadth)
}
main()
{
cout<<area(6);
cout<<area(10,10);
cout<<area(6,area(5));
e) Give the output of the following program segment (Assuming all required
header files are included in the
program):
b) 1) conio.h 2) ctype.h
c)
# include < iostream.h>
const int Max = 10;
void main ( )
{
int Numbers [Max] = { 20, 50,10, 30,40 } ;
for (int Loc= Max-1 ; Loc > = 0 ; Loc - -)
cout<< Numbers [Loc];
}
d) Output:
36100150
e) A OROoIiE
Hide Answer
Q2
MODEL PAPER 3
a) Why prototyping is necessary in C++ program?
b) Name the header files required for the following functions -
1) gets() 2) clrscr()
void main()
{
struct room
{
char room_type[25];
int room_no;
int rate=250;
}
ROOM;
gets(room_type);
gets(room_no);
}
#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 ;
}
(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?
b) 1) stdio.h 2) conio.h
e)
25440
#include<iostream.h>
int vol(int s)
{
return(s*s*s);
}
int vol(int a, int b, int c)
{
return (a*b*c);
}
main()
{
cout<<vol(4);
cout<<vol(2,4,2);
cout<<vol(4,5,vol(2));
}
f) In the following program, if the value of N given by the user is 25, what maximum and minimum
values the program could possibly
display?
b) 1) stdio.h 2) math.h
c) The output is
30
100.
e) Output:
6416160
Hide Answer
MODEL PAPER 5
a) What do you mean by global variables and local variables?
f) In the following program, if the value of N given by the user is 25, what maximum and minimum
values the program could possibly
display?
b) 1) stdio.h 2) math.h
c) The output is
30
100.
d) i) Variable a is global variable.
ii) a=b means the assignment of the value of a local variable to a global variable.
e) Output:
6416160
Hide Answer
2015 QUESTION PAPER
a) Find the correct identifiers out of the following, which can be used for a
naming Variable, Constants or Functions in a C++ program:
(b) Observe the following program very carefully and write the names of those
header files(s), which are essentially needed to compile and execute the following
program successfully:
(c) 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.
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()
{
cout << Level << #<< Point << endl;
}
};
void main()
{
Eval E;
E.Sink(3);
E.show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
(f) 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.
Note:
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 VAL;
VAL= random(3) +2;
char GUESS[]=ABCDEFGHIJK;
for( int I=1; I<=VAL; I++)
{
for(int J=VAL; J<=7;J++)
cout << GUESS[J];
cout << endl;
}
}
[2+1+2+2+3+2=1
2]
Answer
(a) For, INT, NeW, lsiName, name1 are the correct identifiers of C++.
(b) The header files required are-
ctype.h
stdio.h
(c)
#include< iostream.h >
#define float MaxSpeed=60.5;
void main()
{
int MySpeed;
char Alert='N';
int MaxSpeed;
cin>>MySpeed;
cin>>MaxSpeed;
if( MySpeed>MaxSpeed)
Alert='Y';
cout << Alert << endl;
}
(d) Output-
10,8
20,8
(e) Output-
B#0
I#1
G#1
(f) Correct output of the code is (ii) and (iii)
2014 QUESTIOMN PAPER
a) Find the correct identifiers out of the following, which can be used for a
naming Variable, Constants or Functions in a C++ program:
(b) Observe the following program very carefully and write the names of those
header files(s), which are essentially needed to compile and execute the following
program successfully:
(c) 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.
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()
{
cout << Level << #<< Point << endl;
}
};
void main()
{
Eval E;
E.Sink(3);
E.show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
(f) 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.
Note:
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 VAL;
VAL= random(3) +2;
char GUESS[]=ABCDEFGHIJK;
for( int I=1; I<=VAL; I++)
{
for(int J=VAL; J<=7;J++)
cout << GUESS[J];
cout << endl;
}
}
[2+1+2+2+3+2=1
2]
Answer
(a) For, INT, NeW, lsiName, name1 are the correct identifiers of C++.
(b) The header files required are-
ctype.h
stdio.h
(c)
#include< iostream.h >
#define float MaxSpeed=60.5;
void main()
{
int MySpeed;
char Alert='N';
int MaxSpeed;
cin>>MySpeed;
cin>>MaxSpeed;
if( MySpeed>MaxSpeed)
Alert='Y';
cout << Alert << endl;
}
(d) Output-
10,8
20,8
(e) Output-
B#0
I#1
G#1
(f) Correct output of the code is (ii) and (iii)
QUESTION PAPER 2013
(a) What is the benefit of using default parameter/argument in a function? Give a
suitable example to illustrate it by using C++ code.
(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:
void main()
{
float Area, Side;
cin >> Area;
Side=sqrt(Area);
cout << One Side of the Square: << Side << endl;
}
(c) Observe the following C++ code carefully and rewrite the same after removing
all the syntax error(s) present in the code. Ensure that you underline each
correction in the code.
Important Note:
- All the desired header files are already included, which are
Important Note:
- All the desired header files that 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) Observe the following C++ code carefully and obtain the output, which will
appear on the screen after the execution of it.
void main()
{
Mausam M, N(2);
M.Sun(5);
M.CheckOut();
N.Rain(10);
N.Sun(2);
N.CheckOut();
M.Rain(15);
M.CheckOut();
}
(f) Based on the following C++ code, find out the expected correct output(s) from
the options (i) to (iv). Also, find out the minimum and the maximum value that can
be assigned to the variable Guess used in the code at the time when the value of
the Turn is 3.
void main()
{
char Result[ ][10] = {GOLD, SILVER, BRONZE};
int Getit=9, Guess;
(c)
void main()
float X,Y,F;
F=Change(X,Y);
(d)
Output:
1AJANTA
5JANTA
(e)
Output:
City:15&63%
City:12&73%
City:15&78%
(c)
# include< iostream.h>
# include< iomanip.h> //header file for setw()
(d) OUTPUT:
5:1:20
1:1:50
5:2:50
(e) Output:
vR2GooD
R2GoOd
2GOOd
gOOd
The answers (i), (ii) and (iv) are not expected as output.
QUESTION PAPER 2011
a) What is the difference between Type Casting and Automatic Type conversion?
Also, give a suitable C++ code to illustrate
both.
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";
if(Text[ I ] == )
cout<< endl;
else
CH = toupper(Text[ I ]);
cout<< CH;
c) Rewrite the following program after removing the syntactical errors (if any).
Underline each correction.
#include< iostream.h >
void main()
string S="Peace";
int L = strlen(S);
}
d) Find the output of the following program:
#include< iostream.h >
A[ K] += K;
else
A[K]* = K;
(K%2==0) ? cout << A[K] << "%": cout << A[K] << endl;
void main()
int H[ ]={30,40,50,20,10,5};
SwitchOver(H,6,3);
Display(H,6);
void main()
{
int *Queen, Moves[ ]={11,22,33,44};
Queen = Moves;
Moves[ 2 ] += 22;
*Queen -= 11;
Queen += 2;
Queen ++;
}
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.
void main()
randomize();
}
(i) 20*21*22*23*24*25
(ii) 22*23*24*25*
(iii)23*24*
(iv)21*22*23 [ 2+1+2+3+2+2 = 12 ]
Marks:12
Answer:
1 (a)
void main()
string S="Peace";
int L=strlen(S);
cout << S << "has" << L << "characters" << endl;
(d)
30 % 41
52 % 60
40 % 25
(e)
Queen @ 11
Now @ 55
Finally @ 44
New Origin @ 0
(f)
ii) 22*23*24*25*
Minimum value = 20
Maximum value = 24
d) Output:
11,19,6
25, 15, 35
35,5,45
e) Output:
New Text: @@e@ccddIIe
f) iv) 29:26:25:26:
Justification is as follows:
Number
I POIN Minimu Maximum
T m
1 5 25 29
2 4 25 26
3 3 25 25
4 2 25 26
(c) Rewrite the following program after removing the syntactical errors (if any).
Underline each correction. [2]
include < iostream.h >
include < stdio.h >
Class MyStudent
{
int StudentId=1001;
char Name[20] ;
public
MyStudent(){}
void Register () {cin >> StudentId; gets (Name) ;}
void Display () {cout << StudentId << : << Name << endl;}
};
void main ()
{
MyStudent MS;
Register.MS ();
MS. Display ();
}
(d) Find the output of the following program : [3 ]
# include < iostream.h >
void main ()
{
int A[] {10,15, 20, 25, 30};
int *p = A;
while (*p < 30)
{
if (*p %3 ! = 0 )
*p = *p + 2;
else
*p = *p + 1;
p++;
}
for (int J = o; J < = 4; J++)
{
cout << A[J] << * ;
if (J %3 = = 0) count << endl;
}
cout << A[4] * 3 << endl;
}
(e) Find the output of the following program: [ 2]
#include < iostream.h >
#include < ctype.h. >
void Secret (char Msq [], int N);
void main ()
{
char SMS [] = rEPorTmE;
Secret (SMS, 2) ;
cout << SMS << endl;
}
void Secret (char Msq[], int N)
{
for (int C = 0; Msq [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;
}
(f) Study the following program and select the possible output from it:
[2]
#include < iostream.h >
# include < stdlib.h >
const int MAX=3;
void main ()
{
randomize ();
int Number;
Number= 50 + random (MAX) ;
for (int P = Number ; P > = 50; P--)
cout <
count << endl;
}
i. 53#52#51#50#
ii. 50#51#52#
iii. 50#51
iv. 51#50#
Marks:12
Answer:
(a) Formal Parameters:
Formal parameters are written in the function prototype and function header of the
definition. Formal parameters are local variables, which are assigned values from the
arguments when the function is called.
Actual Parameters:
When a function is called, the values (expressions) that are passed in the call are called
the arguments or actual parameters (both terms mean the same thing). At the time of
the call each actual parameter is assigned to the corresponding formal parameter in the
function definition.
Calling programs pass information to called functions in "actual arguments." The called
functions access the information using corresponding "formal arguments.
Example :
void func( long ex1, double ex2);
int main()
{
long a = 1;
double b = 2;
// Call func with actual arguments a and b.
func( a, b );
}
// Define func with formal parameters ex1, ex2.
void func( long ex1, double ex2 )
{
}
(b) The header files to which following functions belong are :
setw() - It belongs to < iomanip.h>
sqrt() - It belongs to < math.h >
(c) The errors in the above code are as follows:
1. public - The keyword public should be followed by a colon. It should be public:
2. Register.MS()- To access the method the correct manner is MS.Register();
(d) The output of the given program code is:
12*
16*22*27*
30*90
(e) The output of the given program code is:
TeRmttoe
(f) The output of the given code will be:
(iv) 51#50#
(c) Rewrite the following files after removing the syntactical errors, if any. [2]
#include < iostream.h>
void main()
{
First = 10, Second = 20;
Jumpto(First; Second);
Jumpto(Second);
}
void Jumpto ( int N1, int N2=20)
{
N1=N1 + N2;
cout << N1 >> N2;
}
(f) In the following program, find the correct possible output(s?) from the options: [2]
(i) DEL:CHN:KOL:
(ii) CHN: KOL: CHN:
(iii) KOL:BOM:BNG:
(iv) KOL:CHN:KOL:
Marks:12
Answer: (a) The #define statement is used as a preprocessor directive that serves to
merely replace a named constant in a program with another text value. E.g.,
#define PI 3.14159
It substitutes the text 3.14159 in every location where PI occurs in the source code.
The const keyword denotes a named variable that is designated by a type (such as int)
that is read-only (or constant) during the run-time of the program, and is utilized by the
compiler rather than the preprocessor, whose value is subject to be changed during
design time in the program.
E.g.,
const int number = 108;
(b) i) iostream.h
ii) iomanip.h
(d) The given code has certain errors due to which it will not execute.
(e) Output:
[1] = 10 & 15
[2] = 21 & 13
[1] = 11 & 16
[2] = 22 & 14
(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);
}
(c) Rewrite the following program after removing the syntactical error(s) if any. Underline each
correction. [2]
# 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];
}
(f) In the following C++ program what is the expected value of MyMarks from options (i) to (iv)
given below. Justify answer. [2 ]
#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
Marks:12
Answer:
Syntax Error:
These are the errors in coding which do not follow language syntax format, i.e., when
statements are wrongly written violating rules of the programming language. It can
occur by human mistake in typing and due to lack of knowledge of language.
Example : Min +14 = FMIN is a syntax error, as an expression can not appear on the
left side of an assignment operator.
(c)
# include < iostream.h >
const int Max 10;
void main ( )
{
int Numbers [Max] = { 20, 50,10, 30,40 } ;
for (Loc= Max-1 ; Loc > = 0 ; Loc - -)
cout >> Numbers [Loc];
}
(d)
Output: 2 @ 4@ 8 @
4# 8 # 16 # 20 #
(e)
Output:
10, 15, 20, 25, 30
10, 15, 20
Number=30
(f)
(ii) 92. This is because random() function generates a random number between 0 and 1,
which added to 2 results in float value greater than 2 but less than 3. As a subscript is
an integer value, decimal portion will be chopped off which results in the subscript to be
2.
QUESTION PAPER 2005
(a) Differentiate between call by value and call by reference, giving suitable
examples of each. [2]
(b) Name the header files to which the following belong: [1]
i) abs()
ii) strcmp()
(c) Rewrite the following program after removing the syntactical error(s), if any. Underline
each correction. [2]
# include < iostream.h >
const int Multiple 3;
void main()
{
Value=15;
for(int Counter=1; Counter =< 5; Counter ++, Value-=2)
if ( Value % Multiple == 0)
cout << Value * Multiple;
cout << endl;
else
cout << Value + Multiple << endl;
}
(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< stdlib.h >
#include< iostream.h >
#include< conio.h >
void main()
{
randomize();
int Num,Rndnum;
cin >> Num;
Rndnum=random(Num)+5;
for(int N=1;N < =Rndnum; N++)
cout << N <<" ";
getch();
}
i) 1234
ii) 12
iii) 123456789
iv) 123
Marks:12
Answer:
(a) Call by value - The values of the actual arguments are passed to the function.
E.g.,
void fun(int,int); //declaration
fun(a,b); // call
Call by reference - The address of the actual arguments is used in the function call.
E.g.,
void fun(int&, int&); // declaration
fun(a, b); // call
(b)
(i) abs() : math.h
(ii) strcmp(): string.h
(d) Output:
10x15x6
11x16x6
10x16x11
(e) Output:
cbse*eXAM*3116
6113*MAXe*esbc
(f) Output:
The correct output will be
(iii) 1 2 3 4 5 6 7 8 9
QUESTION PAPER 2006
(a) Name the header file to which the following belong [1]
(i) abs( ) (ii) isupper()
(b) Illustrate the use of #define in C++ to define a macro. [2]
(c) Rewrite the following program after removing the syntactical [2]
error(s), if any. Underline each correction.
#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);
}
(d) Find the output of the following program: [3]
#include < iostream.h >
#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_nam = 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), S1, S2;
S1.Replace(state1, state2);
S2.Replace(S1, state3);
S1.display();
S2.display();
}
.
(b) #define MAX 15 // Max is a macro with value 15
#include < iostream.h >
void main()
{ int arr[MAX]; //15 value is substituted in place of
//macro MAX
for(i =0;i < MAX; i++)
{
cout << n Enter the value of element << i+1 << :;
cin >> arr[I];
}
}//end of main()