ISC - Object Passing
ISC - Object Passing
S Q Y
2020
QUESTION 9 [10]
A class Mix has been defined to mix two words, character by character, in the following manner:
The first character of the first word is followed by the first character of the second word and so on.
If the words are of different length, the remaining characters of the longer word are put at the end.
Example: If the first word is “JUMP” and the second word is “STROLL”, then the required word
will be “JSUTMRPOLL”
Some of the members of the class are as follows :
Class name : Mix
Data members/instance variables :
wrd : stores a word.
len : to store the length of the word.
Member functions/methods :
Mix( ) : default constructor to initialize data members
with legal initial values.
void feedword( ) : accepts a word in UPPER CASE.
void mix_word( Mix P, Mix Q) : mixes the words of objects P and Q as stated in
the above example and stores the resultant word
in the current object.
void displays( ) : displays the word.
Specify the class Mix giving details of the constructor( ), functions void feedword( ), void
mix_word(Mix, Mix )and void display( ). Define a main( ) function to create objects and call the
methods accordingly to enable the task.
ANSWER:
// The following program is successfully compiled and executed
import [Link].*;
class Mix
{
String wrd; int len; // declaration of string and integer data members
Mix( ) // this is default or non-parameterized constructor
{
wrd = ""; len = 0; // initializing data members
}//end of the non-parameterized constructor
void feedword( ) // function to input a word in uppercase
{ Scanner br = new Scanner( [Link] ); // creation of scanner object ‘br’
[Link]("Enter a word in UPPER CASE or CAPITAL letters = " );
wrd = br . next( ); // the function next( ) will accept only one word and ignores others
len = wrd . length( ); //finding length of the input word
}//end of the function feedword( )
void mix_word( Mix P, Mix Q ) // function to mix words stored in objects P and Q
{
int i; String newWord = ""; // integer variable and string variable to store new
word
if( P . len <= Q . len ) //checking the length of words
{
for( i = 0 ; i < P . len; i++ ) //loop up to smaller length word
{
newWord = newWord + P . wrd . charAt( i ) + Q . wrd . charAt( i ); //characters by
character mixing
}//for i loop block closes
newWord = newWord + Q . wrd . substring( i, Q . len ); //mix last characters of larger
word if any
}//end of if( ) block
else //otherwise
{
for( i = 0 ; i < Q . len; i++ ) //loop up to smaller length word
{
ISC Object Passing Questions
newWord = newWord + P . wrd . charAt( i ) + Q . wrd . charAt( i ); //characters by
character mixing
}//for i loop block closes
newWord = newWord + P . wrd . substring( i, P . len ); //mix last characters of
larger word if any
}//end of else block
wrd = newWord; //storing the mixed word in original data member ‘wrd’
}//end of the function mix_word( )
void display( ) // function to print the result
{
[Link]("The original word = " + wrd );
}//end of the function display( )
public static void main( String args[ ] ) //main function starts
{
Mix obj1 = new Mix( ); // making first object ‘obj1’ of the class
Mix obj2 = new Mix( ); // making second object ‘obj2’ of the class
Mix obj3 = new Mix( ); // making third object ‘obj3’ of the class
obj1 . feedword( ); //calling function to input first word in uppercase
obj2 . feedword( ); //calling function to input second word in uppercase
obj3 . mix_word( obj1, obj2 ); //calling function that passes words in objects ‘obj1’ & ‘obj2’
to objects P & Q
obj3 . display( ); //calling function to print mixed word
}//end of the main( ) function
}//end of the class
2019
QUESTION 8
[10]
Design a class MatRev to reverse each element of a matrix.
Example: 72 371 5 27 173 5
12 6 426 21 6 624
5 123 94 5 321 49
import [Link].*;
class Mixer
{ int n, arr[ ]; // declaration of data members ‘n’ (as size) and declaration of array arr[ ]
Mixer( int nn ) // this is parameterized constructor
{ n = nn; //assign ‘nn’ to ‘n’ as size of the array
arr=new int[ n ]; //creation of array ‘arr[ ]’ of size ‘n’
}//end of parameterized constructor
void accept( ) throws IOException //function to input numbers in the ‘arr[ ]’ upto size ‘n’
{ BufferedReader br = new BufferedReader( new InputStreamReader( [Link] ) );
[Link]("Enter "+ n+ " elements in ascending order: ");
for(int i=0; i < n; i++)
{ [Link]("Enter a number : ");
arr[ i ] = [Link]( [Link]( ) );
}//end for loop
}//end of function accept( );
Mixer mix( Mixer A) //function that takes object ‘A’ as argument and also returns object
{ int c=0;
Mixer ob = new Mixer ( n+A.n ); //object ‘ob’ of class that pass n+A.n to ‘nn’ in constructor
for(int i=0 ; i < n; i++)
{ [Link][ c++ ] = arr[ i ]; //assign numbers in the current object to new array in object ‘ob’
}
for(int j =0; j < A.n; j++)
ISC Object Passing Questions
{ [Link][ c++] = [Link][ j ]; //assign numbers in the object ‘A’ to new array in object ‘ob’
}
return ob ; //returning object ‘ob’ containing the merged array
}//end of function mix( )
void display( ) //function to print the array
{ for(int i=0; i<n; i++)
[Link]( arr[ i ] );
}//end of function display( )
public static void main( String args[ ] ) throws IOException //main function starts
{
BufferedReader bx = new BufferedReader( new InputStreamReader( [Link] ) );
[Link]("Enter the size of 1st array: ");
int s1 = [Link]( [Link]( ) );
[Link]("Enter the size of 2nd array: ");
int s2 = [Link]( [Link]( ) );
Mixer obj1 = new Mixer( s1 ); //making object 1 & pass ‘s1’ to ‘nn’ in constructor as size
Mixer obj2 = new Mixer( s2 ); //making object 2 & pass ‘s2’ to ‘nn’ in constructor as size
Mixer obj3 = new Mixer( s1+s2 ); //making object 3 & pass ‘s1+s2’ to ‘nn’ in constructor
[Link]( );
//calling function to input numbers in array ‘arr[ ]’ and store in object ‘obj1’
[Link]( ); //calling function to input numbers in array ‘arr[ ]’ and store in object ‘obj2’
obj3 = [Link]( obj2 );//calling function by pssing object ‘obj2’ to object ‘A’
// Here ‘obj1’ is current object and ‘obj3’ receives the merged array
[Link]("The numbers in the 1st array are : ");
[Link]( ); //calling function to print 1st array stored in object ‘obj1’
[Link]("The numbers in the 2nd array are : ");
[Link]( ); //calling function to print 2nd array stored in object ‘obj2’
[Link]("The numbers in the merged array are : ");
[Link]( ); //calling function to print the merged array stored in object ‘obj3’
}//end of main( ) function
}//end of class
2 A class Matrix contains a two dimensional integer array of order [m * n]. The maximum value possible for 2013
both ‘m’ and ‘n’ is 25. Design a class Matrix to find the difference of the two matrices. The details of the
members of the class are given below :
Class name : Matrix
Data members /instance variables :
arr[ ][ ] : stores the matrix element
m : integer to store the number of rows
n : integer to store the number of columns
Member functions :
Matrix(int mm, int nn) : to initialize the size of the matrix m=mm and n=nn
void fillarray( ) : to enter elements of the matrix
Matrix SubMat(Matrix A) : subtract the current object from the matrix of
parameterized object and return the resulting object
void display( ) : display the matrix elements
Specify the class Matrix giving the details of the constructor(int, int), void fillarray( ), Matrix
SubMat(Matrix A) and void display( ). Define the main( ) function to create objects and call methods
accordingly to enable the task.
import [Link].*;
class Matrix
{ int m, n; int arr[ ][ ] = new int[ 25 ][ 25 ]; //declaration of variables and array
Matrix ( int mm, int nn ) // It is parameterized constructor with arguments ‘mm’ & ‘nn’
{ m = mm; n = nn; // assign ‘mm’ to ‘m’ , ‘nn’ to ‘n’ as number of rows (m) & columns (n)
}
void fillarray( ) throws IOException // function to input a matrix of ‘m’ rows & ‘n’ columns
{ BufferedReader br = new BufferedReader( new InputStreamReader ( [Link] ));
for( int x = 0; x<m; x++ )
{ for( int y = 0; y<n; y++ )
{ [Link]( "Input a number : " );
arr[ x ][ y ] = [Link]( br. readLine( ) );
}//end of for ‘y’ loop
}//end of for ‘x’ loop
}//function fillarray( ) closes here
Matrix SubMat( Matrix A ) // function that subtract two matrices using object A
ISC Object Passing Questions
{ Matrix mat = new Matrix( m , n ); // making object of class ‘mat’ within function
for( int i = 0; i<m; i++ )
{ for( int j = 0; j<n; j++ )
{[Link][ i ][ j ]=arr[ i ][ j ] - [Link][ i ][ j ]; //subtract matrix in current object and object ‘A’
}//end of for ‘y’ loop
}//end for ‘x’ loop
return ( mat ); // returning the matrix object ‘mat’ containing the subtracted values
}//end of function SubMat( )
void display( ) // function to print the matrix of ‘m’ rows and ‘n’ columns
{for( int x = 0; x<m; x++ )
{ for( int y = 0; y<n; y++ )
{ [Link]( arr[ x ][ y ] + "\t" );
}//end of for ‘y’ loop
[Link]( );
}//end of for ‘x’ loop
}//function display( ) closes here
public static void main( String args[ ]) throws IOException // beginning of main( ) function
{ BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter number of rows of matrix : " );
int row =[Link]( [Link]( ) );
[Link]("Enter number of columns of matrix : " );
int col =[Link]( [Link]( ) );
Matrix obj1=new Matrix( row, col ); //making object 1, pass ‘row’ to ‘mm’ & ‘col’ to ‘nn’
Matrix obj2=new Matrix( row, col ); //making object 2, pass ‘row’ to ‘mm’ & ‘col’ to ‘nn’
Matrix obj3=new Matrix( row, col ); //making object no 3, pass ‘row’ to ‘mm’ & ‘col’ to ‘nn’
obj1. fillarray( ); // calling function to input 1st matrix that stores in object ‘obj1’
obj2. fillarray( ); // calling function to input 2nd matrix that stores in object ‘obj2’
obj3 = [Link]( obj1 ); // calling function that passes object ‘obj1’ to object ‘A’
// and object ‘obj2’ as current object
obj3. display( ); //calling function to print the subtracted matrix stored in object ‘obj3’ }
//end of main( ) function
}
}//class clases here
3 A class Combine contains an array of integers which combines two arrays into a single array including the 2012
duplicate elements, if any, and sorts the combined array. Some of the members of the class are given below:
Class name : Combine
Data members / instance variables :
com[ ] : integer array
size : size of the array
Member functions :
Combine(int nn ) : parameterized constructor to assign size = nn
void inputarray( ) : to accept the array elements
void sort( ) : sorts the elements of combined array in ascending order using
the selection sort technique
void mix(Combine A, Combine B)
: combines the parameterized object arrays and stores the result in
the current object array along with duplicate elements, if any
void display( ) : displays the array elements
Specify the class Combine giving details of the constructor( int ), void inputarray( ), void sort( ),
void mix( Combine, Combine ) and void display( ). Also define main( ) function to create an object and
call methods accordingly to enable the task.
import [Link].*;
class Combine
{
Scanner br=new Scanner([Link]);
int arr[];
int size, i, j, k, p, t;
public Combine(int nn)
{
size=nn;
arr=new int[size];
}
public void inparr()
ISC Object Passing Questions
{
[Link]("Enter elements in an array ");
for(i=0; i<size; i++)
{
[Link]("Enter " + i + " elements in an array ");
arr[i]=[Link]();
}
}
public void mix(Combine A, Combine B)
{
k=0;
for(i=0;i<[Link];i++)
arr[k++]=[Link][i];
for(i=0;i<[Link];i++)
arr[k++]=[Link][i];
}
public void sort()
{
for(i=0;i<size;i++)
{ p=i;
for(j=i+1;j<size;j++)
if(arr[j]<arr[p]) p=j;
t=arr[i];
arr[i]=arr[p];
arr[p]=t;
}
}
public void display( )
{
[Link]("Elements in an array ");
for(i=0; i<size; i++)
[Link](arr[i]);
}
public static void main(String args[])
{
Combine obj1= new Combine(5);
Combine obj2= new Combine(5);
Combine obj3= new Combine(10);
[Link]();
[Link]();
[Link](obj1, obj2);
[Link]();
[Link]();
}
}
4 You are given a sequence of N integers, which are called as pseudo arithmetic sequences (sequences that 2011
are in arithmetic progression).
Sequence of N integers : 2, 5, 6, 8, 9, 12
We observe that 2 + 12 = 5 + 9 = 6 + 8 = 14
The sum of the above sequence can be calculated as 14 x 3 = 42.
For sequence containing an odd number of elements the rule is to double the middle element.
For example 2, 5, 7, 9, 12 = 2 + 12 = 5 + 9 = 7 + 7 = 14
14 x 3 = 42 [middle element 7]
A class Pseudoarithmetic determines whether a given sequence is a pseudo-athmetic sequence. The details
of the class are given below:
Class name : Pseudoarithmetic
Data members / instance variables :
n : to store the size of the sequence
a[ ] : integer array to store the sequence of numbers
ans, flag : store the status
sum : store the sum of sequence of numbers
r : store the sum of the two numbers
Member functions :
ISC Object Passing Questions
Pseudoarithmetic ( ) : default construtor
void accept( int nn) : to assign nn to n and to create an integer array. Fill in the
elements of the array
boolean check( ) : return true if the sequence is a pseudo-arithmetic sequence
otherwise returns false
Specify the class Pseudoarithmetic, giving details of the constructor( ), void accept( ), and boolean
check(int). Also define main( ) function to create an object and call the member functions accordingly to
enable the task.
import [Link].*;
class PseudoArithmetic
{
int n, sum, r, i, j;
boolean ans, flag;
int a[ ];
public PseudoArithmetic()
{
ans = flag = true;
sum = 0;
r = 0;
}
public void accept(int nn)
{
Scanner ob = new Scanner([Link]);
n=nn;
a = new int[n];
for(i=0; i<n; i++)
{
[Link]("Enter " + i + " element ");
a[i] = [Link]();
}
}
public boolean check()
{
r = a[0] + a[n-1];
if(n%2==0)
{
for(i=0; i<n/2; i++)
if( (a[i]+a[n-1-i]) != r)
flag = false;
}
else
{
for(j=0; j<=n/2; j++)
if( (a[j]+a[n-1-j]) != r)
ans = false;
}
if(flag==true && n%2 == 0) sum = n/2 * r;
if(ans==true && n%2 != 0) sum = (n/2 + 1)*r;
if(flag == true || ans == true) return true;
else return false;
}
public static void main(String args[])
{
int x;
Scanner ob = new Scanner([Link]);
PseudoArithmetic obj = new PseudoArithmetic();
[Link]("Enter size of sequence ");
x = [Link]();
[Link](x);
[Link]([Link]());
}
}
5 The coordinates of a point P on a two dimensional plane can be represented by P(x, y) with x as the x- 2010
coordinate and y as the y-coordinate. The coordinates of midpoint of two points P1(x1, y1) and P2(x2, y2)
can be calculated as P(x, y) where:
ISC Object Passing Questions
x = (x1 + x2) , y = (y1 + y2)
2 2
Design a class Point with the following details:
Class name : Point
Data Members/ instance variables:
x : stores the x-coordinate
y : stores the y-coordinate
Member functions:
Point( ) : constructor to initialize x = 0, y = 0
void readpoint( ) : accepts the coordinates x and y of a point
Point midpoint(Point A, Point B): calculates and returns the midpoint of the two
points A and B
void displaypoint( ) : displays the coordinates of a point
Specify the class Point giving details of the constructor( ), member functions void readpoint( ), Point
midpoint( Point, Point) and void displaypoint( ) along with the main( ) function to create an object and call
the functions accordingly to calculate the midpoint between any two given points.
import [Link].*;
class Point
{
Scanner br=new Scanner([Link]);
int x, y;
public Point()
{
x=0;
y=0;
}
public void readPoint( )
{
[Link]("Enter value of x ");
x= [Link]( );
[Link]("Enter value of y ");
y= [Link]( );
}
public void displayPoint( )
{
[Link]("Value of x is " + x);
[Link]("Value of y is " + y);
}
public Point midPoint(Point A, Point B)
{
Point D = new Point( );
D.x = (A.x + B.x)/2;
D.y = (A.y + B.y)/2;
return D;
}
public static void main(String arg[]) throws IOException
{
Point obj1= new Point();
Point obj2= new Point();
Point obj3= new Point();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]("Mid Point values are ");
obj3=[Link](obj1, obj2);
[Link]();
}
}
6 A Transpose of an array is obtained by interchanging the elements of the rows and columns. 2009
A class Transarray contains a two dimensional integer array of order [m * n]. The maximum value possible
for both ‘m’ and ‘n’ is 20.
Design a class Transarray to find the transpose of a given matrix. The details of the members of the class
are given below:
ISC Object Passing Questions
Class name : Transarray
Data members/ instance variables :
arr[ ][ ] : stores the matrix elements
m : integer to store the number of rows
n : integer to store the number of columns
Member functions/methods
Transarray( ) : default constructor
Transarray( int mm, int nn ) : to initialize the size of the matrix, m=mm, n=nn.
void fillarray( ) : to enter the element of the matrix
void transpose(Transarray A) : to find the transpose of a given matrix
void disparray( ) : displays the array in a matrix form
Specify the class Transarray giving the details of the constructors, void fillarray( ), void
transpose(Transarray ) and void disparray( ). Write the main( ) function to create an object and call the
functions accordingly.
import [Link].*;
class Transarray
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
int arr[ ][ ]=new int [20][20];
int m, n, i, j;
public Transarray(int mm, int nn)
{ m=mm;
n=nn;
}
public void fillarray( ) throws IOException
{
[Link]("Enter " + (m*n) + " elements in an array ");
for(i=0; i<m; i++)
for(j=0; j<m; j++)
{
[Link]("Enter " + i + " " + j + " elements in an array ");
arr[i][j]=[Link]([Link]());
}
}
public void disparray()
{
for(i=0; i<m; i++)
{
for(j=0; j<m; j++)
[Link](arr[i][j] + "\t");
[Link]();
}
}
public void transpose(Transarray A)
{
for(i=0; i<m; i++)
{
for(j=0; j<m; j++)
{
arr[i][j] = [Link][j][i];
}
}
}
public static void main(String args[ ]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
int x, y;
[Link]("Enter no. of rows in 2D Array ");
x=[Link]([Link]());
[Link]("Enter no. of columns in 2D Array ");
y=[Link]([Link]());
Transarray obj1= new Transarray(x, y);
Transarray obj2= new Transarray(y, x);
[Link]();
ISC Object Passing Questions
[Link]();
[Link]("Transpose of an array is ");
[Link](obj1);
[Link]();
}
}
7 A class Collection contains an array of 100 integers. Using the following class description create an array 2008
with common elements from two integer arrays. Some of the members of the class are given below:
Class name : Collection
Data members/ instance variables :
arr[ ] : Integer array
len : length of the array
Member functions/methods
Collection( ) : default constructor
Collection( int ) : parameterized constructor to assign the length of the array.
void inparr( ) : to accept the array elements
Collection common(Collection)
: returns a Collection containing the common elements of current
Collection object and the Collection object passed as a parameter
void arrange( ) : sort the array elements of the object containing common elements in
ascending order using any sorting technique
void display( ) : displays the array elements.
Specify the class Collection giving the details of the constructors, void inparr( ) and void arrange(),
Collection common(Collection). Write the main( ) function to create an object and call the functions
accordingly.
import [Link].*;
class Collection
{ BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
int arr[]=new int[100];
int len, i, j, t;
public Collection()
{
}
public Collection(int x)
{ len=x;
}
public void inparr() throws IOException
{
[Link]("Enter elements in an array ");
for(i=0; i<len; i++)
{ [Link]("Enter " + i + " elements in an array ");
arr[i]=[Link]([Link]());
}
}
public Collection common(Collection A)
{
int l=(len<[Link])? len : [Link];
Collection B= new Collection(l);
int x=0, y=0, z=0;
while(x<len && y<[Link])
{
if(arr[x]==[Link][y])
{
[Link][z]=arr[x];
x++;
y++;
z++;
}
else if(arr[x]>[Link][y]) y++;
else x++;
}
[Link]=z;
return B;
}
ISC Object Passing Questions
public void arrange()
{
for(i=0;i<len;i++)
for(j=0;j<len-1;j++)
if(arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
public void disparr()
{
[Link]("Elements in an array ");
for(i=0; i<len; i++)
{
[Link](arr[i]);
}
}
public static void main(String args[]) throws IOException
{
Collection obj1= new Collection(5);
Collection obj2= new Collection(5);
Collection obj3= new Collection(10);
[Link]();
[Link]();
[Link]();
[Link]();
[Link]("Common elements of an array are ");
obj3=[Link](obj1);
[Link]();
}
}
8 There is class Ascending that contains integers that are already arranged in ascending order. Some of the 2004
member functions/methods of Ascending are given below.
Class name : Ascending
Data members/instance variables:
int al[ ] : an array of integers sorted in ascending order
int size : number of integers in the array
Members functions/methods :
Ascending(int n) : constructor to create an Ascending list of size n
void displayList( ) : to display the list of integers
Ascending merge(Ascending al)
: to merge the Ascending list al with the current Ascending list
Object and return a third Ascending list which is also sorted in
ascending order.
Important: While generating the final Ascending list both the original Ascending lists must be scanned only
once. Elements common to the two lists should appear only once in the third Ascending list.
Specify the class Ascending giving details of the functions void displayList( ) and Ascending
merge(Ascending al) only. You may assume that the other functions are written for you. You do not need to
write the main function.
import [Link].*;
class Ascending
{
Scanner br=new Scanner([Link]);
int arr[ ];
int size, i, j, k, p, len;
public Ascending(int nn)
{ size=nn;
arr=new int[size];
}
public void inparr()
{
[Link]("Enter elements in Sorted Order ");
ISC Object Passing Questions
for(i=0; i<size; i++)
{
[Link]("Enter " + i + " elements in an array ");
arr[i]=[Link]();
}
}
public Ascending merge(Ascending A)
{ len=size+[Link];
Ascending B=new Ascending(len);
i=0;
j=0;
k=0;
while(i<size && j<[Link])
{
if(arr[i]<[Link][j])
[Link][k++]=arr[i++];
else [Link][k++]=[Link][j++];
}
if(i<size)
for(p=i;p<size;p++)
[Link][k++]=arr[p];
if(j<[Link])
for(p=j;p<[Link];p++)
[Link][k++]=[Link][p];
return B;
}
public void display()
{
[Link]("Elements in an array ");
for(i=0; i<size; i++)
[Link](arr[i]);
}
public static void main(String args[])
{
Ascending obj1= new Ascending(5);
Ascending obj2= new Ascending(5);
Ascending obj3= new Ascending(10);
[Link]();
[Link]();
obj3 = [Link](obj1);
[Link]();
}
}
9 A class Date has been defined to handle Date related functions i.e. finding the future date n days after the 2003
current date ie. Date 32 days after 01 - 01 will be 02 - 02.
Finding the number of days between the current date and date on which a project ends.
Example : if a project started 01-01 and finished on 02-02, the number of days would be 32. You may assume
that all the dates are in the year 2003 only and are valid dates. To make calculations easy each date can be
converted to its equivalent date number. Date number is the number of days between 1st January (01-01) and
the given date (dd-mm).
import [Link].*;
class Date
{
int dd,mm;
int daysInAMonth[ ]={ 31,28,31,30,31,30,31,31,30,31,30,31};
public Date(int d,int m)
{ dd=d;
mm=m;
}
int dateToDateNumber()
{
int dateNum = dd;
for(int i = 0; i<mm-1; i++)
dateNum + = daysInAMonth[i];
return(dateNum);
}
Date dateNumberToDate(int dn)
{
int m =1;
while(dn>daysInAMonth[m-1])
{ dn=dn-daysInAMonth[m-1];
m++;
}
int d=dn;
Date dat=new Date(d,m);
return dat;
}
Date futureDate(int n)
{ int fDateNum=n+dateToDateNumber( );
return dateNumberToDate(fDateNum);
}
int noOfDays(Date endDate)
{
int diff=[Link]() - dateToDateNumber();
return diff;
}
public static void main(String arg[ ]) throws IOException
{
DataInputStream ob = new DataInputStream([Link]);
int d1,m1,dd=0,mm=0;
[Link]("Enter day and month as starting date");
d1=[Link]([Link]());
m1=[Link]([Link]());
Date date1= new Date(d1,m1);
Date dd1=new Date(dd,mm);
[Link]("Enter no of days to calculate future date ");
int n1;
n1=[Link]([Link]());
dd1=[Link](n1);
[Link]([Link] + "\t" + [Link]);
}
}
10 A set is a collection in which there is no duplication of elements. S = { 1, 6, 9, 24 } is a set of 4 integer 2003
elements. An array of integers may be used to represent a set. You may assume that there will a maximum
of 50 elements in the set.
ISC Object Passing Questions
Following are some member functions of the class Set
Class name : Set
Data members/instance variables:
arr - an array of integers to store the elements of the set
n - an integer to store the total number of elements in the set
Member functions/methods:
Set(int nn) : constructor to initialize n=nn and the array arr
void readElements() : reads the elements of the set
void displayElements() : displays the elements of the set
int getSize() : returns n, the number of elements in the set
int has(int ele) : returns 1 if ele belongs to the current set object and 0 otherwise
Set intersection(Set d) : returns the intersection of set object d and the current set object
i.e. the set containing the elements that are common to both the sets
Set unions(Set d) : returns the union of set object d and the current set object i.e.
the set containing the elements that are present in both the sets
Specify the class Set giving the details of the functions int has(int ele), Set intersection( Set d), Set
union( Set d). You may assume that the other functions/methods are written for you.
import [Link].*;
class Set
{
int arr[ ]=new int[50];
int n, i, j;
DataInputStream obj=new DataInputStream([Link]);
Set(int nn)
{
n=nn;
for(int i=0;i<n;i++)
arr[i]=0;
}
void readElements( ) throws IOException
{
[Link]("ENTER THE ELEMENTS OF THE ARRAY:");
for(i=0;i<n;i++)
{
[Link]("ENTER THE " + i + " ELEMENTS :");
arr[i]=[Link]([Link]());
}
}
void displayElements( )
{
for(i=0;i<n;i++)
[Link](arr[i]+"\t");
}
int getsize() throws IOException
{
[Link]("ENTER THE NUMBER OF ELEMENTS:");
n=[Link]([Link]());
return n;
}
int has(int ele)
{
int ans=0;
for(i=0;i<n;i++)
if(ele==arr[i])
{
ans=1;
break;
}
return ans;
}
A class Time has been defined to calculate the time related functions. Some of the functions/ methods in
Time are shown below:
Class name : Time
Data members/instance variables: hh - hours
mm - minutes
Member functions/methods:
Time( ) : constructor
void readtime( ) : to read time in 24 hour mode as hh mm
ISC Object Passing Questions
void disptimeansi( ) : to display time in 24 hour mode as hh mm
int timetominutes(time) : to find total number of minutes in hh mm
void minutestotime(int) : to convert total number of minutes into hh mm
void diff(time endtime, time starttime)
: to find the difference between endtime and starttime in
hours and minutes
Specify the class Time giving the details of the constructor, int timetominutes(time), void
minutestotime(int), void diff(time endtime, time starttime) only. You may assume that the other
functions are written for you.
import [Link].*;
class time
{
DataInputStream ab = new DataInputStream([Link]);
public int hh,mm;
public time()
{ hh=0;
mm=0;
}
public void readtime() throws IOException
{
do {
[Link]("\n Enter hours in 24 Hours format ");
hh=[Link]([Link]());
} while(hh<0 || hh>23);
do {
[Link]("\n Enter minutes ");
mm=[Link]([Link]());
} while(mm<0 || mm>59);
}
import [Link].*;
class Angle
{
Scanner br=new Scanner([Link]);
int deg, min;
public Angle( )
{
deg = 0;
min = 0;
}
public void readAngle()
{
[Link]("Enter degree ");
deg=[Link]();
[Link]("Enter minutes");
min=[Link]();
}
public void sumAngle(Angle A, Angle B)
{
deg = [Link] + [Link];
min = [Link] + [Link];
if(min>60)
{
deg = deg + 1;
min = min - 60;
}
}
public void diffAngle(Angle A, Angle B)
{
int z;
int x = [Link] * 60 + [Link];
int y = [Link] * 60 + [Link];
if(x>y) z = x - y;
else z = y - x;
deg = z / 60;
min = z % 60;
}
public void dispAngle()
ISC Object Passing Questions
{
[Link]("Angle in degree is = " + deg );
[Link]("Angle in minutes is = " + min );
}
public static void main(String args[])
{
Angle obj1= new Angle();
Angle obj2= new Angle();
Angle obj3= new Angle();
[Link]();
[Link]();
[Link]("Sum of two angle is : ");
[Link](obj1, obj2);
[Link]();
[Link]("Difference of two angle is : ");
[Link](obj1, obj2);
[Link]();
}
}