c1410591899wComputer (C Plus Plus) XI Solutions 6-10

35
8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10 http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 1/35 OSWAAL BOOKS “Oswaal House” 1/11, Sahitya Kunj, M.G. Road, AGRA-282002 Ph.: 0562-2857671, 2527781, Fax : 0562-2854582, 2527784 email : [email protected], website : www.oswaalbooks.com Published by : Class 11 Sampl e Qu e s t i on Paper s Compu ter Science Strictly Based on Latest Syllabus Issued by CBSE for 2015 Examination sol ut ions (Based on C+ +)

Transcript of c1410591899wComputer (C Plus Plus) XI Solutions 6-10

Page 1: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 1/35

OSWAAL BOOKS“Oswaal House” 1/11, Sahitya Kunj, M.G. Road, AGRA-282002Ph.: 0562-2857671, 2527781, Fax : 0562-2854582, 2527784

email : [email protected], website : www.oswaalbooks.com

Published by :

Class11

Sampl eQuest i onPaper s

Com pu ter Scien ce

Strictly Based on Latest Syllabus Issued by CBSEfor 2015 Examination

sol ut i on s

(Based on C+ + )

Page 2: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 2/35

Sample Question Paper–6

1.   (a) PUP 11 and APPLE II are two examples of fourth generation computers.   [1 mark]

(b) Optical storage is any storage method in which data is written and read with a laser for archival or 

 backup purposes. Typically, data is written to optical media, such as CDs and DVDs.   [1 mark]

(c ) Input units are devices we can use to give instructions, communicate with or send data to a computer.

 E.g.  keyboard, mouse, barcode scanner, microphone etc.   [1 mark]

(d) Bit is a single binary digit that can have either value 0 or 1.   [2 marks]

1 byte = 8 bits.

1 nibble = 4 bits.2.   (a) ISCII – Indian Standard Code for Information Interchange   [1 mark]

(b) The formula for expressing real numbers is :   [1 mark]

  1 | (– 1) ^S * 2^ ( E – 127 ) * ( 1 + F )

where:

S is the sign bit and so 0 is understood as positive (– 1^0 = 1).

  E is the exponent to which 127 must be added to obtain the encoded equivalent.

  F is the fraction part, the only one which is expressed, and which is added to 1 to perform thecalculation.

(c) These number systems refer to the number of symbols used to represent numbers. In the decimal

system, we use ten different symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.   [1 mark]

(d) (i) (EB4A)16

  = 14 * 163  + 11 * 162 + 4* 161 + 10 * 160 [1 mark]

= 57344 + 2816 + 64 + 10

= (60234)10

(ii) (2C9)16

  = 2 * 162 + 12 * 161 + 9 * 160 [1 mark]

= 512 + 192 + 9

= (713)10

(e)   Difference between Data Register and Memory Address Register [2 marks]

Data Register Memory Address Register

1. Data registers can be assigned to a variety of functions by the programmer. They can beused with any machine instruction that

 performs operations on data.2. Data registers are used to store intermediate

data values and result when any arithmeticoperation is performed. The registers areallocated to the variables according to the type

of the operation.

3.   (a) Procedural language is a type of computer programming language that specifies a series of well-

structured steps and procedures within its programming context to compose a program. It contains asystematic order of statements, functions and commands to complete a computational task or program.[1 mark]

(b) (i)   Data members : [2 marks]

Classes use the concept of abstraction and are defined as a list of abstract attributes such as size,weight, and cost and uses functions to operate on these attributes. The attributes are sometimescalled as data members because they hold information. E.g.  : int a,b; // a,b are data members

(ii)   Object Member functions :

The functions that operate on these data are called as methods or member functions. E.g.  : Void getdata ( ) ; // member function

1. Address registers contain main memoryaddresses of data and instructions or theycontain a portion of the address that is usedin the calculation of the complete addresses.

2. Memory address registers are used to storethe addresses of other registers and differentmemory locations.

Page 3: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 3/35

2 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

(c) An enumerated datatype is a user-defined datatype, which provides a way for attaching names to

numbers, thereby increasing comprehensibility of the code. The syntax of an enum statement is :

enum shape {circle, square, triangle}

enum color {red, blue, green, yellow}   [2 marks]

(d) Polymorphism is the ability to take more than one form. Function overloading means we can use the

same function name to create functions that perform a variety of different tasks.   [2 marks]

 E.g.  : An overloaded add ( ) function handles different data types as shown below.

// Declarations(i) int add (int a, int b); //add function with 2 arguments of same type

(ii) int add (int a, int b, int c); //add function with 3 arguments of same type

(iii) double add (int p, double q); //add function with 2 arguments of different type

//Function calls

add (3 , 4); //uses prototype (i)

add (3, 4, 5); //uses prototype (ii)

add (3 , 10.0); //uses prototype (iii)

(e) (i) Since C++ allows us to create hierarchy-related objects, we can build special object-oriented

libraries, which can be used later by many programmers.   [1 mark]

(ii) C++ programs are easily maintainable and expandable.   [1 mark]

(iii) C part of C++ gives the language the ability to get close to the machine-level details.   [1 mark]

(iv) Extremely fast, works very well for GUI programming on a computer.   [1 mark]4.   (a) Character set is a set of valid characters that a language can recognise. A character represents any

letter, digit or any other special character. The C++ has the following character set :   [2 marks]

Letters : A–Z, a-zDigits : 0–9Special Characters Space: + - * / ^ \ ( ) [ ] { } = ! = < > . ‘ “ $ , ; : % ! & ? _ # <= >= @White spaces: Horizontal tab (—>), Blank space, Carriage return (< ) Newline, form feed

(b) (i) A token is a group of characters that logically belong together. The programmer can write a

 program by using tokens.   [1 mark]

(ii) C++ uses the following types of tokens: keywords, identifiers, literals, punctuators and operators.[1 mark]

(c) (i)   (a2+b2) = sqrt (pow (a,2) + pow (b,2))   [½ × 4 = 2 marks]

(ii) 2 – y.2ey  + 4y = 2 – y * pow (e, 2*y) + 4 * y(iii) p + q/(r+s)2  = p + q / pow((r + s), 2)(iv) b2  – 4ac = pow (b,2) – 4 * a * c

(d) ‘a’ is a character literal. It’s of type char. “a” is a string literal. It’s of type const char[2], and refersto an array of 2 chars with values ‘a’ and ‘\0’. In most, but not all, contexts, a reference to “a” will beimplicitly converted to a pointer to the first character of the string.   [3 marks]

Bothcout << ‘a’;andcout << “a”;happen to produce the same output, but for different reasons. The first prints a single character value.The second successively prints all the characters of the string (except for the terminating ‘\0’) — which happens to be the single character ‘a’.

(e) (i) Only alphabetic characters, digits and underscore are permitted.   [3 marks](ii) The name cannot start with a digit.

(iii) The upper case and lower case letters are distinct.

(iv) A declared keyword cannot be used as a variable name.

5.   (a) Do- while loop is not a pretest loop.   [1 mark]

(b) (i) A switch statement is generally best to use when you have more than two conditional expressions

 based on a single variable of numeric type. The switch statement is a construct that is used whenmany conditions are being tested for.   [1 mark]

(ii) When there are many conditions, it becomes too difficult and complicated to use the if and else if 

constructs. Nested if/else statements arise when there are multiple alternative paths of execution based on some condition that is being tested for.   [1 mark]

Page 4: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 4/35

Solutions | 3

(c) # include <iostream.h>   [3 marks]

# include <conio.h>int main ( ){int i = 0, ua = 0, ub = 0, uc = 0, fail = 0;while (i <= 5){

switch (i++){case 1 :case 2 : ++ua;case 3 :case 4 : ++ub;case 5 : ++uc;default : ++ fail;}

}cout<<“\n ua = “ <<ua<<“\t”<< “ub = “ << ub << endl;cout << “\nuc = “ << uc<< “\t”<< “fail = “ << fail;getch ( );

return 0;}Ans.   ua = 2 ub = 4

uc = 5 fail = 6

(d)

[3 marks]

Page 5: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 5/35

4 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

(e)   Algorithm : Calculate Simple Interest [4 marks]

Step 1 : input P, N , R 

Step 2 : SI = ( P*N*R)/100

Step 3 : Print ‘Simple Interest = SI’

Step 4 : [End of Algorithm]

Stop

Flowchart :

Start

Input P, N, R

Calculate Interest = P*N*R/100

Print Interest

Stop

6.   (a) The strcpy( ) function is designed to work exclusively with strings. It copies each byte of the source

string to the destination string and stops when the terminating null character (\0) has been reached.

On the other hand, the memcpy ( ) function is designed to work with any type of data.   [1 mark]

(b) Any function prototypes, and type definitions that can be exported from a source code file are put in

a header file. From the point of view of the main application, these functions are external. The

compiler reads the included header file and knows where a particular function comes from. Without

this it would just report an undefined function error.   [2 marks]

The following are four functions found within the <stdio.h> header file :

1. Formatted input/output functions

2. File operation functions

3. Character input/output functions

4. Error handling functions

(c ) /* Program to count the number of words in a string */   [3 marks]

# include<iostream.h>

# include<conio.h>

# include<stdio.h>

# define clrscr ( );

int main ( )

{

clrscr( );

char str[80];

int words = 0;

cout<<“Enter a string:”;gets (str);for(int i = 0; str[i]!=’\0';i++)

{if (str[i]==’’)words++; //Checking for spaces

}

cout<<“The number of words =”<<words+1<<endl;getch ( );return 0;

}

Page 6: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 6/35

Solutions | 5

Output :Enter a string: I love my family

The number of words = 4

(d) 1. Power Function - pow(x,y) : (½ + 1 + ½) [2 marks]

Power function pow(x,y) has two parameters

 pow(x,y) returns value of type double

 pow(x,y) calculates x to the power of y: pow(2,3) = 8.0

x and y called parameters (or arguments) of function pow2. Square Root Function – sqrt(x):

Square root function sqrt(x) has only one parameter 

sqrt(x) returns value of type double

sqrt(x) calculates non-negative square root of x, for x >= 0.0: sqrt(2.25) = 1.5

3. Floor Function - floor(x):

Floor function floor(x) has only one parameter 

floor(x) returns value of type double

floor(x) calculates largest whole number not greater than x: floor(48.79) = 48.0

7.   (a) When an overloaded function or overloaded operator is called, the compiler chooses the function

declaration with the best match on all arguments from all the function declarations that are visible. A

call to an overloaded function has three possible outcomes. The compiler can find :   [1 mark]

An exact match No match or 

An ambiguous match

(b )   The :  (scope resolution) operator is used to qualify hidden names so that you can still use them. You

can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit

declaration of the same name in a block or class.   [2 marks]

Scope resolution operator is used to uncover the hidden variables. It also allows access to global

version of variables.

 E.g.,

# include<iostream.h>

int m=10; // global variable m

void main ( )

{

int m=20; // local variable m

cout<<”m =”<<m<<”\n”;

cout<<”: : m =”<<: : m<<”\n”;

}

output :

20

10 (: : m access global m)

(c ) The call by value method of passing arguments to a function copies the actual value of an argument

into the formal parameter of the function. In this case, changes made to the parameter inside the

function have no effect on the argument.   [2 marks]

Example :

# include <iostream.h>

void change Value (int value);

int main ( )

{

int value = 5;

changeValue(value);

cout << “The value is : “ << value << “.” << endl;

return 0;

}

void changeValue(int value)

{

Page 7: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 7/35

6 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

value = 6;

}

// This doesn’t change the value from 5 to 6. 5 is output.

(d) /*To print the computer science marks of 40 students in descending order */   [3 marks]

# include <iostream.h>

# include <stdio.h>

# include <conio.h>

int main ( ){

int number[40];

int i, j, a, n = 40;

cout << “Enter the computer science marks of 40 students” << endl;

for (i = 0; i < n; ++i)

cin>>number[i];

/* sorting begins ... */

for (i = 0; i < n; ++i)

{

for (j = i + 1; j < n; ++j){

if (number[i] < number[j])

{

a = number[i];

number[i] = number[j];

number[j] = a;

  }

  }

}

cout<< “The marks arranged in descending order are given below”<<endl;

for (i = 0; i < n; ++i){

cout << number[i] << endl;

}

getch ( );

return 0;

}

(e ) /* To find the sum of the diagonals of a square matrix A */   [4 marks]

#include <iostream.h>

#include<conio.h>

int main( )

{

int A[5][5],row,col ;int i,j,d1=0,d2=0 ;

cout<<“Enter no. of rows and columns (max 5): “<<endl;

cin>>row>>col ;

cout<<“Enter the elements of matrix: “ <<endl;

if (row==col)

{

for(i=0; i<row; i++)

{

for(j=0; j<col; j++)

Page 8: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 8/35

Solutions | 7

cin>> A[i][j] ;

}

for (i = 0, j = col-1; i<row || j> = 0; i++,j– –)

{

d1 = d1+A[i][i] ;

d2 = d2+A[i][j] ;

}

cout<<“\nThe sum of first diagonal elements : “ << d1 << endl;cout<<“\n The sum of second diagonal elements :”<< d2 << endl;

}

else

{

cout << “Rows and Columns are not equal !!” << endl ;

}

getch( );

return 0;

}

Output :

Enter no. of rows and columns (max 5):3 3

Enter the elements of matrix:

1 2 3

4 5 6

7 8 9

The sum of first diagonal elements : 15

The sum of second diagonal elements :15

 l

Page 9: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 9/35

Sample Question Paper–7

1.   (a) ROM stands for Read-Only Memory. ROM is typically used to refer to a chip in a computer that

contains permanently stored data.   [1 mark](b) Input devices: keyboard, scanner, mouse   [1 mark]

Output devices: printer, monitor, speaker 

(c) ENIAC – Electronic Numerical Integrator And Computer    [1 mark]

(d)     System software is a type of computer program that is designed to run a computer’s hardware and

application programs. If we think of the computer system as a layered model, the system software

is the interface between the hardware and user applications.   [1 mark]

  The operating system (OS) is the best-known example of system software. The OS manages all

the other programs in a computer.   [1 mark]

2.   (a) Example of CISC instruction set architecture is System/360.   [1 mark]

(b) MDR – Memory Data Register    [1 mark](c)     In computing, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or 

 base of 16.   [2 marks]

  It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and

A, B, C, D, E, F (or alternatively a–f) to represent values ten to fifteen.

  Example of hexadecimal number: 2AF316.

(d) 0.275 * 2 = 0.550 (0)   [2 marks]

0.550 * 2 = 1.100 (1)

0.100 * 2 = 0.200 (0)

0.200 * 2 = 0.400 (0)

0.400 * 2 = 0.800 (0)

0.800 * 2 = 1.600 (1)

Hence, (0.275)10

  = (0.010001)2

3.   (a) The following are the basic concepts of OOPs :   [1 mark]

Classes, Objects, Data abstraction and encapsulation, Polymorphism, Inheritance, Message Passing,

and Dynamic Binding.

(b) Base Class : The parent class of a derived class. Classes may be used to create other classes. A class

that is used to create (or derive) another class is called the base class.   [2 marks]

Derived Class : A class that was created based on a previously existing class (i.e., base class). A

derived class inherits all of the member variables and methods of the base class from which it isderived.

For example, a base class “furniture” can have two derived classes “table” and “chair”. The derived

classes “table” and “chair” inherit all of the member variables and methods of the base class “furniture”.

(c ) A low-level programming language is a programming language that provides little or no abstraction

from a computer’s instruction set architecture.   [2 marks]

  Low-level languages can be converted into machine code without using a compiler or interpreter,

and the resulting code runs directly on the processor.

Page 10: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 10/35

Solutions | 9

(d)   [2 marks]

(e) Namespaces are used in C++ programming language to create a separa te region for a group of 

variables, functions and classes. Namespaces are needed because there can be many functions, variables

for classes in one program and they can conflict with the existing names of variables, functions and

classes. C++ uses namespace to avoid the conflicts.   [4 marks]

The concept is shown using the following diagram :

StandardNamespace

User DefinedNamespace

variables

functions

classes

variables

functions

classes

variables

functions

classes

The following are some reasons due to which a conflict can occur :

  Between User defined variables/functions/classes and built in Library variables/functions/classes

(e.g . sqrt( ), abs( ) etc.)

  Between the separately included library and built in library

  Between the variables/functions/classes of the one separately included library and the same of the

other separately included library

In C++ language the keyword “namespace” has to be included for creating namespaces.

namespace

{

members of namespace;

}

4.   (a)     The logical operators are used to help in creating a test expression that controls program flow. This

type of expression is also known as a Boolean expression because they create a Boolean answer or 

value when evaluated.   [2 marks]

Page 11: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 11/35

10 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

  The answers to Boolean expressions within the C++ programming language are a value of either 1

for true or 0 for false.

  There are three common logical operators that give a Boolean value by manipulating other Boolean

operand(s).

The C++ programming language operators with their meanings are :

C++ Operator Meaning

&& Logical and

|| Logical or  

! Logical not

An example is :

6 > 4 && 2 <= 14

1 && 1

or 

true && true

The final evaluation of the expression is : 1 meaning true.

(b) a = 3, b = 6, c = 4, d = 2.   [2 marks]

(((a+b) > c) && ((b-c) < d || (b+d) >= (a+c)))

= (((3+2) > 4) && ((6-4) < 2 || (6+2) >= (3+4)))

= ((5 >4) && ( 2<2 || 8 >= 7))

= 1 && ( 0 || 1)

= 1 && 1

= 1 (True)

(c)     Constants refer to fixed values that the program may not alter and they are called literals.

[2 marks]

  Constants are treated just like regular variables except that their values cannot be modified after 

their definition.

Defining Constants :

There are two ways in C++ to define constants:

Using #define preprocessor.

Using const keyword.

Example:

# define LENGTH 10

const int WIDTH = 5;

(d)     C++ allows the char, int, and double data types to have modifiers preceding them.   [3 marks]

  A modifier is used to alter the meaning of the base type so that it more precisely fits the needs of 

various situations.

  The data type modifiers are listed as :

o signed

o unsigned

o long

o short

  The modifiers signed, unsigned, long, and short can be applied to integer base types.   In addition, signed and unsigned can be applied to char, and long can be applied to double.

  The modifiers signed and unsigned can also be used as prefix to long or short modifiers. For 

example, unsigned long int.

Example :

unsigned int y;

short unsigned int j;

(e) /* Program to find area and perimeter of triangle : given three sides */   [4 marks]

# include <iostream.h>

# include <conio.h>

Page 12: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 12/35

Solutions | 11

# include <math.h>

int main ( )

{

float a,b,c,s,area,perimeter;

clrscr ( );

cout<<“\n Enter the three sides of the triangle:”;

cin >> a >> b>> c;

s = (a + b + c)/2;area = sqrt (s * (s - a) * (s - b) * (s - c));

 perimeter = a+b+c;

cout<<“Area = “<< area << endl;

cout<<“Perimeter = “<< perimeter <<endl;

getch ( );

return 0;

}Output :

Enter the three sides of the triangle : 10 4 8

Area = 15.1987

Perimeter = 22

5.   (a) A compound statement consists of zero or more statements enclosed in curly braces ({ }).[1 mark]

(b) /* Program to find the largest of any 3 numbers */   [2 marks]

# include <iostream>

# include <conio.h>

using namespace std;

int main ( )

{

int a,b,c,greatest;

cout<<“Enter three numbers : “;

cin >> a >> b >> c;

greatest = (a>b&&a>c)? a : (b>c) ? b : c;

cout<<“Largest number is “<<greatest;getch ( );

return 0;

}

Output :

Enter three numbers : 3 8 5

Largest number is 8

(c) if ( a < b ) [2 marks]

n = a;

else

n = b;

(d) The jump statements unconditionally transfers program control within a program / function.

[3 marks](i) goto statement

(ii) break statement

(iii) continue statement

(i) The goto statement :  goto allows to make a jump to another point in the program.

goto p;

 p : p is known as label. It is a user defined identifier. After the execution of goto statement, the

control transfers to the line after label p.

(ii) The break statement : The break statement, when executed in a switch structure, provides an

immediate exit from the switch structure. When the break statement executes in a loop, it

immediately exits from the loop.

Page 13: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 13/35

12 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

(iii) The continue statement : The continue statement is used in loops and causes a program to skip

the rest of the body of the loop.

while (condition)

{

Statement 1;

If (condition)

continue;statement;

}

The continue statement skips rest of the loop body and starts a new iteration.

(e)   Algorithm : [4 marks]

1. Assign fib = 0, i = 0, j =1, k = 0

2. Get the no. of terms upto which u want to generate the Fibonacci no, i.e., N.

3. Add i and j to get the next Fibonacci number 

4. Assign the value of k to j i.e.  j = k 

5. Assign the value of fib to k i.e.  k = fib

6. Write the value of fib to get next Fibonacci number in the series.

7. increment i with 1 i.e. i = i +1 and repeat step 3,4,5,6 with the last value of i = N (N is the no. of terms which we want to generate Fibonacci no. series.)

8. Stop

Start

i = 0

 j = 1

k = 0

fib = 0

i < N ?

end

No

Output"Fibonacci(i) = fib"

Output carriagereturn and linefeed

fib = j + k

 j = k

k = fib

i = i + 1

Page 14: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 14/35

Solutions | 13

6.   (a) A stream is an abstraction that represents a device on which input and output operations are performed.

[1 mark]

(b) 1. The class is reusable   [2 marks]

2. The users of the class know what member functions the class provides, how to call them and

what return types to expect

3. The users do not know how the class member functions are implemented.

(c ) Any function prototypes, and type definitions that can be exported from a source code file are put ina header file. From the point of view of the main application, these functions are external.

[3 marks]

The compiler reads the included header file and knows where a particular function comes from.

Yes, we can create our own header files.

Steps to create our own header file :

1. Open notepad and write the function that needs to be used in our program. An example is shown

 below.

int sum(int a,int b)

{

return(a+b);

}2. Save the notepad file with .h extension. We are creating a function for sum, so we will save this

file with name sum.h in INCLUDE or BIN folder.

3. Next, we write a program that uses this sum function and include the header file that we created.

# include <iostream.h>

# include <conio.h>

# include<sum.h> //header file created that we created

int main( )

{

int a,b,s;

clrscr( );

cout<<“Enter the value of a and b:”<<endl;cin>>a>>b;

s = sum(a,b);

cout << ‘‘sum=’’ << S;

getch( );

return 0;

}

(d) # include<iostream.h>   [4 marks]

# include<conio.h>

// check given character is alphabets, digit or any other character 

int main( )

{char a;

cout <<“Enter a character : \n”;

cin >> a;

if (((a >= ‘A’) && (a<=’Z’)) || ((a >=’a’) && (a <= ‘z’)))

cout << “You entered an Alphabet\n”;

else if (a >= ‘0’ && a <=’9')

cout << “You entered a digit\n”;

else

Page 15: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 15/35

14 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

cout << “You entered non alpha numeric character\n”;

getch( );

return 0;

}

7.   (a) These are valid code the compiler understands, but they do not do what the programmer, intended.

[1 mark]

(b) Access specifiers defines the access rights for the statements or functions that follows it until another access specifier or till the end of a class. The three types of access specifiers are “private”, “public”,

“protected”.   [2 marks]

  The members declared as “private” can be accessed only within the same class and not from

outside the class.

  The members declared as “public” are accessible within the class as well as from outside the

class.

  The members declared as “protected” cannot be accessed from outside the class, but can be

accessed from a derived class. This is used when inheritaance is applied to the members of a

class.

(c)     Predefined functions are functions that are built into C++ Language to perform some standard

operations.   [2 marks]   The functions that are stand alone used for general purposes and that are not depended on any

classes are stored in the Standard Function Library.

  Predefined functions in the Standard Function Library are listed based on different categories.

(d) (i) An integer array of 50 elements   [3 marks]

An Array, for eg A contains 50 integer elements from A[0] to A[49]

0 1 2 3 4 49

(ii) A string variable that can hold 20 characters.

The individual characters that make up the string are stored in the elements of the array. The

string is terminated by a null character.

For e.g., string apple :

a p p 1 e 0 19

(iii) A 2 dimensional array to store 3x4 matrix

Second Superscript

 E.g ., Mat[2][3]

Second Superscript

  First Superscipt

Mat[0][0] Mat[0][1] Mat[1][2] Mat[0][3]

Mat[1][0] Mat[1][1] Mat[1][2] Mat[2][2]

Mat[2][0] Mat[2][1] Mat[2][2] Mat[2][3]

(e) /* Input 10 numbers in an array and find the sum of the elements*/   [4 marks]

# include <iostream.h>

# include <conio.h>

# define clrscr( );

int main( ){

int sum,counter;

int A[10];

cout<< “Enter 10 numbers \n”;

Page 16: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 16/35

Solutions | 15

sum = 0;

counter = 0;

while (counter < 10){

cin >> A[counter];

sum = sum + A[counter];

counter = counter + 1;

}

cout<< “sum of array elements is “ << sum;

getch ( );

return 0;

}

Output :

Enter 10 numbers

  1 2 3 4 5 6 7 8 9 10

Sum of array elements is 55

 l

Page 17: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 17/35

Sample Question Paper–8

1.   (a) A driver is a software or a firmware that control hardware. Often it connects an operating systemwith specific hardware devices. For example, there are drivers for every card and disk in your 

computer.   [1 mark](b) Firmware makes a part of the computer run. Software is something that makes the part to do something.

Example: firmware makes the CD drive work, but the software makes it burn.   [1 mark]

(c ) Data is the name given to basic facts and entities such as names and numbers.   [1 mark]

(d) Multiprogramming: More than one task/program/job/process can reside into the main memory at one point of time. This ability of the OS is called multiprogramming.   [2 marks]

Multitasking : More than one task/program/job/process can reside into the same CPU at one point of time. This ability of the OS is called multitasking.

2.   (a) MAR – Memory Address Register    [1 mark]

(b) Computers use a fixed number of bits to represent an integer. The commonly-used bit-lengths for integers are 8-bit, 16-bit, 32-bit or 64-bit. Besides bit-lengths, there are two representation schemesfor integers: Unsigned Integers and Signed Integers.   [1 mark]

(c ) The octal numeral system, is the base-8 number system, and uses the digits 0 to 7. Octal numerals can be made from binary numerals by grouping consecutive binary digits into groups of three. For example,the binary representation for decimal 74 is 1001010, which can be grouped into (00)1 001 010 – sothe octal representation is 112.   [1 + 1 = 2 marks]

In the octal system each place is a power of eight. For example :112

8  = 1 × 82 + 1 × 81  + 2 × 80

(d) 0.275 × 8 = 2.2 = 2  + 0.2   [ 2 marks]

0.2 × 8 = 1.6 = 1  + 0.6

0.6 × 8 = 4.8 = 4  + 0.8

0.8 × 8 = 6.4 = 6  + 0.4

Hence, (0.275)10

  = (0.2146)8

3.   (a) .cpp is the file extention for a C++ program.   [1 mark]

(b) Inheritance—is the inclusion of behaviour (i.e. methods) and state (i.e. variables) of a base class in aderived class so that they are accessible in that derived class. The key benefit of Inheritance is that it

 provides the formal mechanism for code reuse.   [2 marks]

Encapsulation—refers to keeping all the related members (variables and methods) together in anobject. Specifying members as private can hide the variables and methods. Objects should hide their 

inner workings from the outside view.

(c) Start

Decision 1

Decision 2

Sequence

True

False

Stop

False

[2 marks]

Page 18: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 18/35

Solutions | 17

( d) Difference between cin and gets( ) [2 marks]

cin gets( )

1. It can be used to take input of a value of any

data type.

2. It takes the white space i.e., a blank, a tab,

or a new line character as a string terminator.

3. It requires header file iostream.h

(e) Difference between Array and Structure [4 marks]

Array Structure

1. Array elements are homogeneous.

2. Array allocates static memory and uses index

/ subscript for accessing elements of the

array.

3. Array is a pointer to the first element of it.

4. Arr ay element access takes less time in

comparison with structures.

 E.g.,int A[20];

char name[80];

float mat[5][5];

4.   (a) Bitwise operators are AND, OR, XOR and NOT used to manipulate data at the bit level by shifting or 

testing bits.   [2 marks]The following is the list of bitwise operators in C++.

~ Bitwise NOT

&& Bitwise AND

|| Bitwise OR  ^ XOR  

<< Bitwise Shift Left

>> Bitwise Shift Right

(b) The process in which one pre-defined type of expression is converted into another type is called type

conversion. There are two types of conversion in C++.   [2 marks]

1. Implicit conversion

2. Explicit conversion

Implicit conversion

Data type can be mixed in the expression. For example

double a;

int b = 5;

float c = 8.5;a = b * c;

Explicit conversion

totalPay = static_cast<double>(salary) + bonus;

(c) # include directive   [4 marks]

Global Declarations

return-type main( )

{

Statements

}

1. It can be used to take input of a string.

2. It does not take the white space i.e., a blank,

a tab, or a new line character, as a string

terminator.3. It requires the header file stdio.h

1. Structure elements are of different data type.

2. Structures allocate dynamic memory and

uses (.) operator for accessing the member 

of a structure.

3. Structure is not a pointer.

4. Structures take more time to be accessed.

struct STUDENT{

int rollno, age;

char name[80];

float marks;

} ;

Page 19: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 19/35

18 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

Example :

# include <iostream.h>

int main( ){

cout << “Hello World!”;return 0;

}

(d) (i) If input is 2000 : output is 400   [3 marks](ii) If input is 1000 : output is 400(iii) If input is 500 : output is 200

(e) /* Program to calculate volume, surface area and space diagonal of a cuboid */   [3 marks]

# include <iostream.h># include <conio.h># include <math.h>

# define clrscr( );int main ( ){clrscr ( );

float width, length, height;float surfacearea, volume, space_diagonal;

cout<< “Enter value of width, length & height of the cuboid:\n”;cin >> width>> length >> height;

surfacearea = 2 *(width * length + length * height + height * width);volume = width * length * height;space_diagonal = sqrt(width * width + length * length + height * height);cout << “Surface area of cuboid is: “<< surfacearea ;

cout << “\n Volume of cuboid is : “ << volume;cout << “\n Space diagonal of cuboid is : “ << space_diagonal;

getch ( );

return 0;}Output :

Enter value of width, length & height of the cuboid:5 3 6Surface area of cuboid is : 126Volume of cuboid is : 90Space diagonal of cuboid is : 8.3666

5.   (a) The final value of x is 10.   [1 mark]

(b) /* Program to input age and print if minor or adult */   [2 marks]

# include <iostream.h># include <conio.h>

# define clrscr( );int main ( ){

clrscr( );

int age;cout<<“\n Enter your age:”;cin >> age;if (age>=18)

cout<<“\n You are an adult!”;elsecout <<“\n You are a Minor!”;getch( );

return 0;}

Page 20: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 20/35

Solutions | 19

Output 1 :

Enter your age : 34

You are an adult!

Output 2 :

Enter your age : 3

You are a Minor!

(c) # include <iostream.h>   [½ × 4 = 2 marks]

# include <conio.h>int main( )

{

int R, W = 90; // ; was used instead of ,

while (W>60) //  ( ) missing

{

R = W-50;

switch(W)

{

case20:cout<<”lower range”<<endl;  // keyword case missing

case  30:cout<<”middle range”<<endl; // endI instead of endl was used.

case  40:cout<<”higher range”<<endl;

}}

getch ( );

return 0;

}

(d) cin object :   [3 marks]

cin can be used to input a value entered by the user from the keyboard. However, the extraction

operator >> is also required to get the typed value from cin and store it in the memory location.

Let us consider the following program segment:

int marks;

cin >> marks;

cout object:

cout is used to print message on screen in conjunction with the insertion operator <<cout << “Hello World”;

(e) Algorithm : Find the largest of two numbers   [4 marks]

Step 1. input numbers A, B

Step 2. Check if (A>B)

Step 3. If true print A is greater than B

Step 4. Else If (B>A)

Step 5. Print B is greater than A

Step 6. Print A and B are equal.

Step 7. [End of Algorithm]

Page 21: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 21/35

20 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

Stop

Flowchart :

Start

Input A, B

 A > B B > AF F

Print A is greater than B

Print A is greater than B

Print A and Bare equal

Start

TT

6.   (a) The execution of a program can be stopped at any point with exit ( ) and a status code can be

informed to the calling program.   [1 mark]

(b) Syntax: int isalpha(int character);   [2 marks]

Based on the ASCII value of the character it will determine if it is an alphabetical character or not.

Example :

//Program accepts a user input, and checks to see if it is an alphabet or not

# include <cctype.h>

# include <iostream.h>

int main( )

{

clrscr ( );

char d;

cout<<“Enter a character, number, or punction sign: “;

cin>>d;

if (isalpha(d))

{

cout<<“You entered an alphabetical character.”;

}

return 0;

}

(c ) The following is a list of functions found within the <math.h> header file :   [3 marks]

(i) Absolute Value Functions(ii) Nearest Integer, Absolute Value, and Remainder Functions

(iii) Exponential and Logarithmic Functions

(iv) Power Functions

(v) Trigonometric Functions

(vi) Hyperbolic Functions

(d) (i) (X + 3)1/3   pow( (X + 3), (1/3))   [2 marks]

(ii) 2(P/q)2  / (r–3)   2* pow((P/q),2)/(r–3)

(iii) Z = tan x   Z = tan (x)

Page 22: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 22/35

Solutions | 21

(iv) W = log (v)    W = log(v)

(v) y = abex  sin x   y = a*pow(b,(e*x))*sin(x)

(vi) y =   (sin (x) – cos (x))   y = sqrt ((sin(x)–cos(x))

(vii) log (a + b) – log (ab)    log (a + b) – log (a*b)

(viii) w = x+y    w = x+y

7.   (a) <cctype.h> is the header file that includes all character functions.   [1 mark]

(b) The storage class of a variable determines which parts of a program can access it and how long it

stays in existence. The storage class can be classified as   [2 marks]   Automatic

  Register 

  Static

  External

(c) Output for the given code is :   [2 marks]

c

ca

cal

cali

calif 

califo

califor californ

californi

california

(d) /* Program to read and print a 3x4matrix */   [3 marks]

# include <iostream.h>

# include <string.h>

# include <conio.h>

# include <iomanip>

/*using namespace std;

using std::setw;*/

int main( )

{ // an array with 3 rows and 4 columns.

int i =3, j=4;

int A[i][j];

clrscr();

// output each array element’s value

for ( int i = 0; i < 3; i++ )

{

cout <<“Enter the row elements”<< endl;

for ( int j = 0; j < 4; j++ )

{

cin>> A[i][j];

}

}

cout <<”Matrix”<<endl;

for ( int i = 0; i < 3; i++ )

{

for ( int j = 0; j < 4; j++ )

cout<<setw(4)<<A[i][j];

cout<<endl;

}

getch ( );

Page 23: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 23/35

22 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

return 0;

}

Output :

Enter the row elements

2

2

2

2Enter the row elements

1

2

3

4

Enter the row elements

24

6

8

Matrix :

2 2 2 2

1 2 3 4

2 4 6 8

(e) (i) int P[4] = {1,4,7,10};   [4 marks]

(ii) int Q[5] = {3,9,2,1,5};

(iii) float X[7] = {3,2,4,7,3,6,1.5}

(iv) char N[7] = {‘S’,’a’,’n’,’j’,’a’,’y’,’\0’}

 l

Page 24: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 24/35

Solutions | 23

Sample Question Paper–9

1.   (a) Random–access memory (RAM) is a form of computer data storage.   [1 mark]

(b) An optical disc drive (ODD) is a disk drive that uses laser light or electromagnetic waves within or near the visible light spectrum as part of the process of reading or writing data to or from optical

discs. Some drives can only read from discs, but recent drives are commonly both readers and

recorders, also called burners or writers.   [1 mark]

(c ) In 1642 a Frenchman called Blaise Pascal invented the first mechanical calculator.   [1 mark]

It was first called the Arithmetic Machine, then Pascal’s Calculator and later Pascaline.

(d) Graphics software or image editing software is a program or collection of programs that enable a

 person to manipulate visual images on a computer. Currently Adobe Photoshop is one of the most

used and best-known graphics programs.   [2 marks]

2.   (a) TR – Temporary Register    [1 mark]

(b) 1 0 . 1 0 0 0   [1 mark]

  0 × 2 – 4 = 0

  0 × 2 – 3 = 0

  0 × 2 – 2 = 0

  1 × 2 – 1 = 0.5

  0 × 20 = 0

  1 × 21 = 2

Ans.   = 2.5

(c ) Using the following subtraction rules :   [2 marks]

0 – 0 = 01 – 0 = 1

1 – 1 = 0

10 – 1 = 1

11010.100 26.500

 – 10110.011 – 22.375

00100.001 4.125

(100.001)2  = (4.125)

10

(d) (i) (327)8

  (ii) (135)8

  [2 marks]

(i)   (327)8

  = 3 × 82 + 3 × 81 + 7 × 80

= (223)10

(ii)   (135)8

  = 1 × 82 + 3 × 81  + 5 × 80

= (93)10

3.   (a) The conditional operator (?) evaluates an expression, returning one value if that expression evaluates

to true, and a different one if the expression evaluates as false. Its syntax is :   [1 mark]

condition ? result1 : result 2

Page 25: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 25/35

24 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

(b)   [2 marks]

  Compilation process in C++

Source Code

Preprocessor 

Compiler 

 Assembly Code

 Assembler 

Object CodeLibraries

Link Editor 

Executable Code

(c ) The “if..else if” statement is an extension of the “if…else” conditional branching statement. When the

expression in the “if” condition is “false” another “if else” construct is used to execute a set of 

statements based on an expression. This belongs to Control Structures.   [2 marks]Syntax :

if (expression)

{ Statements }

else if(expression)

{ Statements }

else if (expression)

{ Statements }

(d) Message Passing is sending and receiving of information by the objects same as people exchange

information. This helps in building systems that simulate real life. Following are the basic steps in

message passing .   [2 marks]

  Creating classes that define objects and its behavior.

  Creating objects from class definitions

  Establishing communication among objects.

In OOPs, Message Passing involves specifying the name of objects, the name of the function, and the

information to be sent.

(e) Object—Oriented Programming groups related data and functions together in a class, generally making

data private and only some functions public. Restricting access decreases coupling and increases

cohesion. OOP’s is often said to incorporate three techniques: inheritance, encapsulation, and

 polymorphism.   [4 marks]

Encapsulation

Encapsulation is grouping data and functions together and keeping their implementation details private.

Greatly restricting access to functions and data reduces coupling, which increases the ability to create

large programs.

Inheritance

Inheritance means that a new class can be defined in terms of an existing class. There are three

common terminologies for the new class: the derived class, the child class, or the subclass. The

original class is the base class, the parent class, or the superclass. The new child class inherits all

capabilities of the parent class and adds its own fields and methods.

Page 26: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 26/35

Solutions | 25

Polymorphism

Polymorphism is the ability of different functions to be invoked with the same name. There are two

forms.

Static polymorphism is the common case of overriding a function by providing additional definitions

with different numbers or types of parameters.

Dynamic polymorphism is much different and relies on parent classes to define virtual functionswhich child classes may redefine. When this virtual member function is called for an object of the

 parent class, the execution dynamically chooses the appropriate function to call— the parent function

if the object really is the parent type, or the child function if the object really is the child type.

4.   (a) Alternate data type names are defined using the keyword “typedef” for the existing datatypes. This is

used to make the code more portable, as the data type can be changed using a single “typedef”

statement.   [2 marks]

Syntax :

typedef type newname;

(b) Characters which cannot be typed directly from keyboard, e.g., backspace, tab,   [2 marks]

carriage return etc are non-graphical characters. These characters can be represented by using a

escape sequence. The following table gives a listing of common escape sequences.

 Newline \ n

Horizontal tab \ t

 Null character \ 0

Non - graphical EscapeSequence

(c ) A preprocessor directive is an instruction to the complier itself. A part of compiler called preprocessor 

deals with these directives, before real compilation process. # is used as preprocessor directive in

C++.   [3 marks]

# define is a preprocessor directive to define a macro in a C++ program. Macros provide a mechanism

for token replacement with or without a set of formal, function line parameters. For example :

# define PIE 3.1416

# define AVG(A,B,C) (A+B+C)/3

(d)   [3 marks]

(e) (i) DATE-REC – Invalid variable name. Hypen (–) cannot be used.

(ii) DATE_7_77– Valid variable name.

(iii) A2BOZ9 – Valid variable name.

(iv) _ant – Valid variable name.

(v) PROG13 – Valid variable name.

Page 27: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 27/35

26 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

(vi) net_amt – Valid variable name.

(vii) 29_ab – Invalid variable name. Variable name cannot start with a number.

(viii) break – Invalid variable name. Variable name cannot use a reserved keyword.

5.   (a) The loop executes 5 times.   [1 mark]

(b) # include <iostream.h>   [2 marks]

int main( )

{

int X,Y;

cin >> X;

for (Y=0;Y<10;Y++) // lower case f for for  

If (X==Y)   // missing ( )

cout << Y+X;

else

cout << Y; // cout uses << and not >>

return 0;

}

(c ) It is a member function of class with the following unique features :   [3 marks]

  It has same name as the name of the class they belong to.

  It has no return type.

  It is defined in public visibility mode.

  It is automatically called & executed when an object is declared/created.

  Constructors can be overloaded.

(d) Single level inheritance, multilevel inheritance, hierarchical inheritance, multiple inheritance and hybrid

inheritance. [2 marks]

(e) Find the smallest of three numbers [4 marks]

Algorithm Flow Chart

Step 1 : input number A, B, C

Step 2 : small = A

Step 3 : Check if (B < small)

Step 4 : If true small = B

Step 5 : If (C < small)

Step 6 : If true small = C

Step 7 : print small

Step 8 : [End of Algorithm]

Stop

Start

Input A, B, C

Small = A

B < Small

C < Small

Small = BT

Print Small

Stop

Small = C

T

F

F

Page 28: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 28/35

Solutions | 27

6.   (a) A class with no instances (no objects) is known as abstract class.   [1 mark](b) Brackets [ ] Opening and closing brackets indicate single and multidimensional array subscript.

Parentheses ( ) Opening and closing brackets indicate functions calls, function parameters for 

grouping expressions etc.

Braces { } Opening and closing braces indicate the start and end of a compound statement.

Semicolon ; It is used as a statement terminator.   [2 marks]

(c)   Function Meaning

isdigit(c) It returns True if c is a digit (0 through 9) otherwise False.

isalnum(c) It returns True if c is a digit from 0 through 9 or an alphabetic character 

(either uppercase or lowercase) otherwise False.

islower(c) It returns True if C is a lowercase letter otherwise False.

isupper(c) It returns True if C is an uppercase letter otherwise False.

toupper(c) It converts c to uppercase letter.

tolower(c) It converts c to lowercase letter.

[3 marks]

(d) (i) Y = toascii(X);   [4 marks]

(ii) Name1 = Name;(iii) W = abs(U-V);

(iv) y = sin (x);

(v) atof(name);

(vi) toupper(Ch);

(vii) Y = strlen (X);

(viii) s3 = strcat(s2,s1);

7.   (a) getch( ), putch( ).   [1 mark](b) void swap(int *px, int *py) /* interchange *px and *py */   [2 marks]

{

int temp;

temp = *px;

*px = *py;*py = temp;

}

(c) 1 1

3 4

6 10

10 20

15 35

21 56

28 84

36 20

45 165

55 22066 286

(d) Insertion is adding a particular value either to the beginning, end or middle of the array.   [3 marks]

Algorithm to insert a key at a[index]. (we need to shift other values up as necessary)

Step 1 : Initialize the variables :

a – array of values.

n – number of values in a, a[0]..a[n-1]

maxsize – maximum number of elements that can fit in a

index – position to insert at

key – value to insert.

Page 29: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 29/35

28 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

Step 2 : Check array size. If n < maxsize goto Step 3 else Step 6.

Step 3 : Move all elements up one position. i is destination.

for (int i=n; i>index; i—) {

  a[i] = a[i-1];

  }

Step 4 : a[index] = key; // put value in vacated position

Step 5 : n++; // update count of items in a

Step 6 : End of algorithm.Stop

(e) /* sum of each row and column of a 2d array */   [4 marks]

# include <iostream.h>

# include <conio.h>

# define clrscr( );

int main( )

{

clrscr ( );

int i,j,n,a[5][5],b,c,x=0;

cout << “enter the number of rows and columns”<< endl;

cin>>n; /*Reading Elements*/

for (i = 0;i<n;i++){

for (j = 0;j<n;j++)

cin >> a[i][j];

}

for (i = 0;i<n;i++)/*Sum Of Rows And Columns*/

{

 b = 0; c = 0;

for (j = 0;j<n;j++)

{

 b = b+a[i][j];

c = c+a[j][i];

}

++x;

cout << “ sum of row “ << i+1 <<“ is “<< b<< endl;

cout << “ sum of column “ << i+1 <<“ is “<< c<< endl;

}

getch ( );

return 0;

}

Output :

enter the number of rows and columns

3

1 2 31 2 3

1 2 3

sum of row 1 is 6

sum of column 1 is 3

sum of row 2 is 6

sum of column 2 is 6

sum of row 3 is 6

sum of column 3 is 9

 l

Page 30: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 30/35

Solutions | 29

Sample Question Paper–10

1.   (a) Program is a sequence of instructions that a computer can interpret and execute.   [1 mark]

(b) Linux, Ubuntu, Windows - XP, Windows Vista are popular operating systems.   [1 mark](c) RAID—Redundant Array of Inexpensive Disks   [1 mark]

(d) Units of Computer Memory Measurements :   [2 marks]

1 Bit = Binary Digit

8 Bits = 1 Byte

1024 Bytes = 1 KB (Kilo Byte)

1024 KB = 1 MB (Mega Byte)

1024 MB = 1 GB (Giga Byte)

1024 GB = 1 TB (Terra Byte)

1024 TB = 1 PB (Peta Byte)

1024 PB = 1 EB (Exa Byte)

1024 EB = 1 ZB (Zetta Byte)

2.   (a) The decimal number system, is a positional numeral system employing 10 as the base and requiring 10

different numerals, the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.   [1 mark]

(b) The American Standard Code for Information Interchange (ASCII) is a character-encoding scheme

originally based on the English alphabet that encodes 128 specified characters into 7-bit binary integers.

[1 mark]

(c) (i) (9AC3)16

 = 9 * 163 + 10 * 162  + 12* 161 + 3 * 160 [1 mark]

= 36864 + 2560 + 192 + 3

= (39619)10

(ii) (FA8)16

  = 15 * 162 + 10 * 161 + 8 * 160 [1 mark]

= 3840 + 160 + 8

= (4008)10

(d) (i) AB + ¬ AC + BC = AB + ¬ AC   [1 mark]AB + ¬ AC + BC = AB + ¬ AC + (A + ¬ A)BC

= AB + ¬ AC + ABC + ¬ ABC

= (AB + ABC) + (¬ AC + ¬ACB)

= AB + ¬ AC

(ii) ¬ A.B.C + A. ¬ B.C + A.B. ¬ C + A.B.C   [1 mark]

= AB + BC + CA

= ¬ A.B.C + A. ¬B.C + A.B. ¬ C + A.B.C

= ¬ A.B.C + A. ¬ B.C + A.B. ¬ C + A.B.C + A.B.C + A.B.C

= (¬ A.B.C + A.B.C) + (A. ¬ B.C + A.B.C) + (A.B. ¬ C + A.B.C)

= (¬ A + A).B.C + (¬ B + B). C.A + (¬ C + C). A.B

= B.C + C.A + A.B

= AB + BC + CA3.   (a) A programming paradigm is a fundamental style of computer programming, a way of building thestructure and elements of computer programs.   [1 mark]

(b)   Compiler —It is a program which converts the program written in a programming language to a program in machine language.   [2 marks]

Linker —It is a program which links a complied program to the necessary library routines, to makeit an executable program.

(c) Type casting refers to the data type conversions specified by the programmer, as opposed to theautomatic type conversions. This can be done when the compiler does not do the conversionsautomatically. Type casting can be done to higher or lower data type.   [2 marks]

For example : cout<<(float)18/5; //displays 3.6, since 18 is converted to float type.

Page 31: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 31/35

30 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

(d) The conditional operator for given problem can be written as [2 marks]

  y = ((x < = 2) ? (2.4 * x + 3) : (3 * x + 5)).

(e) (i) Syntactic error and semantic error   [2 marks]

Syntactic error Semantic error

Syntactic errors also known as compilation

errors are caused by violation of the grammar 

rules of the language. The compiler detects,isolate these errors and terminate the source

 program after listing the errors.

 E.g.  missing or misplaced ; or }

(ii) Run time error and logical error

Run time error Logical error

Errors such as mismatch of data types or array

out of bound error are known as runtime errors.

These errors are generally go undetected by

the compiler so programs with run-time error 

will run but produce erroneous results.

4.   (a) (i) 700 – 300 > 500 – false, hence C = 50   [2 marks]

(ii) 800 – 700 >500 – false, hence C = 50

(b) Whenever a C++ program is executed, execution of the program starts and ends at main ( ). The main

is the driver function of the program. If it is not present in a program, no execution can take place.

[2 marks]

(c ) ‘return’ statement in a function is used to return a value to the calling program. The return statement

takes one of the following forms :   [3 marks]

return; It does not return any value and act as a closing brace of the function.

or 

return (expression); It returns the value of the expression to the called function. A function can have

more than one return statement. This happens when the value returned is based on certain conditions.

For example :

if (x<=y)

return x;

else

return y;

All functions by default return int type data.(d) (i) int code = three;   [1 mark]

Cannot assign value as three. It should be 3.

int code = 3;

(ii) const int size;   [1 mark]

size is a reserved word, cannot use as variable name.(iii) size = 10   [1 mark]

size is a reserved word, cannot use as variable name and semicolon missing.

(e) Every algorithm should have the following five capabilities and qualities :   [4 marks]

1. Input : The algorithm should take zero or more input.

2. Output : The algorithm should produce one or more outputs.

3. Definiteness : Each and every step of algorithm should be defined unambiguously.

4. Effectiveness : A human should be able to calculate the values involved in the procedure of the

algorithm using paper and pencil.

5. Termination : An algorithm must terminate after a finite number of steps.

Semantic errors are logical errors. If there is a

semantic error in a program, it will run

successfully, in the sense that the computer will not generate any error messages, but it

will not do the right thing.

These are the errors related with the logic of 

the program execution. These errors are not

detected by the compiler and are primarily due

to a poor understanding of the problem or a

lack of clarity of hierarchy of operators. Such

errors cause incorrect result.

Page 32: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 32/35

Solutions | 31

5.   (a) A flowchart is a graphical representation of decisions and the results of those decisions mapped out in

individual shapes.   [1 mark]

(b) switch(ch)   [2 marks]

{

case ‘E’: eastern++;

case ‘W’: western++;

case ‘N’: northern++;

case ‘S’: southern++;default: unknown;

}

(c)   Output : [3 marks]

res 1332755 (The number is reversed)

(d)   Output :   (2 + 1) [3 marks]

count = 5

count = 4count = 3

count = 2

count = 1

Value of count is initially 5, it is printed and then count is decremented by 1.

Since count!= 0 so function f1 is called again, 4 is printed and same process is repeated tillcount = 0 so the above output.

(e) Four stages involved in program design are : ( 2 marks for each question) [4 marks]

  Understanding the problem and algorithm designed for the problem.   Decide what is to be given as input and corresponding output.

  Choose an appropriate programming language and data structures.

  Derive test cases and test exhaustively each and every module of the program.

Design is an important phase in software engineering. Two critical resources used in development

 process are execution time and memory. The efficiency of a program is measured in terms of these

two resources. Inefficiencies in software design can result in complexity that is costly in software

maintenance. Program efficiency can be improved with good program design and error free coding.

6.   (a) Console input/output header    [1 mark]

(b) (i) cos ( ) – <cmath.h>   [2 marks](ii) setw( ) – <iomanip.h>

(iii) toupper ( ) – <cctype.h>

(iv) strcpy ( ) – <string.h>

(c ) There are two ways to declare structures. One is to follow the structure definition with a list of one

or more variable names, as is done here :   [3 marks]

struct coord {

int x;

int y;

} first, second;

These statements define the structure type coord and declare two structures, first and second, of type

coord. first and second are each instances of type coord; first contains two integer members named

x and y, and so does second. This method of declaring structures combines the declaration with the

definition.

The second method is to declare structure variables at a different location in your source code from

the definition. The following statements also declare two instances of type coord:

struct coord {

int x;

int y;

};

struct coord first, second;

Page 33: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 33/35

32 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

Structure members can be initialized using a dot operator as follows:

first.x = 10;

first.y = 20;

(d) /* Program to check if string is palindrome */   [4 marls]

# include<iostream.h>

# include<conio.h>

# include<stdio.h>

int main( )

{

clrscr( );

char str[80];

cout<<“Enter a string:”;

gets(str);

int L, C;

for (L=0;str[L]!=’\0';L++); //To find length of the string

for (C=0;(C<L/2) && (str[C]==str[L-C-1]);C++);

if (C==L/2)

cout<<“Palindrome”;

else

cout<<“Not a palindrome”;

getch( );

return 0;

}

Output 1 :

Enter a string: anna

Palindrome

Output 2 :

Enter a string: mark 

 Not a palindrome

7.   (a) arrow ()   [1 mark]

(b) (i) int sum[10] – Declaration for an integer array of size 10.   [1 mark]

(ii) m[1] =10 – Assigns the value 10 to the second position of the array m.   [1 mark]

(c) include <iostream.h>   [2 marks]

int main( )

{

int x[5], *Y, Z[5];

for(i=0; i<5; i++)  // i is not declared

{

x[i] = i;

Z[i] = i +3;

Y = Z;x = Y;  // incompatible types in assignment of int* to int[5]

}

return 0;

}

(d)     Missing semicolon: Every C statement must end with a semicolon. A missing semicolon is confu-

sion to the compiler and may result in misleading error messages.

  Missing braces: Very common error as it is common to forget a closing brace. Number of opening

 braces should match number of closing braces.

  Undeclared variables: C requires declaration of variables before their use.

Page 34: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 34/35

Solutions | 33

  Forgetting the precedence of operators: Expression are evaluated according to precedence of 

operators.

  Mismatch of parameters in function calls: There may be mismatch in actual and formal parameters

in function calls.

  Unending and sometimes wrong loops.

(½ mark for each point) [3 marks]

(e) /* Program to add arrays A and B */   [4 marks]

# include <iostream.h># include <string.h>

# include <conio.h>

# include <iomanip>

/* # define clrscr( );

using namespace std;

using std::setw;*/

int main( )

{

int I =3, J=4;

int A[I][J], B[I][J], C[I][J];

clrscr( );

cout <<“Enter the elements of first array”<< endl;for ( int i = 0; i < I; i++ )

{

for ( int j = 0; j < J; j++ )

{

cin>> A[i][j];

}

}

cout <<“Enter the row elements of second array”<< endl;

for ( int i = 0; i < I; i++ )

{

for ( int j = 0; j < J; j++ )

{ cin>> B[i][j];

}

}

for ( int i = 0; i < I; i++ )

{

for ( int j = 0; j < J; j++ )

{

C[i][j]=A[i][j]+B[i][j];

}

}

cout << “Sum of array A and B:” <<endl;

for ( int i = 0; i < 3; i++ )

{

for ( int j = 0; j < 4; j++ )

cout<<setw(8)<<C[i][j];

cout<<endl;

}

getch ( );

return 0;

}

Page 35: c1410591899wComputer (C Plus Plus) XI Solutions 6-10

8/21/2019 c1410591899wComputer (C Plus Plus) XI Solutions 6-10

http://slidepdf.com/reader/full/c1410591899wcomputer-c-plus-plus-xi-solutions-6-10 35/35

34 | Oswaal CBSE (Sample Question Papers) Computer Science, (C++) Class–  XI 

Output :

Enter the elements of first array

1 1 1 1

2 2 2 2

3 3 3 3

Enter the row elements of second array

4 4 4 45 5 5 5

6 6 6 6

Sum of array A and B :

5 5 5 5

7 7 7 7

9 9 9 9

 ll