Showing posts with label ISC. Show all posts
Showing posts with label ISC. Show all posts

Tuesday, November 5, 2024

BlueJ Program On 2 D Array and Sorting


Details of The Program: CLICK HERE

import java.io.*; 
public class P 
{ 
void sort(int arr[])          //Taking single dimension array as parameter 
{

int i, j, size = arr.length, temp,flag;

/*'size' holds the number of values in the array */ 
for(i=0;i 
{

flag=0; 
/*Sorting using bubble sort technique, so if there is no exchange of values in one pass there is no need to run the loop */ 
for(j=0;j 
{ 
if(arr[j]>arr[j+1])

{
flag=1; temp = arr[j]; 
arr[j] = arr[j+1]; 
arr[j+1] = temp; 
}

} 
if(flag==0)

break;
}

}

void show(int arr[][]) /*Taking 2D array as parameter*/ 
{

int i, j; for(i=0;i

{

for(j=0;j 
/* arr[i] gives one row at a time. arr[i].length gives the number of values in each row */ 
{ 
System.out.print(arr[i][j]+"\t"); 
}

System.out.println();

} 
}
 void sort2D(int arr[][]) 
{ 

/* In java, array is an object, so here the function calling technique is call be reference means any changes made to the formal parameter in this function will be reflected in the original parameter.*/


int i, j; 
for(i=0;i 
{ 
sort(arr[i]); 
} 
}
public static void main(String args[])throws Exception 
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

P obj = new P(); int arr[][], m, n, i, j; 
System.out.println("Enter the number of rows: "); 
m = 
Integer.parseInt(br.readLine()); 
System.out.println("Enter the number of columns: ");
n = Integer.parseInt(br.readLine()); 
if(m< 2 && m >9||n >9 && n< 2) 
{

System.out.println("Matrix out of range"); System.exit(0);

} 
arr = new int[m][n]; 
for(i=0;i< 
{
System.out.println("Enter values for row no "+(i+1) + ":"); for(j=0;j
{

System.out.print("\nColumn No " + (j+1) + ":"); arr[i][j] = Integer.parseInt(br.readLine()); 
} 
}
System.out.println("Original Matrix: ");
obj.show(arr); 
obj.sort2D(arr);

System.out.println("Matrix after sorting rows: "); obj.show(arr);
}
}

Variable Description

Type
Name
Use
BufferedReader
br
Intakes limit from user
int
arr
2 D array to hold the values
Int
m
Holds no of rows in the array
int
n
Holds no of columns in the


array

int
I,j
Loop Control Variable
int
size
Holds the no of elements in


each row the array
Algorithm




Step 1: Create BufferedReader object ‘br’ and int type variables ‘n’ and 'm' to store the column and row size of the 2 D array.

Step 2: Values of ‘n’ and 'm' are checked for validity and if it is invalid, terminate the program otherwise create the 2 D array 'arr'.

Step 3: Stores the values in the two dimensional array 'arr'.

Step 4: Display the original array


Step 5: Pass the two dimensional array to function 'sort2D()' which sends each rows of the 2 d array to 'sort()' function which sorts the elements bubble sort technique.


Back To 2018 Computer Practical Paper: CLICK HERE

Sunday, December 10, 2023

2 D Array To Store Only Composite Numbers - BlueJ Program

 A class Composite contains a two-dimensional array of order [m x n]. The maximum values possible for both ‘m’ and ‘n’ is 20. Design a class Composite to fill the array with the first (m x n) composite numbers in column wise. [Composite numbers are those which have more than two factors.]The details of the members of the class are given below:

Class name: Composite

Data members/instance variables :arr[ ] [ ] :integer array to store the composite numbers column wise

 m        :integer to store the number of rows 

n:integer to store the number of columns 

Member functions/methods:

Composite(int mm, int nn ):to initialize the size of the matrix, m=mm and n=nn

 int isComposite( int p ):to return 1 if the number is composite otherwise returns 0

void fill ( ):to fill the elements of the array with the first (m × n) composite numbers in column wise

void display( ):to display the array in a matrix form Specify     the     class Composite giving     details of     the constructor(int,int), int isComposite(int), void fill( ) and void display( ). Define a main( ) function to create an object and call all the functions accordingly to enable the task.


import java.util.*;
class Composite
{
int m,n,arr[][];
Scanner sc=new Scanner(System.in);
Composite(int mm, int nn)
{
    m=mm;
    n=nn;
    arr=new int [m][n];
}
private int isComposite( int p )
{
   int i;
   for(i=2;i<p;i++)
   {
        if(p%i==0)
        break;
   }
   if(i==p)
   return 0;
   else
   return 1;
}
private void display()
{
   int i,j;
   for(i=0;i<m;i++)
   {
        for(j=0;j<n;j++)
        {
            System.out.print(" "+arr[i][j]);
        }
        System.out.println();
   }
}
void fill ( )
{
    int i,j;
   for(i=0;i<m;i++)
   {
        for(j=0;j<n;j++)
        {
            System.out.print("\nEnter Number:");
            int d=sc.nextInt();
            if(isComposite(d)==1)
            arr[i][j]=d;
            else
            {
                System.out.print("\nEnter Composite Number "+d + "  is not composite");
                j--;
            }   
        }
    }
}
public static void main(String args[])
{
    int m,n;
    Scanner sc=new Scanner(System.in);
    while(true)
    {
        System.out.print("\nEnter Row Number:");
        m=sc.nextInt();
        if(m>0 && m<=20)
        break;
    }
    while(true)
    {
        System.out.print("\nEnter Column Number:");
        n=sc.nextInt();
        if(n>0 && n<=20)
        break;
    }
Composite ob=new Composite(m,n);
ob.fill();
System.out.print("\nFinal Matrix\n");
ob.display();
}
}   
    
         
    
      

Sunday, October 1, 2023

Converting Non-Palindrome Word Into Palindrome

 Convert the non-palindrome words of the sentence into palindrome words by concatenating the word by its reverse (excluding the last character).

Example: The reverse word of HELP would be LEH (omitting the last alphabet) and by concatenating both, the new palindrome word is HELPLEH. Thus the word HELP becomes HELPLEH.

Note: The words which end with repeated alphabets, for example ABB would become ABBA and not ABBBA and XAZZZ becomes XAZZZAX.


import java.util.*;

class Ab

{

  String str1,str2;

  Scanner sc=new Scanner(System.in);

  int c=0;

  void show()

  {

      int len,i;

      c=1;

      System.out.print("\nEnter the Word:");

      str1=sc.next();

      if(notPalin(str1))

      {

         len=str1.length();

         for(i=len-1;i>0;i--)

         {

             if(str1.charAt(i)==str1.charAt(i-1))

             c++; /* 'c' marks the index where mismatch of characters happen */

            }

         }

         str2=leftRev(str1.substring(0,str1.length()-c)); 

         str1=str1+str2;

         System.out.println("\nModified="+str1);

      }

    

    private boolean notPalin(String str1)

    {

       int i,len;

       len=str1.length()-1;

       for(i=0;i<=len;i++)

       {

           if(str1.charAt(i)!=str1.charAt(len-1))

           break;

       }

       if(i<=len)

       return true;

       else

       return false;

    }

    private String leftRev(String str1)

    {

       int i,len;

       String str2="";

       len=str1.length(); 

       for(i=len-1;i>=0;i--)

       str2=str2+str1.charAt(i);

       return str2;

    }

public static void main(String args[])

{

Ab obj=new Ab();

obj.show();

}

Sunday, May 28, 2023

2023 ISC Computer Application Paper With Solutions

 

Maximum Marks: 70 Time allowed: Three hours

(Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time.)


Answer all questions in Part I (compulsory) and six questions from Part-II, choosing two

questions from Section-A, two from Section-B and two from Section-C.

All working including rough work, should be done on the same sheet as the

rest of the answer.

The intended marks for questions or parts of questions are given in brackets [].


PART I 20 MARKS

Answer all questions.

While answering questions in this Part, indicate briefly your working and reasoning, wherever required.

Question 1

(i)            According to De Morgan’s law (a + b + c’)’ will be equal to:                                                                                                         1

(a) a + b + c                                                                   (b) a + b + c

(c)     a . b . c                                                                        (d) a . b . c

(ii)             The dual of (X’ + 1) . (Y’ + 0) = Y’ is:                                                                                                                                             1

(a) X . 0 + Y . 1 = Y                                                              (b) X’ . 1 + Y’ . 0 = Y’

(c)     X’ . 0 + Y’ . 1 = Y’                                                          (d) (X’ + 0) + (Y’ + 1) = Y’

(iii)             The reduced expression of the Boolean function F(P, Q) = P’ + PQ is:                                                                                            1

(a) P’ + Q                                                                           (b) P

(c)     P’                                                                                  (d) P + Q

(iv)             If (~p => ~q) then its contra positive will be:                                                                                                                       1

(a) p => q                                                                         (b) q => p

(c)     ~q => p                                                                       (d) ~p => q

(v)             The keyword that allows multi-level inheritance in Java programming is:                                                                    1

(a) implements                                                                (b) super

(c)     extends                                                                       (d) this

(vi)             Write the minterm of F(A, B, C, D) when A = 1, B = 0, C = 0 and D = 1.                                                                                            1

(vii)             Verify if (A + A’)’ is a Tautology, Contradiction, or a Contingency.                                                                                                 1

(viii)          State any one purpose of using the keyboard this in Java programming.                                                                         1

(ix)             Mention any two properties of the data members of an Interface.                                                                                  1

(x)            What is the importance of the reference part in a Linked List?                                                                                          1

Question 2

(i)            Convert the following infix notation to prefix notation.                                                                                                    2

(A B)/C*(D + E)

(ii)             A matrix M[–6...10m 4. 15] is stored in the memory with each element requiring 4 bytes of storage. If the base

address is 1025, find the address of M[4][8] when the matrix is stored in Column Major Wise.                              2

(iii)             With reference to the code given below, answer the questions that follow along with dry run/working. boolean num(int x)

{int a=1;

for(int c=x; c>0’c/=10) a*=10;

return(x*x%a)=x;}


(a)        What will the function num() return when the value of x = 25?                                                                                              2

(b)       What is the method num() performing?                                                                                                                       1

(iv)             The following function task() is a part of some class. Assume m and n are positive integers, greater than 0. Answer the questions given below along with dry run/working.

int task(int m, int n)

{if(m==n) return m;

else if(m>n)

return task(m–n,n); else

return task(m,n–m);

}

(a)        What will the function task() return when the value of m = 30 and n = 45?                                                                           2

(b)       What function does task() perform, apart from recursion?                                                                                       1

PART II 50 MARKS

SECTION - A

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

Answer any two questions.

Question 3

(i)            Given the Boolean function F(A, B, C, D) = S(2, 3, 6, 7, 8, 10, 12, 14, 15).

(a)        Reduce the above expression by using 4-variable Karnaugh map, showing the various groups (i.e., octal, quads and pairs).                                                                                                                                                                                             4

(b)       Draw the logic gate diagram for the reduced expression. Assume that the variables and their complements are available as inputs.                                                                                                                                                                                             1

(ii)             Given the Boolean function F(A, B, C, D) = p(0, 1, 2, 4, 5, 8, 10, 11, 14, 15).

(a)        Reduce the above expression by using 4-variable Karnaugh map, showing the various groups (i.e., octal, quads and pairs).                                                                                                                                                                                             4

(b)       Draw the logic gate diagram for the reduced expression. Assume that the variables and their complements are available as inputs.                                                                                                                                                                                             1

Question 4

(i)            A shopping mall allows customers to shop using cash or credit card or any nationalised bank. It awards’ bonus points to their customers on the basis of criteria given below:                                                                                                                    5

l The customer is an employee of the shopping mall and makes the payment using a credit card.

OR

l The customer shops items which carry bonus points and makes the payment using a credit card with a shopping amount of less than `10,000

OR

l The customer is not an employee of the shopping mall and makes the payment not through a credit card but in cash for the shopping amount above `10,000

The inputs are:

 

INPUTS

 

C

Payment through a credit card

A

Shopping amount is above `10,000

E

The customer is an employee of the shopping mall

I

Item carries a bonus point

(In all the above cases, I indicates yes and 0 indicated nd.)

Output: X[1 indicates bonus point awarded, 0 indicates bonus point not awarded for all cases]

Draw the truth table for the inputs and outputs given above and write the POS expression for X(C, A, E, I).

(ii)             Differentiate between half adder and full adder. Write the Boolean expression and draw the logic circuit diagram for the SUM and CARRY of a full adder.                                                                                                                                                             3


(iii)             Verify the following expression by using the truth table:                                                                                                2

(A Ã… B)’ = (A Ã… B)

Question 5

(i)            What is an encoder? How is it different from a decoder? Draw the logic circuit for a 4 : 1 multiplexer and explain its working.            5

(ii)             Form the logic diagram given below, write the Boolean expression for (1) and (2). Also, derive the Boolean expression (F) and simplify it.                                                                                                                                                                          3

(iii)             Convert the following cardinal expression to its canonical form:                                                                                    2

F(P, Q, R) = p(0, 1, 3, 4)


 

 

 

 

 

 

Question 6


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


Design a class NumDude to check if a given number is a Dudeney number or not.                                                        10

(A Dudeney number is a positive integer that is a perfect cube, such that the sum of its digits is equal to the cube root of the number.)

Example: 5832 = (5 + 8 + 3 + 2)3 = (18)3 = 5832

Some of the members of the class are given below:

Class name                                                                      :       NumDude

Data member/instance/variable:

num                                                                    :       to store a positive integer number

Methods/Member functions:

NumDude()                                                       :       default constructor to initialise the data member with legal initial value

void input()                                                      :       to accept a positive integer number

int sumDigits(int x)                                          :  returns the sum of the digits of number x using recursive technique

void is Dude()                                                   :  checks whether the given number is a Dudeney number by invoking the function sumDigits() and displays the result with an appropriate message

Specify the class NumDude giving details of the constructor(), void input(), int sumDigits(int) and void is Dude(). Define a main() function to create an object and call the functions accordingly to enable the task.

Question 7                                                                                                                                                                                         10

A class Trans is defined to find the transpose of a square matrix. A transpose of a matrix is obtained by interchanging the elements of the rows and columns.

Example: If size of the matrix = 3, then

 

ORIGINAL

 

TRANSPOSE

11

5

7

11

8

1

8

13

9

5

13

6

1

6

20

7

9

20

Some of the members of the class are given below:

Class name                                                                      :       Trans

Data members/instance variable:

arr[][]                                                                 :       to store integers in the matrix

m                                                                         :       integer to store the size of the matrix

Methods/Member functions:

Trans(int mm)                                                  :       parameterised constructor to initialise the data member m = mm


void fillarray()                                                  :       to enter integer elements in the matrix

void transpose()                                               :       to create the transpose of the given matrix

void display()                                                    :       displays the original matrix and the transport matrix by invoking the method transpose()

Specify the class Trans giving details of the constructor(), void fillarray(), void transpose() and void display(). Define a main() function to create an object and call the functions accordingly to enable the task.

Question 8                                                                                                                                                                                        10

A class SortAlpha has been defined to sort the words in the sentence in alphabetical order. Example: Input: THE SKY IS BLUE

Output: BLUE IS SKY THE

Some of the members of the class are given below:

Class name                                                                      :       SortAlpha

Data members/instance variable:

sent                                                                    :       to store a sentence

n                                                                          :       integer to store the number of words in a sentence

Methods/Member functions:

SortAlpha()                                                       :       default constructor to initialise data members with legal initial value

void acceptsent()                                             :       to accept a sentence in UPPER CASE

void sort(SortAlpha P)                                    :       sorts the words of the sentence of object P in alphabetical

order and stores the sorted sentence in the current object

void display()                                                    :       display the original sentence along with the sorted sentence by invoking the method sort()

Specify the class SortAlpha giving details of the constructor(), void acceptsent(), void sort(SortAlpha) and void display(). Define a main() function to create an object and call the functions accordingly to enable the task.

Text Box: SECTION - C

Answer any two questions.

Each program should be written in such a way that it clearly depicts the logic of the problem stepwise.

This can be achieved by using comments in the program and mnemonic names or pseudo codes for algorithms. The programs must be written in Java and the algorithms must be written in general/standard form, wherever required/

specified.

(Flowcharts are not required.)

Question 9

A double ended queue is a linear data structure which enables the user to add and remove integers from either ends i.e., from front or rear.

The details of the class deQueue are given below:

Class name                                                                      :       deQueue

Data members/instance variable:

Qrr[]                                                                   :       array to hold integer elements

lim                                                                       :       maximum capacity of the dequeue

front                                                                    :       to point the index of the front end

rear                                                                     :       to point the index of the rear end

Methods/Member functions:

deQueue(int I)                                                     :  constructor to initialise lim = 1, front = 0 and rear = 0

void add Front(int v)                                       :  to add integers in the dequeue at the front end if possible, otherwise display the message “OVERFLOW FROM FRONT”

void add Rear(int v)                                         :  to add integers in the dequeue at the rear end if possible, otherwise display the message “OVERFLOW FROM REAR”

int popFront()                                                   :       removes and returns the integers from the front end of the dequeue if any, else returns-999

int popRear()                                                    :       removes and returns the integers from the rear end of the dequeue if any, else returns-999

void show()                                                         :       displays the elements of the dequeue


(i)       Specify the class deQueue giving details of the functions void addFront(int) and int popFront(). Assume that the other functions have been defined.                                                                                                                                                            4

The main() function and algorithm need NOT be written.

(ii)    Differentiate between a stack and a queue.                                                                                                                    1

Question 10

A super class Demand has been defined to store the details of the demands for a product. Define a subclass

Supply which contains the production and supply details of the products.                                                                                   5

The details of the members of both the classes are given below:

Class name                                                                      :       Demand

Data members/instance variable:

pid                                                                      :       string to store the product ID

pname                                                                :       string to store the product name

pdemand                                                             :       integer to store the quantity demanded for the product

Methods/Member functions:

Demand(...)                                                       :       parameterised constructor to assign values to the data members

void display()                                                      :       to display the details of the product

Class name                                                                             Supply

Data members/instance variables:

pproduced                                                           :       integer to store the quantity of the product produced

prate                                                                  :       to store the cost per unit of the product in decimal

Mathods/Member function:

Supply(...)                                                         : parameterised constructor to assign values to the data members of both the classes

double calculation()                                             : returns the difference between the amount of demand (rate × demand) and the amount produced (rate × produced)

void display()                                                      :  to display the details of the product and the difference in amount of demand and amount of supply by invoking the method calculation()

Assume that the super class Demand has been defined. Using the concept to inheritance, specify the class Supply

giving the details of the constructor(. ), double calculation() and void display(). The super class, main function and algorithm need NOT be written.


Question 11

(i)            A linked list is formed from the objects of the class given below:                                                                                  2

Class Node

{

double sal;

Node next;

}

Write and Algorithm OR a Method to add a node at the end of an existing linked list. The method declaration is as follows:

void addNode(Node ptr, double ss)

(ii)             Answer the following questions from the diagram of a Binary Tree given below:

(a) Write the pre-order traversal of the above tree structure.

1

(b) Name the parent of the nodes D and B.

1

(c) State the level of nodes E and F when the root is at level 0.

1



Solutions Coming Soon.......

Subscribe via email

Enter your email address:

Delivered by FeedBurner