Formatting page ...
I Pre Board Exam 03/12/2019 Computer Applications Class: X Time: 2 hrs Marks: 100 Answers to this Paper must be written on the paper provided separately. You will not be allowed to write during the first 15 minutes. This time is to be spent in reading the question paper. The time given at the head of this Paper is the time allowed for writing the answers. 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 Question 1. 1] Differentiate between autoboxing and unboxing. 2] Explain the purpose of using a new keyword in a Java program. 3] Rewrite the following loop using for loop: while (true) System.out.print("*"); 4] Mention the types of access specifiers. 5] What is constructor overloading? Question 2. 1] Find and correct the errors in the following program segment. int No[10] = new int[]; for (int i=0; i<=10; i++) no[i] = i; 2] Write the prototype of a function search which takes two arguments a string and a character and returns an integer value. 3] What is the use of void keyword? 4] What is the difference between a constructor and a member function of a class? 5] What is the difference between a static member function and a member function which is not static? Question 3. 1] State the number of bytes and bits occupied by a character array of 10 elements. [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] 2] Differentiate between Binary Search and Linear Search techniques. 3] Predict output of the following: int i = 1; while(i++<=1) { i++; System.out.print(i + ); } System.out.print(i); 4] Give the output of the following java statements: System.out.println("TRANSPARENT".toLowerCase()); System.out.println("TRANSPARENT".compareTo("TRANSITION")) 5] Write a java statement for each to perform the following task: a] Find and display the position of the last space in a string str. b] Extract the second character of the string str. Question 4: 1] Name the following: i] the keyword which is used to resolve the conflict between instance variables and method parameters. ii] the keyword which is used to declare a variable as class variable. 2] Study the given class and answer the following questions. class Library { static int count; String bookname; double price; void calc() { bookname = The Truth ; price = 200.0; double discount = price * 20.0/100; } void display() { System.out.println(bookname + + price); } } a] Name the pure and impure methods in the above class. b] Write a parameterized constructor to initialize the data members. c] Write a statement to execute the parameterized constructor. d] Write down the class variables used in the program. e] Write down the instance variables of the class. f] Name the local variables. [2] [2] [2] [2] [2] [2] [2] [1] [1] [1] [1] SECTION B (60 Marks) Attempt any four questions from this Section. The answers in this Section should consist of the Programs in either Blue J environment or any program environment with Java as the base. Each program should be written using Variable descriptions/Mnemonic Codes so that the logic of the program is clearly depicted. Flow-Charts and Algorithms are not required. Question 4: Anshul transport company charges for the parcels of its customers as per the following specifications given below: Class name : Atransport Member variables : String name to store the name of the customer int w to store the weight of the parcel in Kg int charge to store the charge of the parcel Member functions: Atransport() Default constructor to initialize integer data members with 0 and String data members with null. void accept ( ) to accept the name of the customer, weight of the parcel from the user (using Scanner class) void calculate ( ) to calculate the charge as per the weight of the parcel as per the following criteria Weight in Kg Charge per Kg Upto 10 Kgs Rs.25 per Kg Next 20 Kgs Rs.20 per Kg Above 30 Kgs Rs.10 per Kg A surcharge of 5% is charged on the bill. void print ( ) to print the name of the customer, weight of the parcel, total bill inclusive of surcharge in a tabular form in the following format : Name Weight Bill amount ----------------------------XXXXXX XXXX XXXXXXXXX Define a class with the above-mentioned specifications, create the main method, create an object and invoke the member methods. Question 5: [15] Write a program to input name and percentage of 35 students of class X in two separate one dimensional arrays. Arrange the students details according to their percentage in the descending order using selection sort method. Display name and percentage of first ten toppers of the class. Question 6: Design a class to overload a function Sum( ) as follows: (i) int Sum(int A, int B) with two integer arguments (A and B) calculate and return sum of all the even numbers in the range of A and B. Sample input: A=4 and B=16 Sample output: sum = 4 + 6 + 8 + 10 + 12 + 14 + 16 (ii) double Sum(double N ) with one double arguments(N) calculate and return the product of the following series: sum = 1.0 x 1.2 x 1.4 x ......................... x N (iii) int Sum(int N) - with one integer argument (N) calculate and return sum of only odd digits of the number N. Sample input : N=43961 Sample output : sum = 3 + 9 + 1 = 13 Write the main method to create an object and invoke the above methods. Question 7: Using the switch statement, write a menu driven program to perform following operations: (i) To find the sum of the following series S= 1 + -4 + 7 + -10 + -40 (ii) To print the Floyds triangle with N rows Example: If N = 4, Output: 1 2 3 4 5 6 7 8 9 10 Question 8. Write a program to input and store integer elements in a double dimensional array of size 4 4 and find the sum of all the elements. Display the sum and the array in matrix form Example: 7 3 4 5 5 4 6 1 6 9 4 2 3 2 7 5 Sum of all the elements: 73 Question 9: Write a program to accept a sentence and print only the first letter of each word of the sentence in capital letters separated by a full stop. Example : Input : ACTS Secondary School Bangalore Output : A.S.S.B **************** Question 1 1] The automatic conversion of primitive data type into an object of its equivalent wrapper class is known as autoboxing It is a system of converting an object of wrapper class into primitive data type. 2] new keyword is used to allocate memory for non-primitive data type like arrays and objects 3] for(;;) System.out.println( * ); 4] private, public, protected 5] Using the constructer name with different parameter list. Question 2 1] int No[] = new int[10]; for(int i=0;i<10; i++) No[i]=I; 2] int search (String s, char c) 3] when the function does not return a value to the caller program, void keyword is used as function prototype. 4] Constuctor has the same name as the class name whereas functions can be any user defined name. constructor does not have return type but functions must have a return type. 5] static member function can be used without creating an object, but non static functions can be called with an object. Question 3 1] 20 bytes, 160 bits. 2] binary search uses sorted array and linear search will work with sorted or unsorted array. 3] 3 4 4] transparent 7 5] a] str.lastindexOf( ) b] str.charAt(1) Question 4 1] i] this ii] static 2] a] pure display(), impure calc() b] Library(int c, string b, double p) { count =c; bookname =b; price =c; } c] Library ob = new Library(2, APC , 190.89); d] count e] bookname, price f] discount Question 5 import java.util.*; class ATransport{ String name; int w; int charge; public void accept(){ Scanner sc = new Scanner(System.in); System.out.print("Name: "); name = sc.nextLine(); System.out.print("Weight of the parcel in kg: "); w = sc.nextInt(); } public void calculate(){ if(w <= 10) charge = w * 25; else if(w <= 30) charge = 250 + (w - 10) * 20; else charge = 450 + (w - 30) * 10; charge += (int)(5.0 / 100 * charge); } public void print(){ System.out.println("Name\tWeight\tBill Amount"); System.out.println(name + "\t" + w + "\t" + charge); } public static void main(String args[]){ ATransport obj = new ATransport(); obj.accept(); obj.calculate(); obj.print(); } } Question 6 import java.io.*; class SelectionDescending{ public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int p[] = new int[35]; String n[] = new String[35]; for(int i = 0; i < p.length; i++){ System.out.print("Name: "); n[i] = br.readLine(); System.out.print("Percentage: "); p[i] = Integer.parseInt(br.readLine()); } for(int i = 0; i < p.length; i++){ int large = p[i]; int pos = i; for(int j = i + 1; j < p.length; j++){ if(p[j] > large){ large = p[j]; pos = j; } } int temp = p[i]; p[i] = large; p[pos] = temp; String t = n[i]; n[i] = n[pos]; n[pos] = t; } System.out.println("Names and Percentages of First 10 Toppers:"); for(int i = 0; i < 10; i++) System.out.println(n[i] + " - " + p[i]); } } Question 7 import java.io.*; class Overload{ public int sum(int a, int b){ int s = 0; for(int i = a; i <= b; i++){ if(i % 2 == 0) s += i; } return s; } public double sum(double n){ double p = 1.0; for(double i = 1.0; i <= n; i += 0.2) p *= i; return p; } public int sum(int n){ int s = 0; for(int i = n; i != 0; i /= 10){ if((i % 10) % 2 == 1) s += i % 10; } return s; } public static void main(String args[])throws IOException{ Overload obj = new Overload(); int result = obj.sum(6,12); System.out.println("sum " + result); double product = obj.sum(20.2); System.out.println("Product: " + product); result = obj.sum(43791); System.out.println("Sum of odd digits: " + result); } } Question 8 import java.io.*; class Menu{ public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("1. sum of series"); System.out.println("2. Floyd's Triangle with N rows"); System.out.print("Enter your choice: "); int choice = Integer.parseInt(br.readLine()); switch(choice){ case 1: int y=1; double z=0; for(int x = 1; x <= 40; x += 3) { if(y%2==0) z = z-x; else z=z+x; y=y+1; } System.out.print(z); break; case 2: int num = 1; System.out.print("N = "); int n = Integer.parseInt(br.readLine()); for(int i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ System.out.print(num + "\t"); num++; } System.out.println(); } break; default: System.out.println("Invalid choice!"); } } } Question 9 import java.io.*; class DDarray { public static void main(String args[])throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int a[][] = new int[4][4]; int sum = 0; System.out.println("Enter 16 integers:"); for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { a[i][j] = Integer.parseInt(br.readLine()); sum += a[i][j]; } } for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } } Question 10: import java.io.*; class shortform { public static void main()throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; System.out.println("Enter the string"); s = br.readLine();int l = s.length(); String s1=""; char ch; s1=s1+s.charAt(0); for(int i=1;i<l;i++) { ch=s.charAt(i); if (ch==' ') s1=s1+"."+s.charAt(i+1); } System.out.println(s1); } }
|