Program – no. of words starts with Vowel


Write a Java program to input a sentence and count the number of words that start with a vowel (A, E, I, O, U). The program should be case-insensitive and display the count.

Example:
Input: "An elephant is outside the umbrella"
Output: Number of words starting with a vowel: 4

import java.util.Scanner;

public class VowelWordCounter {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Input sentence
        System.out.print("Enter a sentence: ");
        String sentence = sc.nextLine();
        sc.close();

        int vowelWordCount = 0;
        int length = sentence.length();
        boolean isWord = false; // Flag to track a new word

        for (int i = 0; i < length; i++) {
            char ch = sentence.charAt(i);

            // Check if current character is a letter (indicating start of a word)
            if (Character.isLetter(ch)) {
                if (!isWord) { // New word detected
                    isWord = true;
                    char firstChar = Character.toLowerCase(ch); // Convert to lowercase
                    if ("aeiou".indexOf(firstChar) != -1) { // Check if it starts with a vowel
                        vowelWordCount++;
                    }
                }
            } else {
                isWord = false; // Reset flag when encountering space or punctuation
            }
        }

        // Output the count
        System.out.println("Number of words starting with a vowel: " + vowelWordCount);
    }
}

Loops through each character in the sentence.
Detects the start of a word (first letter after a space or punctuation).
Checks if the first letter is a vowel (aeiou).
Counts only words that start with vowels.

Output:

Enter a sentence: An elephant is outside the umbrella
Number of words starting with a vowel: 4

6th Year -Happy Anniversary


Thank you Universe…

Thank you WordPress…

Thank you Subscribers …

Thank you Visitors…

I am really thankful to everyone visited my blog and please comment your valuable feedback. WordPress, has given me a platform to share my programming topics to entire world. Surprisingly this is the 6th year. Realizing that I am not consistent in doing blog. Before a couple of days I could retrieve my logins after 1-2 years. In this 6th year anniversary, I like to resume my blogging of ISC, ICSE Computer topics.

Emirp Number


An emirp number is a number which is prime backwards and forwards. Example : 13 and 31 are both prime numbers. Thus 13 is a emirp number.

import java.util.*;
class Emirp
{ 
    int n, rev,f;
    Emirp(int nn)
    {
        n=nn;
        rev=0;
        f=2;
    }
    int isprime(int x)
    {
        if(n==x)
        return 1;
        else if (n%x==0 || n==1)
        return 0;
        else
        return isprime(x+1);
    }
    void isEmirp()
    {
        int x=n;
        while(x!=0)
     {
         rev=rev*10 + x%10;
         x=x/10;
         
        }
        int ans1=isprime(f);
        n=rev;
        f=2;
        int ans2=isprime(f);
        if(ans1==1 && ans2==1)
        System.out.println(n+"is an emirp no");
        else
        System.out.println(n+"is not an emirp no.");
        
    }
    public static void main(String[] args) 
    { 
      int a; 
      Scanner sc= new Scanner(System.in);
      System.out.println("Enter the number:");
      a=sc.nextInt();
        Emirp emp=new Emirp(a);
        emp.isEmirp();

    } 
} 

Enter the number:
13
31is an emirp no
Enter the number:
51
15is not an emirp no.

final keyword – variable into constant- 2 marks


Rating: 5 out of 5.

final keyword – converts the variable into constant whose value cannot be changed at any stage in the program.

Syntax:
final datatype variable name=actual value

eg: final int a=15; // value of ‘a’ is constant as 15

Find the output:

int x=10;
final int y=20;
x=x+4;
y=y+4;

What is the updated value of x and y? or Displays any error message, then What is the reason?

Compile time error message – cannot assign a value to final variable ‘y’

Explanation:

int x=10; // an integer variable.

final int y= 20; // an integer variable declared as constant, so value of ‘y’ //cannot be changed anywhere in the program

x=x+4; //change the value of ‘x’ by adding 4 to it.

// so the value of ‘x’ is 14 (10+4)

y=y+4; //value of y’ will not be changed as keyword final has converted //variable ‘yinto constant

// In this case during compilation of the program the error message “Cannot assign a value to final variable y”

Tips – ISC Computer Science Board Exam


Keep up on the Exam pattern and Syllabus

Learn the concepts with examples

Dont memorize programs, think logically and write

Practice previous year question papers and specimen copies

Notice and follow the examiners comment from analysis.

Revise everyday.


Be Careful – Whenever practising the programs

Read the questions twice before starting your answer

Use the variables, method and class name what has given in the questions. Instead of that dont use your own variable, method and class. (especially Section B & Section C questions)

You have written the program with correct logic and not following the same variable, method and class name reduce your marks.

Dont forget to create main() and invoke specified methods to main(), if its asked in the question paper.

In Section C, Inheritance programs
DONT WRITE super class, main() and algorithm. (if its specified as NOT to be written)

Do more practice on recursion programs.

Java program to check Unique Number


Write a Program in Java to input a number and check whether it is a Unique Number or not.

( A Unique number is a positive integer (without leading zeros) with no duplicate digits. For example 7, 135, 214 , 5243 are all unique numbers whereas 33, 3121, 200 are not.)

 
import java.util.*;

class UniqueNumber

{

public static void main(String args[] )

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number :");

int n=sc.nextInt();

String s= Integer.toString(n); // converting the given number into String datatype

// Int datatype is converting to String , String helps to extract the character by charAt() and check each character is matching with the rest.

int l=s.length();

int flag=0,i, j;

//Loops to check the digits are repeated

for(i=0;i<l-1;i++)

{

for(j=i+1;j<l;j++){

if(s.charAt(i)==s.charAt(j)) // if any digits are repeated, then it is not a UniqueNumber

{ flag=1;

break; }

}

}

if(flag ==0)

System.out.println(" It is an UniqueNumber");

else

System.out.println(" It is not an UniqueNumber");

}

}

Output:

Enter a number: 5673

It is an UniqueNumber

Enter a number: 5675

It is not an UniqueNumber

Conversion of octal to decimal number


import java.util.*;
public class Octal2Decimal{

//method definition to convert octal numbers into decimal

public static int getDecimal(int octal){
int decimal = 0;
//Declaring variable to use in power
int ct = 0;
while(true){
if(octal == 0){
break;
} else {
int temp = octal % 10;
decimal += temp*Math.pow(8, ct); //
octal = octal/10;
ct++;
}
}
return decimal;
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println(“Enter an octal number:”);
int num=sc.nextInt();
Octal2Decimal od=new Octal2Decimal();

System.out.println(“Decimal of given octal is: “+ od.getDecimal(num));
}
}

String program using StringTokenizer


ISC – Model Question Paper -October 2018

Design a class Chord that accepts a string and prints the number of vowels present in each word of the string. Also note that a string is considered valid if it does not contain any repeated spaces. For example : String : “SUMMER IN AUSTRALIA IS IN DECEMBER.
Output: SUMMER : 2
IN : 1
AUSTRALIA : 5
IS : 1
IN : 1
DECEMBER : 3
Some of the members of the class Chord are given below:
Class Name : Chord
Data members
cd : the string
Member functions:
Chord() : to initialize the member string to null
void fnInput() : to input the member string
void fnOperate() : to print “invalid Sting “ if the string is not valid, otherwise print the words of the member string along with the number of vowels present in them.

boolean isValid() : to verify whether the given string is valid or not and return true or false.
int fnVowel(String w) : to count and return the no. of vowels present in argument ‘w’.

import java.util.*;
class cord
{
String cd;
cord()
{
cd=””;
}
void fnInput()
{
Scanner sc=new Scanner(System.in);
System.out.println(“enter the string:”);
cd=sc.nextLine();
}

//Check the String is valid
boolean isValid()
{
for(int j=0;j<=cd.length()-2;j++)
{
if(cd.charAt(j)==’ ‘ && cd.charAt(j+1)==’ ‘) // checking repeated space
{
return false; //if repeated space, String is invalid
}
}
return true;

}
void fnOperate()
{
fnInput();
if(isValid() == false)
{
System.out.println(“Invalid string”);
return;
}
StringTokenizer st=new StringTokenizer(cd);
int ct=st.countTokens();
for(int j=1;j<=ct;j++)
{
String wrd=st.nextToken();
int cw=fnVowel(wrd);
System.out.println(wrd +” ” +cw);

}
}

//counting the vowels in the argument ‘w’
int fnVowel(String w)
{
int c=0;
w=w.toUpperCase();
for(int j=0; j<=w.length()-1;j++)
{
if(w.charAt(j)==’A’||w.charAt(j)==’E’||w.charAt(j)==’I’||w.charAt(j)==’O’||w.charAt(j)==’U’)
c++;
}
return c;
}
public static void main(String args[])
{
cord c1=new cord();
c1.fnOperate();
}

}

ICSE-Computer Applications- October 2018


                                  Section A (40 Marks)
                                Answer all questions.

Question 1                                                                                                                              [10]

  1. Declare a single dimensional array of 10 integer values.
  2. Convert the following while loop to the corresponding for loop.
    int m=5, n=10;

while(n>=1)   {
System.out.println(m*n);
n–;
}

  1. Convert the following segment into an equivalent do loop:

int x,c;

for(x=10, c=20;c>=20;c=c-2)

x++:

  1. What is the final value of ctr when the iteration process given below, executes?

int ctr=0;
for(int j=1;j<=5;j+=2)
++ctr;

  1. If, array[]={1,4,5,6,3,32,23,90}; i) What is array.length?  ii) What is array[10]?

Question 2                                                                                                                                [10]

  1. Which keyword used to acquire the properties of one class to another class?
  2. Here is a skeleton definition of a class
    class Sample {
    int i;
    char c;
    float f;
    } Implement the constructor.
  3. Write a program to check whether the given number is palindrome or not.
  4. Differentiate between public and private modifiers for members of a class.
  5. What type of inheritance does Java here?

Question 3                                                                                                                                [10]

  1. Write a program to print Fibonacci series i.e., 0 1 1 2 3 5 8…..The number of terms required, is to be passed as parameter.
  2. What will be the result stored in x after evaluating the following expression?
    int x =42;
    x+ = (x++ ) + (++x) +x;
  3. What will be the output of the following code?

int m=3;

int n=15;

for(int i=1;i<5;i++)

m++;

–n;

System.out.println(“m=”+m);

System.out.println(“n=”+n);

  1. Analyze the following program segment and determine how many times the loop will be executed and what will be the output of the program segment?
    int p=200;

while(true)

{

if(p<100)

break;

p=p-40;

}

System.out.println(p);

  1. 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  ii) 0 ?

Question 4                                                                                                                                [10]

  1. Give two differences between the switch statement and if else statement.
  2. Write two difference between linear search and binary search.
  3. Given that in x[][]={{2,4,6},{3,5,7}}, what will be the value of x[1][1] and x[0][2]?
  4. State the total size in bytes, of the arrays a[4] of char data type and p[6] of float data type.
  5. If int x[]={4,3,7,8,9,10}; What are the values of p and q?
    i) p= x.length     ii)   q=x[2] +x[5] * x[1]

   

 

         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.
Flow-Charts and Algorithms are not required.

Question 5                                                                                                                              [15]
Designa class to overload a function polygon() as follows:
i)          void polygon(int n, char ch)       : with one integer argument and one character type argument that draws a filled square of side n using the character stored in ch.

  1. ii) void polygon(int x, int y) : with two integer arguments that draws a filled rectangle of length x and breadth y using the symbol ‘@’.

iii)         void polygon()              : with no argument that draws a filled triangle shown below.

Example:

  1. i) Input value of n=2, ch=’O’

Output: OO
OO

  1. ii) Input value of x=2,y=5

Output

@@@@@

@@@@@

 

iii) Output

*

* *

* * *

 
Question 6                                                                                                                              [15]

Write  a menu driven program  to accept a number and check and display whether it is a prime number or not OR an automorphic number or not.

  1. a) Prime number : A number is said to be a prime number if it is divisible only by 1 and itself and not by any other number. Example; 3,5,7,11,13..
  2. b) Automorphic number : An automorphic is the number which is contained in the last digit of the square. Example : 25 is an automorphic number as its square is 625 and 25 is present as the last two digits.

 

Question 7                                                                                                                              [15]

Special words are those words which start and end with the same letter.
Examples:  EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.

Examples: MALAYALAM, MADAM, LEVEL, ROTATOR

All palindromes are special words, but all special words are not palindromes.

Write a program to accept a word check and print whether the word is a palindrome or only special word.

Question 8                                                                                                                              [15]
Write a program that encodes a word into Piglatin. To translate a word into a Piglatin word, convert the word into upper case and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end following by  “YZ”.

Sample input : Flowers     Sample Output: OWERSFLYZ
Sample input : Olympics            Sample Output : OLYMPICSYZ

Question 9                                                                                                                             

 1)  Write a program to initialize the given data in an array and find the minimum and maximum    values along with the sum of the given elements.                                                                                                                             [5]

Numbers: 2 5 4 1 3

Output: Minimum value  : 1
Maximum value=5

Sum of the elements=15

 

2) Write a program to accept 15 integers from the keyboard, assuming that no integer entered is a zero. Perform selection sort on the integers and then print them in ascending order.        [10]

 

Question 10                                                                                                                            [15] Define a class and store the given city names in a single dimensional array. Sort these names in alphabetical order using the bubble sort technique only.

Input:  Calcutta, Agra, Mumbai, Bangalore, Delhi

Output: Agra, Bangalore, Calcutta, Delhi, Mumbai

 

.

ICSE


  1. Define abstraction.
  2. Define escape sequence with examples.
  3. Write a difference between the functions isUpperCase( ) and toUpperCase( ).
  4. How are private members of a class different from public members?
  5. Classify the following as primitive or non-primitive datatypes:
    (i) char(ii) arrays(iii) int(iv) classes

Model Question Paper -ISC Computer Science – Oct 2018


PART – I (20 Marks)
Answer
all questions.
While answering questions in this Part, indicate briefly your working and reasoning, wherever required.

Question 1

  1. Verify using the truth table, if (x => y).(y =>x) is a tautology, contradiction and contingency.                                                               [1]
  2. State the two Idempotence law. Verify any one using truth table.      [1]
  3. If F(A,B,C)=A’(BC’+B’C), then find F’.                                                        [1]
  4. Verify using truth table ( A ^ ~B ) V (~A ^ B) V A = AVB [1]
  5. Write the dual of (a.b’+0).(a’.b+1)                                                   [1]

Question 2

  1. An array DR[-2…2,-3…3] stores elements in Col major wise, with address DR[0][0] as 2500. If each element requires 2 bytes of storage, find the base address.                                                                [2]
  2. Explain the given keyword in brief: 1) import 2) extends              [2]
  3. State the difference between Function overloading and Function overriding [2]
  4. What is the difference between private and protected access specifier with an example.    [2]
  5. A char array B[7][6] has a base address 1046 at(0,0). If the address at B[2][q] is 1096. Find the value of q, given that the array is stored column major wise. Each char requires 2 bytes of storage. [2]

 Question 3   [5]

Give the output of the following function where x and y are arguments greater than 0. Show the dry run/working.

void confusing(int x, int y) 
{
if(x>1)  { 
               if( x%y==0) { 
                               System.out.print(y+””);
                              confusing(x/y, y);
                            }
else   {
confusing(x, y+1); }
}

1) What will be the function confusing(24,2 ) return?
2) What will be the function confusing(84,2) return?
3) In one line, state what is the function is doing, apart from recursion?

                                             PART II (50 Marks)

   Answer six questions in this part, choosing two questions from Section A, two from Section B and two from Section C.
SECTION – A
                                        Answer any two
questions

Question 4 [10]

  • Given the Boolean function : F(A,B,C,D) =Ʃ(0,1,2,5,8,9,10)
    i)  Reduce the above expression by using 4 variable Karnaugh map, showing     the various groups (i.e., octal, quads, pairs).
    ii) Draw the logic gate diagram for the reduced expression. Assume that the      variables and their complements are available as inputs.
  • Given the Boolean function : F(P, Q,R,S) =Π (3,4,6,7,11,12,13,14,15)
  • Reduce the above expression by using 4 variable Karnaugh map, showing
    the various groups (i.e., octal, quads, pairs).
  • Draw the logic gate diagram for the reduced expression. Assume that the variables and their complements are available as inputs.

Question 5 [10]

  1. A person is allowed to travel in a reserved coach of the train, if he/she satisfies any one of the criteria given below:
    The person has a valid reservation ticket and a valid ID proof.
    OR
    The person does not have a valid reservation ticket, but holds a valid pass issued by the Railway department with a valid ID proof.
    OR
    The person is a senior citizen and holds a valid pass issued by the Railway department along with a valid ID proof.
    The inputs are:
            Inputs
    R         The person has a valid reservation ticket
    P          The person holds a valid pass issued by the Railway department
    D         The person has a valid ID proof.
    S          The person is a senior citizen.
    Output: T denotes allowed to travel [1 indicate yes, 0 indicates no for all cases]
    Draw the truth table for the inputs and outputs given above and write the SOP expression for T(R,P,D,S).
  2. Verify using truth table, whether the given expression is a contradiction or not.             P(A,B) = A. (A’ +B)      +AB’
  3. Write the cardinal form of P(A,B,C) =ABC’+ A’BC+ A’BC’ +ABC                                 

Question 6 [10]

  1. What is an encoder? Draw the logic circuit of an Octal to Binary encoder.
  2. What is a decoder? Draw the logic gate diagram, block diagram for a 3 to 8 decoder.

            SECTION – B

     Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
The programs must be written in Java.

Question 7 [10]

An Armstrong number is such that the sum of the cube of the digits of the number is the number itself. Example 153= 13+53+33
Design  a class Arm to perform the given task. Some of the members of the class are given below:

Class name                              : Arm
Data member/Instance variables         :
no                                            : integer to store the number
sum                                          : integer to store the sum of the cube of the digits
Member methods:
Arm(….)                                 : to initialize member data no, and assign 0 to sum.
long fnPower(int a, int b)        : to calculate a^b using recursive function
void fnPerform()                     : to verify and print whether the member data is an Armstrong number or not.
Specify the class Arm, giving the details of the above member data and methods. Also define the main() to create an object and call the relevant methods accordingly to enable the task.

Question 8                   [10]

Design a class EQUA that contains a 2D integer array of order [m *n]. The maximum value possible for m,n is 10. The details of some of the members of the class are given below:

Class name                              :           EQUA
Data member/Instance variables  :
Tam [] []                                              : to store the matrix
int m,n                                                 : integers to store the number of rows and columns
Member functions  :
EQUA(….)                                         : parameterized constructor to initialize m, n and to allocate memory to member array
void fnGet()                                        : to fill the member array with random integers
void fnDisplay()                                  : to show the member matrix
Boolean fnlsEqual(EQUA M)                        : to compare the matrix of the
argument object and the current matrix for equality. If equal, then return true else return false. [ two matrices are equal if all elements are same in corresponding cells]

Specify the class EQUA, giving the details of the above member data and methods. Also define the main() to create an object and call the other methods accordingly to enable the task.

Question 9                     [10]

Design a class Alpha which enables a word to be arranged in ascending order according to its 10 alphabets. The details of the members of the class are given below:
Class name                                          : Alpha
Data members
Str                                                       : to store a word
Member methods:
Alpha()                                    : default constructor
void readword()                      : to accept the inputted word
void arrange()                          : to arrange the word in alphabetical order using any standard sorting technique.
void disp()                               : displays the word.

Specify the class Alpha giving details of the constructor and the member functions void readword(), void arrange(), void disp() and defining the main() to create an object and call the function in order to execute the class by displaying the original word and the changed word with proper message.

    SECTION – C
           Answer
any two questions.
Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
         The programs must be written in Java.

Question 10                                                                                                        [5]

A super class Tour has a sub class Tourist. The details of both the classes are given below.

The details of the base class:
Class name                  : Tour

Data member/ instance variable :
int budget                    : to store the tour budget
int dist             : to store the proposed distance to travel in kilometer
Member functions/methods
Tour(….)                     : parameterized constructor to initialize the data members.
Void print()                 : to print the member data with proper messages.

The details of the derived class:
Class name                  : Tourist
Data member               :
String Name                 : to store the name of the tourist
double rate                  : to store the rate proposed per kilometer
Member functions
Tourist(…)                  : parameterized constructor to initialize the data members of the base and current class
void modify()              : modifies the rate after giving certain discounts, depending on proposed distance to travel as per the following chart
Distance                                  Discount
>=10000                                  40% of rate
<10000 && >=5000               20% of rate
<5000  && >=1000                10 % of rate
void print()                  : to display the details of both the classes with proper messages. Also note to print the rate proposed and the rate applied.

Specify the base class, derived class and write the main() and call above member methods.

Question 11                                                                                 [5]

Given the following code, answer the questions given below(Show the dry run/working)

void design(int d) {
int k=d, r=0, pw=0;
double b=0.0;
do {
r=k%10;
b=b*0.1 +r;
k/=10;
System.out.println(k+””+b+”*10^”+pw);
pw++;
}while(k!=0);

}

  1. What will be the output if d=2345?
  2. What will be the output if d=46?

Question 12                                                                                                              [5]

A class Admission contains the admission numbers of 100 students. Some of the data members/ functions are given below:
Class name      :           Admission
Data members:
Adno[]                        :
integer array to store admission numbers
Member functions:
Admission()    :
constructor to initialize the array elements
void fillArray():
to accept the elements of the array in ascending order
int binSearch(int l, int u, int v): to search for a particular admission number(v) using binary search and recursive technique and returns 1 if found otherwise returns -1.

Specify the class Admission, giving details of the constructor , void fillArray(), and int binSeacrh(int, int, int). Define the main() to create an object and call the function accordingly to enable the task.

N1 to create another number N2 by attaching the sum of the digits of N1 behind it.


A class Attach works on a number N1 to create another number N2 by attaching the sum of the digits of N1 behind it.

For example N1= 712          N2=71210
For example  N1= 123          N2= 1236

Design a class  Attach some of the members of the class are given below:
Class Name     : Attach
Data members:
N1,N2           : inegers
Member functions:
Attach()       : constructor to assign null to the member data
void getNum () : input a 3 digit number in N1. If not a 3 digit number, N1 is entered again
void makeNum()  :  to create N2 using N1 as per given criteria ( utilize method addDigits()]
int addDigits(int n)   :   to add the digits of argument ‘n’ and return the sum
Specify the class Attach, giving the details of the above member data and methods. Also define the main() to create an object and call the other methods accordingly to enable the task.

Program:

import java.util.*;
class Attach
{
int N1,N2;
public Attach()
{
N1=0;
N2=0;
}
void getNum()
{
Scanner sc=new Scanner(System.in);
do
{
System.out.print(“\f Enter a 3 digit number:”);
N1=sc.nextInt();
}while(N1<100 || N1>999);
}
int addDigits(int n)
{
int c=n, sum=0;
while(c!=0)
{
sum=sum +c%10;
c/=10;
}
return sum;
}
void makeNum()
{
int sum=addDigits(N1);
int copy=sum, nd=0;
while(copy!=0)
{
nd++;
copy/=10;
}
N2=(int) (N1* Math.pow(10,nd))+sum;
}
public static void main(String args[])
{
Attach obj=new Attach();
obj.getNum();
obj.makeNum();
System.out.println(“N1=”+obj.N1+”\t”+”N2=” +obj.N2);
}
}

Output:

Enter a 3 digit number:   125
N1=125 N2=1258

Enter a 3 digit number:   205
N1=205 N2=2057

Subtraction of matrix (object)


A class matrix  contains a @d integer array of order[m * n]. The maximum value possible for both m and n is 10. Design a class matrix to find the difference of the two matrices. the details of the members of the class are given below:
Class name     : matrix
Data members:
atm[][]      : to store the matrix
m, n          :  integer to store the number of rows and columns
Member functions:
Matrix(…..)   : initialize m, n  and to allocate memory to member array
void fnGet()   : to fill the member array
void fnDisplay() : to show the member matrix
Matrix fnSub(Matrix A)  : Subtract the current object from the matrix of parameterized object and return the resulting object.
Specify the class Matrix,  Define main(), giving the details of the above member data and methods only.

Program:

import java.util.*;
class Matrix
{
int atm[][];
int m,n;

public Matrix(int r, int c)
{m=r;
n=c;
atm= new int [m][n];

}
void fnGet()
{
Scanner sc=new Scanner(System.in);
int i,j;
System.out.println(“Enter the elements:”);
for(i=0;i<m;i++){
System.out.println(“Enter the elements of row:”+(i+1));
{for(j=0;j<n;j++)
{
atm[i][j]=sc.nextInt();
}
System.out.println();
}}
}
void fnDisplay()
{
System.out.println(“The array elements:”);
int i,j;
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
{
System.out.print(atm[i][j]+”\t”);
}
System.out.println();
}
}
public Matrix1 fnSub(Matrix1 o1)
{
int i, j;
Matrix1 o3=new Matrix1(m,n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
o3.atm[i][j]=o1.atm[i][j]-atm[i][j];
return o3;
}

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the values of row and columns:”);
int r=sc.nextInt();
int c=sc.nextInt();
Matrix m1=new Matrix(r,c);
Matrix m2=new Matrix(r,c);
Matrix m3=new Matrix(r,c);
System.out.println(“Enter the 1st array:”);
m1.fnGet();
System.out.println(“Enter the 2nd array”);
m2.fnGet();

System.out.println(“\u000c”);
System.out.println(“array1 elements:”);
m1.fnDisplay();
System.out.println(“array2 elements:”);
m2.fnDisplay();
m3=m2.fnSub(m1);

System.out.println(“Subtracted” );
m3.fnDisplay();
}
}

Output:

Enter the values of row and columns:
2
3
Enter the 1st array:
Enter the elements:
Enter the elements of row:1
9
8
7

Enter the elements of row:2
6
5
4

Enter the 2nd array
Enter the elements:
Enter the elements of row:1
6
5
4

Enter the elements of row:2
4
3
2

array1 elements:
The array elements:
9 8 7
6 5 4
array2 elements:
The array elements:
6 5 4
4 3 2
Subtracted
The array elements:
3 3 3
2 2 2

 

 

Anti clockwise spiral matrix / anti clockwise circular matrix – java


import java.util.*;
class anticlockwise
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements : ");
int n = sc.nextInt();

int A[][] = new int[n][n];
int k=n*n, c1=0, c2=n-1, r1=0, r2=n-1;

while(k>=1)
{
for(int i=c1;i<=c2;i++)
{
A[r1][i]=k--;
}

for(int j=r1+1;j<=r2;j++)
{
A[j][c2]=k--;
}

for(int i=c2-1;i>=c1;i--)
{
A[r2][i]=k--;
}

for(int j=r2-1;j>=r1+1;j--)
{
A[j][c1]=k--;
}
c1++;
c2--;
r1++;
r2--;
}

/* Printing the Circular matrix */
System.out.println("The Circular Matrix is:");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+ "\t");
}
System.out.println();
}
}
}

Output:

Enter the number of elements : 4
The Circular Matrix is:
16 15 14 13
5 4 3 12
6 1 2 11
7 8 9 10

Transpose of a matrix using object


The transpose of a matrix is found by interchanging the elements of rows and columns.
Design a class matrix that contains a 2D array of order [n * n ]. The maximum value possible for n is 20. The details of some of the members of the class are given below
Class name    : matrix
Data members:
int t[][]                   : to store the matrix
int n                        : integer to store the number of rows and columns
Member functions:
matrix(…..)             : parameterized constructor to initialize n and to allocate memory to member array
void fnGet()       :  to fill the member array
void fnDisplay() : to show the member matrix
matrix fnTrans(matrix A)  : to store the transpose of the argument matrix in the current object and return that.
Specify the class matrix giving the details of the above member data and methods only.

 

Program:

import java.util.*;
class matrix
{
int t[][];
int n;

public matrix(int n1)
{n=n1;
t= new int [n][n];

}
void get()
{
Scanner sc=new Scanner(System.in);
int i,j;
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{
t[i][j]=sc.nextInt();
}
}
}
void disp()
{
int i,j;
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{
System.out.print(t[i][j]+”\t”);
}
System.out.println();
}
}
public matrix Trans(matrix o1)
{
int i, j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
t[i][j]=o1.t[j][i];
return this;
}

public static void main(String args[])
{
matrix m1=new matrix(3);
matrix o1=new matrix(3);
matrix o2=new matrix(3);
m1.get();
m1.disp();
o2=o2.Trans(m1);

System.out.println(“Transpose of matrix”);
o2.disp();
}
}

 

Output:

Enter the elements:
9
8
7
6
5
4
3
2
1
9 8 7
6 5 4
3 2 1
Transpose of matrix
9 6 3
8 5 2
7 4 1

Model Question Paper June 2018-ISC Computer Science


Model Question Paper ISC Computer Science 2018

PART – I (20 Marks)
Answer all questions.
While answering questions in this Part, indicate briefly your working and
reasoning, wherever required.

Question 1

  1. Write the distributive laws. Prove anyone using truth table.
  2. Simplify the expression using Boolean laws
    F1=(a+c’).(a’+b’+c’)
  3. Find the complement of :
    F 2 =ab’ + a’ + a’b+b’
  1. Verify using truth table ( ~p ^ q) V (p^q) = q.
  2. Write the dual of F3 = (p +1).(q’ + 0)

Question 2

  1. An array D [-2…10][3…8] contains double type elements. If the base address is 4110, find the address of D[4][5], when the array is stored in Column Major Wise
  2. I) Name the keyword it is used for memory allocation.                                          
  3. Write the syntax of a character input.
  4. If (~P => Q) then write its:
  5. Inverse ii)         Converse
  6. Differentiate between a method and a constructor of a class.
  7. State De Morgan’s laws. Verify anyone using a truth table                                         

Question 3

  1. Given the following method

void fnM(int p)

{

int RM[]={2,4,6,8,10};

for( int j=1; j<=RM.length-1; j++)

{

RM[j-1] = RM[j-1] +RM[j];

RM[j] = RM[j-1] *2;

}

System.out.print(“OUTCOME=” +RM[p]);

}

  • What will be the output if p=1?
  • What will be the output if p=4?
  • Which token finds the size of the array?

                                                     PART II (50 Marks)

          Answer six questions in this part, choosing two questions from Section A,
                              two from Section B and two from Section C.
SECTION – A
                                               Answer any two questions

Question 4

  • Given the Boolean function : F(A,B,C,D) =Ʃ(0,2,3,6,7,8,10,12,13,14,15)

  • Reduce the above expression by using 4 variable Karnaugh map, showing
    the various groups (i.e., octal, quads, pairs).
  • Draw the logic gate diagram for the reduced expression. Assume that the
    variables and their complements are available as inputs.
  • Given the Boolean function : F(P, Q,R,S) =Π (0, 1, 2, 4, 5, 6, 8, 10)
  • Reduce the above expression by using 4 variable Karnaugh map, showing
    the various groups (i.e., octal, quads, pairs).
  • Draw the logic gate diagram for the reduced expression. Assume that the
    variables and their complements are available as inputs.

Question 5

  • Given the Boolean function: F(A,B,C,D)= Π (0,1,2,3,5,7,8,9,10,11)
    Reduce  the above expression by using 4-variable K map, showing the various groups (i.e., octet, quads and pairs)
  • Given the Boolean function : F(A,B,C,D) =ABC’D’ +A’BC’D’ + A’BC’D + ABC’D+ A’BCD+ABCD
    Reduce the above expression by using 4 variable K map showing the various groups ( octet, quads and pairs).

Question 6

A school intends to select candidates for an inter-school essay competition as per the criteria given below:

The student has participated in an earlier competition and is very creative.
OR
The student is very creative and has excellent general awareness, but has not participated in any competition earlier.

 OR

The student has excellent general awareness and has won prize in an inter-house competition.

The inputs are:

INPUTS
A                     participated in a competition earlier
B                      is very creative
C                     won prize in an inter-house competition
D                     has excellent general awareness
(in all the above cases 1 indicates yes and 0 indicates no for all cases)

Output: X [1 indicates yes, 0 indicates no for all cases]
Draw the truth table for the inputs and outputs given above and write the POS expression for X(A,B,C,D).

  • Write the idempotence law and verify using truth table.
  • Convert the following Boolean expression into its Canonical POS form:            F(A,B,C) = (B+C’).(A’+B)

                                            SECTION – B

                             Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
The programs must be written in Java.

Question 7

A Special is a number in which the sum of the factorial of its digits is equal                  to the number. Example  1!+4!+5! =145. Thus 145 is a special number.
Design a class Special to check if the number is a Special number or not. Some of the members of the class are given below:

Class Name                :                                   Special
Data member/Instance Variables:   n :          integer  to store the number
Member functions:
Special()                                   : constructor to initialize data members with legal initial values
void accept()                            : to accept the number
int factorial(int x)                       : returns the factorial of a number using recursive technique.
boolean isSpecial()                   : checks for the special number by invoking the function factorial() and returns true if Special, otherwise returns false.
void display()                            : to display the result with an appropriate message.

Specify the class Special, giving the details of the above member data and methods only. Define the main() function to create an object and call the member function accordingly to enable the task.

Question 8                                                                                                                              [10]

A beam number is a number in which the sum of the square of the digits of the number is larger than the number itself.

For example  :  N= 25 Sum of square of digits = 22 + 52 = 4 +25 = 29
Number 25 is a Beam Number
For example  : N = 34 Sum  of square of digits = 32+ 42  = 9 + 16 = 25
Number 34 is Not a Beam Number
Design a class BEAM to check if a given number is a beam number.

Class Name                                        : BEAM
Data Member/Instance Variables    :
int m                                                     : integer
Member Functions:
BEAM()                                               : Constructor to initialize member data to null
void fnGet( int mm)                               : To input value for the member data
int fnSqSum (int d)                                : To return the sum of the square of the digits of the argument
For example : d= 69
Final method return 62 + 9 2 = 36 +81 = 117
boolean isBeam()                                  : To  verify whether the member data is a Beam Number or not as per the criteria given above.
Specify the class
BEAM, giving details of the above member data and methods only. Also define the main() to create an object and call the other methods accordingly to enable the task.

Question 9                                                                                                                              [10]

Write a class called Numbers with following specifications:

ArmStrong Number = 407= 43+03+73

ArmStrongLike Numbers = 165033 = 163+503+333

Class Name                                        : Numbers
Data Member/Instance Variables    :
number                                     : long type
Member Functions:
boolean isArmStrong()              : checks whether the number is Armstrong or not.
boolean isArmStrongLike()                   : checks whether the number is ArmstrongLike numbers or not.
void genArmStrongNos()                      : generates Armstrong number

void genArmStrongLikeNo()                : generates Armstrong number Like

Specify the class Numbers, giving the details of the above member data and methods only. Define the main() function to create an object and call the member function accordingly to enable the task.

SECTION – C

Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
The programs must be written in Java.

Question 10                                                                                                                [5]

Show the output of the following code;

public class BreakDemo

{

   public static void main(String[] args)

   {

      for (int i = 1; i <= 10; i++)

      {

         if (i == 5)

         {

            break;   

         }

    System.out.print(i + ” “);

      }

  System.out.println(“Loop is over.”);

   }

          }

 Question 11                                                                                                                [5]

The following function is a part of some class. Assume n is a positive integer. Answer the given questions along with dry run/working.

int unknown(int n)

{

int I, K;

if(n%2==0)

{
I=n/2;

            K=1;

}

else

{

K=n;

n–;

I= n/2;

}

while(I >0)

{

K=K*I*n;

I–;

n–;

}

return k;

}

  • What will be returned by unknown(5) ?
  • What will be returned by unknown(7) ?

Question 12                                                                                                                [5]

Briefly describe static and instance member with example.

 

 

Model Question Paper – ISC computer science -July 2018


PART – I (20 Marks)
Answer all questions.
While answering questions in this Part, indicate briefly your working and
reasoning, wherever required.

Question 1

  1. State the involution law. Prove anyone using truth table.                       [1]
  2. Simplify expression using Boolean laws
    F1=a.b’ + a’ + a’.b +b’                                                                                                [1]
  3. Find the complement of :

F 2 =(a’ +c’ +d)(b +c+d’)(a+b’+c)                                                                                        [1]

  1. Verify using truth table ( ~p ^ q) V (p^q) = q.                                                  [1]
  2. Write the dual of F3 = p’.0 + q.1 +r’                                                                     [1]

Question 2

  1. An array D [-2…10][3…8] contains double type elements. If the base address is
    4110, find the address of D[5][5], when the array is stored in Column Major Wise. [2]
  2. I) What do you understand by the keyword : Integer                                          [2]      
  3. Write the syntax of a string input.
  4. From the premises p àq and q àp, conclude q’ +pq                                               [2]
  5. What are wrapper classes? Give two examples.                                                    [2]
  6. State De Morgan’s laws. Verify anyone using truth table                                    [2]

 

 


Question 3

  1. Given the following method                                                                                          [5]

void fnM(int p)

{

int RM[]={3,6,9,12,15};

for( int j=1; j<=RM.length-1; j++)

{

RM[j-1] = RM[j-1] +RM[j];

RM[j] = RM[j-1] *3;

}

System.out.print(“OUTCOME=” +RM[p]);

}
i)What will be the output if p=2?
ii)What will be the output if p=4?
iii)Which token finds the size of the array?
PART II (50 Marks)
Answer six questions in this part, choosing two questions from Section A,
                               two from Section B and two from Section C.
SECTION – A
                                    Answer any two questions

Question 4

  • Given the Boolean function : F(A,B,C,D) =Ʃ(0,2,4,5,8,9,10,12,13)
    i)  Reduce the above expression by using 4 variable Karnaugh map, showing                                                                                                                                 [4]
    the various groups (i.e., octal, quads, pairs).
    ii) Draw the logic gate diagram for the reduced expression. Assume that the                                                                                                                                           [1]
    variables and their complements are available as inputs.
  • Given the Boolean function : F(P, Q,R,S) =Π (0, 1, 3, 5,7, 8, 9,10,11,14,15)
  • Reduce the above expression by using 4 variable Karnaugh map, showing   [4]
    the various groups (i.e., octal, quads, pairs).
  • Draw the logic gate diagram for the reduced expression. Assume that the        [1]
    variables and their complements are available as inputs.

Question 5

  • Given the Boolean function: F(A,B,C,D)=  Ʃ(5,6,7,8,9,10,14)
    a. Reduce  the above expression by using 4-variable K map, showing the various groups   (i.e., octet, quads and pairs)                                                                                                                                         [4]
  1. b. Draw the logic gate diagram for the reduced expression. Assume that the  [1]
    variables and their complements are available as inputs.

 

  • Given the Boolean function: F (A, B, C, D) =(A+B+C+D)(A+B+C+D’)(A+B+C’+D’)(A+B+C’+D)(A+B’+C+D’)(A+B’+C’+D)(A’+B+C+D)(A’+B+C’+D)
    Reduce the above expression by using 4 variable K map showing the various     groups (i.e., octet, quads and pairs).             
  1. Draw the logic gate diagram for the reduced expression. Assume that the
    variables and their complements are available as inputs                                                             

Question 6

A person is allowed to travel in a reserved coach of the train, if he/she satisfies any one of the criteria given below:

The person has a valid reservation ticket and a valid ID, proof.

The person does not have a valid reservation ticket, but holds a valid pass issued by the Railway department with a valid ID proof.

The person is a senior citizen and holds a valid pass issued by the Railway department along with a valid ID proof.
The inputs are:

INPUTS
R                     The person has a valid reservation ticket

P                      The person holds a valid pass issued by the Railway department

D                     The person has a valid ID proof.

S                      The person is a senior citizen
(in all the above cases 1 indicates yes and 0 indicates no for all cases)

Output:            T – Denotes allowed to travel [1 indicates yes and 0 indicates no.]
Draw the truth table for the inputs and outputs given above and write the SOP expression for T(R, P, D and S).                                                                                                    

What is redundant group?                                                   [2]
Convert the following Boolean expression into its Canonical SOP form:             [3]
XY’ + X’Y + X’Z’                

                                              SECTION – B

                                      Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
The programs must be written in Java.

Question 7

A class SeriesSum is desgined to calculate the sum of the following series:                         [10]
Sum = x2/1! + x4/3! + x6/5! + xn/(n-1)!
Some of the members of the class are given below:
class name                   :           SeriesSum
Data members/ instance variables :
x                      :           to store an integer number
n                      :           to store number of terms
sum                  :           double variable to store the sum of the series

Member functions:
SeriesSum(int xx, int nm)       : constructor to assign x=xx and n=nn
double findfact(int m)                        : to return the factorial of m using recursive technique
double findpower(int x, int y) : to return x raised to the power of y using recursive technique
void calculate()                       : to calculate the sum of the series by invoking the recursive functions respectively.
void display()                          : to display the sum of the series.
Specify the class
SeriesSum, giving the details of the above member data and methods only. Define the main() function to create an object and call the member function accordingly to enable the task.

Question 8                                                                                                                             

  1. Write a program in Java to perform Bubble Sort in a given array of integers in ascending order.
  2. Write a program to obtain maximum and minimum element in an array using
    maximum( int[] t) and minimum( int[] t). Also define a main() and call the
    methods to enable the task.

Question 9                                                                                                                              [10]

A class Binary defines a recursive function to convert a binary number into its equivalent decimal form.
Example: Let Binary number 1101, its equivalent decimal 1*23 + 1*22 +0*21 + 1*20= 8+4+0+1=13.
The details of the class are given below:
class name                  :           Binary
Data members/ instance variables :
bin                               :           long integer data to store binary number
de                                :           long integer data to store decimal number
Member functions/methods:
Binary()                       :           default constructor
void readBin()             :           to read a binary number in bin.
long convertDec(long):           to convert the binary number stored in
bin into its equivalent decimal using Recursive technique. Store the decimal number into dec and return.
void Show()                :           to display the binary number and its equivalent decimal number stored in
dec by invoking the recursive function.

Specify the class Binary, giving the details of the above member data and methods only. Define the main() function to create an object and call the member function accordingly to enable the task.

SECTION – C

Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
The programs must be written in Java.

Question 10                                                                                                                            [5]

Show the output of the following code;

( In all output questions you must give dry run/ working and after that final output should be written.)

void fnCheck(int n)

{

int s=0,t=1;
do
{

n=n/t++;

System.out.println(“n =”+ n+ “t =” +t);

} while(n>0);

}

  1. What will be the output if n=25?

 

Question 11                                                                                                                            [5]

The following is a public member function of some class which finds whether an integer number ‘n’ is a perfect number or not. There are five places in the code marked as ?1?, ?2?, ?3?, ?4?, ?5? which must be replaced by the expressions or statements so that the program works correctly. Answer the questions given after function.

void Check_Number(int a)

{

int s = ?1? ;

for (int q=1; q <n; q++)

{

if(a% ?2? ==0)

s=s+ ?3?;

}

if( ?4? === ?5?)

System.out.println(n+ “is a perfect number”);

else

System.out.println(n+ “is not a perfect number”);

}

  1. What is the expression or statement at ?1?
  2. What is the expression or statement at ?2?
  3. What is the expression or statement at ?3?
  4. What is the expression or statement at ?4?
  5. What is the expression or statement at ?5?

Question 12                                                                                                                            [5]

The following is a function of some class which sorts an array arr[] in descending order using the bubble sort technique. There are five places in the code marked by ?1?, ?2? , ?3? , ?4? , ?5? which must be replaced by an expression or statement so the function works correctly.

void bubblesort(int arr[])  {

int i, j, k, temp;

for(i=0;i < ?1? ; i++)

{

for( j=0; j< ?2? ; j++)

{

if(?4??3?){

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]= ?5? ;

}

}

  1. What is the expression or statement at ?1?
  2. What is the expression or statement at ?2?
  3. What is the expression or statement at ?3?
  4. What is the expression or statement at ?4?
  5. What is the expression or statement at ?5?

 

Model Question Paper ISC Computer Science 2018


PART – I (20 Marks)
Answer all questions.
While answering questions in this Part, indicate briefly your working and
reasoning, wherever required.

Question 1

  1. State the involution law. Prove anyone using truth table.                   [1]
  2. Convert the following expression into its canonical POS form:                                     F(X,Y,Z)=(X+Y’).(Y’+Z)                                                                                    [1]
  3. If F(A,B,C)=A’(BC’+B’C), then find F’.                                                          [1]
  4. Verify using truth table ( P ^ Q) V (P ^ ~Q) = P.                                        [1]
  5. Write the dual of (A’+B).(1+B’)=A’+B                                                          [1]

Question 2

  1. Each element of an array DR[-5..2, -2..5] requires one byte of storage. If the array is stored in column major order beginning location 3500, find the address of DR [0,0].
  2. State the difference between instance member and static member. How to access
    non static members to static method?
  1. What is map rolling? What is redundant group?
  2. What is recursion? Write the types of recursion with example.
  3. A 2D array as X[3..6,-2…2] requires 2 bytes of storage space for each element. If the array is stored in Row major order, determine the address of X[5,1] given the base address as 1200.

 

Question 3                                                                                                                                   [5]

  1. The following function is a part of some class. What will the function Check() return when the values of both ‘m’ and ‘n’ are equal to 5? Show the dry run / working.

int Check(int m, int n)

{ if(n==1)
return – m–;
else
return ++m + Check(m, –n);
}

PART II (50 Marks)
Answer six questions in this part, choosing two questions from Section A,
                               two from Section B and two from Section C.
SECTION – A
Answer any two questions

Question 4

  • Given the Boolean function : F(A,B,C,D) =Ʃ(0,2,4,8,9,10,12,13)
    i)  Reduce the above expression by using 4 variable Karnaugh map, showing               [4]
    the various groups (i.e., octal, quads, pairs).
    ii) Draw the logic gate diagram for the reduced expression. Assume that the              [1]
    variables and their complements are available as inputs.
  • Given the Boolean function : F(P, Q,R,S) =Π (0, 2,4,5,6,7,8,10,13,15)
  • Reduce the above expression by using 4 variable Karnaugh map, showing      [4]
    the various groups (i.e., octal, quads, pairs).
  • Draw the logic gate diagram for the reduced expression. Assume that the        [1]
    variables and their complements are available as inputs.

Question 5

  1. A training institute intends to give scholarship to its students as per the criteria given below:
    The student has excellent academic record but is financially weak.
    OR
    The student does not have an excellent academic record and belongs to a backward class.
    OR
    The student does not have an excellent academic record and is physically impaired.
    The inputs are:
    Inputs
    A         Has excellent academic record
    B         Financially sound
    C         Belongs to a backward class
    I          Is physically impaired
    (In all the above cases 1 indicate yes and 0 indicates no).
    Output: X[1 indicate yes, 0 indicates no for all cases]
    Draw the truth table for the inputs and outputs given above and write the SOP expression for X(A,F,C,I).                                                                                                        [5]
  2. Using the truth table, state whether the following proposition is a tautology, contingency or a contradiction. ~(A ^  B) V ( ~A => B)                                                     [3]
  3. Simplify the following expression, using Boolean laws :
    A. (A’ +B).C.(A+B)

Question 6

  1. Differentiate between Half Adder and Full Adder. Draw the logic circuit diagram for a Full Adder.                                                                                                                            [4]
  2. Describe about universal gates with logic diagram and truth table.                          [3]
  3. Write two inferences rules and inferred using algebraic method.                             [3]

SECTION – B

     Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
The programs must be written in Java.

Question 7

A class SeriesSum is desgined to calculate the sum of the following series:                                  [10]
S= 1 + x/1! + x3/2! + x5/3! +…….+ x2n-1/n!
Some of the members of the class are given below:
class name                    :           SeriesSum
Data members/ instance variables :
x                                              :           to store an integer number
n                                              :           to store number of terms
sum                                          :           double variable to store the sum of the series

Member functions:
SeriesSum(int xx, int nm)      : constructor to assign x=xx and n=nn
double findfact(int m) : to return the factorial of m using recursive technique
double findpower(int x, int y) : to return x raised to the power of y using recursive technique
void calculate()                          : to calculate the sum of the series by invoking the recursive functions respectively.
void display()                             : to display the sum of the series.
Specify the class SeriesSum, giving the details of the above member data and methods only. Define the main() function to create an object and call the member function accordingly to enable the task.

Question 8

Two matrices are said to be equal if they have the same dimension and their corresponding elements are equal.
For example, the two matrices A and B given below are equal:

Matrix A                                  Matrix B

1   2   3                                    1    2    3
2   4   5                                    2    4    5
3   5   6                                    3    5    6

Design a class EqMat to check if two matrices are equal or not. Assume that the two matrices have the same dimension. Some of the members of the class are given below:
Class name                 :  EqMat
Data members/Instance variables:
a[][]                             : to store integer elements
m                                 : to store the number of rows
n                                  : to store the number of columns
Member fuctions/Methods:
EqMat( int mm, int nn)                      : parameterized constructor to initialize the data members m=mm and n=nn
void readarray()                                 : to enter elements in the array
int check(EqMat P, EqMat Q)          : checks if the parameterized objects P and Q are equal and returns 1 if true, otherwise returns 0.
void print()                                          : displays the array elements.
Define the class EqMat giving details of the constructor(), void readarray(), int check(EqMat,EqMat) and void print(). Define the main() to create objects and call the functions accordingly to enable the task.

Question 9                                                                                                                              [10]

A Jumbled String contains all type of characters in it. A class JUMBLE is designed to reorganize the characters of a Jumbled String. Some of the members of the class are given below:
Class Name                                        : JUMBLE
Data Member/Instance Variables    :
jum                               :           the jumbled string
Member functions:
JUMBLE()                   :           constructor to initialize member string to null
void fnInput()                :           to input the jumbled string
void fnShow()               :           to show the member string and the modified string with proper messages
String fnOrganize()        :           to return a string that contains the Upper Case alphabets then the Lower case alphabets and then the digits and then the special characters of string jum.
Specify the class JUMBLE, giving the details of the above member data and methods only.

EXAMPLE :
input:    abc234ABC
output: ABCabc234                             SECTION – C
                                                     Answer any two questions.
Each program should be written in such a way that it clearly depicts the logic of the problem. This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are
not required.)
                                       The programs must be written in Java.

Question 10                                                                                                                            [5]

The following function is a part of some class. Assume x and y are positive integers with value greater than 0. Answer the given questions along with dry run/working.
void someFun(int x, int y)    {
if(x > 1 && x>y)     {
System.out.print(“\n SomeFun x=”+x +”y=”+y);
if(x%y==0)   {
System.out.print(“\n”+y+”…”);
SomeFun(x/y7, y);  }
else
someFun(x,y+1);
}          I)          What will be returned by someFun(210,2)?
II)        What will be returned by someFun(77,5)?
III)       What will happen for someFun(5,10)?

Question 11                                                                                                                            [5]

Given the code, answer the questions following it

void fnQ(int p, int q)
{ int mx=Math.max(p,q);
int my=Math.min(p,q);
while(my <=mx)  {

p=p+q;
q=p+q;
System.out.println(“P=”+p+”Q=”+q);
my++;   }  }

  1. What will be the output of fnQ(4,5)?
  2. What will be the output of fnQ(10,8)?

Question 12                                                                                                                            [5]

Write a program in Java to sort an array in ascending order using Selection Sort.

Model Question ICSE Computer Applications 2018


Question 1                                                                                                                              [10]

  1. What is dynamic initialization, with an example?
  2. How are the following passed in Java? i) primitive types ii) reference types
  3. Consider the following class:
    public class myClass {
    public static int x=3, y=5;
    public int a=2, b=3; }
    i)          Name the variables for which each object of the class will have its own
    distinct copy.
  4. ii) Name the variables that are common to all objects of the class.
  5. Create a class with one integer instance variable and one class variable. Initialize the variable using i) default constructor (ii) parameterized constructor
  6. Write a java statement to create an object mp4 of class digital.

Question 2                                                                                                                               [10]

  1. Differentiate between String and Stringbuffer type data.
  2. Here is a skeleton definition of a class
    class Sample {
    int i;
    char c;
    float f;
    } Implement the constructor.
  3. What will be the output of the following code fragment?
    If the input given is i) 7 ii) 5
    if(a=5)
    out.println(“Five”);
    else
    System.out.println(“Not Five”);
  4. Differentiate between
    i) equals() and compareTo() with examples and return value.
  5. ii) throw and throws
  6. Write an expression in Java for  x4+ 6x2 + 25 / x

Question 3                                                                                                                               [10]

  1. What are the values of x and y when the following statements are executed?
    int a=63, b=36;
    boolean x=(a>b) ?a:b;
    int y=(a<b)?a:b;
  2. What will be the result stored in x after evaluating the following expression?
    int x =4;
    x+ = (x++ ) + (++x) +x;
  3. State the method that:
    i) Converts a string to a primitive float data type.
  4. ii) Determines if the specified character is an uppercase characters.
  5. Write the Identifier Naming Rules. (All rules)
  6. Rewrite the following program segment using the if –else statements instead of the ternary operator.

String grade= (mark >= 90)?”A”: (mark >=80)? “B”: “C”;

Question 4                                                                                                                               [10]

  1. Give the output of the following code
    double m=6.25, n=7.45;
    out.println(Math.sqrt(m));

System.out.println(Math.min(m,n));

System.out.println(Math.abs(6.25-7.45));
System.out.println(Math.ceil(m));

  1. Name the type of error (syntax, runtime or logical error) in each case given below:
    i) Division of a variable that contains a value of zero.
    ii) Multiplication operator used when the operation should be division
    iii) Missing semicolon
  2. Write a java statement to input/read the following from the user using the keyboard.
  3. Character ii) String (using scanner class)
  4. Write about the differences between Primitive and Reference data types with example.
  5. What is temporary instance with example?

     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.
Flow-Charts and Algorithms are not required.

Question 5                                                                                                                              [15]
Given below is a  hypothetical table showing rate of income tax for male citizens below the age of 65 years.
Taxable income(Ti) in Rs.                                                    Income Tax in Rs.
Does not exceed Rs. 1,60,000                                                                        Nil
Is greater than Rs.1,60,000 and less
than or equal to Rs. 5,00,000                                             (Ti-1,60,000)* 10%
Is greater than Rs. 5,00,000 and less than or
equal to Rs. 8,00,000                                                      [(Ti – 5,00,000) * 20%] +34,000
Is greater than Rs. 8,00,000                                                    [(Ti – 8,00,000)* 30%] + 94,000

 

Write a program to input that age, gender (male or female) and taxable income of a person. If the age is more than 65 years or the gender is female, display “Wrong category”. If the age is less than or equal to 65 years and the gender is male, compute and display the income tax payable as per the table given above.
Question 6                                                                                                                              [15]

 

Define a class Library having the following description:

Instance variables/Data members:

int acnum        stores the accession number of the book

String title       stores the title of the book

String author   stores name of the author.

Member Methods:

  1. void input() –           to input and store accession number, title and author.
  2. void compute() –           to accept the number of days late, calculate and display the fine charge at the rate Rs. 2 per day.
  • void display() –           to display the details in the following format:

 

Accession number                             Title                            Author

Write a main() to create an object of the class and call the above member methods.

 

Question 7                                                                                                                              [15]

Write a program to accept a word and convert it into lower case if its in uppercase and display the new word by replacing only the vowels with the preceeding characters.

Sample Input : computer
Sample Output : cnmpttdr

 

Question 8                                                                                                                              [15]

Write a program that encodes a word into Piglatin. To translate a word into a Piglatin word, convert the word into upper case and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end following by  “YZ”.

Sample input : Flowers     Sample Output: OWERSFLYZ
Sample input : Olympics         Sample Output : OLYMPICSYZ
Question 9                                                                                                                              [15]

 

Design a class named FruitJuice with the following description:

Instance variables/Data members:

int product_code         –           stores the product code number

String flavor                –           stores the flavor of the juice (eg: orange, apple etc.)

String pack_Type        –           stores the type oif packaging (eg:tetra-pack, PET bottle etc.)

int pack_size               –           stores package size(eg: 200mL, 400 mL, etc.)

int product_price         –           stores the price of the product.

Member Methods:

  1. FruitJuice() –           deault constructor to initialize integer data members to 0 and String data members to “”
  2. void input() –           to input and store the product code, flavor, pack type, pack size and product price.
  • void discount() –           to reduce the product price by 10%.
  1. void display() –           to display the product code, flavor, pack type, pack size and product price.

Write a main method to create an object of the class and call the above member methods.

 

Question 10                                                                                                                            [15]

Design a class to overload a function JoyString() as follows:

  1. void JoyString(String s, char c1, char c2) :  with one string argument and two character arguments that replaces the character argument c1 with the character argument c2 in the given string s and prints the new string with first character as uppercase.

Example:  s=”technology”
c1=’a’, c2=’o’
Output: “Technology”

  1. void JoyString(String s1, String s2) : check and print string having more characters compared to the other one.
  • void JoyString(String s) : prints the position of the first space and last space of the given string s.
    Example :  Input value of= “Cloud computing means Internet based computing”
    Output: First index= 5, Last index = 36

Write the main() and call the above member methods.

 

Sort the array elements in ascending order


A class Collection contains an array of  100 integers. using the following class description create an array with common elements from two integer arrays.

Class name  : Collection
Data members
arr[], len
Member functions:
Collection()   : default constructor
Collection(int) : parameterized constructor to assign the length of the array
void input()    : to accept the array elements
Collection common(Collection) : returns a Collection containing the common elements of current Collection object and the Collection object passed as a parameter.
void arrange()  : sort the array element of the object containing common elements in ascending order using any sorting technique
void display()  : displays the array elements
Define the main() to call above member methods.

Program

import java.util.*;
class Collection
{
int arr[];
int len;
Collection()
{
arr=new int[10];
len=10;
}
Collection(int size)
{
arr=new int [size];
len=size;
}
public void input(){
Scanner sc=new Scanner(System.in);
int val=0;
for(int i=0;i<len;i++)
{
System.out.println(“Enter the elements “+(i+1));
val=sc.nextInt();
arr[i]=val;}
}
private void setLength(int le)
{
len=le;
}
public Collection common(Collection c2)
{
Collection c3=new Collection();
int val, k=0;
for(int i=0;i<len;++i)
{
val=arr[i];
for(int j=0;j<c2.arr.length ; ++j) {
if(val==c2.arr[j]) {
k++;
}
}
}c3.setLength(k);
return c3;
}
public void display()
{
for(int i=0;i<len;i++) {
System.out.print(arr[i]+””);
}
System.out.println();
}
public void arrange()
{
for(int i=len-1;i>=0;i–)
{int highestIndex=i;
for(int j=i;j>=0;j–)
{
if(arr[j]>arr[highestIndex])
highestIndex=j;
}
int temp=arr[i];
arr[i]=arr[highestIndex];
arr[highestIndex]=temp;
}
display();
}

public static void main(String args[])
{
Collection c1=new Collection(10);
Collection c7= new Collection();
c1.input();
System.out.println(“Display the entered matrix”);
c1.display();
System.out.println(“Ascending order”);
c1.arrange();
c7=c7.common(c1);
}
}

Output:

Enter the elementts 1
9
Enter the elements 2
8
Enter the elements 3
7
Enter the elements 4
6
Enter the elements 5
5
Enter the elements 6
4
Enter the elements 7
3
Enter the elements 8
2
Enter the elements 9
1
Enter the elements 10
10
Display the entered matrix
9 8 7 6 5 4 3 2 1 10
Ascending order
1 2 3 4 5 6 7 8 9 10

Clockwise Spiral matrix/circular matrix in java


import java.util.*;
class Circular_Matrix
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements : ");
int n = sc.nextInt();

int A[][] = new int[n][n];
int k=1, c1=0, c2=n-1, r1=0, r2=n-1;

while(k<=n*n)
{
for(int i=c1;i<=c2;i++)
{
A[r1][i]=k++;
}

for(int j=r1+1;j<=r2;j++)
{
A[j][c2]=k++;
}

for(int i=c2-1;i>=c1;i--)
{
A[r2][i]=k++;
}

for(int j=r2-1;j>=r1+1;j--)
{
A[j][c1]=k++;
}

c1++;
c2--;
r1++;
r2--;
}

/* Printing the Circular matrix */
System.out.println("The Circular Matrix is:");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+ "\t");
}
System.out.println();
}
}
}

Output:

Enter the number of elements : 3
The Circular Matrix is:
1 2 3
8 9 4
7 6 5

Random numbers


class TEST
{
public static void main(String a[]){
System.out.println(“Random number between 0 and 1 : ” + Math.random());
System.out.println(“Random number between 0 and 1 : ” + Math.random());

// Now let’s get random number between 1 and 10
for(int i=1;i<=6;i++)
{
System.out.println(“Random value between 0 and 6 : ”
+ getRandomInteger(0,6));
}

public static int getRandomInteger(int maximum, int minimum){
return ((int) (Math.random()*(maximum – minimum))) + minimum;
}

Output:

Random value between 0 and 6 : 1
Random value between 0 and 6 : 5
Random value between 0 and 6 : 6
Random value between 0 and 6 : 2
Random value between 0 and 6 : 6
Random value between 0 and 6 : 6

 

Recursive method


Find the output of the following fragment:

public class st
{

static int strange(int x,int y)
{
if(x>=y)
{
x=x-y;
return strange(x,y);
}
else
return x;
}

}

 

dry run

1    x=20,y=5               strange(20,5)

2.  x=15,y=5                strange (15,5)

3. x=10,y=5                strange (10,5)

4. x=5,y=5                   strange(5,5)

5. x=0,y=5                   strange(0,5)

returns  0;

 

Factorial using loop and using recursive method


Factorial of a number is the product of all descending numbers from the given number n. 

Example 5!  Means 5*4*3*2*1

The product of the descending numbers from 5 is 120.

Let’s look, can write a program using loop and recursion.

Looping statements 3

1. for loop

2. while loop

3. do while loop

I. Using for  loop

class FactorialLoop1
{  
 public static void main(String args[])
{  
  int i,fact=1;  
  int number=5; // to find the factorial of value that assigned to the variable number
  for(i=1;i<=number;i++)
{    
      fact=fact*i;    
  }    
  System.out.println("Factorial of the given number "+number+" is: "+fact);    
 }  
}  

Output

Factorial of the given number 5 is : 120.

2. Using while loop

class FactorialLoop2
{  
 public static void main(String args[])
{  
  int i=1, fact=1;
  int number=5; // to find the factorial of value that assigned to the variable number
while( i<=number)
{    
      fact=fact*i;    
      i++;
  }    
  System.out.println("Factorial of the given number "+number+" is: "+fact);    
 }  
} 

Output

Factorial of the given number 5 is:  120.

III. Using do while loop

class FactorialLoop3
{  
 public static void main(String args[])
{  
  int i=1, fact=1;
  int number=5; // to find the factorial of value that assigned to the variable number
do
{    
      fact=fact*i;    
      i++;
  }   while( i<=number);
  System.out.println("Factorial of the given number "+number+" is: "+fact);    
 }  
} 

Output

Factorial of the given number 5 is : 120.

Using Recursion

class FactorialUsingRecursion 
 static int factorial(int n)
{
  if (n == 0)    
    return 1;    
  else    
    return(n * factorial(n-1));    
 }    
 public static void main(String args[]){  
  int  fact=1;  
  int number=5; //It is the number to calculate factorial    
  fact = factorial(number);   
  System.out.println("Factorial of the given number"+number+" is: "+fact);    
 }  
}  

Output

Factorial of the given number is: 120

Welldone my dear students


Really, I am so glad to share my students results that declared on today at 3 pm from the council. ICSE and ISC results and my students of 66 from ICSE and 3 students from ISC has secured 100% success in all subjects. Especially for computer science one centum in ICSE and with 30 out of 66 scored above 95. ISC students secured 89 as highest marks and one of my computer science student is the school first. Today again I am proud to be as a teacher for my students. God gave me another golden quill to me as the way of my students result. 

To find the sum of the given digits


Write a program in Java to find the sum of the given digits.

import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException
{
int n,sum=0,rem;
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
System.out.println(“Enter the value of ‘n’ : “);
n=Integer.parseInt(br.readLine());
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
System.out.println(“The sum of digits : “+sum);
}
}

 

Output:

Enter the value of ‘n’ :
12345
The sum of digits : 15