Sei sulla pagina 1di 4

CLASS XI

FIRST TERM EXAMINATION 2013-2014


SUBJECT : COMPUTER SCIENCE
SET B1
Time allowed: 3 hours

Max Marks : 70

General Instructions :

This paper consists of 4 pages


There are 5 questions in this paper
Attempt all questions neatly and in order
Programming language : C++

Q1a) Name the header files are required for the following :
i)
cout
ii)
setw( )
iii)
pow( )
iv)
exit( )

(2)

b)

Differentiate between a while loop and a do- while loop with example. (2)

c)

How many bytes are reserved for the following data types:
i)
float
ii)
int

(2)

d) Given the following two expressions :


(2)
i)
x = 10;
ii)
x == 10;
How are these two different? What will be the final value of x after
execution of the two statements if the initial value of x is 15?
e)

Construct logical expressions to represent the following conditions :

(2)

i) fare is greater than or equal to 115 but less than 125


ii) fees is in the range 4000-5000 or grade = A
f)

Differentiate between pre increment and post increment operators. Also,


give a suitable C++ code to illustrate the same.
(2)

g)

Explain the role of sizeof operator with the help of an example.

h)

Explain the difference between break and continue with the help of an
example.
(3)

i)

What is meant by type promotion and type casting? Explain with an


example of each.
(3)

(2)

Q2 Find the syntax errors in the following code and write the corrected code
underlining the corrections made.
a) #include(iostream.h)
(3)
void main( )
int x; y;
cin>>x;
for (y= =0; y<10, y++)
if x= =y
cout<<y+x;
else
cout<<y;
b) #include<<iostream.h>>
void main( );
{
const int max=0;
int a,b;
cin>>a>>b;
if(a>b) max=a;
for(x; x<max; x++)cout>>x;
}
c) #include<iostream.h>
int main
{
int j=99,a;
float u=10.0;
cin(a);
while a<=j
{
a+=10
u=/a;
}
}
Q3.

(3)

(3)

Find the output of the following code (assuming all the necessary files are
included.)

a) #include<iostream.h>
void main( )
{
int i,j,k,x=0;
for(i=0;i<3;++i)
for(j=0;j<i;j++)
{ switch(i+j-1)
{
case -1:
case 0:
2

(4)

x+=1;
break;
case 1:
case 2:
case 3:
x+=3;
default:
x+=3;
}
cout<<x<< ;
}
cout<<"\n "<<x;
}
b)

int x=25, y=10;


cout<<++x<<@<<y++<<@<<--y<<endl;
cout<<x++<<@<<--y<<@<<x++<<endl;

(3)

c)

#include<iostream.h>

(4)

void main( )
{ for ( int a = 3 ; a< 10 ; a++ )
{ if ( a==4)
a+=5;
for ( int b = 4 ; b > 0 ; b--)
{ cout << b * a << @ ;
}
cout<< endl;
}
}
Q4.

Convert the following codes as directed.


a)

if. else to switch case


int num,val;
cin>>num;
if (num= =5)
{
val=num*25-20;
cout<<num+val;
}
else
if (num= =10)
{
val=num*20-15;
cout<<val-num;
}
3

(2)

b) for to do . While loop


for ( int x=1; x<=n; x++)
for ( int y=1; y<=x; y++)
{ sum+ = (x+y);
cout<<sum<<endl;
}

(2)

c)

(2)

do while loop to for loop


int n=0,x=0;
do{
if ( (n%2 ==0)
{
x=x+n ;
cout<<x;
}
n++;
} while (n<10);

Q5 a) Write a program that reads the value of an integer n and then display the
following patterns till n number of lines. For e.g. If n=4 then the output
should be:
(4)

3
3

2
2
2

1
1
1
1

2
2
2

3
3

b) Write a program that reads two integer numbers n & m and then prints
every integer between 1 and n divisible by m. Also report whether the
number that is divisible by m is even or odd.
(4)
c)

Write a program that reads a given number and prints whether it is prime
or not. The program should continue as long as user wants.
(4)

d)

Write a program that reads a number, n and prints all armstrong numbers
from 1 to n.
(4)

e)

Write a program that reads a number n and find the sum of Fibonacci
series upto n terms.
(4)

f)

What is the significance of default clause in switch statement? Is it


necessary to include default statement in switch statement?
(2)

g)

What is the difference between a and \a?

(2)

Potrebbero piacerti anche