You are on page 1of 16

CLASS XI QUESTION BANK CS

1.
2.
3.
4.
5.
6.
7.
8.
9.

State major new changes done during 2nd generations of computers.


State featuresof 1st generations of computers.
State featuresof 3rd generations of computers.
What are different type of softwares. Give 5 examples of each type of softwares.
Explain and write Full form of the following terms
ASCII, ENIAC, ISCII, RISC Processors, EPIC, CISC Processors
Write short note on the following Open Source Concepts:
Open Source Software, Freeware, Shareware, Proprietary Software.
Explain the following Memory Concepts: Units: Byte, Kilo Byte, Mega Byte, Giga Byte, Tera
Byte, Peta Byte, Exa Byte, Zetta Byte, Yotta Byte.
Explain and find Differentiate between Cache, RAM, ROM
Perform the following conversions
(i)
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
(viii)
(ix)
(x)

(625.375)10=(?)8
(10011110.110011)2=(?)16
(3ABFE.4B2)16=(?)10
(55.678)10=(?)8
(10010.1111)2=(?)8
(45CAE.4DE2)16=(?)8
(625.375)10=(?)4
(10011110.110011)2=(?)8
(3ABFE.4BCD2)16=(?)4
(12345.25)10=(?)8

10. What is OOP? What is difference between Procedural Programming and Object Oriented
Programming ?
11. Explain the following in terms of OOP:
(A) CLASS (B) OBJECT (C) POLYMORPHISM (D) Data Abstraction ( E ) Inheritance
12. . What is special thing about main() function ? What are its rolls?
13. .What is identifier? What is the naming convention for the identifiers ?
14. Identify valid and invalid identifiers and justify your answer also .
Minus 3ABC int INT _SUM printf scanf _sum _float pow num^2
$sum num 1 ram.shyam
salry_max
15. What are the implicit type conversion rules in C++ when adding, multiplying, etc. Fill ?
int + float = ?
int * float = ?
float * int = ?
int / float = ?
float / int = ?
int / int = ?

int ^ float = ?

16. Explain the difference between type promotion and type casting with suitable example code.
17. Find he output of the following
void main()
{
int camel=15,cow=33;
cout<<( camel ++)*b camel <<endl;
cout<<( cow ++)*(-- camel)<<endl;
}
1 QUESTION BANK CLASS XI COMPUTER SCIENCE

18. Find he output of the following


void main()
{
int c=10,d=30;
cout<<( ++d)*b c<<\t;
cout<<( d++)*(-- d)<<\t;
cout<<( d --)*b c<<\t;
cout<<( +++d)*(-- d);
}
19. In the following program , find the correct possible outputs(s) form the given options :
#include<iostream.h>
#include<stdlib.h>
Void main()
{
Randomize();
Char places[][20]={VARANASI, VIZAG, KANPUR, AGRA};
Int city;
For(int i=0 ; i<=2;i++)
{
city =random(2) + 1;
Cout<<places[city]<<@@;
}
}
Output :
(i)
iii)

VIZAG @@ KANPUR @@VIZAG ii)


VIZAG@@KANPUR@@AGRA
iv)

VARANASI @@ VIZAG@@KANPUR
VIZAG@@KANPUR@@KANPUR

20. Rewrite the code after removing errors. Underline each correction
#include<iostream.h>
void main()
{
int n1,n2,n3,avg;
cout<"\nEnter three numbers ";
cin>>n1,n2,n3;
sum=n1+n2+n3;
avg=sum/3
cout<<"Average of three numbers is "<<avg;
}
21. Write a program to find area and perimeter of a circle, a rectangle , a square.
22. What is escape sequence? Explain with example?
23. Name the header files which are required for successful execution of the following c++ code:
void main( ){
char String[ ] = String;

QUESTION BANK

CLASS XI COMPUTER SCIENCE

cout << setw(2)<<String;


}
24. Rewrite the following program after removing all the syntax error(s), if any]
#include[iostream]

// line 1

void main(){
int LIST[ ]=[100,200,300,400] , Y; // line 2
COUNT= 4;

// line 3

cin>>Y;
for(i=COUNT-1 ; I >=0;,i--)
switch(i) {
case 0 :
case 2 : cout<<Y*LIST[i]<endl; // line 4
break;
case 1:
case 3 : cout >> Y+LIST[i];
}
}
25.
26.
27.
28.
29.
30.
31.
32.

Explain Robustness?
Explain different types of errors with example.
What is purpose of comments in a program?
What is a Self-documenting code? How documentations are useful?
What is system maintenance? How many different types of maintenance?
. Explain different types of programming paradigm in details.
Name the header files to which the following belong:

(i)
abs( )
(ii) random( )
Rewrite the following program after
#include<iostream.h>
void main( )

removing

all

the

{ F = 10, S = 20;
test(F;S);
test(S); }
void test(int x, int y = 20)
{ x=x+y;

QUESTION BANK

CLASS XI COMPUTER SCIENCE

syntax

error(s),

if

any

count<<x>>y;}
33. Write the output of the following program
#include<iostream.h>
#include<conio.h>
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<<(F-S);
getch();
}
34. Rewrite the following code using conditional operator.
if (age>=18)
cout<<"Major";
else
cout<<"Minor";
35. Give the output of the following code
void main()
{
int x,y;
for(x=1; x<=4; x++)
{
for(y=1; y<=x; y++)
cout<<x<<y<<" ";
cout<<endl;
}
}
36. Write a program to display 2, 4, 8, 16, 32,.,1024.
37. Name the header file to be used for the functions clrscr() and strcpy().
38. Differentiate between Call by Value and Call by Reference with suitable code.

QUESTION BANK

CLASS XI COMPUTER SCIENCE

39. Find the possible output(s) of the following code. Also write the minimum and maximum value of r.
void main()
{

int n=4, r,i;


randomize();
r=random(n)+120;
for(i=r; i<125; i++)
cout<<i<<",";

}
(i) 120,121,122,123,

(ii)122,123,124,125,

(iii) 121,122,123,124,

(iv)123,124,
40. Observe the following program GUESS.CPP carefully, if the value of variable 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 Name : GUESS.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();
}
Output :
(i)1##2##3##4##
(ii)1##2##
(iii)1##2##3##4##5##6##7##8##9##
(iv)1##2##3##
41. Write a program to check if a given number is a prime number or not?

QUESTION BANK

CLASS XI COMPUTER SCIENCE

42. Find the output of the following code snippet :


char str[]="NAUSENABAUGH@VIZAG";
int i, j;
for(i=0; str[i]!='\0'; i++)
{
for(j=0; j<=i; j++)
cout<<str[j];
cout<<endl;
}
43. Write a functions FIND_MAX(int a[] , int n ) that returns the maximum value stored in array.
44. Find size of an 2-D array matrix[15][25] when each element is having 8 bytes.
45. Write user defined functions to implement toupper(), tolower().
46. Write a program to perform operations on 2 D matrices (ADD, SUB, TRANSPOSE)
47. Define a structure PERSON with the following descriptions

[4]

AADHARno , Name , RESIDENCE PLACE , PROFESSION , DOB, GENDER


Declare an array of the PERSON structure to store details of 30 persons and display
them.
**************************THE END ***************************

DISTRIBUTION OF MARKS (UNIT-WISE)


Unit No.

Unit Name

Total Marks

COMPUTER FUNDAMENTALS

10

II

INTRODUCTION TO C++

14

III

PROGRAMMING METHODOLOGY

12

IV

PROGRAMMING IN C++

34
70

BLUEPRINT
Unit
No.

Unit Name

VSA(1)

VSA(2)

SA(3)

LA(4)

Total Marks

COMPUTER
FUNDAMENTALS

3(3)

4(2)

3(1)

10

II

INTRODUCTION TO C++

1(1)

10(5)

3(1)

14

III

PROGRAMMING
METHODOLOGY

2(2)

6(3)

4(1)

12

IV

PROGRAMMING IN C++

3(3)

6(3)

9(3)

16(4)

34

QUESTION BANK

CLASS XI COMPUTER SCIENCE

Total

9(9)

26(13)

15(5)

20(5)

70

Note:Within bracket indicates number of questions, outside bracket indicates marks


***************REFERENCE STUDY MATTER***********************
If either is

long

double the other is promoted to

If either is

If either is long long

int

unsigned int

If either is long

If either is

double

float the other is promoted to

If either is long long unsigned int

if either is

double

double the other is promoted to

If either is

If either is long

long

int

float

the other is promoted to long long unsigned int


the other is promoted to long long
the other is promoted to long
the other is promoted to long

unsigned int

the other is promoted to

int

the other is promoted to

int

unsigned int
int
unsigned int
int

Both operators are promoted to int

Note. The minimum size of operations is int. So short/char are promted to int before the
operation is done In all your expressions the int is promoted to a float before the operation is
performed. The result of the operation is a float.
int + float => float + float = float
int * float => float * float = float
float * int => float * float = float
int / float => float / float = float
float / int => float / float = float
int / int

= int

int ^ float => <compiler error>

down
vote

Whole chapter 4 talks about conversions, but I think you should be mostly interested in these :
4.5 Integral promotions [conv.prom]
An rvalue of type char, signed char, unsigned char, short int, or unsigned short int can be

QUESTION BANK

CLASS XI COMPUTER SCIENCE

converted to an rvalue of type int if int can represent all the values of the source type; otherwise, the source rvalue can be converted to an rvalue of type unsigned int.
An rvalue of type wchar_t (3.9.1) or an enumeration type (7.2) can be converted to an rvalue of
the first
of the following types that can represent all the values of its underlying type: int, unsigned int,
long, or unsigned long.
An rvalue for an integral bit-field (9.6) can be converted to an rvalue of type int if int can
represent all
the values of the bit-field; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bit-field. If the bit-field is larger yet, no integral promotion applies to
it. If the
bit-field has an enumerated type, it is treated as any other value of that type for promotion
purposes.
An rvalue of type bool can be converted to an rvalue of type int, with false becoming zero and
true
becoming one.
These conversions are called integral promotions.
4.6 Floating point promotion [conv.fpprom]
An rvalue of type float can be converted to an rvalue of type double. The value is unchanged.
This conversion is called floating point promotion.
Therefore, all conversions involving float - the result is float.
Only the one involving both int - the result is int : int / int = int

int nValue1 = 10;


int nValue2 = 4;
float fValue = float(nValue1) / nValue2;
The C style cast can be inherently misused, because it will let you do things that may not make sense, such
as getting rid of a const or changing a data type without changing the underlying representation. C++
introduces a new casting operator called static_cast. A static cast works similarly to the C style cast,
except it will only do standard type conversions, which reduces the potential for inadvertant misuse:
1
2
3

int nValue1 = 10;


int nValue2 = 4;
float fValue = static_cast<float>(nValue1) / nValue2

Previously, you learned that the value of a variable is stored as a sequence of bits, and the data type of the
variable tells the compiler how to translate those bits into meaningful values. Often it is the case that data
needs to be converted from one type to another type. This is called type conversion.

QUESTION BANK

CLASS XI COMPUTER SCIENCE

Implicit type conversion is done automatically by the compiler whenever data from different types is
intermixed. When a value from one type is assigned to another type, the compiler implicitly converts the
value into a value of the new type. For example:
1
2

double dValue = 3; // implicit conversion to double value 3.0


int nValue = 3.14156; // implicit conversion to integer value 3

In the top example, the value 3 is promoted to a double value and then assigned to dValue. The compiler
will not complain about doing this. However, some type conversions are inherently unsafe, and if the
compiler can detect that an unsafe conversion is being implicitly requested, it will issue a warning. In the
second example, the fractional part of the double value is dropped because integers can not support
fractional values. Because converting a double to an int usually causes data loss (making it unsafe),
compilers such as Visual Studio Express 2005 will typically issue a warning. Other unsafe conversions
involve assigning unsigned variables to signed variables (and vice-versa), and assigning large integers
(eg. a 4-byte long) to integer variables of a smaller size (eg. a 2-byte short).
Warning: Microsofts Visual C++ 2005 does not seem to issue warnings for unsafe signed/unsigned
conversions.
When evaluating
When evaluating expressions, the compiler breaks each expression down into individual subexpressions.
Typically, these subexpressions involve a unary or binary operator and some operands. Most binary
operators require their operands to be of the same type. If operands of mixed types are used, the compiler
will convert one operand to agree with the other. To do this, it uses a heirarchy of data types:

Long double (highest)


Double
Float
Unsigned long int
Long int
Unsigned int
Int (lowest)
For example, in the expression 2 + 3.14159, the + operator requires both operands to be the same type. In
this case, the left operand is an int, and the right operand is a double. Because double is higher in the
heirarchy, the int gets converted to a double. Consequently, this expression is evaluated as 2.0 + 3.14159,
which evaluates to 5.14159.
A good question is, why is integer at the bottom of the tree? What about char and short?. Char and
short are always implicitly promoted to integers (or unsigned integers) before evaluation. This is called
widening.
This heirarchy can cause some interesting issues. For example, you might expect the expression 5u - 10 to
evalute to -5 (5u means 5 as an unsigned integer). But in this case, the signed integer (10) is promoted to
an unsigned integer, and the result of this expression is the unsigned integer 4294967291!
Many mixed conversion work as expected. For example, int nValue = 10 * 2.7 yields the result 27. 10 is
promoted to a float, 10.0 * 2.7 evaluates to 27.0, and 27.0 is truncated into an integer (which the compiler
will complain about).
Many binary operators that expect operands of arithmetic or enumeration type cause conversions and
yield result types in a similar way. The purpose is to yield a common type, which is also the type of the
result.
This pattern is called the usual arithmetic conversions, which are defined as follows:

QUESTION BANK

CLASS XI COMPUTER SCIENCE

If either operand is of type long double, the other shall be converted to long double.
Otherwise, if either operand is double, the other shall be converted to double.
Otherwise, if either operand is float, the other shall be converted to float.
Otherwise, the integral promotions (4.5) shall be performed on both operands.54)
Then, if either operand is unsigned long the other shall be converted to unsigned long.
Otherwise, if one operand is a long int and the other unsigned int, then if a long int can represent all the
values of an unsigned int, the unsigned int shall be converted to a long int; otherwise both operands shall
be converted to unsigned long int.
Otherwise, if either operand is long, the other shall be converted to long.
Otherwise, if either operand is unsigned, the other shall be converted to unsigned.
Only the one involving both int - the result is int : int / int = int

Defining a symbol name using typedef keyword and


defining a macro using #define preprocessor directive.
#define defines macros.
typedef defines types.
Now saying that, here are a few differences:
With #define you can define constants that can be used in compile time.
You can also use #define to declare miniature find-and-replace Macro functions.
typedef can be used to give aliases to types (which you could probably do with #define as
well), but it's safer because of the find-and-replace nature of #define constants.
Besides that, you can use forward declaration with typedef which allows you to declare a
type that will be used, but isn't yet linked to the file you're writing in.

typedef is a C keyword that creates an alias for a type.


#define is a pre-processor instruction, that creates a text replacement event prior to
compilation. When the compiler gets to the code, the original "#defined" word is no longer
there. #define is mostly used for macros and global constants
#define is handled by the pre-processor (like a cut-and-paste operation) before the

compiler sees the code, and typedef is interpreted by the compiler.


One of the main differences (at least when it comes to defining data types) is
that typedef allows for more specific type checking. For example,

10

QUESTION BANK

CLASS XI COMPUTER SCIENCE

#define defType int


typedef int tdType
defType x;
tdType y;

Here, the compiler sees variable x as an int, but variable y as a data type called 'tdType'
that happens to be the same size as an int. If you wrote a function that took a parameter of
type defType, the caller could pass a normal int and the compiler wouldn't know the
difference. If the function instead took a parameter of type tdType, the compiler would
ensure that a variable of the proper type was used during function calls.
Preprocessor macros ("#define's") are a lexical replacement tool a la "search and replace".
They are entirely agnostic of the programming language and have no understanding what
you're trying to do. You can think of them as a glorified copy/paste mechanic -occasionally that's useful, but you should use it with care.
Typedefs are a C language feature that lets you create aliases for types. This is extremely
useful to make complicated compound types (like structs and function pointers) readable
and handlable (in C++ there are even situations where you must typedef a type).
Example program for #define, #include preprocessors in C:

#define - This macro defines constant value and can be any of the basic data types.

#include <file_name> - The source code of the file file_name is included in the main C
program where #include <file_name> is mentioned.

#include <stdio.h>
#define height 100
#define number 3.14
#define letter 'A'
#define letter_sequence "ABC"
#define backslash_char '\?'
void main()
{
printf("value
printf("value
printf("value
printf("value
printf("value

of
of
of
of
of

height
: %d \n", height );
number : %f \n", number );
letter : %c \n", letter );
letter_sequence : %s \n", letter_sequence);
backslash_char : %c \n", backslash_char);

}
Output:
value of height : 100
value of number : 3.140000
value of letter : A
value of letter_sequence : ABC
value of backslash_char : ?

11

QUESTION BANK

CLASS XI COMPUTER SCIENCE

http://fresh2refresh.com

The #define Preprocessor Directive: Symbolic Constants

12

QUESTION BANK

CLASS XI COMPUTER SCIENCE

The #define directive creates symbolic constants, constants that represented as


symbols and macros (operations defined as symbols). The format is as follows:
#define identifier replacement-text

When this line appears in a file, all subsequent occurrences of identifier will be
replaced by the replacement-text automatically before the program is compiled.
For example:
#define PI 3.14159

Replaces all subsequent occurrences of the symbolic constant PI with the numeric
constant 3.14159. const type qualifier also can be used to declare numeric
constant that will be discussed in another Module.

Symbolic constants enable the programmer to create a name for a constant and
use the name throughout the program, the advantage is, it only need to be
modified once in the #define directive, and when the program is recompiled, all
occurrences of the constant in the program will be modified automatically, making
writing the source code easier in big programs.

That means everything, to the right of the symbolic constant name replaces the
symbolic constant.

Other #define examples include the stringizing as shown below:


#define STR "This is a simple string"
#define NIL ""
#define GETSTDLIB #include <stdlib.h>
#define HEADER "myheader.h"

The #define Preprocessor Directive: Macros

A macro is an operation defined in #define preprocessor directive.

As with symbolic constants, the macro-identifier is replaced in the program with


the replacement-text before the program is compiled. Macros may be defined
with or without arguments.

A macro without arguments is processed like a symbolic constant while a macro


with arguments, the arguments are substituted in the replacement text, then the
macro is expanded, that is the replacement-text replaces the identifier and
argument list in the program.

Consider the following macro definition with one argument for a circle area:
#define

13

QUESTION BANK

CIR_AREA(x)

PI*(x)*(x)

CLASS XI COMPUTER SCIENCE

Wherever CIR_AREA(x) appears in the file, the value of x is substituted for x in


the replacement text, the symbolic constant PI is replaced by its value (defined
previously), and the macro is expanded in the program. For example, the
following statement:
area = CIR_AREA(4);

Is expanded to:
area = 3.14159*(4)*(4);

Since the expression consists only of constants, at compile time, the value of the
expression is evaluated and assigned to variable area.

The parentheses around each x in the replacement text, force a proper order of
evaluation when the macro argument is an expression. For example, the
following statement:
area = CIR_AREA(y + 2);

Is expanded to:
area = 3.14159*(y + 2)*(y + 2);

This evaluates correctly because the parentheses force the proper order of
evaluation. If the parentheses are omitted, the macro expression is:
area = 3.14159*y+2*y+2;

Which evaluates incorrectly (following the operator precedence rules) as:


area = (3.14159 * y) + (2 * y) + 2;

Because of the operator precedence rules, you have to be careful about this.

Macro CIR_AREA could be defined as a function. Let say, name it a circleArea:


double circleArea(double x)
{
return (3.14159*x*x);
}

Performs the same calculation as macro CIR_AREA, but here the overhead of a
function call is associated with circleArea function.

The advantages of macro CIR_AREA are that macros insert code directly in the
program, avoiding function overhead (creating and dismantling the stack), and the
program remains readable because the CIR_AREA calculation is defined
separately and named meaningfully. The disadvantage is that its argument is
evaluated twice. Another better alternative is using the inline function, by adding
the inline keyword.

14

QUESTION BANK

CLASS XI COMPUTER SCIENCE

inline double circleArea(double x)


{
return (3.14159 * x * x);
}

The following is a macro definition with 2 arguments for the area of a rectangle:
#define

RECTANGLE_AREA(p, q)

(p)*(q)

Wherever RECTANGLE_AREA(p, q) appears in the program, the values of p and


q are substituted in the macro replacement text, and the macro is expanded in
place of the macro name. For example, the statement:
rectArea = RECTANGLE_AREA(a+4, b+7);

Will be expanded to:


rectArea = (a+4)*(b+7);

The value of the expression is evaluated and assigned to variable rectArea.

If the replacement text for a macro or symbolic constant is longer than the
remainder of the line, a backslash (\) must be placed at the end of the line
indicating that the replacement text continues on the next line. For example:
#define

RECTANGLE_AREA(p, q) \
(p)*(q)

Symbolic constants and macros can be discarded by using


the #undef preprocessor directive. Directive #undef, undefine a symbolic constant
or macro name.

The scope of a symbolic constant or macro is from its definition until it is undefined
with #undef, or until the end of the file. Once undefined, a name can be redefined
with#define.

Functions in the standard library sometimes are defined as macros based on


other library functions. For example, a macro commonly defined in
the stdio.h header file is:
#define

getchar()

getc(stdin)

The macro definition of getchar() uses function getc() to get one character from
the standard input stream. putchar() function of the stdio.h header, and the
character handling functions of the ctype.h header implemented as macros as
well.

A program example.

15

QUESTION BANK

CLASS XI COMPUTER SCIENCE

#include <iostream>
#define

THREETIMES(x)

#define

CIRAREA(y)

#define

REC(z, a)

#define

PI

(x)*(x)*(x)

(PI)*(y)*(y)

(z)*(a)

3.14159

int main(void)
{
float p = 2.5;
float r = 3.5, s, t, u = 1.5, v = 2.5;

cout<<"Power to three of "<<p<<" is "<<THREETIMES(p)<<endl;


cout<<"Circle circumference = 2*PI*r = "<<(2*PI*r)<<endl;

s = CIRAREA(r+p);
cout<<"Circle area = PI*r*r = "<<s<<endl;

t = REC(u, v);
cout<<"Rectangle area = u*v = "<<t<<endl;
return 0;
}
[THE END]

16

QUESTION BANK

CLASS XI COMPUTER SCIENCE