32
XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

Embed Size (px)

Citation preview

Page 1: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

XII CBSE Previous Year Question

Paper

QUESTION NO 1 (a)

1 OR 2 Marks

Page 2: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

11. (a) Name the header file to which the

following belong 1(i) abs( )(ii) isupper( ) 2006 Delhi

1. (a) (i) math.h (ii) ctype.h( ½ Marks for each correct Header File)

Page 3: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

21. (a) Name the header file to which the

following belong : 1(i) pow()(ii) random() 2006 OD

1. (a) (i) math.h / complex.h (ii) stdlib.h(1/2 Marks for each correct Header File)

Page 4: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

3

1. (a) Differentiate between a Logical Error and Syntax Error. Also give suitable examples of each in C++.2 2007 Delhi

1. (a) Logical Error:Error occurred due to incorrect logic applied by the programmer.Syntax Error:Error occurred due to not following the proper grammar/syntax of the languageORError occurred due to violating rules of the programming language

Page 5: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

Example://Program to find area and perimeter of rectanglevoid main(){int A,B,AR,P;A=10;B=20;AR=2*(A*B); //Logical Error – Wrong FormulaP=2*(A+B);cout<<A<<P>>endl; //Syntax Error – Use of >> with cout}(½ Mark for each correct explanation of Logical Error and SyntaxError)(½ Mark for each correct example of Logical Error and Syntax Error)OR(Full 2 Marks for correct examples demonstrating the differencebetween Logical Error and Syntax Error)Note: Only 1 Mark to be awarded if Explanation is given withoutsupporting example.

Page 6: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

4

1. (a) Differentiate between a Run Time Error and Syntax Error. Also give suitable examples of each in C++. 2 2007 OD

1. (a) Run Time Error : Error occurring in a program during its execution. Program execution halts when such an error is encountered.Example:int A,B,C;cin>>A>>B;C=A/B;//Runtime error if value of B is zero.Syntax Error: Error occurred due to wrong syntax of language detected by the compiler during compilation.Example:cout>>”A C++ Program”;(½ Mark for each correct explanation of Runtime Error and SyntaxError)

Page 7: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

(½ Mark for each correct example of Runtime Error and Syntax Error)OR(Full 2 Marks for correct examples demonstrating the differencebetween Runtime Error and Syntax Error)OR(Only 1 Mark to be awarded if Explanation with out supportingexamples)

Page 8: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

51. (a) What is the difference between #define and const? Explain with suitable example. 2

2008 D#define: It is a pre-processor directive in C++ for creating a Macro.Example:#define sqr(i) i*iconst: It is an Access Modifier in C++ that assigns a constant (non modifiable) value to a variable. Any attempt in modifying the value assigned to such a variable is reported as an error by the compiler.Example:const float Pi = 3.14;(½ Mark for each correct explanation of #define and const)(½ Mark for each correct example of #define and const)OR(Full 2 Marks for correct examples demonstrating the difference between #define and const)OR(Only 1 Mark to be awarded if Explanation without supporting examples)

Page 9: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

6 (a) What is the purpose of using a typedef command in C++.

Explain with suitable example. 2 2008

ODAns: Typedef:

This keyword allows creating synonyms or aliases for previously defined data types The general form of typedef istypedef old_name new_name;

ORtypedef is used for renaming a data type.Example:typedef char STR [80]; OR typedef signed char SMALLNUM;OR typedef float REAL; OR typedef long int BIGNUM;OR typedef int MAT[2][3] ;(1 Mark for definition of typedef)(1 Mark for example of typedef)OR(Full 2 Marks for an example with an appropriate explanation)

Page 10: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

71. (a) What is the difference between call by value and call by reference? Give an example in C++ to illustrate both. 2

2009 D

Call by value is used to create a temporary copy of the data coming from the actual parameter into the formal parameter. The changes done in the function in formal parameter are not reflected back in the calling environment. It does not use ‘&’ sign.Call by reference is used to share the same memory location for actual and formal parameters and so changes done in the function are reflected back in the calling environment. It uses ‘&’ sign.

Page 11: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

void Compute(int A, int &B){A++;B++;cout<<”In the function”<<endl;cout<<”A=”<<A<<“&”<<“B=”<<B<<endl;}void main (){int I=50,J=25;cout<<”Before function call “<<endl;cout<<”I=”<<I<<”&”<<”J=”<<J <<endl;Compute (I,J) ;cout<<”After function call “<<endl;cout<<I=”<<I<<”&”<<”J=”<<J <<endl;}

Page 12: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

OUTPUTBefore function callI=50&J=25In the functionA=51&B=26After function callI=50&J=26(½ Mark for each correct explanation of Call by Value and Call by Reference)(½ Mark for each correct example of Call by Value and Call by Reference)OR(Full 2 Marks for correct examples demonstrating the difference betweenCall by Value and Call by Reference)OR(Only 1 Mark to be awarded if Explanation without supporting examples)Note: Output is optional

Page 13: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

81. (a) What is the difference between Actual Parameter and Formal Parameter? Give an example in C++ to illustrate both types of parameters. 2

2009 ODA parameter used in the function call is known as Actual Parameter. It is used to send the data to function. A parameter used in the function definition is known as Formal Parameter, It is used to accept the data from actual parameter.void Seventimes(int A)//A is formal parameter{cout<<7*A;}

Page 14: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

void main (){int P=6;Seventimes(P);//p is actual parameter}(½ Mark for each correct explanation of Actual Parameter and Formal Parameter)(½ Mark for each correct example of Actual Parameter and Formal Parameter)OR(Full 2 Marks for correct examples demonstrating the difference between Actual Parameter and Formal Parameter)OR(Only 1 Mark to be awarded for Explanation given without supporting examples)

Page 15: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

91. (a) What is the difference between automatic type conversion and type casting? Also, give a suitable C++ code to illustrate both. 2

2010 D

Automatic Type Conversion: it is an implicit process of conversion of a data from one type to another. For exampleint N = 65;char C = N; // Automatic type conversioncout<<C;OUTPUT:AType Casting: It is an explicit process of conversion of a data from one type to another. For example

Page 16: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

int A=1, B=2;float C = (float)A/B; //Type Castingcout<<C;OUTPUT:0.5(½ Mark for each correct explanation of Automatic Type Conversion and Type Casting)(½ Mark for each correct example of Automatic Type Conversion and Type Casting)OR(Full 2 Marks for correct example(s) demonstrating the meaning of / difference between Automatic Type Conversion and Type Casting)OR(Only 1 Mack to be awarded if Explanation without supporting examples)Note: Output is optional

Page 17: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

101. (a) What is the difference between call by value and call by reference? Give an example in C++ to illustrate both. 2

2010 ODCall by value is used to create a temporary copy of the data coming from the actual parameter into the formal parameter. The changes done in the function in formal parameter are not reflected back in the calling environment. It does not use ‘&’ sign.Call by reference is used to share the same memory location for actual and formal parameters and so changes done in the function are reflected back in the calling environment. It uses ‘&’ sign.

Page 18: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

void Compute(int A, int &B){A++;B++;cout<<”In the function”<<endl;cout<<”A=”<<A<<“&”<<“B=”<<B<<endl;}void main (){int I=50,J=25;cout<<”Before function call “<<endl;cout<<”I=”<<I<<”&”<<”J=”<<J <<endl;Compute (I,J) ;cout<<”After function call “<<endl;cout<<I=”<<I<<”&”<<”J=”<<J <<endl;}

Page 19: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

OUTPUTBefore function callI=50&J=25In the functionA=51&B=26After function callI=50&J=26(½ Mark for each correct explanation of Call by Value and Call by Reference)(½ Mark for each correct example of Call by Value and Call by Reference)OR(Full 2 Marks for correct examples demonstrating the difference betweenCall by Value and Call by Reference)OR(Only 1 Mark to be awarded if Explanation without supporting examples)Note: Output is optional

Page 20: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

111. (a) What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code to illustrate both. 2

2011 D

Local Variables: Local variables are those variables which are declared within a function or a compound statement and these variables can only be used within that function/scope.

Global Variables: Global variables are those variables which are not declared within any function or scope. So, these variables can be accessed by any function of the program

Page 21: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

Example#include<iostream.h>#include<conio.h.>int G; // Global variable declaredvoid Fun ( ){int L = 25; // Local variable of function Fun ( ) assigned value 25G=5; // Global Variable is accessed and assigned value 5Cout<<G<<endl; // Value of global variable is displayed as 5Cout<<L<<endl; // Value of local variable is displayed as 25}void main ( ){Fun ( ) ; // Function callG = G + 5; // Global variable is incremented by 5cout<<G<<endl; // Global variable is displayed as 10}(½ Mark for each correct explanation of Local Variable and Global Variable)(½ Mark for each correct example of Local variable and Global Variable)OR(Full 2 Maries for correct example(s) demonstrating the meaning of / difference between Local Variable and Global Variable) OR(Only 1 Mark to be awarded if Explanation without supporting examples)

Page 22: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

121. (a) What is the difference between automatic type conversion and type casting? Also, give a suitable C++ code to illustrate both. 2

2011 OD

Automatic Type Conversion: it is an implicit process of conversion of a data from one type to another. For exampleint N = 65;char C = N; // Automatic type conversioncout<<C;OUTPUT:AType Casting: It is an explicit process of conversion of a data from one type to another. For example

Page 23: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

int A=1, B=2;float C = (float)A/B; //Type Castingcout<<C;OUTPUT:0.5(½ Mark for each correct explanation of Automatic Type Conversion and Type Casting)(½ Mark for each correct example of Automatic Type Conversion and Type Casting)OR(Full 2 Marks for correct example(s) demonstrating the meaning of / difference between Automatic Type Conversion and Type Casting)OR(Only 1 Mack to be awarded if Explanation without supporting examples)Note: Output is optional

Page 24: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

131. (a) What is the difference between Global Variable and Local Variable?

Sample Paper Set I 2009

Global Variable Local Variable

It is a variable, which is declared outside all the functions

It is accessible throughout the program

It is a variable, which is declared with in a function or with in a compound statementIt is accessible only within a function/compound statement in which it is declared.

Example :#include <iostream.h>float NUM=900; //NUM is a global variablevoid LOCAL(int T){ int Total=0; //Total is a local variable for (int I=0;I<T;I++) Total+=I; cout<<NUM+Total;}void main(){ LOCAL(45);}

Page 25: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

141.(a) What is the difference between Object Oriented Programming and Procedural Programming? 2

Sample Paper Set II 2009

Object Oriented Programming

Procedural Programming

Emphasis on DataFollows Bottom-Up approach in program designData hiding feature prevents accidental change in dataFeatures like data encapsulation, polymorphism, inheritance are present

Emphasis on doing things (functions)Follows Top-down approach in program designPresence of Global variables increase chances of accidental change in dataSuch features are not available

Page 26: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

151. (a) What is the difference between Global Variable and Local Variable? (Sample Paper 2010 (Repeated it was asked in Sample Paper Set 1 2009) )

Global Variable Local Variable

It is a variable, which is declared outside all the functions

It is accessible throughout the program

It is a variable, which is declared with in a function or with in a compound statementIt is accessible only within a function/compound statement in which it is declared.

Example :#include <iostream.h>float NUM=900; //NUM is a global variablevoid LOCAL(int T){ int Total=0; //Total is a local variable for (int I=0;I<T;I++) Total+=I; cout<<NUM+Total;}void main(){ LOCAL(45);}

Page 27: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

16

Sample Paper Set II - 2010 (asked in 2009 OD)Actual Parameter Formal Parameter

It is a parameter, which is used in function call to send the value from the calling environment.

It is the parameter, which is used in function header, to receive the value from the actual parameter.

Example :#include <iostream.h> void Calc ( int T ) // T is formal parameter{ cout<< 5 * T;}void main ( ){int A=45;Calc ( A ); // A is actual parameter}(1 Mark for stating difference)( 1 Mark for the suitable example)OR(Full 2 Marks for explanation of differences with the help of example)( 1 Mark for the example)

1 ( a ) What is the difference between Actual Parameter and Formal Parameters ? Also, give a suitable C++ code to illustrate both. 2

Page 28: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

17

Sample Paper Set I - 2012

Post-increment Pre-increment

++ is an increment operator to increment the value of a variable by one , when used after the operand it is known as post – increment operator.

When it is used before an operand to increment its value by one, it is called pre – increment operator.

Example :#include <iostream.h>void main ( ){int NUM=9;cout<<++NUM ; // 10 will be displayedcout<<NUM++ ; // 10 will be displayedCout<< NUM ; // 11 will be displayed}(1 Mark for stating difference)( 1 Mark for the suitable example)OR(Full 2 Marks for explanation of differences with the help of example)( 1 Mark for the example)

1 (a) Differentiate between the post-increment and pre-increment operators. Also, give suitable C++ code to illustrate both.

Page 29: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

18

Sample Paper Set II - 2010 (asked in 2009 OD and Sample Paper 2010 Set II)

Actual Parameter Formal Parameter

It is a parameter, which is used in function call to send the value from the calling environment.

It is the parameter, which is used in function header, to receive the value from the actual parameter.

Example :#include <iostream.h> void Calc ( int T ) // T is formal parameter{ cout<< 5 * T;}void main ( ){int A=45;Calc ( A ); // A is actual parameter}(1 Mark for stating difference)( 1 Mark for the suitable example)OR(Full 2 Marks for explanation of differences with the help of example)( 1 Mark for the example)

1 ( a ) What is the difference between Actual Parameter and Formal Parameters ? Also, give a suitable C++ code to illustrate both. 2

Page 30: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

191. (a) What is the difference between automatic type conversion and type casting? Also, give a suitable C++ code to illustrate both. 2 2012 OD ( Repeated, asked in the year 2010 Delhi Paper)

Automatic Type Conversion: it is an implicit process of conversion of a data from one type to another. For exampleint N = 65;char C = N; // Automatic type conversioncout<<C;OUTPUT:AType Casting: It is an explicit process of conversion of a data from one type to another. For example

Page 31: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

int A=1, B=2;float C = (float)A/B; //Type Castingcout<<C;OUTPUT:0.5(½ Mark for each correct explanation of Automatic Type Conversion and Type Casting)(½ Mark for each correct example of Automatic Type Conversion and Type Casting)OR(Full 2 Marks for correct example(s) demonstrating the meaning of / difference between Automatic Type Conversion and Type Casting)OR(Only 1 Mack to be awarded if Explanation without supporting examples)Note: Output is optional

Page 32: XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks

THANK YOU