Wednesday , 22 May 2019
Home » Array Related Programs » ISC 2014 [Question 8] Theory Paper Solved – Merging Arrays Inside Object

ISC 2014 [Question 8] Theory Paper Solved – Merging Arrays Inside Object

Question:

A class Mixer has been defined to merge two sorted integer arrays in ascending order. Some of the members of the class are given below:

Class name                         :               Mixer

Data members/instance variables:

int arr[]                                 :               to store the elements of an array
int n                                      :              to store the size of the array

Member functions:

Mixer( int nn)                     :               constructor to assign n = nn
void accept()                     :               to accept the elements of the array in ascending order without any duplicates
Mixer mix( Mixer A)             :              to merge the current object array elements with the parameterized array elements and return the resultant object
void display()                    :               to display the elements of the array

Specify the class Mixer, giving details of the constructor(int), void accept(), Mixer mix(Mixer) and void display(). Define the main() function to create an object and call the function accordingly to enable the task.

Programming Code:

/**
* The class Mixer merges the array of the current object with the array of the
* object passed as parameter
* @author : www.javaforschool.com
* @Program Type : BlueJ Program – Java
* @Question Year : ISC 2014 Question 8 (Theory)
*/

import java.io.*;
class Mixer
{
int arr[];
int n;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Mixer(int nn)
{
n = nn;
arr = new int[n];
}

void accept()throws IOException
{
System.out.println(“\n* Input the Array *\n”);
for(int i=0; iB.arr[j])
{
temp = B.arr[i];
B.arr[i] = B.arr[j];
B.arr[j] = temp;
}
}
}

return B;
}

void display()
{
for(int i=0; i

Output:

Enter size of the 1st array : 5

* Input the Array *

Enter Element [1] : 11
Enter Element [2] : 13
Enter Element [3] : 17
Enter Element [4] : 24
Enter Element [5] : 33

Enter size of the 2nd array : 3

* Input the Array *

Enter Element [1] : 5
Enter Element [2] : 19
Enter Element [3] : 30

The 1st Array is : 11 13 17 24 33
The 2nd Array is : 5 19 30
The Merged Array is : 5 11 13 17 19 24 30 33

Check Also

Infix Postfix Prefix Conversion – Correct Method (ISC Computer Science)

In this video we discuss about the correct way of converting an Infix Expression to Postfix and Prefix.

6 comments

  1. Nice steps …and nice documentation or comments as required by the isc

  2. Proper steps with nice documentation apt for isc

  3. nice way of doing the program…

  4. excellent program…

  5. very nicely done…

Leave a Reply

Your email address will not be published. Required fields are marked *