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.

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”

ISC – Model Question Paper -October 2018


Question 1

  1. Draw the truth table and logic diagram for the 2 inputs XOR gate. [1]
  2. Using the truth table, verify the following expression. X+(Y+Z) = (X+Y)+Z [1]
  3. If F(A,B,C)=A.B’+A’+A’.B+B’, then find F’.                                                 [1]
  4. Verify using truth table ( A ^ ~B ) V (~A ^ B) V A = AVB                                     [1]
  5. Simply the given expression using Boolean laws: F1=(a+c’).(a’+b’+c’) [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. Write a java statement for the following:
    i) write data to a file “emp.dat” in binary form.
    ii) Read data from a file “story.txt” in text form.                             [2]
  3. Convert the following infix to postfix form:
    ((M/N-P) * (Q+R)) /(C+D)     [2]
  4. State one case when the error “Queue Overflow” occur.                                                  [2]
  5. Convert from infix to prefix form P*Q/R*(S+T/(U-V))                                            [2]

 

Question 3                                                                                                                                   [5]

The following function witty() is a part of some class. What will be the output of the function witty() when the value of n is “SCIENCE” the value of p is 5. Show the dry run/working.
void witty(String n, int p) {
if (p<0)
System.out.println(“”);
else{
System.out.println(n.charAt(p) +”.”};
witty(n, p-1);
System.out.println(n.charAt(p));
}
}

                                             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,5,7,8,10,11,13,14,15)
    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 using NAND gates only.    [1]
    Assume that the variables and their complements are available as inputs.
  • Given the Boolean function : F(P, Q,R,S) =Π (2,3,6,7,9,11,12,13,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 using NOR gates only. [1]
    Assume that the  variables and their complements are available as inputs.

Question 5

  1. The person is not an Indian citizen but has taken active part in activities for the upliftment of the nation. The inputs are:
    Inputs
          A         The person is/was an Indian citizen
    B          Has a continuous service of more than 20 years.

C         lost his/her life in a war.
D   Taken part in activities for upliftment of the nation.

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

  1. Write the cardinal form of P(A,B,C) = ABC’ +A’BC +A’BC’+ABC                     [2]

                      

Question 6

  1. Using a truth table, verify the following proposition is valid or invalid [3]
    (a
    àb) ^(bàc) =(aàc)
  2. Draw the truth table representing a 2 input XNOR gate and derive its SOP expression and draw its logic gate diagram. [2]
  3. What is a multiplexer? Draw the truth table and logic diagram of 8*1 multiplexer. [5]                                                                                                

                                                                                   

            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 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.

Question 8                                                                                                                             

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
matrixfnTrans(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

Question 9                                                                                                                              [10]

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 fnIn()        : to input the member string
void fnOp()      : 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.

                                                            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 Circle has a sub class Circumference. The details of both the classes are given below.

The details of the base class:
Class name                   : Circle

Data member/ instance variable :

int rad               : an integer to store the  radius

Member functions/methods

Circle (….)                   : parameterized constructor to initialize the data members.

void show()                  : to display the  member data.

 

The details of the derived class:

Class name                   : Circumference

Data member                :

double cir                     : to store the Circumference

Member functions

Circumference (…)                   : parameterized constructor to initialize the data members of the base and current class

void calCirum               : calculates the circumference by using the formula (2*pi*r) (pi=3.14)
void show()                  : to display the details of both the classes with proper messages(apply method overriding).
Specify the class Circumference giving the details of its mentioned methods. Assume that class Circle is already present. Write the main ().

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

 

Question 11                                                                                                                            [5]

A class  Flow allows that a user to add and delete names in a list from the same end(top). The following details of the class Flow are given below:
Class name                   :Flow

Data members :
names[]                        : a string array to hold a maximum of 10 names
top                               : stores the position of the topmost element.
Member methods:
Flow(….)                     : initialize the data member top=-1 and to create the string array
void pushName(String n): to push a name into the stack at position top, if possible, else display the message “Overflow”.
String popName()         : to remove and return element from the top. If the list is empty then return “Underflow”.

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.

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.

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

 

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

To find the sum of the first ‘n’ natural numbers – while loop


Write a program in java to find the sum of  the first ‘n’ natural numbers.

import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException
{
int n,sum=0,i=1;
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
System.out.println(“Enter the value of ‘n’ : “);
n=Integer.parseInt(br.readLine());
while(i<=n)
{
sum=sum+i;
i++;
}
System.out.println(“The sum of  first”+n+ “natural numbers:”+sum);
}
}

Output:

Enter the value of ‘n’ :
15
The sum of  first 15 natural numbers: 120

Write a program to input a word from the user and remove the duplicate characters present in it.


Write a program to input a word from the user and remove the duplicate characters present in it.

Example:

INPUT – abcabcabc
OUTPUT – abc

INPUT – javaforschool
OUTPUT – javforschl

INPUT – Mississippi
OUTPUT – Misp

Programs:

import java.io.*;

class RemoveDupChar

{

public static void main(String args[])throws IOException

{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print(“Enter any word : “);

String s = br.readLine();

int l = s.length();

char ch;

String ans=””;

for(int i=0; i<l; i++)

{

ch = s.charAt(i);

if(ch!=’ ‘)

ans = ans + ch;

s = s.replace(ch,’ ‘); //Replacing all occurrence of the current character by a space

}

System.out.println(“Word after removing duplicate characters : ” + ans);

}

}

Output:

Example 1:
Enter any word : Mississippi
Word after removing duplicate characters : Misp

Example 2:
Enter any word : Attitude
Word after removing duplicate characters : Atiude

Encrypt a character


A simple encryption system uses a shifting process to hide a message. The value of the shift can be in the range 1 to 26.

For example a shift of 7 means that A = U, B =V,C = W, etc.i e.

Text : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Code: U V W X Y Z A B C D E F G H I J K L M N O P Q R S T

Fist an extra space is added to the end of the string. To make things little more difficult, spaces within the original text are replaced with QQ before the text is encrypted. Double Q (QQ) was selected because no English word ends in Q or contains QQ.

Additionally the coded message is printed in blocks of six characters separated by spaces. The last block might not contain six characters. Write a program that takes the coded text (less than 100 characters), the shift value and prints the decoded original text.Your program must reject any non-valid value for shift and display an error message “INVALID SHIFT VALUE)”. Assume all characters are upper case. Test your program for the following data and some data that you have coded, using the rules given above:

 

SAMPLE DATA:

  1. INPUT:
    CODED TEXT : “UHINBY LKKQCH HYLKK”
    SHIFT : 7
    OUTPUT:
    DECODED TEXT : ANOTHER VALUE
  2. INPUT:
    CODED TEXT : “RUIJGG EVGGBK SAGG”
    SHIFT : 11
    OUTPUT:
    DECODED TEST : BEST OF LUCK
  3. INPUT:
    CODED TEXT : “DKSMMW NAMMUK QMM”
    SHIFT : 29
    OUTPUT:
    INVALID SHIFT VAULE

 

import java.io.*;

public class Decode

{

public static void main(String args[])throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.print(“Enter Coded Text : “); // inputting coded text

String s = br.readLine();

int l = s.length();

s = s.toUpperCase(); // converting the coded text into Uppercase

s = s + ” “; // adding a space at the end

if(l>=100) // checking whether length of inputted code is less than 100

System.out.println(“!!! Invalid Length of Coded Text !!!”);

else

{

System.out.print(“Enter the Shift Value : “);

int shift = Integer.parseInt(br.readLine());

if(shift<1 || shift>26) // checking whether shift value is between 1 and 26

System.out.println(“!!! Invalid Shift Value !!!”);

else

{

int a, b;

char ch1, ch2;

String dec=””; //new String for storing the decoded text

for(int i=0; i<l; i++)

{

ch1 = s.charAt(i); // extracting characters one by one

ch2 = s.charAt(i+1); // extracting the next character

/*  after finding each character in ch1 and ch2

*Below we are adding shift value to the characters

* if ch1 = ‘A’ and shift = 7,

* then ch1 + shift – 1 will give us: ‘A’+7-1 = 65+7-1 = 71

* which is the ASCII value of ‘G’

*/

a = ch1 + shift – 1; // storing ASCII values after adding shift to the current character

b = ch2 + shift – 1; // storing ASCII values after adding shift to the next character

 

/* If the currrent character and the next character are both ‘Q’ then we have a ‘space’

* hence the ASCII value should be 32

*/

if((char)a == ‘Q’ && (char)b == ‘Q’)

{

a = 32;

i++;

}

 

/* If ASCII value after adding the shift becomes more than 90,

* then we subtract 26 from it, to make it circular,

* eg. ‘U’+7-1 = 85+7-1 = 91, but we want ‘A’ whose ASCII value is 65

* so 91-26 will give us 65

*/

if(a>90)

a = a – 26;

if(ch1 != ‘ ‘)

dec = dec + (char)a; // finally adding the decoded character to the new String

}

System.out.println(“Decoded Text : “+dec);

}

}

}

}

 

Output

Enter Coded Text : anu

Enter the Shift Value : 2

Decoded Text : BOV

Enter Coded Text : anu

Enter the Shift Value : 8

Decoded Text : HUB

FREQUENCY OF CHARACTER IN A STRING – using array


Java program to find the frequency of each character in a given string:

import java.util.Scanner;
public class freqSample
{
public static void main(String args[])
{
String str;
int i, length, count[] = new int[256];
Scanner scanner = new Scanner(System.in);
System.out.println(“Enter a String”);
str = scanner.nextLine();
length = str.length();
// Count the frequency of each character and store
// it in count array (count[])
for (i = 0; i < length; i++)
{
count[(int) str.charAt(i)]++;
}
// Print Frequency( number of times each character occured in a string)

for (i = 0; i < 256; i++) {
if (count[i] != 0) {
System.out.println((char) i + ” – ” + count[i]);
}
}
}
}

 

Output:

Enter a String
school
c – 1
h – 1
l – 1
o – 2
s – 1

Design a class to overload a function compare()


Design a class Perform to overload a function  as follows:
(i) void compare (int, int)    – to compare two integer values and print the greater of the two integers.
(ii) void compare(char, char)  – to compare the numeric value of two characters and print with the higher numeric value.
(iii)void compare(String, String)  –  to compare the length of the two strings and print the longer of the two.

Answer:

class Perform
{
void compare(int m, int n)
{
if(m > n)
System.out.println(“The first number is greater”+m);
else
System.out.println(“The second  number is greater”+n);
}
void compare(char c, char d)
{
if(c > d)
System.out.println(“The first character is greater and the numeric  value”+(int)c);
else
System.out.println(“The second character is greater and the numeric  value”+(int)d);
}
void compare(String s1, String s2)
{
if(s1.compareTo(s2) > 0)
System.out.println(“The first string is longer”+s1);
else
System.out.println(“The second string is longer”+s2);
}

}

Program to check an alphabet using method


class Alphabet
{
 public void checkVowel(char ch)
{
if(ch==‘a’||ch==‘e’||ch==‘i’||ch==‘o’||ch==‘u’||ch==‘A’||ch==‘E’||ch==‘I’||ch==‘O’||ch==‘U’)
{
System.out.println(“Given alphabet “+ch+” is an Vowel”);
}
else if((ch>=‘a’&&ch<=‘z’)||(ch>=‘A’&&ch<=‘Z’))
System.out.println(“Given alphabet “+ch+” is Consonant”);
else
System.out.println(“Not an alphabet”);
}
public static void main(String[ ] arg)
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Enter a character : “);

char chr=(char)br.read();

checkVowel(chr);

}

}

Analyze the given code fragment


Analyze the given program segment and answer the following questions :
(i) Write the output of the code snippet.
(ii) How many times does the body of the loop gets executed?

for(int a=5; a<=20; a+=5)
{
if(a%3 == 0)
break;
else
if(a%5 == 0)
System.out.println(a);
continue;
}

answer :
(i) 5 10
(ii) 3 times

Working :

When a = 5,
if(a%3 == 0) is false
if(a%5 == 0) is true
so it prints ‘5’
Loop executed 1 time.

When a = 10,
if(a%3 == 0) is false
if(a%5 == 0) is true
so it prints ‘10’
Loop executed 2 times.

When a = 15,
if(a%3 == 0) is true
so, break is encountered and loop terminates.
Loop executed 3 times.

 

ISC Computer Science Practical – Marking pattern


ISC Computer science —  practical paper(30 marks)

Marking procedure for practical paper

Total Marks : 30

Algorithm : 3 marks

Program : 5 marks

Comments/Mnemonics code : 2 marks

Printed code that compiled correctly : 2 marks

Run the code and get correct output : 5 marks

Viva – 3 marks

Programs done in lab class throughout the year : 10 marks ( 5 from external examiner and 5 mark from your computer teacher)