Formatting page ...
SMT. SULOCHANADEVI SINGHANIA SCHOOL, THANE Sub. Exam Date Marks Time Total No. of Printed sides 10 Computer Prelim II 08.02.17 100 2 2 Application hours This paper is divided into two sections. Attempt all questions from Section A and any four questions from Section B. The intended marks for questions or parts of questions are given in brackets [ ]. Section A (40 Marks) Attempt all questions. Class Question 1 [10] (a) Why a class is called a factory of objects? (b) What is the purpose of the new operator? (c) Mention any two components required for class declaration. (d) Write a statement in Java to assign the value of pie (i.e. 3.142) to a variable with requisite data type. (e) Explain any two types of access specifiers. Question 2 [10] (a) Write the function prototype for the function isValid ( ) that takes a character as its argument and returns true or false. (b) State any two special properties of the constructor. (c) Differentiate between formal and actual parameter. (d) Define impure function. Give example of an impure library function in Java. (e) State the appropriate keyword for the following. (i) Command which enables the use of a particular package in your program. (ii) The command that refers to the property of the current object, in case identifiers of the class and the function arguments are identical. Question 3 [20] (a) When there are multiple definitions with the same function name, what makes them different from each other? (b) What is mixed expression? Will explicit type conversion be required for mixed expression? (c) Give output of the following statement. System.out.println(" \" "+true+" \" "+" \\ "+" \' "+false+" \' "); (d) Give output of the following statements. do System.out.println("hard work"); while(false); while(true) System.out.println("success"); (e) Give output of the following statements. int i, j, k; for(i=1, j=10, k=7; i<=7 ; i+=2, j--, k*=1) System.out.print( i + "\t" + j + "\t" + k +"\n"); (f) Explain local and global scope of a variable, with example. (g) Differentiate between isUpperCase ( ) and toUpperCase ( ) methods. 1 (h) Following program code contains errors. Rewrite the corrected program code. int x[5]={6, -2, 2, 3, 5, 6}; for (int i=1;i<=6;i=i+1) System.out.println(x[i]); (i) State the ASCII values of letters A to Z and a to z. (j) State the significance of the access modifier static for an attribute of a class. Section B(60 marks) Attempt any four questions from this section The answer in this section should consist of the programs in either BlueJ environment or any other program environment with Java as the base. Each program should be written using Variable description / Mnemonic codes such that the logic of the program is clearly depicted. Flowcharts and Algorithms are not required. Question 4 [15] Write a program using a method palin ( ) to check whether a string is palindrome or not. Illustrate the call of this method in driver method of the class. A palindrome is a string that reads the same from left to right and vice versa. E.g. MADAM, ARORA,ABBA, etc Question 5 [15] Design a class to overload a function num_calc ( ) as follows. (a) void num_calc (int num, char ch) which computes the square of integer argument if choice ch is s otherwise finds its cube. (b) void num_calc (int a, int b, char ch) which computes the product of the integer arguments, if choice ch is p else adds the integers. (c) void num_calc (String s1, String s2) which prints whether the strings are equal or not. Question 6 [15] Write a menu driven program to calculate and print the sum of each of the following series. Value of x is to be input by the user. (a) Sum = 1 -2 + 3 -4 -10 (b) Sum = + + + .. + Question 7 [15] The details of the class Search are as given below: Class name : Search Data members/instance variables: names[ ] : to store names of 10 batsmen countries[ ] : to store the respective countries of 10 batsmen centuries[ ] : to store the respective total number of centuries made by the batsmen 2 Member functions/methods: void accept( ) : to accept the values in names[ ], countries[ ] and centuries[ ]. void search (String c) : Display the cricketer names with their centuries belonging to the country c. If the country is not found, display a message Country Not Found . Write main( ) function to create object and call the functions appropriately. Question 8 [15] Many persons are visiting the election booth. Election commissioner wants to know certain statistics about these persons as follows. (a) Number of literate male voters (b) Number of illiterate male voters (c) Number of literate female voters (d) Number of illiterate female voters Write a program to input gender of a person (variable char g for storing values m or f ) and to input literacy of a person (variable char lit for storing values y or n indicating literacy and illiteracy respectively). Input of values will continue as long as user wishes to, as the number of persons visiting the election booth is unknown. Question 9 [15] Define a class Book with following specifications: Private data members : bookno, booktitle, price Parameterized constructor : to initialize data members int totalCost (int n) : to calculate the total cost for n quantity of books where n is input by the user. void display ( ) : to display book number, name, price and total cost for n books. Write a program to create an object of the class Book in main ( ) method and call all the methods appropriately. ALL THE BEST 3
|