Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks."— Presentation transcript:

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

2 1 1. (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)

3 2 1. (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)

4 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 language OR Error occurred due to violating rules of the programming language

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

6 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 Syntax Error)

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

8 5 1. (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*i const: 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)

9 6 (a) What is the purpose of using a typedef command in C++. Explain with suitable example.2 2008 OD Ans: Typedef: This keyword allows creating synonyms or aliases for previously defined data types The general form of typedef is typedef old_name new_name; OR typedef 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)

10 7 1. (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.

11 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; }

12 OUTPUT Before function call I=50&J=25 In the function A=51&B=26 After function call I=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 between Call by Value and Call by Reference) OR (Only 1 Mark to be awarded if Explanation without supporting examples) Note: Output is optional

13 8 1. (a) What is the difference between Actual Parameter and Formal Parameter? Give an example in C++ to illustrate both types of parameters. 2 2009 OD A 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; }

14 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)

15 9 1. (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 example int N = 65; char C = N; // Automatic type conversion cout<<C; OUTPUT: A Type Casting: It is an explicit process of conversion of a data from one type to another. For example

16 int A=1, B=2; float C = (float)A/B; //Type Casting cout<<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

17 10 1. (a) What is the difference between call by value and call by reference? Give an example in C++ to illustrate both. 2 2010 OD 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.

18 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; }

19 OUTPUT Before function call I=50&J=25 In the function A=51&B=26 After function call I=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 between Call by Value and Call by Reference) OR (Only 1 Mark to be awarded if Explanation without supporting examples) Note: Output is optional

20 11 1. (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

21 Example #include int G; // Global variable declared void Fun ( ) { int L = 25; // Local variable of function Fun ( ) assigned value 25 G=5; // Global Variable is accessed and assigned value 5 Cout<<G<<endl; // Value of global variable is displayed as 5 Cout<<L<<endl; // Value of local variable is displayed as 25 } void main ( ) { Fun ( ) ; // Function call G = G + 5; // Global variable is incremented by 5 cout<<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)

22 12 1. (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 example int N = 65; char C = N; // Automatic type conversion cout<<C; OUTPUT: A Type Casting: It is an explicit process of conversion of a data from one type to another. For example

23 int A=1, B=2; float C = (float)A/B; //Type Casting cout<<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

24 13 1. (a) What is the difference between Global Variable and Local Variable? Sample Paper Set I 2009 Global VariableLocal 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 statement It is accessible only within a function/compound statement in which it is declared. Example : #include float NUM=900; //NUM is a global variable void 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); }

25 14 1. (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 Data Follows Bottom-Up approach in program design Data hiding feature prevents accidental change in data Features like data encapsulation, polymorphism, inheritance are present Emphasis on doing things (functions) Follows Top-down approach in program design Presence of Global variables increase chances of accidental change in data Such features are not available

26 15 1. (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 VariableLocal 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 statement It is accessible only within a function/compound statement in which it is declared. Example : #include float NUM=900; //NUM is a global variable void 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); }

27 16 Sample Paper Set II - 2010 (asked in 2009 OD) Actual ParameterFormal 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 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

28 17 Sample Paper Set I - 2012 Post-incrementPre-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 void main ( ) { int NUM=9; cout<<++NUM ; // 10 will be displayed cout<<NUM++ ; // 10 will be displayed Cout<< 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.

29 18 Sample Paper Set II - 2010 (asked in 2009 OD and Sample Paper 2010 Set II) Actual ParameterFormal 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 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

30 19 1. (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 example int N = 65; char C = N; // Automatic type conversion cout<<C; OUTPUT: A Type Casting: It is an explicit process of conversion of a data from one type to another. For example

31 int A=1, B=2; float C = (float)A/B; //Type Casting cout<<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

32 THANK YOU


Download ppt "XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks."

Similar presentations


Ads by Google