ICSE Computer Applications 2009

 COMPUTER APPLICATIONS
(Theory)
(Two hours)
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 [ ].

Question 1
(a) Why is a class called a factory of objects?
A class is called a factory of objects because from one class, we can create several objects of similar type.
(b) State the difference between a boolean literal and a character literal.
A boolean literal occupies 1 byte of memory and can be either true or false.
A character literal occupies 2 bytes of memory and can be any character.
(c) What is the use and syntax of a ternary operator?
The ternary operator is used as an alternative to the if-else statement.
Syntax:
(condition)? value 1 : value 2;
(d) Write one word answer for the following:
i) A method that converts a string to a primitive integer data type.
Integer.parseInt()
ii) The default initial value of a boolean variable data type.
false
(e) State one similarity and one difference between while and for loop.
Similarity: Both while and for loop are entry-controlled loops.
Difference: The while loop is used when the number of iterations is not known, whereas the for loop is used when the number of iterations is known.

Question 2
(a) Write the function prototype for the function "sum" that takes an integer variable (x) as its argument and returns a value of float data type.
float sum(int x)
(b) What is the use of the keyword 'this'?
The 'this' keyword is used to refer to the currently calling object.
(c) Why is a class known as a composite data type?
A class is known as a composite data type because it is a complex data type as it can contain data members and methods within itself.
(d) Name the keyword that:
i) is used for allocating memory to an array.
new keyword
ii) causes the control to transfer back to the method call.
return keyword
(e) Differentiate between pure and impure function.
A function that doesn't change the state of an object is a pure function.
A function that changes the state of an object is an impure function.

Question 3
(a) Write an expression for 





Math.pow(a + b, n) / (Math.sqrt(3) + b)
(b) The following is a segment of a program:
x = 1;
y = 1;
if(n > 0)
{
    x = x + 1;
    y = y - 1;
}
What will be the value of x and y, if n assumes a value:
(i) 1
x = 2
y = 0
(ii) 0
x = 1
y = 1
(c) Analyze the following program segment and determine how many times the body of the loop will be executed (show the working).
x = 5;
y = 50;
while(x <= y)
{
    y = y / x;
    System.out.println(y);
}
Number of iterations: 2
Output:
10
2
(d) When there are multiple definitions with the same function name, what makes them different from each other?
The function signature.
(e) Given that int x[][] = {{2, 4, 6}, {3, 5, 7}};
What will be the value of x[1][0] and x[0][2]?
x[1][0] = 3
x[0][2] = 6
(f) Give the output of the following code segment when: [3]
(i) opn = 'b'
(ii) opn = 'x'
(iii) opn = 'a'
switch(opn){
    case 'a':
    System.out.println("Platform independent");
    break;
    case 'b':
    System.out.println("Object Oriented");
    case 'c':
    System.out.println("Robust and Secure");
    break;
    default:
    System.out.println("Wrong Input");
}
(i) OUTPUT:
Object Oriented
Robust and Secure
(ii) OUTPUT:
Wrong Input
(iii) OUTPUT:
Platform independent
(g) Consider the following code and answer the questions that follow: [4]
class Academic{
    int x, y;
    void access(){
        int a, b;
        Academic student = new Academic();
        System.out.println("Object created");
    }
}
i) What is the object name of class Academic?
student
ii) Name the class variables used in the program.
x and y
iii) Write the local variables used i the program.
a and b
iv) Give the type of function and its name.
Function type: void
Function name: access()
(h) Convert the following segment into an equivalent do loop. [3]
int x, c;
for(x = 10, c = 20; c > 10; c = c - 2)
    x++;
int x = 10, c = 20;
do{
    x++;
    c = c - 2;
}while(c > 10);

SECTION B (60 Marks)
Attempt any four questions from this section.
The answers in this section should consist of the programs in either BlueJ environment or any program environment with Java as the base. Each program should be written using variable descriptions/mnemonic codes such that the logic of the program is clearly depicted.
Flowcharts and Algorithms are not required.

Question 4 [15]
An electronics shop has announced the following seasonal discounts on the purchase of certain items:
Purchase Amount in Rs.Discount on LaptopDiscount on Desktop PC
0 - 250000.0%5.0%
25001 - 570005.0%7.6%
57001 - 1000007.5%10.0%
More than 10000010%15.0%
Write a program based on the above criteria to input name, address, amount of purchase and type of purchase (L for Laptop and D for Desktop) by a customer. Compute and print the net amount to be paid by a customer along with his/her name and address.
Hint: discount = discount rate / 100 * amount of purchase
Net amount = amount of purchase - discount
import java.util.Scanner;
class Shop{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.print("Name: ");
        String n = in.nextLine();
        System.out.print("Address: ");
        String a = in.nextLine();
        System.out.print("Amount of purchase: ");
        int amt = Integer.parseInt(in.nextLine());
        System.out.print("Type of purchase: ");
        char type = in.nextLine().charAt(0);
        double dp = 0.0;
        switch(type){
            case 'L':
            case 'l':
            if(amt <= 25000)
                dp = 0.0;
            else if(amt <= 57000)
                dp = 5.0;
            else if(amt <= 100000)
                dp = 7.5;
            else
                dp = 10.0;
            break;
            case 'D':
            case 'd':
            if(amt <= 25000)
                dp = 5.0;
            else if(amt <= 57000)
                dp = 7.6;
            else if(amt <= 100000)
                dp = 10.0;
            else
                dp = 15.0;
        }
        double da = dp / 100 * amt;
        double net = amt - da;
        System.out.println("Name: " + n);
        System.out.println("Address: " + a);
        System.out.println("Net amount: " + net);
    }
}

Question 5 [15]
Write a program to generate a triangle or an inverted triangle till n terms based upon the user's choice of triangle to be displayed.
Example 1:
INPUT:
Type 1 for a triangle and
Type 2 for an inverted triangle
1
Enter the number of terms
5
OUTPUT:
1
22
333
4444
55555
Example 2:
INPUT:
Type 1 for a triangle and
Type 2 for an inverted triangle
2
Enter the number of terms
6
OUTPUT:
666666
55555
4444
333
22
1
import java.util.Scanner;
class Triangle{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.println("Type 1 for a triangle");
        System.out.println("Type 2 for an inverted triangle");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(in.nextLine());
        switch(choice){
            case 1:
            System.out.print("Number of terms: ");
            int n = Integer.parseInt(in.nextLine());
            for(int i = 1; i <= n; i++){
                for(int j = 1; j <= i; j++)
                    System.out.print(i);
                System.out.println();
            }
            break;
            case 2:
            System.out.print("Number of terms: ");
            n = Integer.parseInt(in.nextLine());
            for(int i = n; i >= 1; i--){
                for(int j = 1; j <= i; j++)
                    System.out.print(i);
                System.out.println();
            }
            break;
            default:
            System.out.println("Invalid choice!");
        }
    }
}

Question 6 [15]
Write a program to input a sentence and print the number of characters found in the longest word of the given sentence.
For example:
s = "India is my country." then the output should be 7.
import java.util.Scanner;
class Longest{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the sentence: ");
        String s = in.nextLine();
        String l = "";
        String w = "";
        for(int i = 0; i < s.length(); i++){
            char ch = s.charAt(i);
            if(ch == ' ' || i == s.length() - 1){
                if(w.length() > l.length())
                    l = w;
                w = "";
            }
            else if(Character.isLetterOrDigit(ch))
                w += ch;
        }
        int len = l.length();
        System.out.println("Longest word length: " + len);
    }
}

Question 7 [15]
Write a class to overload a function numCalc() as follows:
i) void numCalc(int num, char ch) - with one integer argument and one character argument, computes the square of integer argument if choice ch is 's' otherwise finds its cube.
ii) void numCalc(int a, int b, char ch) - with two integer arguments and one character argument. It computes the product of integer arguments if ch is 'p' else adds the integers.
iii) void numCalc(String s1, String s2) - with two string arguments, which prints whether the strings are equal or not.
class Overload{
    public static void numCalc(int num, char ch){
        int result = 0;
        if(ch == 's' || ch == 'S'){
            result = num * num;
            System.out.println("Square: " + result);
        }
        else{
            result = num * num * num;
            System.out.println("Cube: " + result);
        }
    }
    public static void numCalc(int a, int b, char ch){
        int result = 0;
        if(ch == 'p' || ch == 'P'){
            result = a * b;
            System.out.println("Product: " + result);
        }
        else{
            result = a + b;
            System.out.println("Sum: " + result);
        }
    }
    public static void numCalc(String s1, String s2){
        if(s1.equals(s2))
            System.out.println("Equal");
        else
            System.out.println("Unequal");
    }
}

Question 8 [15]
Write a menu-driven program to access a number from the user and check whether it is a Buzz number or to accept any two numbers and print their GCD.
a) A Buzz number is a number which either ends with 7 or is divisible by 7.
b) GCD (Greatest Common Divisor) of two integers is calculated by continued division method. Divide the larger number by the smaller; the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.
import java.util.Scanner;
class Menu{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.println("1. Buzz number");
        System.out.println("2. GCD");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(in.nextLine());
        switch(choice){
            case 1:
            System.out.print("Enter the number: ");
            int n = Integer.parseInt(in.nextLine());
            if(n % 7 == 0 || n % 10 == 7)
                System.out.println("Buzz number");
            else
                System.out.println("Not a Buzz number");
            break;
            case 2:
            System.out.print("First number: ");
            int a = Integer.parseInt(in.nextLine());
            System.out.print("Second number: ");
            int b = Integer.parseInt(in.nextLine());
            while(a % b != 0){
                int rem = a % b;
                a = b;
                b = rem;
            }
            System.out.println("GCD = " + b);
            break;
            default:
            System.out.println("Invalid choice!");
        }
    }
}

Question 9 [15]
The annual examination results of 50 students in a class is tabulated as follows:
Roll No.Subject ASubject BSubject C
............
Write a program to read the data, calculate and display the following:
a) Average marks obtained by each student.
b) Print the roll number and average marks of the students whose average mark is above 80.
c) Print the roll number and average marks of the students whose average mark is below 40.
import java.util.Scanner;
class Students{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int roll[] = new int[50];
        int a[] = new int[50];
        int b[] = new int[50];
        int c[] = new int[50];
        double avg[] = new double[50];
        for(int i = 0; i < a.length; i++){
            System.out.print("Roll: ");
            roll[i] = Integer.parseInt(in.nextLine());
            System.out.print("Subject A marks: ");
            a[i] = Integer.parseInt(in.nextLine());
            System.out.print("Subject B marks: ");
            b[i] = Integer.parseInt(in.nextLine());
            System.out.print("Subject C marks: ");
            c[i] = Integer.parseInt(in.nextLine());
            avg[i] = (a[i] + b[i] + c[i]) / 3.0;
        }
        System.out.println("Roll\tAverage");
        for(int i = 0; i < a.length; i++)
            System.out.println(roll[i] + "\t" + avg[i]);
        System.out.println("Students with average > 80");
        for(int i = 0; i < a.length; i++){
            if(avg[i] > 80)
                System.out.println(roll[i] + "\t" + avg[i]);
        }
        System.out.println("Students with average < 40");
        for(int i = 0; i < a.length; i++){
            if(avg[i] < 40)
                System.out.println(roll[i] + "\t" + avg[i]);
        }
    }
}

Comments

Popular posts from this blog

Encrypt Program ISC Specimen 2023 Theory

No Repeat Program ISC Computer Science 2022 Semester 2 Theory

Bank Inheritance Program ISC Specimen 2023 Theory