Sie sind auf Seite 1von 23

Delhi Public School Bangalore North

Class XI
Computer Science
Question Bank
Chapter 1: Getting Started With C++ .....................................................................................2
Chapter 2: Data Handling .......................................................................................................3
Chapter 3: Operators and Expressions in C++ ......................................................................5
Chapter 4: Flow of Control ......................................................................................................8
Chapter 5: Functions .............................................................................................................. 10
Chapter 6: Arrays ................................................................................................................... 13
Chapter 7: Structures ............................................................................................................. 19
Chapter 8: Programming Methodology and Number System ........................................... 23

Page 1/23

Chapter 1: Getting Started With C++


1. Define Character Set
2. Define Token
3. Name the different tokens used in C++.
4. What is the difference between keyword and an identifier?
5. What are literals in C++? How many types of literals are allowed in C++?
6. How many ways are there in C++ to represent an integer constant?
7. What is the difference between a and a in C++?
8. What is the purpose of header file in a program?
9. What are comments? Why is it important?
10. Why is main() function so important?
11. Write the rules followed to choose a valid identifier in C++.
12. What type of errors generally occur while programming?
13. Differentiate between Syntax and semantic errors with example.
14. Differentiate between runtime error and logical error.
15. Explain Type Errors.
16. What are punctuators / separators?
17. What is the use of Input and Output operators?
18. What are the predefined stream objects in the I/O library?
19. Give examples for the types of Integer and Floating point constants.
20. Why is it important to include iostream.h in a C++ program?
21. Point out the errors in the following program.
int main( )
{

cout<<Enter Variable;
cin>>var
sqrs=var*var
cout<<The square is<<sqrs;

22. State whether the following are valid identifiers or not. If invalid, state the reason
why they are invalid.
a. 11abc
b. class11
c. int
d. discount%
23. Write a C++ Program to accept students marls in 5 subjects (Out of 100) and
print the total and percentage.
24. How are nongraphic characters represented in C++?
25. Write a C++ program that accepts radius of a circle and pints its area.
Page 2/23

Chapter 2: Data Handling


1.
2.
3.
4.

5.
6.

7.

8.

9.

What is #include directive?


What do you understand by the term Datatype?
Define fundamental datatypes.
Write the statements for each situation described below:
i.
Assign the value of the variable number1 to the variable total.
ii.
Assign the sum of the two variables loop_count and petrol_cost to the
variable sum.
iii.
Divide the variable total by the value 10 and leave the result in the
variable discount.
iv.
Assign the character W to the char variable letter.
v.
Assign the result of dividing the integer variable sum by 3 into the float
variable costing. Use type-casting to ensure that the remainder is also held
by the float variable.
vi.
Use the statement to print out the value of the integer variable sum.
vii.
Use a statement to print out the character variable letter.
viii. Use a statement to read a float variable into the variable discount_rate.
ix.
Use a statement to read a single character from the keyboard into the
variable operator. Skip leading blanks, tabs, and new line characters.
What value is returned by the main ( ) function?
Write the value stored in the variable Num by each of the following statements.
i.
Num=2*3-4
ii.
Num=2+3-1*3
iii.
Num=(2+3)*2
iv.
Num=pow(3,4)+5
What will be the output of following program?
#include<iostream.h>
void main()
{
cout<<My \ncountry \n is \n great;
}
Give the output of the following program segment:
int i=100, j=9;
cout<<i/j<<endl;
What will be the output of the following program?
#include<iostream.h>
int i=20;
void main()
{
int i=7;
cout<<i<< >>::i<<endl;
}
Page 3/23

10. Why is char often treated as integer data type?


11. What are advantages and disadvantages of floating point numbers over integer?
12. What is a reference variable? What is its usage?
13. What is a variable? How many values are associated with it?
14. In how many ways a variable can be declared in C++?
15. Explain the difference among 0, 0, \0, 0.
16. What is the impact of access modifier const over a variable?
17. Write a program to read two numbers and print their quotient and remainder?
18. What do you understand by Dynamic initialization of variables?
19. Why are so many datatypes provided in C++?
20. List the different integer datatypes offered in C++.
21. What is the advantage of unsigned integers over signed integers?
22. What do you understand by ASCII values?
23. Explain with example the concept of constant variables?
24. What is meant by formatted Output?
25. Explain the purpose of setw() and setprecision().

Page 4/23

Chapter 3: Operators and Expressions in C++


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

What is operator?
What is arithmetic operator?
What is the difference between / and % operator?
What is the relation operator? What is the purpose of each of these operators?
What is the logical operator?
What is unary operator? List some unary operators.
What is the purpose of assignment operator? How is it different from cin
statements?
8. Which ternary operator is available in C++?
9. What is the purpose of sizeof operator?
10. What is the purpose of type conversion?
11. Differentiate between implicit type conversion and type casting.
12. What is simple assignment and compound assignment?
13. The modulus operator works only with integers ---True or False
14. What is integral expression and float expression?
15. Explain the concept of local and global identifiers in C++ program.
16. What will be the output of the following program segment?
#include<iostream.h>
void main()
{
int x;
x=5;
cout<<x++;
cout<<x;
cout<<++x;
}
17. Determine the error in the following statements:
a. cout>>hello;
b. int a=2, b=5, c=11; d=21;
c. cin>>x>>y;>>z;
d. a=b*c=a+b;
18. Suppose x, y, z, w, and v are numeric type variables that have been assigned the
following values:
Variable
Data type
x
8
y
3
z
2.3
w
0.8
v
-1.1
Page 5/23

What will be the output of the following expressions?


a. (x-y)/(z*w)
b. (x-y)*(x%y)
c. (x-2)*(3*z-w+2*v)
d. 0.02*(z-v)
e. 3*sqrt(w+z)
f. (x-y)%2
g. y+sqrt(sqr(y)-y*x*z)/(2*x)
19. What will be the output of the following program segments?
a. #include<iostream.h>
main()
{
float x;
int a=10;
int b=6;
x=(float)a/b;
cout<<x;
}
b. #include<iostream.h>
main()
{
int a,b,z;
z=a>b?10:20;
cout<<z;
}
(a). if a=5 and b=7 (b). if a=17 and b=10
20. Determine the hierarchy of operation and evaluate:
a. x=j/3*2+10/5+j
(j=6)
b. s=q*a/4-6/2+2/3*6/g
(q=2, a=4, g=3)
c. root=sqrt(b*b-4*a*c)
(a=2, b=7, c=2)
21. Determine the output:
a. a=2;
b=++a;
cout<<a; cout<<b;
cout<<a++; cout<<++b;
b. a=1;
b=a++;
cout<<a++;
cout<<(b+a);
cout<<++b;
Page 6/23

22. What is the output of the following program?


#include<iostream.h>
void main()
{
float num;
num=4+(float) 7/ (int) 2.0;
cout<<num;
}
23. Write a program to find the maximum of two numbers using conditional
operator.
24. Write a program to enter the time in minutes and print in the following format:
________________ hours ____________ minutes
25. Write a program to calculate:
a. energy=m*g*h
b. distance=u*t+1/2*a*t2
c. speed=distance/time

Page 7/23

Chapter 4: Flow of Control


1. Explain the difference between Sequential, Selection and iterative statements and
their flow of execution.
2. Write the difference between if-else-if and switch statement.
3. Explain the usage of conditional operator with code example.
4. What is dangling else problem?
5. What is the purpose of default and break statements in switch construct?
6. Explain the fall through situation in switch construct.
7. What are the four main elements that form a loop?
8. Define the following terms
a) Definite / Predetermined loop
b) Indefinite loop
c) Infinite loop
d) Empty loop
9. What is the output of the following code fragment?
for ( int i=1; i<=10;++i);
cout<<i;
10. What is meant by an entry-controlled loop? Which C++ loops are entry-controlled?
11. What is meant by an exit-controlled loop? Which C++ loops are exit-controlled?
12. What is the difference between a while and do-while loop?
13. Write a program to display the following output
*
1
1
A
**
or
1 2 or 2 2 or B B
***
123
333
CCC
****
1234
4444 DDDD
14. Rewrite the following code using switch.
if (ch= = E)
eastern++;
if (ch= = W)
western++;
if (ch= = N)
northern++;
if (ch= = S)
southern++;
15. Write a C++ program to find the largest number among three numbers.
Page 8/23

16. Write a program that demonstrates the use of exit( ) function.


17. Write a program to swap two numbers without using third variable.
18. Write a program to find the factorial of a given number.
19. Write a program to find whether the entered number is palindrome or not.
20. Write a program to print Fibonacci series (10 terms).
21. Write a program to find whether the entered number is perfect number or not.
22. Given the four sides of a rectangle. Write a program to find out whether its area is
greater than its perimeter.
23. Write a program to input a digit and print it in words.
24. Predict the output for the following code snippet.
int n=2015,s=0;
while(n>0)
{
s = s * 10 + n % 10;
n = n / 10;
cout<<s<<endl;
}
25. Rewrite the above loop using for statement and do-while statement.

Page 9/23

Chapter 5: Functions
1. What are functions?
2. What is a user- defined function?
3. Is it necessary that the name of actual parameter be same as that of formal
parameter?
4. How will you call a function?
5. How many times can a function be called?
6. What is the difference between Call by value and Call by reference? Explain with
code example.
7. Write a function to find the sum of N natural numbers.
8. What is recursive function?
9. What is a function? Name its types
10. Distinguish between Declaration and Definition of a function.
11. Summarize the rules that must be followed during function call.
12. What are default arguments? Explain with code example.
13. Give the output of the following program:
#include<iostream.h>
int & max(int &x ,int &y)
{
if(x>y)
return(x);
else
return(y);
}
void main ( )
{
in a =10,b=13;
max (a,b)=-1
cout<<a=<<a<<b=<<b<< endl;
max (b,a)=7
cout<<a=<<a++<<b+<<b--<<endl;
max (a,b)=3;
cout<<a=<<a<<b=<< b<<endl;
}
14. Write a function to find the sum of odd numbers till N where N is user input.
15. Find the syntax error (s), if any, in the following program;
#include (iostream.h)
void main( )
{
int x,y;
cin >> x;
for (y=0; y < 10 , y++)
Page 10/23

if x== y
cout<< y+x;
else
cout >>y;
}
16. Write the function that interchanges the value of two integers A and B
without using any variable.
17. Write a program in C++ to print first 10 multiples of an integer N, where N is
to be entered by user.
18. Write a function to find the sum of series.
1+2+3+4+5+6+.upto N terms
19. Read the program given below and choose the possible output(s) among the
options (i) to (iv). Justify your answer
#include<iostream.h>
#include<stdlib.h>
void main()
{
randomize();
int MyNum, Max=5;
MyNum= 20 + random (Max);
for (int N= MyNum; N<=25; N++)
cout<<N<<*;
}
Outputs :
i)
ii)

20*21*22*23*24*25*
22*23*24*25*

iii)
iv)

20. Write the output of the following program


#include<iostream.h>
int max (int &x, int &y, int &z)
{
if (x>y && y>z)
{
y++;
z++;
return x;
}
else
if (y > x)
return y;
else
return z;
}
void main()
Page 11/23

23*24*
21*22*23*24*25

{
int a = 10, b=13, )c=8;
a= max (a,b,c);
cout <<a<<b<<c,,endl;
b=max (a,b,c);
cout<<++a<<++b<<++c<<endl;
c=max(a,b,c);
cout<<a++<<++b<<++c<<endl;
}
21. How many values can be returned by a function?
22. Summarize the rules must be followed during the function call.
23. Differentiate between actual parameters and formal parameters.
24. Write a program to calculate the root of quadratic equation using
Function.
25. Identify the problem with the following code:
void large ( int &a, int &b);
int main( )
{
..
..
large(5, 7);

}
void large (int &a, int &b)
{
if (a>b) a= -1;
else b = -1;
}

Page 12/23

Chapter 6: Arrays
1. How many elements can the array store?
2. Consider the following array declaration;
int x [5][50];
long y [5] [10] ;
Find the number of elements in each array.
3. Which is the last character of a string?
4. What is the base address of an array?
5. What is an array? How does it differ from ordinary variables?
6. Give the proper array declaration for the following :
(i)Declare an integer array which can hold 25 values.
(ii)Declare a one dimensional array of four character called letter.
(iii)Define a two dimensional array called max 3*4 of integer.
7. What will be the address of 6th element in a float type array implemented in
C++? The array is specified as Amount[16]. The base address of the array is 1200.
8. An array VAL[1..15][1..10] is stored in the memory with each element requiring 4
bytes of storage. If the base address of array VAL is 1500, determine the location
of VAL[12][9] when the array VAL is stored (i) Row wise (ii) Column wise.
9. Find out the syntactical errors in the C++program:
#include <iostream . h >
Main()
{
Int Ch =9,Sch =90 ;
Char S[2,2]
If Ch <=9
Cout <<Ch ;
For (int y = 0; y <2; y++)
{
If (y==0)S[x][y]=A;
else S [x][y] =,B,;
cout >>S{x][y];
}
10. What will be the output of the following segment?
void main()
{
int a [6]={6,5,4,3,2,1};
int i;
for (i=5; i>=0;i--)
{
cout<<a[i];
}
}
Page 13/23

11. What will be the output of the following program?


#include<iostream.h>
void main()
{
int a, b=0;
static int c[10] = { 1, 2, 3, 4, 5, 6 , 7, 8, 9, 0, };
for (a = 0; a < 10 ;++a)
if ((a % 2 )==0) b += c[a] ;
cout <<b ;
}
12. Find the output of the following program:
#include< iostream.h>
#include<ctype.h>
void main ( )
{
char text [ ]=India@WoRk!;
for (int i = 0; text[i]! = \0; i++)
{
if ( !isalpha (text [i]))
text[i] =!*!;
else if ( !isupper (text[i] ))
text[i] = text[i]+1;
elsa
text[i] =text[i+1];
}
cout <<text ;
}

13. In the following program, find the correct possible output (s) from the options :
void main( )
{
randomize ( );
char city [ ] [10] ={ DEL, CHN , KOL, BOM, BNG};
int fly ;
for (int i = 0; i< 3 ;i++)
{
fly = random (2 )+1;
cout <<city {fly ] <<;;
}
}
Output :
(i). DEL:CHN : KOL:
(ii) CHN:KOL :CHN :

(iii)KOL: BOM: BNG :


(iv)KOL: CHN :KOL:
Page 14/23

Give the output of the following program (Assuming all required header files are
included in the program).
14. [3 Marks]
void swap(char &c1,char &c2)
{
char temp;
temp=c1;
c1=c2;
c2=temp;
}
void update(char str[])
{
int k,j,l1,l2;
l1 = (strlen(str)+1)/2;
l2=strlen(str);
for(k=0,j=l1-1;k<j;k++,j)
{
if(islower(str[k]))
swap(str[k],str[j]);
}
for(k=l1,j=l2-1;k<j;k++,j)
{
if(isupper(str[k]))
swap(str[k],str[j]);
}
}
void main()
{
char data[100]={gOoDLUck};
cout<<Original Data : <<data<<endl;
update(data);
cout<<Updated Data <<data;
}
15. [2 Marks]
void Secret(char Str[ ])
{
for (int L=0;Str[L]!= \0;L++);
for (int C=0;C<L/2;C++)
if (Str[C]==A || Str[C]==E)
Str[C]=#;
else
{
char Temp=Str[C];
Str[C]=Str[L-C-1];
Str[L-C-1]=Temp;
}
}
void main()
{ char Message[ ]=ArabSagar;
Secret(Message);
Page 15/23

cout<<Message<<endl;
}
16. [2 Marks]
void Location(int &X,int Y=4) {
Y+=2;
X+=Y;
}
void main()
{ int PX=10,PY=2;
Location(PY); cout<<PX<<,PY<<endl; Location(PX,PY);
cout<<PX<<,PY<<endl;
}
17. [3 Marks]
int Execute (int M)
{
if(M%3==0)
return M=3;
else
return M+10;
}
void Output (int B=2)
{
for(int T=0;T<B;T++)
cout<<Execute(T)<<*;
cout<<endl;
}
void main()
{
Output(4);
Output();
Output(3);
}
18. [2 Marks]
void Position (int &C1, int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<,<<P2<<endl;
Position(P2,P1);
cout<<P1<<,<<P2<<endl;
}
Page 16/23

19. Correct the errors [2 Marks]


int sum(const int arr[], int size)
void caller()
{
int A[10],i=0;
for(;i<10;i++)
cin>>A[i];
sum(A,10);
}
void main()
{
caller()
}
int sum(const int arr[], size)
{
int s=0,i=-1;
while(++i<size)
{
s=+arr[i];
}
return s;
}
Questions based on arrays and functions
20. Write the definition of a function Change(int P[ ], int N) in C++, which should
change all the multiples of 10 in the array to 10 and rest of the elements as 1. For
example, if an array of 10 integers is as follows : [2 Marks]

21. Write a function REVROW(int P[ ][5],int N,int M) in C++ to display the content
of a two dimensional array, with each row content in reverse order. [3 Marks]
For example, if the content of array is as follows :

The function should display output as


Page 17/23

51 45 56 12 15
63 87 92 91 13
81 46 61 23 81
22. Write an user defined function ABSOLUTE(), that takes an integer array, its size
and an integer value to be searched from the array. If the integer value exist in
the array, then the function should return the absolute value of the element and
if the integer value does not exist in the array, then the function should return
zero. (3 marks)
23. Let A [n x n] be a given matrix. Write a program to find the
sum of all the elements which lie on either diagonal. For
example, for the matrix shown below, your program should
output 68=(1+6+11+6+16+4+7+10+13);

24. Write the definition of a function Alter(int A[], int N) in C++, which should
change all the multiples of 5 in the array to 5 and rest of the elements as 0. For
example, if an array of 10 integers is as follows:

25. Write a function REVCOL (int P[][5], int N, int M) in C++to display the content
of a two dimensional array, with each column content in reverse order. [3
Marks]
Note: Array may contain any number of rows.
For example, if the content of array is as follows:
15 12 56 45 51
13 91 92 87 63
11 23 61 46 81
The function should display output as:
11 23 61 46 81
13 91 92 87 63
15 12 56 45 51

Page 18/23

Chapter 7: Structures
1. Declare a structure in C++ with Empno, Ename and Salary as components.
2. Ten integers are to be stored in the memory. Which would you prefer an
array or structure?
3. struct Dates
{
int dd;
int mm;
int yy;
};
Dates D;
Using above declaration, which of the following refers mm:
(i)
Dates.mm
(ii)
Datesmm
(iii) D. mm;
4. What is the size of the variable D in the above question?
5. Use typedef to define long int, signed char.
6. What are the individual elements of a structure called?
7. Do you pass structures by copy or by address? Differentiate with example.
8. Declare a structure Play having following fields:
(i)
an integer quantity won
(ii)
an integer quantity lost
(iii) a floatingpoint quantity result.
9. How is an array of structure initialized?
10. For what purpose typedef keyword is incremented?
11. What is meant by nesting of structure?
12. What are the different ways of declaring a structure variable?
13. Illustrate the use of #define in C++ to define a macro.
14. Distinguish between structure datatype variables and other datatypes
variables.
15. Write the purpose of dot operator.
16. Explain the concept of Nested structures with example.
17. Write a program to initialize the information for the following record for 10
Actors using array of structures: Take Sample Data for Hollywood /
Bollywood Actors)
Actor

Country

Number of Movies released

Amitabh Bachchan Hollywood

500

Salman Khan

150

Hollywood

Page 19/23

And Display the following information:


Display the list of Hollywood actors.
Display list of actors acted in more than 100 movies.
18. Write a program to initialize the information for the following record for 10
food Items using array of structures: Take Sample Data)
i.
ii.

Food Item

Calories

Type

Apple

50

Fruit

Banana

95

Fruit

Potato

97

Vegetable

and Display the following information:


(i) Display the list of Vegetable
(ii) Display list of Food items having calorie more than 100.
19. Rewrite the following program after removing the syntactical 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);
}
20. Rewrite the following program after removing the syntactical error(s), if any.
Underline each correction.
#include<iostream.h>
void main( )
{ struct movie
{ char movie_name[20];
char movie_type;
int ticket_cost=100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}

Page 20/23

21. Write output for the following.


typedef char STRING[80];
void main() {
STRING Txt[] = We love Peace;
int Count=0;
while (Txt[Count]!=\0)
if (isalpha(Txt[Count]))
Txt[Count++]=@;
else
Txt[Count++]=#;
puts(Txt);
}
22. Find the output of the following program:
#include<iostream.h>
struct MyBox
{ int Length,Breadth,Height;
};
void Dimension(MyBox M)
{ cout<<M.Length<<x<<M.Breadth<<x ;
cout<<M.Height<<endl;
}
void main( )
{
MyBox B1={10,15,5},B2,B3;
++B1.Height;
Dimension(B1);B3=B1;
++B3.Length;
B3.Breadth++;
Dimension(B3);
B2=B3;
B2.Height+=5;
B2.Length--;
Dimension(B2);
}
23. Find the output of the following program:
struct Package
{ int Length,Breadth,Height; };
void Occupies(Package M)
{ cout<<M.Length<<x<<M.Breadth<<x ;
cout<<M.Height<<endl;
}
void main( )
{
Package P1={100,150,50},P2,P3;
++P1.Height;
Occupies(P1);
Page 21/23

P3=P1;
++P3.Lengh;
P3.Breadth++;
Occupies(P3);
P2=P3;
P2.Height+=50;
P2.Length--;
Occupies(P2);}
24. Rewrite the corrected code for the following program. Underline each
correction if any.
#include<iostream.h>
structure Supergym
{ int member number;
char membername[20];
char membertype[]=HIG;
};
void main( )
{ Supergym person1,person2;
cin>>Member Number: ;
cin>>person1.membhernumber;
cout<<Member Name: ;
cin>>person1.membername;
person1.member type = MIG;
person2=person1;
cin>>Member Number; <<person2.membernumber;
cin<<Member Name <<person2.membername;
cin<<Member Number:<<person2.membertype;
}
25. 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.
#Define float Max=70.0;
Void main()
{
int Speed
char Stop=N;
cin>>Speed;
if Speed>Max
Stop=Y;
cout<<Stop<<end;
}

Page 22/23

Chapter 8: Programming Methodology and Number System


1. Convert the following binary numbers to decimal.
i) 0001 1001 ii) 1111 1101 iii) 0010 1001 1000
iv) 1101 0101 v) 0011 1010 vi) 1110 1110 1110
2. Convert the following decimal numbers to binary.
i)
29
ii) 250
iii) 1000
iv)78 v) 315 vi) 2049
3. Convert the following binary numbers to OCTAL.
i)
0001 1001 ii) 1111 1101 iii) 0010 1001 1000
iv)
1101 0101 v) 0011 1010 vi) 1110 1110 1110
4. Convert the following binary numbers to HEXADECIMAL
i)
11001 1001 10 ii) 1011 0010 1101 iii) 1110 1101 1001.101
5. Convert the following binary numbers to decimal.
i) 0001 1001 ii) 1111 1101 iii) 0010 1001 1000
6. Convert the following OCTAL numbers to BINARY and HEXADECIMAL.
i.
12
ii) 56
iii) 107
7. Convert the following HEXADECIMAL numbers to BINARY and OCTAL
i)
25
ii) 256 iii) 6A03
8. All the data and the instructions are implemented internally in machine
language, a language consisting of ___________.
9. List the methods of integer representation inside the computer memory.
10. What do you understand by debugging and testing a program?
11. What is the portability of program?
12. Define algorithm.
13. Define Flowchart.
14. Expand ASCII
15. Write two advantages of using flowchart?
16. Define documentation.
17. What is modularity?
18. Write two advantages of modularity.
19. What are the methods used to analyze a problem step by step?
20. What does a problem definition do?
21. Write the importance of comments in a program.
22. What are the different control structures used in problem solving technique?
23. Write an algorithm to compute the square of Numbers.
24. Draw a flowchart to input any three numbers and find the greatest among them.
25. Name the types of errors that generally occur during programming.

Page 23/23