XI COMPUTER SCIENCE Sample Paper 2 with solutions Time: 3 Hrs .Marks:70 1. Define Software and its types. (2) A. Software: Software represents the set of programs that govern the operation of a computer System and make the hardware run. Eg: Dos, MS-Word, C++,Visual Basic,Paint Brush, etc. Software can be classified broadly into two categories: (i)System Software: a)Operating System b) Language Processors (ii) Application Software 2. What are the basic operations of a computer. (2) A. Basic Operations of a Computer: (i) Taking input from the input device and stores it in memory. (ii) Processing according to the programs(instructions) and covert input to the output. This process will be performed in Microprocessor which consists Arithmetic and Logic Unit and Control unit. (iii) Displaying output on any output device. 3. Write two types of Micro Computers? (1) A. Types of Micro Computers: i) PDA ( Personal Digital Assistants). ii) Desktop Computers and Laptop (Notebook) Computers. iii) Workstations. 4. What is a Source Code? (1) A. The program written in a high level language (here in C++) is called as source code. (The program that is converted into the machine language is called as object code). 5. Differentiate between the logical errors and runtime errors with one example each? (2) A. Logical Error: A logical error is that error which causes a program to produce incorrect or undesired output. For instance, if we are trying to print the table of a number 3 and if we say ctr=1; while(ctr>10) { cout<10) is not fulfilled at all. Runtime Error (Execution Error):A run time error is that occurs during the execution of a program. It is caused of some illegal operation taking place or unavailability of desired or required conditions for the execution of the program. Eg: Division by zero, Trying to open a file which does not exist or it could not be opened, If enough memory is not available. 6. Write down the steps to be followed while running a program. (2) A. ( To run a C++ Program, the following steps: 1. Write the program. 2. Compile the program. 3. Run the program. ) Steps to create a working program: (1) Understand the problem well. (2) Analyze the problem to * Identify minimum number of inputs required for output. * Identify processing components. (3) Design the program by * Deciding step by step solution. * Breaking down solution into simple steps. (4) Code the program by * Identifying arithmetic and logical operations required for solutions. * Using appropriate control structures such as conditional or looping control structure. Praise The Lord Any Doubt? Contact:mrkdata@yahoo.com MRK 11 Computer Sample – 2 1(5) Test and Debug your program by * Finding errors in it. * Rectifying the errors. (6) Complete your documentation. (7) Maintain your program. 7. What is the use of comments in a program and its types? (2) A. Use of Comments: Comments play a very important role as they provide internal documentation of a program. With comments, readability and understandability will be increased. (There are two types of comments depending on number of lines: 1. Single line comments. Starts with //2. Multi line comments. Starts with /* and ends with */) Types of comments: 1. Prologues: The comments in the beginning of a program that summarizes the purpose of the program. 2. Explanatory comments: Wherever applicable, after the statement, keep //and write Comment about that statement. 3. Use comments to help identify {…} pairs greatly and enhance program understanding. 8. What are the characteristics of a good program? (2) A. Characteristics of a good program: (i) Effective and efficient. (ii) User friendly. (iii) Self-Documenting code. (iv) Reliable. (v) Portable. 9. An Error in a program is known as _________. (1) A. Bug 10. Draw the symbol used in the flow chart to read the values? (1) A. 11. What is the difference between the ‘a’ and “a”? (1) A. ‘a’ is a character literal so it takes 1 Byte to represent. “a” is a string literal so it takes 2 Bytes to represent. 12. Write any four escape sequence characters? (1) A. (i) \a -Audible bell (ii)\b -Backspace (iii)\n -Newline (iv) \r – Carriage return (v) \t -Horizontal tab (vi) \0 -Null 13. What will be the result of the following two expressions if i=10 initially? 1) ++i<=10 2)i++<=10 (2) A. (i) False (ii) True 14. Explain tokens in details with example. (3) A. Token: The smallest individual unit in a program is known as a token (Lexical Unit). There are 5 types of tokens. (i) Keywords (ii) Identifiers (iii) Literals (iv) Punctuators (v) Operators. (i) Keywords: Keywords are the words that convey a special meaning to the language compiler. These are reserved for special purpose and must not be used as normal identifier names. Original C++ consists 48 keywords and ANSI C++ consists 63 keywords. Eg: int, switch, while, etc. (ii)Identifiers:Identifiers are the names given variables, objects, classes, functions,arrays, etc. Eg: rno, myfile, etc. (iii)Literals (Constants):are data items that never change their value during a program run. Different types of literals… (i) Integer constant (ii) Floating Constant (iii) Character Constant (iv) String Constant. Praise The Lord Any Doubt? Contact:mrkdata@yahoo.com MRK 11 Computer Sample – 2 2(iv)Operators :The operations (specific tasks) are represented by operators and the objects of the operation(s) are referred to as operands. They can be classified into 3 categories depending on number of operands it is working: (a) Unary operators: Works on single operand. Eg: ++ , --, sizeof, etc (b) Binary operators: Works on two operands. Eg: +, -, *, /, %, <, >, etc. (c)Ternary operator: Works on three operands. Eg: Conditional operators. (exp1)?exp2:exp3 (v) Punctuators (Separators): [ , ], ( , ), { , } , ;, :, #, etc. 15. Find errors if any in the following statements. (2) cout<<”X=”;X; cin>>x;>>y; cout<<”Enter a number”; cin>>x; A. Errors in Line 1: (a) ; is given in place of << (b)X is given in place of x cout<<”X=”;X ; //Correct: cout<<”X=”<>x;>>y; //Correct: cin>>x>>y; 16. Define operators and its types? (4) A. Operators :The operations (specific tasks) are represented by operators and the objects of the operation(s) are referred to as operands. They can be classified into 3 categories depending on number of operands it is working: (a) Unary operators: Works on single operand. Eg (i) ++ (Increment operator). Used to increment ‘one’ to the existing value. A=10; A++; After the execution of above statement, A value will becomes as 11. (ii) --(Decrement Operator). Used to decrement ‘one’ to the existing value. (iii) sizeof( ): This is used to return the number of bytes for the given data type or variable. int a; sizeof(a); //returns 2 since a is of type int. (iv) Unary + : It will give the value with same sign. A=10; +A will gives 10 only. A= -10; +A will gives -10. (v) Unary -: It will give the value with opposite sign. A=10; -A will gives – 10. A=-10; -A will gives 10. (vi) !: Not (b) Binary operators: Works on two operands. Eg: Arithmetic Operators: + , -, * , /, % + for addition on two operands. -for subtraction * for multiplication /for quotient % for remainder. Relational Operators: < , <=, >, >=, !=, = =. Logical Operators: &&, | | Etc., (c)Ternary operator: Works on three operands. Eg: Conditional operators. (exp1)?exp2:exp3 Here when the expression 1 becomes true expression 2 will be executed and if it becomes false, then expression 3 will be executed. 17. void main( ) (2) { int val,res,n=1000; cin>>val; Praise The Lord Any Doubt? Contact:mrkdata@yahoo.com MRK 11 Computer Sample – 2 3res=n+val >1750 ?400:200; //Note:Actually instead of >, ? was printed, I corrected it. cout< #include void main( ) {clrscr( ); int first,second,third,i,n; cout<<"\nHow many numbers you want to generate the fibonacci numbers.."; cin>>n; first=0; second=1; cout< #include void main( ) { int A[10][10],B[10][10]; int M,N,i,j; cout<<"\nEnter the number of Rows: "; cin>>M; cout<<"\nEnter the number of Columns: "; cin>>N; cout<<"\nEnter "<>A[i][j]; B[j][i]=A[i][j]; } cout<<"\nThe entered Array..........\n"; for(i=0;i #include #include #include void main() {char str1[10],str2[10]; int l1=0,l2=0,i,flag=0; clrscr( ); cout<<"\nEnter the first string: "; gets(str1); cout<<"\nEnter the second string: "; gets(str2); for(i=0;str1[i]!='\0';i++); l1=i; for(i=0;str2[i]!='\0';i++); l2=i; if(l1!=l2) { cout<<"\nBoth strings are not the same..."; getch( ); exit(0); } for(i=0;str1[i]!='\0';i++) { if(str1[i]!=str2[i]) { flag=1; break; } } if(flag= =0) cout<<"\nEntered strings are identicle..."; else Praise The Lord Any Doubt? Contact:mrkdata@yahoo.com MRK 11 Computer Sample – 2 6cout<<"\nEntered strings are not identicle..."; getch( ); } 23. Write a program to find the factorial of 10 using recursion? (4) A. #include #include long f=1; long factorial(int n) {if (n==0) return f; else f=n*factorial(n-1); }void main( ) { clrscr( ); cout<<"\nThe factorial of the number 10 = "< Praise The Lord Any Doubt? Contact:mrkdata@yahoo.com MRK 11 Computer Sample – 2 7int func(int &x,int y=10) { if (x%y= = 0) return ++x; Else return y--; } void main( ) { int p=20,q=23; q=func(p,q); cout<