Class - Xi - Computer Science - MS - Final Term Examination
Class - Xi - Computer Science - MS - Final Term Examination
3 a. (i) When input or output ( >>or <<) are used more than one time in a single statement then it is 1x3
called as cascading of operators. e.g cout<< roll<< age<< endl;
(ii) It is an error in a program's source code that results in incorrect or unexpected result during
runtime. Any valid example.
(iii)What is the meaning of type casting.
Type casting operators allow you to convert a data item of a given type to another data type
according to the requirement. It is explicit conversion by the programmer.
1 m each for correct answer.
b. Comments are the pieces of code that compiler ignores to compile. There are two types of 2
comments in C++.
Single line comment: The comments that begin with// are single line comments.
eg // print sum
Multiline Comment : The multiline comment begin with /* and end with */ .
/* print
Sum */
2 m for the correct answer.
c. int size 2 bytes and range -32768 to 32767 2
char size 1 byte and range -128 t0 127
1 m each for the correct answer
d. These are the data types that are composed of fundamental data types. e.g., array, class, 2
structure etc.
1 m each for definition and 1 m for correct example
e. 1 m for declaration, input & output statements 2
1 m for conditional operator statement.
f. (i)Evaluate the expression (++c + a>b) || (c%2+5>a/5) where a=1, b=2, c=3 3
1 (true)
(ii)Give the output
int ch=5;
cout << ++ch<< "\t"<<ch+1<<"\n";
6 6
(iii)Construct logical expression to represent: Either marks are more than 80 or grade is ‘A’.
marks>80 ||grade==’A’
1 m each for the correct answer
4. a. #include<iostream.h> 2
void main()
{ int num=12, a=1 ,b ,c ,d ;
while ( a<num )
{ b = num % a;
Page 2 of 5
if (b==0)
cout<<a<<endl;
a++;
}
cout<<”Press any key to continue”;
}
1 m for correct initialization & updation 1 m for correct while statement
b. void main() 2
{ int i=5,x[5] = [1,2,4,5,6]; {1,2,4,5,6};
int const j=10; const int j=10;
++i;
j+=i; j+=i; j being a constant cannot modify
cout<<x[i]; i is at position 6 and will print junk value
}
½ m each for error
c. 1 3
21
321
4321
54321
4321
321
21
1
Header file, declarations 1 mark
Correct nested loop & output statement with endl at correct place 2 m
d. Void main() 3
{
int A[]={10,12,15,17,20,30};
for(int i = 0; i<6; i++)
{
if(A[i]%2==0)
A[i] /= 2;
else if(A[i]%3==0)
A[i] /= 3;
if(A[i]%5==0)
A[i] /=5;
}
for(i = 0; i<6; i++)
Page 3 of 5
cout<<A[i]<<”#”;
}
1#6#1#17#2#3#
½ m each for the correct output
e. Example: 3
If an array contains: ‒2, 4, ‒1, 6, ‒7, 9, ‒23, 10
The function should rearrange the array as: 2, 4, 1, 6, 7, 9, 23, 10
Header file, declarations, input statement 1 m
Correct logic for checking & changing value and displaying 2 m
5 a. void main() 1
{ char Txt[] = "Welcome";
for(int C= 0;C<strlen(Txt);++C)
cout<<Txt[C] ;
cout<<endl;
}
iostream.h and string.h
½ m for correct header file
b. void main( ) 1
{ randomize( );
int PICKER,H=5;
PICKER=random(H)+30;
for(int i=35;i>PICKER;i--)
cout<<i<<’$’;
}
(i) 35$34$33$32$31$30$ (ii) 35$34$33$32$31$
(iii) 30$31$32$33$34$35$36$ (iv) 35$34$33$32$31$30$
Possible output is Option (ii) & justification ½ m each
c. ½ m for declaration & input statement 2
1 ½ m for checking & displaying correct output
d. Header file, declarations, input statement 2 m 4
Correct logic for checking and displaying 2 m
6 a. int a=30; 2
void print(int &x,int z,int y=10)
{ int temp=z+y;
x+=temp;
if(y==10)
cout<<x<<temp<< "\n"; }
void main( )
{ int a=15, b=40;
print(::a,a);
Page 4 of 5
cout<<a<<::a;
print(b,::a,a);
cout<< "\t"<<a<<b;
}
5525
1555 15110
1 m for each line correct output
b. Example: 3
124
456
789
Major Diagonal : 1+5+9 = 15
Minor Diagonal : 4+5+7 = 16
Header file, declarations, input statement 1 m
Correct logic for displaying the diagonal elements with their sum 2 m
c. Function header with correct arguments 1 m 4
Correct logic for converting to upper case and checking for vowels & return statement 2 m
(i) Define a macro with an example.
Macro is a one line function statement used to replace a token sequence. It is always declared
with #define statement.
Eg #define area(l,b) l*b
1 m for the correct definition with example
d. Header file, declarations, input statement, calling function 2 m 4
Correct logic for checking and displaying the result 2 m
Page 5 of 5