
ISC & ICSE Computer Science – Crash Course 2nd SEM Board Exams


We are happy to share the news on launching Online Tuitions 1 to 1 mode. Focusing on Board Classes (10th, 12th ) & Pre Board Classes (9th , 11th) also. Grab your opportunity to score 90+ in Board Exams…. Place your seat now !!! @ compogeniusacademy@gmail.com Limited Seats. We are having limited seats for Online […]
u Cn eXpLR !!! & comment
https://rhythmhoney.wordpress.com/
https://sunmarkgroups.wordpress.com/
harvestfarmfresh.com – buy online natural products
Write a program to accept a sentence and check whether it is terminated by ‘.’ or ‘? ‘ or ‘!’ . Display the words using default delimiter (space) and the first character of each word should be converted into Upper Case.
Sample Input :
converting first character.
Sample Output:
converting Converting
first First
character Character
import java.util.*;
class strDec
{
public static String firstLetter(String wrd)
{
String res="";char ch2=' ';
int l=wrd.length();
for(int i=1;i<l;i++)
{
char ch1=wrd.charAt(i);
ch2=wrd.charAt(0);
if(Character.isLowerCase(ch2))
{
ch2 =Character.toUpperCase(ch2);
}
//System.out.println(ch1);
res=res +ch1;
}
res=ch2+res;
return res;
//System.out.println(res);
}
public static void main(String args[])
{ strDec strd=new strDec();
String str;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence:");
str=sc.nextLine();
int l=str.length();
char c=str.charAt(l-1);
if(c=='.'||c=='?'||c=='!')
{
StringTokenizer st=new StringTokenizer( str, " .?!");
int n=st.countTokens();
String wrd[]=new String [n];
String ch[]=new String[n];
for(int i=0;i<n;i++){
wrd[i]=st.nextToken();
ch[i]=firstLetter(wrd[i]);
System.out.println(wrd[i] + " "+ch[i]+" " );
}
}
else
{
System.out.println("Enter a sentence terminated with . or ? or ! :");
}
}
}
Output:
Enter a sentence:
the sky is the limit.
the The
sky Sky
is Is
the The
limit Limit
import java.util.*;
class permutationDigits
{
int count = 0;
void input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a digit: ");
int a= sc.nextInt();
String s=String.valueOf(a); //converting int into string
System.out.println("The Anagrams are : ");
compute("",s);
System.out.println("Total Number of Anagrams = "+count);
}
void compute(String s1, String s2)
{
if(s2.length()<=1)
{
count++;
System.out.println(s1+s2);
}
else
{
for(int i=0; i<s2.length(); i++)
{
String a = s2.substring(i, i+1);
String b = s2.substring(0, i);
String c = s2.substring(i+1);
compute(s1+a, b+c);
}
}
}
public static void main(String args[])
{
permutationDigits ob=new permutationDigits();
ob.input();
}
}
Output:
Enter a digit: 234
The Anagrams are :
234
243
324
342
423
432
Total Number of Anagrams = 6
import java.util.*;
class anagramsWord
{
int count = 0;
void input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a word : ");
String s = sc.next();
System.out.println("The Anagrams are : ");
compute("",s);
System.out.println("Total NO. of Anagrams = "+count);
}
void compute(String s1, String s2)
{
if(s2.length()<=1)
{
count++; // no of combination words
System.out.println(s1+s2);
}
else
{
for(int i=0; i<s2.length(); i++)
{
String a = s2.substring(i, i+1);
String b = s2.substring(0, i);
String c = s2.substring(i+1);
compute(s1+a, b+c); // recursive method
}
}
}
public static void main(String args[])throws Exception
{
anagramsWord ob=new anagramsWord();
ob.input();
}
}
Output:
Enter a word : TOP
The Anagrams are :
TOP
TPO
OTP
OPT
PTO
POT
Total NO. of Anagrams = 6
ISC 12th Boolean Algebra- very important question and answers
Hai frnds,
Check it out the videos of ISC 12th Computer Science – Boolean algebra section, having Part 1 to 6


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?

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 ‘y‘ into constant
// In this case during compilation of the program the error message “Cannot assign a value to final variable y”
How to write a program with methods?
Unique Number program by methods.
Each program has different parts
1. importing package
2. define class with instance variables
3. constructor to initialize variables
4. input method – to read an input
5. calculate method- processing
6. display method – to display the processed data
7. main method- invoke above mentioned methods by creating an object
import java.util.*;
public class UniqueNumber
{
// instance variables -
int n;
String s;
int flag,i, j,l;
/**
* Constructor for objects of class UniqueNumber
*/
public UniqueNumber()
{
// initialise instance variables
n = 0;
flag=0;
s=" ";
}
public void input() // to input an integer
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number :");
n=sc.nextInt();
}
public void calculate()
{
s= Integer.toString(n); // converting the given number into String datatype
// Int datatype is converting to String,
// String helps to extract the character by charAt() and check each character is matching with the rest.
l=s.length();
//Loops to check the digits are repeated
for(i=0;i<l-1;i++)
{
for(j=i+1;j<l;j++)
{
if(s.charAt(i)==s.charAt(j)) // if any digits are repeated, then it is not a UniqueNumber
{ flag=1;
break;
}
}
}
}
public void display()
{
calculate(); //invoke calculate()
if(flag ==0)
System.out.println(" It is an UniqueNumber");
else
System.out.println(" It is not an UniqueNumber");
}
public static void main(String args[]) throws Exception
{
UniqueNumber un=new UniqueNumber(); //creating object
un.input(); //calling input() to main()
un.display(); //calling display() to main()
}
}
Output:
Enter a number: 5673
It is an UniqueNumber
Enter a number: 5675
It is not an UniqueNumber
import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
int ci, i, j, k, l=0;
String str, str1;
char c, ch;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a String : ");
str=scan.nextLine();
i=str.length();
for(c='A'; c<='z'; c++)
{
k=0;
for(j=0; j<i; j++)
{
ch = str.charAt(j);
if(ch == c)
{
k++;
}
}
if(k>0)
{
System.out.println("The character " + c + " has occurred for " + k + " times");
}
}
}
}
Enter a String : hai how are you bye take care
The character a has occurred for 4 times
The character b has occurred for 1 times
The character c has occurred for 1 times
The character e has occurred for 4 times
The character h has occurred for 2 times
The character i has occurred for 1 times
The character k has occurred for 1 times
The character o has occurred for 2 times
The character r has occurred for 2 times
The character t has occurred for 1 times
The character u has occurred for 1 times
The character w has occurred for 1 times
The character y has occurred for 2 times
import java.io.*;
class dequeue
{
int arr[]=new int[10];
int f,r;
int i,n;
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
dequeue()
{
f=-1;
r=-1;
}
public void push()throws IOException
{
if(r==9)
{
System.out.println("Queue Overflow");
return;
}
System.out.println("Specify the location(front or rear):");
str=br.readLine().toLowerCase();
System.out.println("Enter the value to insert:");
n=Integer.parseInt(br.readLine());
if(f==-1)
{
arr[++f]=n;
r=0;
}
else if(str.charAt(0)=='f')
{
for(i=r+1;i>f;i--)
arr[i]=arr[i-1];
arr[i]=n;
r++;
}
else
{
arr[++r]=n;
}
}
public void display()
{
if(f==-1)
return;
for(i=f;i<=r;i++)
System.out.println(""+arr[i]);
}
public void pop()throws IOException
{
if(f==-1)
{
System.out.println("Queue Overflow");
return;
}
System.out.println("Specify the location(front or rear):");
str=br.readLine().toLowerCase();
if(f==r)
{
f=-1;
r=-1;
}
else if(str.charAt(0)=='f')
{
f++;
}
else
{
r--;
}
}
public static void main(String args[])throws IOException
{
char op;
BufferedReader br;
dequeue ob=new dequeue();
while(true)
{
br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nPress'P' for Push,'D' for Pop and 'Q' for Quit:");
op=(char)br.read();
if(op=='p' || op=='P')
ob.push();
else if(op=='d' || op=='D')
ob.pop();
ob.display();
if(op=='q' || op=='Q')
break;
br=null;
}
}
}
press’P’ for push,’D’ for pop and ‘Q’ for quit:
p
Specify the location(f or r):
f
Enter the value to insert:
5
5
press’P’ for push,’D’ for pop and ‘Q’ for quit:
p
Specify the location(f or r):
r
Enter the value to insert:
6
5
6
press’P’ for push,’D’ for pop and ‘Q’ for quit:
p
Specify the location(f or r):
f
Enter the value to insert:
4
4
5
6
press’P’ for push,’D’ for pop and ‘Q’ for quit:
p
Specify the location(f or r):
r
Enter the value to insert:
7
4
5
6
7
press’P’ for push,’D’ for pop and ‘Q’ for quit:
p
Specify the location(f or r):
f
Enter the value to insert:
3
3
4
5
6
7
press’P’ for push,’D’ for pop and ‘Q’ for quit:
d
Specify the location(f or r):
f
4
5
6
7
press’P’ for push,’D’ for pop and ‘Q’ for quit:
d
Specify the location(f or r):
r
4
5
6
press’P’ for push,’D’ for pop and ‘Q’ for quit:
q
4
5
6
write a program to convert time in numbers to time in words.
import java.io.*;
public class timeinwords
{
public static void main(String args[]) throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader x=new BufferedReader (read);
System.out.println("enter hours");
int h=Integer.parseInt(x.readLine());
System.out.println("enter minutes");
int m=Integer.parseInt(x.readLine());
if((h>=1&&h<=12)&&(m>=0&&m<=59))
{
String word[]={"","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten "," eleven "," twelwe "," thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twenty one","twenty two","twenty three","twenty four","twenty five","twenty six","twenty seven","twenty eight","twenty nine"};
String plu,a;
if(m==1||m==59)
plu="minute";
else
plu="minutes";
if(h==12)
a=word[1];
else
a=word[h+1];
System.out.print("output: "\n+h+":"+m+"-----");
if(m==0)
System.out.println(word[h]+"o'clock");
else if(m==15)
System.out.println("quarter past"+word[h]);
else if(m==30)
System.out.println("half past"+word[h]);
else if(m==45)
System.out.println("quarter to"+a);
else if(m<30)
System.out.println(word[m]+" "+plu+" past+words[h] ");
else
System.out.println(word[60-m]+" "+plu+" to "+a);
}
else
System.out.println("invalid input!");
}
}
output:
enter hours
10
enter minutes
55
output:
10:55—–five minutes to eleven
import java.io.*;
import java.util.*;
class revstr
{
public void main()throws IOException
{
Scanner sc=new Scanner(System.in);
String str="",word;
int l,l1,i;
String a[]=new String[20];
System.out.println("enter string");
str=sc.nextLine();
StringTokenizer data=new StringTokenizer(str);
l=data.countTokens();
for(i=0;i<l;i++)
{
word=data.nextToken();
a[i]=word;
}
for(i=l-1;i>=0;i--)
{
System.out.print(a[i]+" ");
}
}
}
OUTPUT:
enter string
one important thing to know, seattle delivered his speech in his native language.
language. native his in speech his delivered seattle know, to thing important one
Write a program to convert decimal into binary without using array and display the number of 1’sand 0’s.
import java.util.Scanner;
class bintoDec
{
public static void main(String args[])
{
int n, a, count0 = 0, count1=0;
String s = "";
Scanner sc = new Scanner(System.in);
System.out.println("Enter decimal number ");
n = sc.nextInt();
while(n>0)
{
a = n%2;
if(a == 1)
{
count1++;
}
else
count0++;
s = s+" "+a;
n = n/2;
}
System.out.println("Binary number: "+s);
System.out.println("No. of 1s: "+count1);
System.out.println("No. of 0 s: "+count0);
}
}
Output:
Enter decimal number
2
Binary number: 0 1
No. of 1s: 1
No. of 0 s: 1
Enter decimal number
6
Binary number: 0 1 1
No. of 1s: 2
No. of 0 s: 1
Enter decimal number
16
Binary number: 0 0 0 0 1
No. of 1s: 1
No. of 0 s: 4
Enter decimal number
An evil number is a non-negative number that has an even number of 1s in its binary expansion. (Binary Expansion – is representation of a number in the binary numeral system or base-2 numeral system which represents numeric values using two different symbols: typically 0 (zero) and 1 (one)).
Odious Numbers: Numbers that are not Evil are called Odious Numbers. Given a number, the task is to check if it is Evil Number or Odious Numbers.
import java.util.*;
class EvilNumber
{
String toBinary(int n) // Function to convert a number to Binary
{
int r;
String s=""; //variable for storing the result
char dig[]={'0','1'}; //array storing the digits (as characters) in a binary number system
while(n>0)
{
r=n%2; //finding remainder by dividing the number by 2
s=dig[r]+s; //adding the remainder to the result and reversing at the same time
n=n/2;
}
return s;
}
int countOne(String s) // Function to count no of 1’s in binary number
{
int c = 0, l = s.length();
char ch;
for(int i=0; i<l; i++)
{
ch=s.charAt(i);
if(ch=='1')
{
c++;
}
}
return c;
}
public static void main(String args[])
{
EvilNumber ob = new EvilNumber();
Scanner sc = new Scanner(System.in);
System.out.print("Enter a positive number : ");
int n = sc.nextInt();
String bin = ob.toBinary(n);
System.out.println("Binary Equivalent = "+bin);
int x = ob.countOne(bin);
System.out.println("Number of Ones = "+x);
if(x%2==0)
System.out.println(n+" is an Evil Number.");
else
System.out.println(n+" is an Odious Number.");
}
}
Output:
Enter a positive number : 23
Binary Equivalent = 10111
Number of Ones = 4
23 is an Evil Number.
Enter a positive number : 21
Binary Equivalent = 10101
Number of Ones = 3
21 is an Odious Number.
ISC – Model Question Paper -October 2018
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 fnInput() : to input the member string
void fnOperate() : 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.
boolean isValid() : to verify whether the given string is valid or not and return true or false.
int fnVowel(String w) : to count and return the no. of vowels present in argument ‘w’.
import java.util.*;
class cord
{
String cd;
cord()
{
cd=””;
}
void fnInput()
{
Scanner sc=new Scanner(System.in);
System.out.println(“enter the string:”);
cd=sc.nextLine();
}
//Check the String is valid
boolean isValid()
{
for(int j=0;j<=cd.length()-2;j++)
{
if(cd.charAt(j)==’ ‘ && cd.charAt(j+1)==’ ‘) // checking repeated space
{
return false; //if repeated space, String is invalid
}
}
return true;
}
void fnOperate()
{
fnInput();
if(isValid() == false)
{
System.out.println(“Invalid string”);
return;
}
StringTokenizer st=new StringTokenizer(cd);
int ct=st.countTokens();
for(int j=1;j<=ct;j++)
{
String wrd=st.nextToken();
int cw=fnVowel(wrd);
System.out.println(wrd +” ” +cw);
}
}
//counting the vowels in the argument ‘w’
int fnVowel(String w)
{
int c=0;
w=w.toUpperCase();
for(int j=0; j<=w.length()-1;j++)
{
if(w.charAt(j)==’A’||w.charAt(j)==’E’||w.charAt(j)==’I’||w.charAt(j)==’O’||w.charAt(j)==’U’)
c++;
}
return c;
}
public static void main(String args[])
{
cord c1=new cord();
c1.fnOperate();
}
}
Question 1
Question 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
Question 5
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]
Question 6
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
Question 7
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
Program
import java.util.*;
class Arm
{
int no, sum;
Arm(int n1)
{
no=n1;
sum=0;
}
long fnPower(int a, int b)
{
if(b==0)
return 1;
else
return a*fnPower(a,b-1);
} // recursive ()
void fnPerform()
{
int an=no,r;
long sum1=(long) sum;
while(an>0)
{
r=an%10;
an=an/10;
sum1=sum1+fnPower(r,3); // recursive fnPower() invoked here
}
if(no==sum1)
System.out.println(“Armstrong number”);
else
System.out.println(“Not an Armstrong number”);
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(“Enter the number:”);
int num=sc.nextInt();
Arm a1=new Arm(num);
a1.fnPerform();
}
}
Output:
Enter the number: 153
Armstrong number
Enter the number: 135
Not an Armstrong number
PART – I (20 Marks)
Answer all questions.
While answering questions in this Part, indicate briefly your working and reasoning, wherever required.
Question 1
Question 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]
Question 5 [10]
Question 6 [10]
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);
}
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.
A class Stricom contains two strings and creates a new string using the common characters present in both the strings(without repetition)
For example: String1 : “Chinese” String 2 : “Checkers”
New string : “Ches”
Some of the members of the class are given below:
Class Name : Stricom
Data members:
stA, stB : the member strings
Member functions:
Stricom(…) : to initialize member string to the arguments
String fnCommon() : to create a new string using the common characters of both the member strings and return that(use member method fnLen())
void fnShow() : to print the member strings and the new string as per the question [ to use the member method fnCommon]
int fnLen(String s) : to return the length of the argument string.
Specify the class Stricom, and define main() giving the details of the above member data and methods only.
Program:
import java.util.*;
class Stricom
{
String stA, stB;
Stricom(String s1, String s2)
{
stA=s1;
stB=s2;
}
int fnLen(String s)
{
return s.length();
}
void fnShow()
{
String ns=fnCommon();
System.out.println(“string stA :”+ stA +”\nString stB :”+stB);
System.out.print(“New String :”+ns);
}
String fnCommon()
{
//int count=0;
String ns=””, ans=””;
char ch;
for(int j=0;j<=fnLen(stA)-1;j++)
{
for(int k=0;k<=fnLen(stB)-1;k++)
{
if(stA.charAt(j)==stB.charAt(k))
{
// count++;
ns+=stA.charAt(j);
// if(count>=1)
// break;
}
}
}
// return ns;
String ns1=ns;
for(int i=0;i<ns1.length(); i++)
{
ch=ns1.charAt(i);
if(ch!=’ ‘)
{
ans=ans+ch;
ns1=ns1.replace(ch,’ ‘);
}
}
return ans;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the first string:”);
String st1=sc.next();
System.out.println(“Enter the second string:”);
String st2=sc.next();
Stricom sm=new Stricom(st1,st2);
sm.fnShow();
}
}
Output:
Enter the first string:
chinese
Enter the second string:
checkers
string stA :chinese
String stB :checkers
New String :ches
A class Shift contains a 2D array of order (m*n) where the maximum values of both m and n is 5. Design the class Shift to shuffle the matrix (the first row becomes the last, the second row becomes the first and so on.)
Class name :Shift
Data members
mat[][], m,n;
Member functions:
Shift(int mm, int nn) : constructor to initialize the data members m=mm and n=nn
void input() : enters the elements of the array
void cyclic(Shift P) : enables the matrix of the object(P) to shift each row upwards in a cyclic manner and store the resultant matrix in the current object.
void display() : display the matrix elements.
Define the main() to create an object and call the methods accordingly to enable the task of shifting the array elements.
Program:
import java.util.Scanner;
public class Shift {
static Scanner sc=new Scanner(System.in);
int mat[][];
int m,n;
Shift(int mm,int nn)
{ m=mm;
n=nn;
mat=new int[m][n];
}
void input()
{ System.out.println("Enter elements");
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
mat[i][j]=sc.nextInt();
}
void display()
{
for(int i=0;i<m;i++)
{ System.out.println();
for(int j=0;j<n;j++)
System.out.print(mat[i][j] +"\t");
} }
void cyclic(Shift P)
{ for(int i=0;i<m;i++)
for(int j =0;j<n;j++)
{ if(i!=0)
mat[i-1][j]=P.mat[i][j];
else
mat[m-1][j]=P.mat[0][j];
}
}
static void main()
{ Shift x=new Shift(2,3);
Shift y=new Shift(2,3);
x.input();
y.cyclic(x);
System.out.println("Initial array is ");
x.display();
System.out.println();
System.out.print("Array after the shift ");
y.display();
} }
Output:
