ISC Sample Programs
ISC Sample Programs
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.)
Question 7
A class Composite contains a two dimensional array of order [m x n]. The maximum value [10]
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. The details of the members of the class are given below:
: Composite
Class name
Member functions/methods:
Composite(int mm, int nn ) : to initialize the size of the matrix m=mm and n=nn
void fill ( ) : to fill the elements of the array with the first (m × n)
composite numbers in column wise
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 the functions
accordingly to enable the task.
Question 8
Design a class Sort which enables a word to be arranged in alphabetical order. The details of [10]
the members of the class are given below :
Methods/Member functions:
Specify the class Sort giving details of the constructor, void readword( ), void arrange( )
and void display( ). Define the main( ) function to create an object and call the functions
accordingly to enable the task
Question 9
A Special number is a number in which the sum of the factorial of its digits is equal to the [10]
number.
Example: 145 ( 1! + 4! + 5! = 145 ). Thus, 145 is a Special number.
Design a class Special to check if the given number is a Special number or not. Some of the
members of the class are given below:
Member functions/methods:
Specify the class Special, giving details of the Constructor, void read( ), int factorial(int),
boolean isSpecial( ) and void display( ). Define the main() function to create an object and
call the member function according to enable the task.
Solution 7
import java.util.Scanner;
class Composite
{
int m;
int n;
int arr[][];
int isComposite(int p)
{
int i,count=0,num=p;
for(i=1;i<=num;i++)
{
if(num%i==0)
{
count++;
}
}
if(count>2)
return 1;
else
return 0;
}
void fill()
{
int row,column,numbers=0,check=0;
for(column=0;column<n;column++)
{
for(row=0;row<m;row++)
{
check=0;
while(check!=1)
{
check=isComposite(numbers);
numbers++;
}
numbers--;
arr[row][column]=numbers;
numbers++;
}
}
}
void display()
{
int dispr,dispc;
for(dispr=0;dispr<m;dispr++)
{
for(dispc=0;dispc<n;dispc++)
{
System.out.print(arr[dispr][dispc]+ " ");
}
System.out.println();
}
}
}
}
Question 8
import java.util.Scanner;
class Sort
{
String str,sorted;
int len;
Sort()
{
str="";
len=0;
sorted="";
}
void readword()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter word");
str=in.next();
len=str.length();
}
void arrange()
{
char letter=' ';
int i,pos,charnum=0;
for(i=65;i<=90;i++)
{
for(pos=0;pos<len;pos++)
{
letter=str.charAt(pos);
charnum=(int)letter;
if((charnum==i)||(charnum==32+i))
{
sorted=sorted+letter;
}
}
}
}
void display()
{
System.out.println("Original word : "+str);
System.out.println("Sorted word : "+sorted);
}
Question 9
import java.util.Scanner;
class Special
{
int n,fact;
Special()
{
n=0;
fact=0;
}
void read()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number");
n=in.nextInt();
}
int factorial(int x)
{
if(x==1)
return 1;
else
fact=factorial(x-1)*x;
return fact;
}
boolean isSpecial()
{
int rem,sum=0,ncopy=n;
while(ncopy>0)
{
rem=ncopy%10;
sum=sum+factorial(rem);
ncopy=ncopy/10;
}
if(sum==n)
return true;
else
return false;
}
void display()
{
boolean check=isSpecial();
if(check==true)
System.out.println("Special number");
else
System.out.println("Not special number");
}