You are on page 1of 14

CBSE

Class 11th Computer Science (083)


Unit Test-1 (SET - B) 2016-2017
Indraprastha International School

General Instructions

This question paper contains 7 questions.


All the questions are compulsory.
Marks for each question are indicated against it.
Write answers neatly and legibly.

1. Rewrite the following set of statements after removing all the errors (two errors each
program): (2)

a. void main()

int a,b, break;

cin>>a, b;

if(a= =b)

cout<<a*break;

getch();

b. void main()

clrscr;

int x,y;

Material downloaded from myCBSEguide.com. 1 / 14


cin>>x;

switch(x)

case 1.5:

cout<<”hello”;

case 2:

cout<<”welcome’;

case 3:

case 4:

cout<<”Windows”;

getch();

Ans. a. void main()

int a,b, br;

cin>>a>>b;

if(a= =b)

cout<<a*br;

getch();

Material downloaded from myCBSEguide.com. 2 / 14


b. void main()

clrscr();

int x,y;

cin>>x;

switch(x)

case 1:

cout<<”hello”;

case 2:

cout<<”welcome’;

case 3:

case 4:

cout<<”Windows”;

getch();

2. What will be the output for the following code of statements? (7)

a. void main()

char str[20];

cin>>str;

Material downloaded from myCBSEguide.com. 3 / 14


cout<<” First output displays “<<str<<endl;

gets(str);

cout<<”The second output displays”<<str;

getch();

// the string entered is My World

b. void main()

char a=’z’;

int b=a;

cout<<b<<endl<<b+3;

c. void main()

int a =500, b=500;

int c= ((a+b)<900) ? 900 : 1000;

cout<<c;

d. void main()

char a;

Material downloaded from myCBSEguide.com. 4 / 14


cin>>a;

switch (a)

case ‘A’:

case ‘B’:

cout<<” Sunday”<<endl<<”Monday”;

break;

case ‘C’:

case ‘D’:

cout<<”Tuesday”;

break;

case ‘E’:

cout<”Thursday”;

break;

getch();

//if the value entered is C

e. void main()

int x=20;

Material downloaded from myCBSEguide.com. 5 / 14


cout<<++ x <<x<<x++<<x<<++x;

f. void main()

int a=10, b=20;

if(a> b && b>15)

cout<<”Input Device”;

else if( a<15 && b>20)

cout<<”Output Device”;

else if (a<b || b<a)

cout<< “Storage Device”;

getch();

g. void main()

int a=21, b=4,c,d;

c=a/b;

d=a%b;

cout<<”the first output is “ <<c<<endl;

cout<< “The second output is”<<d;

Material downloaded from myCBSEguide.com. 6 / 14


Ans. a. The first output displays My
The second output displaysMy World
b. 122
125
c. 1000
d. Tuesday
e. 23 22 21 21 21
f. Storage Device
g. the first output is 5
The second output is 1

3. Do the following as directed: (4)

a. Convert the following switch case program using if-else statements:

void main()

char d;

int a,b,c, d;

cin>>a>>b>>d;

switch(d)

case ‘+’:

c=a+b;

cout<<”The sum is”<<c;

break;

case ‘-‘:

c= a-b;

Material downloaded from myCBSEguide.com. 7 / 14


cout<<”The difference is”<<c;

break;

case ‘*’:

case ‘#’:

c=a*b;

cout<<”The product is”<<c;

break;

default:

cout<<”Invalid Input”;

break;

getch();

b. Convert the following if else program into switch case:

void main()

int a,b,c,x;

cin>>x>>a>>b;

if(x= =100 || x= =200)

a+=100;

Material downloaded from myCBSEguide.com. 8 / 14


cout<<a<<b;

else if(x= =300)

a= b+900;

cout<<a<<b;

else if(x= =400)

a= b+100;

b=a+900;

cout<<b<<a;;

else

cout<<”invalid input”;

getch();

Ans. a. void main()

char d;

int a,b,c, d;

Material downloaded from myCBSEguide.com. 9 / 14


cin>>a>>b>>d;

if(d==’+’)

c=a+b;

cout<<”The sum is”<<c;

else if (d==’-‘)

c= a-b;

cout<<”The difference is”<<c;

else if(d==’*’ || d==’#’)

c=a*b;

cout<<”The product is”<<c;

else

cout<<”Invalid Input”;

getch();

b) void main()

Material downloaded from myCBSEguide.com. 10 / 14


{

int a,b,c,x;

cin>>x>>a>>b;

switch(x)

case 100:

case 200:

a+=100;

cout<<a<<b;

break;

case 300:

a= b+900;

cout<<a<<b;

break;

case 400:

a= b+100;

b=a+900;

cout<<b<<a;;

break;

default:

cout<<”invalid input”;

Material downloaded from myCBSEguide.com. 11 / 14


}

getch();

4. Convert the following as directed: (4)

a. (288)10 to Binary

b. (11011101)2 to Decimal

c. (145)16 to Decimal

d. (174)10 to octal

Ans. a. 100100000

b. 221

c. 325

d. 256

5. Define the following terms with example: (3)

a. Variables

b. Logical Operator

c. Fundamental Data type

Ans. a. Variables : Values that do may change during program execution

b. Logical Operator: operators used to set relation between the operands and execute the
statements accordingly.

c. Fundamental data type: data types that are not composed of any other data type

6. Answer any four of the following questions: (8)

Material downloaded from myCBSEguide.com. 12 / 14


a. How is a++ different from ++a? Explain with the help of an exmaple.

b. Write any two differences between int a and int a[20].

c. Draw the truth table and logical circuit for OR operator.

d. Name the two types of conditional statements used in C++. Also write any two differences
between them.

e. Define the terms software and Language processors.

Ans. a. ++a: operation which means change the operand first and then use it whereas a++

means use the operand first and then change it.

b.

Int a Int a[20]

Fundamental data type Derived data type

Stores 1 element Can store 20 elements

Occupies 2 bytes Occupies 40 bytes

c.

d.

if else switch case

can check multiple variables simultaneously only one variable checking at a time

Can check floating values can not

Can check the range can not

Material downloaded from myCBSEguide.com. 13 / 14


More versatile Less versatile

e. Software : programs and data inside the system. Language processors are the translators
that convert machine language into low and high level language and vice versa.

7. Write a program to find the smallest of three numbers. (2)

Ans. void main()


{
int a,b,c;
cin>>a>>b>>c;
if(a<b && a<c)
cout<<a;
else if (b<a && b<c)
cout<<b;
else if(c<a && c<b)
cout<<c;
getch();
}

Material downloaded from myCBSEguide.com. 14 / 14

You might also like