ISC Computer Project 2019-20 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 137

ISC Std XII Computer Project 2020-2021

Note: Your Project must have Cover Page, Certificate, Acknowledgements, Index Page, Topicwise
Questions, Algorithm, Program Listing, Output Listing

Note: Submit for assessment the softcopy on pen drive and hard copy in a file, of the
following programs to be done as part of continuous year long class work
assignments on the given submission dates as mentioned topic wise below

Important Note: Attempt the programs to the best of your ability completely on
your own in BlueJ Ensure that you do not discuss the program logic or take any help
or hint from anyone or anywhere else as this will defeat the purpose oof this project.
The purpose of this project/assignments is your logic and programming skill
development. Unless you do the program entirely on your own in BlueJ and do not
copy or discuss the algorithm or take any help orhint from others , your logic and
programming skills wont develop. Even if you are unable to crack the program and
get desired program output as on the date of topic submission , still you must
attempt the program only by yourself

Topic#0: Fundamental Programs - Submission Date : 10/6/2020

Question 1

An electronics shop has announced the following seasonal discounts on the purchase of
certain items.
Write a program based on the above criteria, to input name, address, amount of purchase
and the type of purchase (L for Laptop and D for Desktop) by a customer. Compute and
print the net amount to be paid by a customer along with his name and address.
( Hint : discount = discount rate/100) * amount of purchase
Net amount = amount of purchase – discount )
Purchase Amount
in Rs.
Discount on
Laptop
Discount on
Desktop PC
0 - 25000 0.0% 5.0%
25001 – 57000 5.0% 7.5%
57000 - 100000 7.5% 10.0%
More than 100000 10.0% 15.0%

Question 2

Write a program to generate a trianglepattern or an inverted triangle patterntill n terms based


upon the user’s choice of triangle to be displayed.

Example 1 Example 2 Example3 Example 4 Example 5 Example 6 Example 7

Input : Type 1 for triangle and Input : Type 1 for triangle and

Type 2 for an inverted triangle Type 2 for an inverted triangle

Type 3 for exapmple 3 Type 4 for exaample 4 Type 5 for examplle 5 Type 6 for example
6 Type 7 for example 7

Enter number of terms Enter number of terms

Output:

22

333

4444

55555
Question 3

Write a program to input a sentence and print the number of characters found in the longest
word of the given sentence.
For example if S = “India is my country” then the output should be 7.

Question 4

Design a class to overload a function num_calc( ) as follows:

(a) void num_calc( int num , char ch) with one integer argument and one character

argument, computes the square of integer argument if choice ch is ‘s’ otherwise

finds its cube.

(b) void num_calc( int a, int b, char ch) with two integer arguments and one character
argument. It computes the product of integer arguments if ch is ‘p’ else adds the integers.

(c) void num_calc( String s1, String s2) with two string arguments, which prints

whether the strings are equal or not.

Question 5

Write a menu driven program to accept a number from the user and check whether it is a
‘BUZZ’ number or to accept any two numbers and print the ‘GCD’ of them.

(a) A BUZZ number is the number which either ends with 7 or divisible by 7.

(b) GCD (Greatest Common Divisor) of two integers is calculated by continued division
method. Divide the larger number by the smaller; the remainder then divides the previous
divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.

Question 6

The annual examination results of 50 students in a class are tabulated as follows.

Roll No. Subject A Subject B Subject C


----- ------ ------ -----

----- ------ ------ -----

Write a program to read the data, calculate and display the following:

(a) Average mark obtained by each student.

(b) Print the roll number and average marks of the students whose average mark is

above 80.

(c) Print the roll number and average marks of the students whose average mark is

below 40.

Question 7.

Write a program to calculate and print the sum of odd numbers and the sum of even numbers
for the first n natural numbers. The integer n is to be entered by the user.

Question 8.

A cloth showroom has announced the following festival discounts on the purchase of items,
based on the total cost of the items purchased.

Total cost Discount (in Percentage)

Less than Rs.2000 5%

Rs.2001 to Rs.5000 25%

Rs.5001 to Rs.10000 35%

Above Rs.10000 50%

Write a program to input the total cost and to compute and display the amount to be paid by
the customer after availing the discount.

Question 9.

Consider the following statement:-


"January 26 is celebrated as the Republic Day of India".

Write a program to change 26 to 15,January to August. Republic to Independence and finally


print "August 15 is celebrated as the Independence Day of India".

Question 10.

Write a program that outputs the results of the following evaluations based on the numbered
entered by the user.

(i) Natural logarithm of the number.

(ii) Absolute value of the number.

(iii) Square root of the number.

(iv) Random numbers between 0 and 1.

Questions 11.

The marks obtained by 50 students in a subject are tabulated as follows:-

Name Marks

* *

* *

* *

Write a program to input the names and marks of the students in the subject Calculate and
display:

(i) The subject average marks (subject average marks=subject total/50)

(ii) The highest mark in the subject and the name of the student

(The maximum marks in the subject are 100).


Questions 12.

Write a program to accept 15 integers from the keyboard, assuming that no integer entered is
a zero. Perform selection sort on the integers and then print them in ascending order.

Question 13.

Define a class Salary described as below:


Data Members:
Name, Address, Phone, Subject Specialization, Monthly Salary, Income Tax.

Member methods:
(i) To accept the details of a teacher including the monthly salary.

(ii) To display the details, of the teacher.

(iii) To compute the annual Income Tax as 5% of the annual salary above Rs. 1,75,000.

Write a main method to create object of a class and call the above member method.

Question 14.

Write a program to compute and display the sum of the following series:

1+2 1+2+3 1+2+3+4....n


--- + ----- + ........ + ------------
1x2 1x2x3 1x2x3x4....n

Question 15.

Write a program to initialize the given data in an array and find the minimum and maximum
values along with the sum of the given elements.
Numbers : 2 5 4 1 3
Output: Minimum value: 1
Maximum value: 5
Sum of the elements: 15
Question 16.

Write a program to enter a sentence from the keyboard and count the number of times a
particular word occurs in it. Display the frequency of the search word.
Example:
INPUT:
Enter a sentence : the quick brown fox jumps over the lazy dog.
Enter a word to be searched : the
OUTPUT:
Searched word occurs : 2 times.

Questions 17.

Using a switch statement, write a menu driven program to convert a given temperature from
Fahrenheit to Celsius and vice versa. For an incorrect choice, an appropriate error message
should be displayed.'

(HINT : C = 5 x (F - 32) and F = 1.8 x C + 32 )


9

Questions 18.

Write a program using a method Palin( ), to check whether a string is a Palindrome or not. A
Palindrome is a string that reads the same from left to right and vice versa.
E.g. MADAM, ARORA, ABBA, etc.

Question 19.

Define a class employee having the following description:-

Data members / int pan to store personal account number

Instance variables String name to store name

double taxincome to store annual taxable income

double tax to store tax that is calculated

Member functions:

input( ) Store the pan number, name, taxableincome

calc( ) Calculate tax for an employee


display( ) Output details of an employee

Write a program to compute the tax according to the given conditions and display the output

as per given format.

Total Annual Taxable Income Tax Rate

Upto Rs 1,00,000 No tax

From 1,00,001 to 1,50,000 10% of the income exceeding Rs 1,00,000

From 1,50,001 to 2,50,000 Rs 5000 + 20% of the income exceeding Rs 1,50,000

Above Rs 2,50,00 Rs 25,000 + 30% of the income exceeding Rs 2,50,000

Output:

Pan Number Name Tax-income Tax

----

----

----

Question 20.

Write a program to input a string and print out the text with the uppercase and lowercase

letters reversed, but all other characters should remain the same as before.

Example : INPUT : WelComE TO School

OUTPUT : wELcOMe to sCHOOL

Question 21.

Define a class and store the given city names in a single dimensional array. Sort these

names in alphabetical order using the Bubble Sort technique only.

INPUT : Delhi, Bangalore, Agra, Mumbai, Calcutta

OUTPUT : Agra, Bangalore, Calcutta, Delhi, Mumbai

Question 22.

Write a menu driven class to accept a number from the user and check whether it is

Palindrome or a Perfect number.


(a) Palindrome number – ( a number is a Palindrome which when read in reverse order is

same as read in the right order ) Example : 11, 101, 151 etc.

(b) Perfect number - ( a number is called Perfect if it is equal to the sum of its factors

other than the number itself. ) Example : 6 = 1 + 2 + 3

Question 23.

Write a class with the name volume using function overloading that computes the volume of

a cube, a sphere and a cuboid.

Formula : volume of a cube vc = s * s * s

volume of a sphere vs = 4/3 *  * r * r * r (where  = 3.14 or 22/7 )

volume of a cuboid vcd = l * b * h

Question 24.

Write a program to calculate and print the sum of each of the following series:

(a) Sum ( S ) = 2 – 4 + 6 – 8 + ….. – 20

(b) Sum ( S ) = x + x + x + x + …….. x.

2 5 8 11 20

( Value of x to be input by the user. )

Question 25.

Write a class with name employee and basic as its data member, to find the gross pay of an
employee for the following allowances and deduction. Use meaningful variable.

Dearness Allowance = 25% of Basic Pay.

House Rent Allowance = 15% of Basic Pay.

Provident Fund = 8.33% of Basic Pay.

Net Pay = Basic Pay + Dearness Allowance + House Rent Allowance.


Gross Pay = Net Pay - Provident Fund.

Question 26.

Write a program to input any given string to calculate the total number of characters and
vowels present in the string and also reverse the string.

Example: INPUT

Enter String : SNOWY

OUTPUT:

Total number of characters : 05

Number of Vowels : 01

Reverse String : YWONS

Question 27.

Write a program using a function area() to compute the area of a:

(i) circle (PI*r2) where PI=3.14

(ii) square (side * side)

(iii) rectangle (length * breadth)

Display the menu to output the area as per User's choice.

Question 28.

Write a program to bubble sort the following set of values in ascending order. 5, 3, 8, 4, 9, 2, 1,
12, 98, 16
Output:
1

12

16
98

Questions 29.

Write a program to print the sum of negative numbers, sum of positive even numbers and
sum of positive odd numbers from a list of numbers (N) entered by the user. The list
terminates when the User enters a zero.

Questions 30.

Write a program to initialize an array of 5 names and initialize another array with their
respective telephone numbers. Search for a name input by the user, in the list. If found,
display "Search Successful" and print the name along with the telephone number, otherwise
display "Search unsuccessful. Name not enlisted".

Question 31
Design a class RailwayTicket with the following description:
Instance variables/data members:
String name: to store the name of the customer.
String coach: to store the type of coach customer wants to travel.
long mobno: to store customer’s mobile number.
int amt: to store basic amount of ticket.
int totalamt: to store the amount to be paid after updating the original amount.
Methods:
void accept(): to take input for name, coach, mobile number and amount.
void update(): to update the amount as per the coach selected. Extra amount to
be added in the amount as follows:

Type of coaches Amount


First_AC 700
Second_AC 500
Third_AC 250
sleeper None
void display(): To display all details of a customer such as name, coach, total
amount and mobile number.
Write a main() method to create an object of the class and call the above
methods.

Question 32
Write a program to input a number and check and print whether it is a Pronic
number or not. Pronic number is the number which is the product of two
consecutive integers.
Examples:
12 = 3 × 4
20 = 4 × 5
42 = 6 × 7

Question 33

Write a program in Java to accept a string in lowercase and change the first letter
of every word to uppercase. Display the new string.
Sample INPUT: we are in cyber world
Sample OUTPUT: We Are In Cyber World

Question 34
Design a class to overload a function volume() as follows:
(i) double volume(double r) – with radius ‘r’ as an argument, returns the volume
of sphere using the formula:
v = 4 / 3 × 22 / 7 × r3
(ii)double volume(double h, double r) – with height ‘h’ and radius ‘r’ as the
arguments, returns the volume of a cylinder using the formula:
v = 22 / 7 × r2 × h
(iii) double volume(double l, double b, double h) – with length ‘l’, breadth ‘b’ and
height ‘h’ as the arguments, returns the volume of a cuboid using the formula:
v=l×b×h

Question 35
Write a menu-driven program to display the pattern as per user’s choice:

Pattern 1 Pattern 2
ABCDE B
ABCD LL
ABC UUU
AB EEEE
A
For an incorrect option, an appropriate error message should be displayed.

Question 36
Write a program to accept name and total marks of N number of students in two
single subscripts array name[] and totalmarks[].

Calculate and print:


(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students) / N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]

Question 37.
Define a class Electric Bill with the following specifications:
class: ElectricBill
Instance Variable/ data member:
String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to paid
Member methods:
Void accept() – to accept the name of the customer and number of units
consumed
Void calculate() – to calculate the bill as per the following tariff :
Number of units — Rate per unit
First 100 units — Rs.2.00
Next 200 units — Rs.3.00
Above 300 units — Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
Void print() – To print the details as follows :
Name of the customer ………
Number of units consumed ……
Bill amount …….
Write a main method to create an object of the class and call the above member
methods.

Question 38.

Write a program to accept a number and check and display whether it is a spy
number or not.
(A number is spy if the sum its digits equals the product of the digits.)
Example: consider the number 1124 , sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 X 1 X 2 X 4=8

Question 39.
Using switch statement, write a menu driven program for the following:
i) To find and display the sum of the series given below:
S = x1 – x2 + x3 – x4 + x5 … – x20
(where x=2)
ii) To display the following series:
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.

Question 40.
Write a program to input integer elements into an array of size 20 and perform
the following operations:
i) Display largest number from the array
ii) Display smallest number from the array
iii) Display sum of all the elements of the array

Question 41:
Design a class to overload a function check() as follows:
i) void check(String str, char ch) – to find and print the frequency of a character
in a string.
Example :
Input — Output
Str = “success” number of s present is=3
ch = ‘s’
ii) void check (String s1) – to display only the vowels from string s1 , after
converting it to lower case.
Example :
Input:
S1= “computer” output: o u e

Question 42:
Write a program to input forty words in an array. Arrange these words in
descending order of alphabets, using selection sort technique. Print the sorted
array.

Question 43.
Define a class named BookFair with the following description:

Instance variables/Data members:


String Bname – stores the name of the book.
double price – stores the price of the book.

Member Methods:
(i) BookFair() – Default constructor to initialize data members.
(ii) void Input() – To input and store the name and the price of the book.
(iii) void calculate() – To calculate the price after discount. Discount is calculated
based on the following criteria.

PRICE DISCOUNT
Less than or equal to Rs 1000 2% of price

More than Rs 1000 and less than or equal to Rs 3000 10% of price

More than Rs 3000 15% of price

(iv) void display() – To display the name and price of the book after discount.

Write a main method to create an object of the class and call the above member
methods.

Question 44.

Using the switch statement, write a menu driven program for the following:

(i) To print the Floyd’s triangle [Given below]

1
23
456
7 8 9 10
11 12 13 14 15

(ii) To display the following pattern

I
IC
ICS
ICSE
For an incorrect option, an appropriate error message should be displayed.

Question 45.
Special words are those words which starts and ends with the same letter.
Examples:
EXISTENCE
COMIC
WINDOW

Palindrome words are those words which read the same from left to right and
vice-versa.
Example:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC

All palindromes are special words, but all special words are not palindromes.

Write a program to accept a word check and print whether the word is a
palindrome or only special word.

Question 46:
Design a class to overload a function SumSeries() as follows:
(i) void SumSeries(int n, double x) – with one integer argument and one double
argument to find and display the sum of the series given below:
s = (x/1) – (x/2) + (x/3) – (x/4) + (x/5) … to n terms
(ii) void SumSeries() – To find and display the sum of the following series:
s = 1 + (1 X 2) + (1 X 2 X 3) + … + (1 X 2 X 3 X 4 X … 20)
Question 47:

Write a program to accept a number and check and display whether it is a

Niven number of not.

(Niven number is that number which is divisible by its sum of digits).

Example:

Consider the number 126.

Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.

Question 48:
Write a program to initialize the seven Wonders of the World along with their
locations in two different arrays. Search for a name of the country input by the
user. If found, display the name of the country along with its Wonder, otherwise
display “Sorry Not Found!”
Seven wonders – CHICHEN ITZA, CHRIST THE RDEEEMER, TAJMAHAL, GREAT
WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations – MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example – Country Name: INDIA Output: INDIA – TAJMAHAL
Country Name: USA Output: Sorry Not Found!

Question 49.

Define a class ParkingLot with the following description:


Instance variables/data members:
int vno – To store the vehicle number
int hours – To store the number of hours the vehicle is parked in the parking lot
double bill – To store the bill amount
Member methods:
void input() – To input and store vno and hours
void calculate() – To compute the parking charge at the rate of Rs.3 for the first
hour or part thereof, and Rs.1.50 for each additional hour or part thereof.
void display() – To display the detail
Write a main method to create an object of the class and call the above methods

Question 50

Write two separate programs to generate the following patterns using


iteration(loop) statements:
(a)
*
* #
* # *
* # * #
* # * # *
(b)

5 4321
5 432
5 43
5 4
5

Question 51

Write a program in to input and store all roll numbers, names and marks in 3
subjects of n number of students in five single dimensional arrays and display
the remark based on average marks as given below:

Average marks = total marks/3

AVERAGE MARKS REMARK


85 – 100 EXCELLENT

75 – 84 DISTINCTION

60 – 74 FIRST CLASS

40 – 59 PASS

Less than 40 POOR

Question 52

Design a class to overload a function Joystring() as follows:


(i) void Joystring(String s, char ch1, char ch2) with one string and two character
arguments that replaces the character argument ch1 with the character
argument ch2 in the given string s and prints the new string
Example:
Input value of s = "TECHNALAGY"
ch1 = 'A'
ch2 = 'O'
Output : "TECHNOLOGY"
(ii) void Joystring(String s) with one string argument that prints the position of
the first space and the last space of the given String s.
Example:
Input value of = "Cloud computing means Internet based computing"
First Index : 5
Last Index : 36

(iii) void Joystring(String s1, String s2) with two string arguments that combines
the two strings with a space between them and prints the resultant string
Example :
Input value of s1 = "COMMON WEALTH"
s2 = "GAMES"
Output : "COMMON WEALTH GAMES"
(use library functions)

Question 53

Write a program to input twenty names in an array. Arrange these names in


descending order of alphabets , using the bubble sort technique.

Question 54.
Define a class named movieMagic with the following description:
Instance variables/data members:
int year – to store the year of release of a movie
String title – to store the title of the movie.
float rating – to store the popularity rating of the movie.
(minimum rating = 0.0 and maximum rating = 5.0)
Member Methods:
(i) movieMagic() Default constructor to initialize numeric data members to 0 and String data
member to “”.
(ii) void accept() To input and store year, title and rating.
(iii) void display() To display the title of a movie and a message based on the rating as per the
table below.
RATING MESSAGE TO BE DISPLAYED
0.0 to 2.0 Flop

2.1 to 3.4 Semi-hit

3.5 to 4.5 Hit

4.6 to 5.0 Super Hit

Write a main method to create an object of the class and call the above member methods.
Question 55.

A special two-digit number is such that when the sum of its digits is added to the product of its
digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits= 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits.
If the value is equal to the number input, output the message “Special 2-digit number” otherwise,
output the message “Not a Special 2-digit number”.

Question 56.
Write a program to assign a full path and file name as given below. Using library functions,
extract and output the file path, file name and file extension separately as shown.
Input C:\Users\admin\Pictures\flower.jpg
Output Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg

Question 57.
Design a class to overload a function area() as follows:
(i) double area(double a. double b, double e) with three double arguments, returns the
area of a scalene triangle using the formula:

where

(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a trapezium
using the formula:

(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns
the area of a rhombus using the formula:

Question 58.
Using the switch statement. write a menu driven program to calculate the maturity amount of a
Bank Deposit.
The user is given the following options:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept principal(P), rare of ¡interest(r) and time period in years(n). Calculate and
output the maturity amount(A) receivable using the formula

For option (ii) accept Monthly Installment (P), rate of interest(r) and time period in months (n).
Calculate and output the maturity amount(A) receivable using the formula

For an incorrect option, an appropriate error message should be displayed.

Question 59.
Write a program to accept the year of graduation from school as an integer value from the user.
Using the Binary Search technique on the sorted array of integers given below, output the message
‘Record exists’ if the value input is located in the array. If not, output the message Record does
not exist”.
(1982, 1987, 1993. 1996, 1999, 2003, 2006, 2007, 2009, 2010)

Question 60:

Define a class called FruitJuice with the following description:


Instance variables/data members:
int product_code – stores the product code number
String flavour – stores the flavor of the juice.(orange, apple, etc)
String pack_type – stores the type of packaging (tetra-pack, bottle etc)
int pack_size – stores package size (200ml, 400ml etc)
int product_price – stores the price of the product
Member Methods:
FriuitJuice() – default constructor to initialize integer data members
to zero and string data members to “”.
void input() – to input and store the product code, flavor, pack type,
pack size and product price.
void discount() – to reduce the product price by 10.
void display() – to display the product code, flavor, pack type,
pack size and product price.
Question 61:

The International Standard Book Number (ISBN) is a unique numeric book


identifier which is printed on every book. The ISBN is based upon a 10-digit code.
The ISBN is legal if:
1xdigit1 + 2xdigit2 + 3xdigit3 + 4xdigit4 + 5xdigit5 + 6xdigit6 + 7xdigit7 +
8xdigit8 + 9xdigit9 + 10xdigit10 is divisible by 11.
Example: For an ISBN 1401601499
Sum=1×1 + 2×4 + 3×0 + 4×1 + 5×6 + 6×0 + 7×1 + 8×4 + 9×9 + 10×9 = 253
which is divisible by 11.
Write a program to:
(i) input the ISBN code as a 10-digit integer.
(ii) If the ISBN is not a 10-digit integer, output the message “Illegal ISBN” and
terminate the program.
(iii) If the number is 10-digit, extract the digits of the number and compute the
sum as explained above.
If the sum is divisible by 11, output the message, “Legal ISBN”. If the sum is not
divisible by 11, output the message, “Illegal ISBN”.

Question 62:

Write a program that encodes a word into Piglatin. To translate word into Piglatin
word, convert the word into uppercase and then place the first vowel of the
original word as the start of the new word along with the remaining alphabets.
The alphabets present before the vowel being shifted towards the end followed
by “AY”.
Sample Input(1): London Sample Output(1): ONDONLAY
Sample Input(2): Olympics Sample Output(2): OLYMPICSAY

Question 63:

Write a program to input 10 integer elements in an array and sort them


In descending order using bubble sort technique.
Question 64:

Design a class to overload a function series() as follows:


(i) double series(double n) with one double argument and
returns the sum of the series.
sum = 1/1 + 1/2 + 1/3 + ….. 1/n
(ii) double series(double a, double n) with two double arguments
and returns the sum of the series.
2 5 8 11
sum = 1/a + 4/a + 7/a + 10/a ….. to n terms
Question 65:

Using the switch statement, write a menu driven program:


(i) To check and display whether a number input by the user is
a composite number or not (A number is said to be a composite, if it
has one or more then one factors excluding 1 and the number itself).
Example: 4, 6, 8, 9…
(ii) To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.

Question 66

Define a class called Library with the following description:


Instance variables/data members:
Int acc_num – stores the accession number of the book
String title – stores the title of the book stores the name of the author
Member Methods:
(i) void input() – To input and store the accession number, title and author.
(ii)void compute – To accept the number of days late, calculate and display and
fine charged at the rate of Rs.2 per day.
(iii) void display() To display the details in the following format:
Accession Number Title Author
Write a main method to create an object of the class and call the above member
methods.

Question 67

Given below is a hypothetical table showing rates of Income Tax for male
citizens below the age of 65 years:

Taxable Income (TI) in Income Tax in

Does not exceed 1,60,000 Nil

Is greater than 1,60,000 and less than or equal to 5,00,000 ( TI – 1,60,000 ) * 10%

Is greater than 5,00,000 and less than or equal to 8,00,000 [ (TI - 5,00,000 ) *20% ] + 34,000

Is greater than 8,00,000 [ (TI - 8,00,000 ) *30% ] + 94,000

Write a program to input the age, gender (male or female) and Taxable Income
of a person.If the age is more than 65 years or the gender is female, display
“wrong category*.
If the age is less than or equal to 65 years and the gender is male, compute and
display the Income Tax payable as per the table given above.

Question 68

Write a program to accept a string. Convert the string to uppercase. Count and
output the number of double letter sequences that exist in the string.
Sample Input: “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE
Sample Output: 4

Question 69

Design a class to overload a function polygon() as follows:


(i) void polygon(int n, char ch) : with one integer argument and one character
type argument that draws a filled square of side n using the character stored in
ch.
(ii) void polygon(int x, int y) : with two integer arguments that draws a filled
rectangle of length x and breadth y, using the symbol ‘@’
(iii)void polygon( ) : with no argument that draws a filled triangle shown below.

Example:
(i) Input value of n=2, ch=’O’
Output:
OO
OO
(ii) Input value of x=2, y=5
Output:
@@@@@
@@@@@
(iii) Output:
*
**
***

Question 70

Using the switch statement, writw a menu driven program to:


(i) Generate and display the first 10 terms of the Fibonacci series
0,1,1,2,3,5….The first two Fibonacci numbers are 0 and 1, and each subsequent
number is the sum of the previous two.
(ii)Find the sum of the digits of an integer that is input.
Sample Input: 15390
Sample Output: Sum of the digits=18
For an incorrect choice, an appropriate error message should be displayed

Question 71

Write a program to accept the names of 10 cities in a single dimension string


array and their STD (Subscribers Trunk Dialing) codes in another single
dimension integer array. Search for a name of a city input by the user in the list.
If found, display “Search Successful” and print the name of the city along with its
STD code, or else display the message “Search Unsuccessful, No such city in the
list’.

Question 72.

Define a class called mobike with the following description:


Instance variables/data members: int bno – to store the bike’s number
int phno – to store the phone number of the customer
String name – to store the name of the customer
int days – to store the number of days the bike is taken on rent
int charge – to calculate and store the rental charge
Member methods:
void input( ) – to input and store the detail of the customer.
void computer( ) – to compute the rental charge
The rent for a mobike is charged on the following basis.
First five days Rs 500 per day;
Next five days Rs 400 per day
Rest of the days Rs 200 per day
void display ( ) – to display the details in the following format:
Bike No. PhoneNo. No. of days Charge

Question 73.

Write a program to input and sort the weight of ten people. Sort and display
them in descending order using the selection sort technique. Question 6.

Write a program to input a number and print whether the number is a special
number or not. (A number is said to be a special number, if the sum of the
factorial of the digits of the number is same as the original number).
Question 74

Write a program to accept a word and convert it into lowercase if it is in


uppercase, and display the new word by replacing only the vowels with the
character following it.

Example
Sample Input : computer
Sample Output : cpmpvtfr

Question 75.
Design a class to overload a function compare ( ) as follows:
(a) void compare (int, int) – to compare two integer values and print the greater
of the two integers.
(b) void compare (char, char) – to compare the numeric value of two character
with higher numeric value
(c) void compare (String, String) – to compare the length of the two strings and
print the longer of the two.

Question 76
Write a menu driven program to perform the following . (Use switch-case
statement)
(a) To print the series 0, 3, 8, 15, 24 ……. n terms (value of ‘n’ is to be an input
by the user).
(b) To find the sum of the series given below:
S = 1/2+ 3/4 + 5/6 + 7/8 … 19/20

Question 77.
Write a program to perform binary search on a list of integers given below, to search for an
element input by the user. If it is found display the element along with its position, otherwise
display the message “Search element not found”.
5,7,9,11,15,20,30,45,89,97

Question 78

Define a class ‘Student described as below:


Data members/instance variables : name,age,m1,m2,m3 (marks in 3 subjects), maximum, average
Member methods :
(i) A parameterized constructor to initialize the data members.
(ii) To accept the details of a student.
(iii) To compute the average and the maximum out of three marks.
(iv) To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.

Question 79
Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket amount Discount
Above Rs 70000 – 18%
Rs 55001 to Rs 70000 – 16%
Rs 35001 to Rs 55000 – 12%
Rs 25001 to Rs 35000 – 10%
less than Rs 25001 – 2%
Write a program to input the name and ticket amount for the customer and calculate the discount
amount and net amount to be paid. Display the output in the following format for each customer :
1 SL. NO. Name Ticket
charges Discount Net
amount
2 1 -
-
-
-
(Assume that there are 15 customers, first customer is given the serial no (SlNo.) 1, next customer
2 … and so on.

Question 80

Write a menu driven program to accept a number and check and display whether it is a Prime
Number or not OR an Automorphic Number or not. (Use switch-case statement).
(a) Prime number : A number is said to be a prime number if it is divisible only by 1 and itself and
not by any other number. Example : 3,5,7,11,13 etc.
(b) Automorphic number : An automorphic number is the number which is contained in the last
digit(s) of its square.
Example: 25 is an automorphic number as its square is 625 and 25 is present as the last two digits.

Question 81.

Write a program to store 6 element in an array P, and 4 elements in an array Q and produce a third
array R, containing all elements of array P and Q. Display the resultant array
Example:
1 INPUT OUTPUT
2 P[] Q
[] R []
3 4 19 4
4 6 23 6
5 1 7 1
6 2 8 2
7 3 3
8 10 10
9 19
10 23
11 7
12 8

Question 82
Write a program to input a string in uppercase and print the frequency of each character.
1 INPUT :
COMPUTER
HARDWARE
2 OUTPUT :
3 CHARACTERS
FREQUENCY
4 A 2
5 C 1
6 D 1
7 E 2
8 H 1
9 M 1
10 O 1
11 P 1
12 R 3
13 T 1
14 U 1
15 W 1

Question 83

/**1. Write a program to accept a two different characters &

display the sum & difference of their

ASCII values.

SampLe i/p: A

Sample o/p: The sum of ASCII values = 165

The difference of ASCII values =35 * */


Question 84

/**2. Write a program to accept a alphabet in upper case or in

lower case. Display the next alphabet

accordingly. i.e 'a' follows 'b' & 'z' follows 'a' * */

Question 85

/** * 3. Write a program to accept a character if it is a letter then

display the case i.e lower or upper,

otherwise check whether it is digit or special character

Sampke i/p: p

Sample o/p: p is a letter

p is in lower case.

* */

Question 86

/** 4. Write a program in java to accept a string/word and display

the new string after removing all

the vowels present in it.

SampLe i/p: COMPUTER APPLICATIONS

Sample o/p: CMPTR PPLCTNS **/


Question 87

/** 5.Write a program to input a word/string, count all the

alphabets excluding vowels present in

the word/string and display the result.

* Sample i/p: Happy New Year

* Sample o/p: no of alphabets excluding vowels = 8 **/

Question 88

/**6. Write a program in java to accept a name(containing three

word)and display only the

initials(i.e first alphabet of each word). display the longest word and

the length of the longest

word present in the string.

Sampke i/p: LAL KRISHNA ADVANI

Sample o/p: L K A ` * */

Question 89

/**7. Write a program in java to accept a name containing three

words and display the surname


first followed by the first and middle names.

Sampke i/p: MOHANDAS KARAMCHAND GANDHI

Sample o/p: GANDHI MOHANDAS KARAMCHAND * */

Question 90

/**8. Write a program in java to accept a string/sentence and find

the frequency of given alphabets.

display the longest word and the length of the longest word present

in the string.

Sample i/p: WE ARE LIVING IN COMPUTER WORLD

Enter an alphabets whose frequency is to be

checked :E

Sample o/p: The frequency of 'E' is 3 * */

Question 91

/**9. A man has written a statement as "My name is Alok Kumar

Gupta and my age is 45 years".

Later on he realized that he had declared his name as Alok instead

of Ashok and age 45 instead of

35. Write a Program in java to correct his age in the predicted

statement. Display the o/p as


Sample o/p: My name is Ashok Kumar Gupta and my age is 35

years. ` * */

Question 92

10. Write a program to accept a string/sentence in upper case

and Display the longest word and the

length of the longest word present in the string.

SampLe i/p: "TATA FOOTBALL ACADEMY WILL PLAY AGAINST

MOHAN BAGAN"

Sample o/p: The longest word : FOOTBALL : The length of

word :8 ` * */

Question 93

/**11. Write a program to accept a string in upper case and find

the frequency of each vowel present

in string:

Sample i/p: "RAIN WATER HARVESTING ORGANIZED BY JUSCO"

Sample o/p: Frequency of 'A' = 4

Frequency of 'E' = 3

Frequency of 'I' = 3

Frequency of 'O' = 2

Frequency of 'U' = 1 * */
Question 94

/**

*12. Write a program to accept a string as: IF IT RAINS, YOU

WILL NOT GO TO PLAY" Convert all characters of the word in

lower case other than the first characters so as to obtain the

following

output:

Sample o/p: If It Rains, You Will Not Go To

Play. * */

Question 95

/** 13.Write a program to accept a word and display the ASCII of

each character.

Sample i/p: BLUEJ

Sample o/p: ASCII of B = 66

ASCII of L = 75

ASCII OF U = 84

ASCII OF E = 69

ASCII of L = 73 * */
Question 96

/**14. Write a program to input a string in upper case and replace

all the vowels with Asterisk(*)

present in the string.

Sample i/p: TATA STEEL IS IN JAMSHEDPUR

Sample o/p: T*T* ST**L I* J*MSH*DP*R * */

Question 97

/**15. Write a program in java to enter a string and frame a word

by joining all the first characters

of each word.Display the new word.

Sample i/p: Vital Information Resource Under Seize

Sample o/p: VIRUS */

Question 98

/**16. Write a program in java to enter a string and display all the

palindrome words present in the

String.

Sample i/p: MOM AND DAD ARE NOT AT HOME

Sample o/p: MOM


DAD */

Question 99

/**17. Write a program to accept a string and display the string in

a reverse order.

Sample i/p: COMPUTER IS FUN

Sample o/p: FUN IS COMPUTER */

Question 100

/**18. Write a Program to input a string and print the character

which occur maximum no of times

within a string.

Sample i/p: James Gosling developed java

Sample o/p: The character with maximum no of times:

e */

Question 101

/**19. Write a program to input a string and print the word

containing maximum no of vowels.

SAMPLE i/p: HAPPY NEW YEAR

SAMPLE O/P: THE WORD WITH MAXIMUM NO OF VOWELS :

YEAR */
Question 102

/**20. Consider the string as “Blue bottle is in Blue bag lying on

the Blue carpet”. Write a program to accept a sample string and

replace the word 'Blue' with 'red'. The new string is displayed as

“Red bottle is in Red bag lying on the Red carpet”

*/

Question 103

/**21. A computer typist has the habit of deleting the middle

name 'kumar' while entering the names containing three

words,write a program to enter a name contaning three words and

display the new name after deleting middle name 'kumar'.

sample input : Ashish Kumar Nehra

Sample o/p: Ashish Nehra */

Question 104

/**22. Write a program to accept a word & convert it into lower

case, if it is in upper case. Display a

new word by replacing only the vowels with the character following

it.
Sample i/p: Computer

Sample o/p: cpmpvtfr */

Question 105

/*23. Write a program to input a word & print the new word

after removing all the repeated alphabets

* sample i/p: applications

* sample o/p: aplictons */

Question 106

/**24. A string is said to be 'unique' if none of the alphabets

present in the string are repeated. Write

a program to accept a string and check whether the string is

unique or not. The program displays a message accordingly.

Sample i/p: COMPUTER

SAMPLE O/P: UNIQUE STRING */

Question 107

/**25. Write a program to input a string and print the frequency

of vowels of each word present in the string.


SAMPLE I/P: MASTERING INFORMATION TECHNOLOGY

SAMPLE O/P: NO OF VOWELS PRESENT IN MASTERING : 3

NO OF VOWELS PRESENT IN INFORMATION :

NO OF VOWELS PRESENT IN

TECHNOLOGY :3 */

Question 108

/**

26. A non Palindromte word can be a palindrome word just by

adding reverse of the word with the

original word. Write a program to accept a non -palidrome word

and display the new word after

making it a palindrome.

Sample i/p: ICSE

Sample o/p: The new word aftter making it palindrome as:

ICSEESCI */

Question 109

/**27. Write a program to input a string. Count and dispaly the

frequency of each alphabet in an


order, Which is present in the string.

Sample i/p: COMPUTER APPLICATIONS

Sample o/p: A-2,C-2,I-1,L-2,M-1,N-1,O-2,P-3,R-1,S-1,T-

2,U-1 * */

Question 110

/**28. Write a program to input a string. Convert it into upper

case. Count and output the numberof

double letter sequences that exists in the string

Sample i/p: SHE WAS FEEDING THE LITTLE RABBIT WITH AN

APPLE.

Sample o/p: 4 **/

Question 111

/**29A.

BLUEJ

BLUE

BLU

BL

*/
/**29B

E E

UUU

L L L L

B B B B B

*/

/**29C.

BLUEJ

LUEJ

UEJ

EJ

*/

Question 112

/**30A.

ABCDE

BCDE

CDE

DE

F
*/

/**30B.

BC

DEF

GHIJ

KLMNO

*/

/**30C.

ABCDE

ABCDA

ABCAB

ABABC

AABCD

*/

/*30D.

ABCDE

BCDE

CDE

DE

*/
/**30E. Write a program to display the pattern

EDCBA

EDCB

EDC

ED

*/

/** 30F. Write a program to display the pattern

AB

ABC

ABCD

ABCDE

*/

Question 113

/**31. Write a program to generate a triangle or an inverted

triangle till n terms based upon user's

choice of triangle to be displayed.

Example 1

Sample input : Type1 for a triangle

Type2 for an Inverted Triangle


Enter your choice: 1

Enter the no of Terms:5

Sample Output:

*****

****

***

**

Example 2

Sample input : Type1 for a triangle

Type2 for an Inverted Triangle

Enter your choice: 2

Enter the no of Terms:5

Sample Output:

ABCDE

ABCD

ABC

AB

A */
Question 114

/**32A. Write a program to generate a triangle or an inverted

triangle till n terms based upon user's choice of triangle to be

displayed.

Example 1

Sample input : Type1 for a triangle

Type2 for an Inverted Triangle

Enter your choice: 1

Enter a word: BLUEJ

Sample Output:

L L

U U U

E E E E

J J J J J

Example 2

input : Type1 for a triangle

Type2 for an Inverted Triangle

Enter your choice: 2

Enter a word: BLUEJ

Sample Output:

BLUEJ
BLUE

BLU

BL

B */

/**32A.

BLUEJ

BLUE

BLU

BL

*/

/*32B.

*B

* BL

* BLU

* BLUE

* BLUEJ

*/

/**32C.

BLUEJ

LUEJB

UEJBL
EJBLU

JBLUE

*/

/*32D.

BLUEJ

BLUE

BLU

BL

*/

/**32E.

BL

BLU

BLUE

BLUEJ

*/

/**32F.

ABCDEF

GHIJK

LMNO
PQR

ST

*/

Topic #1: Scanner class Submission Date : 10/6/2020

Q9. Define a class called FruitJuice with the following description:


Instance variables/data members:
Int product_code – stores the product code number
String flavour – stores the flavor of the juice. (orangle, apple, etc.)
String pack_type – stores the type of packaging (tetra-pack, bottle, etc.)
intpack_size – stores package size (200ml, 400ml, etc.)
intproduct_price – stores the price of the product
Member methods:
FruitJuice() – default constructor to initialize integer data members to zero and string data
members to “”
void input() – to input and store the product code, flavor, pack type, pack size and product
price
void discount() – to reduce the product price by 10
void display() – to display the product code, flavor, pack type, pack size and product price

Q 9B

A class called EvenSeries has been defined to find the smallest value of integer, n, such that,
2 + 4/2!+ 8/3!+16/4!+….2n/n! >= S, where 2.0 < S < 7.0.
Some of the members of the class EvenSeries are given below:
Class name : EvenSeries
Data members:
n : long integer type to store number of terms.
S : float variable where 2.0 < S < 7.0.
k : float variable to store the value of series evaluated.
Member functions:
EvenSeries() : constructor to initialize data members to 0.
void accept() : to accept value of data member S.
long fact(long x) : to compute and return factorial of x.
voiddisp() : calculates and displays the least value of n.
Specify the class EvenSeries giving details of the constructor and functions void accept(),
long fact(long)
and void disp(). The main function need not be written.

Q Extra)

WAP that obtain input comprising of five numbers and averages them. Use Scanner object
for input purposes.

Topic #2: Menu-Driven Iterations - Submission Date : 10/6/2020

Q2. Write a menu driven class to accept a number from the user and
using switch-case construct check whether it is a Palindrome or find
the sum of digits of the number.
Palindrome is a number which when read in reverse order is same as
read in the right order. Eg:11,101,151.[Hint: Write a function
boolean isPalindrome(int n). Invoke this function in the switch-case.]
Find the number of digits of the number, the sum of the digits, the
product of the digits, the average of the digits and the highest and
lowest digit of the number Eg. 521 has 3 digits, sum of digits = 8,
product of digits = 10, average = 2.66, smallest digit = 1

Q3.

Using the switch statement, write a menu driven program to:


(i) To find and display all the factors of a number input by the user
(including 1 and excluding number itself).
Example:
Sample Input : n=15 Sample Output : 1,3, 5
(ii)To find and display the factorial of a number input by the user
(the factorial of a non-negative integer n, denoted by n!, is the
product of all integers less than or equal to n.
Example:
Sample Input : n =5
Sample Output : 5! = 1x2x3x4x5=120.
(iii) To find the sum, product, average, minimum and maximum among
numbers entered by the user till user presses 0.
For an incorrect choice, an appropriate error message should be
displayed.

Topic #3: Functions - Submission Date : 10/7/20

QExtra1. Write a Class With Functions To Show That Primitive Variables


Are Passed As Parameter By Value/VariableCopy and Any Change Made to
the Parameter In The Called Function Changes Only the Copy of the
Variable And Not The Value of the Original Variable. Also include
Functions To Show That Class With Functions To Show That Reference
Variables Such As Objects and Arrays Are Passed As Parameter By
Reference/Address and Any Change Made to the Parameter In The Called
Function Also Changes The Original Value Stored At That Address.

Q.Extra2 Writea Class With Functions To Show Function Overloading


WAP to overload 3 functions named Area with 1 integer parameter s to
find area of a square, with 1 double type argument to find area of
circle, with 2 double type parameters to find area of rectangle.

Q.1Design a class to overload a function series() as follows:


(i) double series(double n) with one double argument and returns the
sum of the series.
sum = 1/1! + ½! + 1/3! + … 1/n!
(ii) double series(double a, double n) with two double arguments and
returns the sum of the series.
sum = 1/a2 - 4/a5 + 7/a8 - 10/a11 … to n terms

Q3A.

A class Numbers contains the following data members and member


functions to check for triangular numbers. [ A triangular number is
formed by the addition of a consecutive sequence of integers starting
from 1.]
Eg.
1 + 2 = 3
1 + 2 + 3 =6
1+ 2 + 3 + 4 =10
1+ 2 + 3 + 4 + 5 = 15
Therefore 3,6,10,15 are triangular numbers.
Class name : Numbers
Data members
n : integer to be checked whether it is triangular or not.
Member functions
void getnum() : to accept integer n.
int check(int) : to check if n is triangular.
void dispnum() : to display message whether n is triangular or not.

Specify the class Numbers giving details of the functions void


getnum(), int check(int) and void dispnum(). The main function need
not be written.

Q3B.

Sum= 1 + x/1!+x3/2!+x5/3!+……..+x2n-1/n!

A class seriessum has been defined to calculate the sum of the above
series. Some of the members
of the class are given below:
Class name : seriessum
Data members
x, n : int
sum : double
Member functions
sumseries() : constructor
int factorial(int n) : calculates and returns the factorial of n( n!)
where n!=1 x 2 x 3 x 4 x….x n.
double term(int p, int q): Calculates and returns the value of p/q!
by making
use of factorial(int).
void accept() : Inputs the value of member data x,n
void displaysum() : displays the value of member data sum.
double calsum() : calculates the sum of the given series using the
appropriate
data and other member functions.
a) Specify the class sumseries giving details of the constructor, int
factorial(int), double term(int,int), void displaysum(). You may
assume that other member functions are written for you. You do not
need to write the main function.
b) What care do you need to take while designing double term(int,
int).
Q3C

A class Telcall calculates the monthly telephone bill of a consumer.


Some of the members of the class are given below:
Class Name : Telcall
Data Members
phno : phone number
name : name of consumer
n : number of calls made
amt : bill amount
Member functions
Telcall( ) : Parameterised constructor to assign values to data
members
void compute() : to calculate the phone bill amount based on the
slabs given
below.
void dispdata() : to display the details in the specified format.
Number of calls Rate
1-100 Rs. 500/- rental charge only
101-200 Re. 1.00/- per call + rental charge
201-300 Rs.1.20/- per call + rental charge
Above 300 Rs.1.50/- per call + rental charge
The calculation needs to be done as per the slabs.
Specify the class Telcall, giving the details of the constructor,
void compute() and void dispdata().
In the main function, create an object of type Telcall and display
the phone bill in the following format:
Phone number Name Total calls Amount
XXXXXXXXX XXXXX XXXXX XXXXX

Q3D

A special number is a number in which the sum of the factorial of


each digit is equal to the number itself.
For example:- 145 = 1! + 4! + 5! = 1 + 24 + 120
Design a class Special to check if a given number is a special number.
Some of the members of the class are given below:
Class name : Special
Data members
N : Integer
Member functions
Special() : constructor to assign 0 to n
Special(int) : Parameterized constructor to assign a value to ‘n’
void sum() : calculate and display the sum of the first and last
digit of n.
void isSpecial() : check and display if the number n is a special
number.
Specify the class Special giving details of the constructor, void
sum() and void isSpecial(). You need not write the main function.

Q3E

A magic number is a number in which the eventual sum of digits of the


number is equal to 1. For example, 172 = 1 + 7 + 2 = 10
10 = 1 + 0 = 1
Then 172 is a magic number.
Design a class Magic to check if a given number is a magic number.
Some of the members of the class
are given below:
Class name : Magic
Data members
n : stores the number
Member functions
Magic() : constructor to assign 0 to n
void getnum(intnn) : to assign the parameter value to the number,n=nn
int Sum_of_digits(int) : return the sum of the digits of number
void ismagic() : checks if the given number is a magic number
by calling the function Sum_of_digits(int) and displays appropriate
message.
Specify the class Magic by giving details of the constructor, void
getnum(int), intSum_of_digits(int) and void ismagic(). You need not
write the main function.

Q3F

WAP to input a no and check whether it is a Smith no. or not, A Smith


Number is a composite no. whose sum of digits is equal to the sum of
the digits of it’s prime factors obtained as a result of prime
factorization.
(Excluding 1) e.g. 666, coz sum of digits is 6+6+6=18, prime factors
of 666 = 2, 3, 3, 37 so 2+3+3+(3+7)=18
Q3G
WAP to input a number and print its Primorial. A Primorial number
also known as p-prime number (denoted by Pn# which is a product of
all the prime numbers up to ‘n’ i.e. P5# = 2 x 3 x 5 = 30

Q3H
WAP to input a number and check whether it is a Mersenne number or
not. A Mersenne number has all ones in its Binary counterpart, it can
also be defined as n2 – 1 for e.g. Binary of 7 = (111)2 which is also
equal to 23 – 1
Binary of 15 = (1111)2 which is also equal to 24 – 1

Q3I

WAP to input a number and check whether it is a Kaprekar’s number or


not. Consider an n – digit number K, Square it and add the right ‘n’
number of digits to the left n – 1 digits. If the resultant sum is K,
then K is called a Kaprekar’s number. For example, 297 is a
Kaprekar’s number as 2972 = 88209 and 297 has 3 digits hence
extracting 3 digits from RHS and adding it to the rest of the digits,
i.e. 209 + 88 = 297.

Q3J

Program to print GCD and LCM of two numbers using Euclid’s method.
Methods:
public int lcm(int a, int b)
public int gcd(int a, int b)
void Relation(int a, int b)
public static void main(String [] args)

Sample Input/Output
Enter two numbers
57 24
The LCM of 57 and 24 is : 456
The GCD of 57 and 24 is : 3
The product of lcm and gcd of 57 and 24 is : 1368
The product of 57 and 24 is : 1368
It satisfies the equation: lcm(a, b) * gcd(a, b) = ab
Q3J

Program to print Brun’s Constant:


Twin primes are the prime numbefs with a difference of 2 e.g., (3, 5), (5, 7), (11, 13), (17, 19),
(29, 31)… etc.
The sum of reciprocals of the twin primes converges to a sum, known as Brun’s Constant
Methods:
boolean IsPrime(int n)
void twinPrimes(int lim)
double BrunConstant(int lim)

Sample Input/Output
Enter limit: 13
(1/3 + 1/5) + (1/5+ 1/7) + (1/11 +1/13)
Brun’s Constant below limit 13 is : 1.0440226793289185

Q3K

Create a Java class that stores original numeerator and denominator of a fraction and then
simplifies it to find numerator and denominator of simplified fraction.
Class name : RationalClass
Instance Variables :
int numerator
int denominator
int nr : numerator of simplified fraction
int dr : denominator of simplified fraction
Methods:
simplify()
gcd(int,int)
print() : prints fraction in original as weell as in simplified form
Constructor : receives two parameters and initialises the numerator and denominator
main() : reads the values for numerator and denominatorcand then prints the simplifiedd
expression.

QExtra)

WAP to read in a year and determine whether it is a Leap Year. Every


4th year is a Leap Year. It is a year divisible by 4 (Also last 2
digits are divisible by 4). Every 4th Century Year is a Leap Year eg.
400, 800, 1200, 1600, 2000, 2400.
Topic #4 Number Conversions - Submission Date : 10/7/2020

Q.34 Write a program to convert Decimal to Octal number.

Q.35 Write a program to convert Hexadecimal to Binary number.

Topic #5 Sorting Algorithms - Submission Date: 10/7/2020

Q.59 Write algorithm and program for Quick Sort

Q.60 Write algorithm and program for Insertion Sort

QExtra) Write algorithm and program for Bubble Sort

QExtra) Write algorithm and program for Selection Sort

QExtra) Write algorithm and program for a general Sorting method

Topic #6: Inheritance Submission Date: 10/8/2020

Q.4 A class Student defines the personal data of a student while another class Marks defines
the register number, name of subject and marks obtained by the student. The details of both
the classes are given below:

Class name : Student

Data members: name : string to store name.


gender : string to store gender
age : integer to store age

Member functions

void inpdetails() : to accept values for data members.

void show() : to display personal data of student.

Class name : Marks


Data members: regnum : int to store registration number.
marks :int to store marks.

subject : String to store subject name.

Member functions

void inpdetails() : to accept values for data members.

void show() : to display exam and student details.

a) Specify the class Student giving details of the functions void inpdetails() and void show().

b) Specify the class Marks using the concept of inheritance giving details of the functions
void inpdetails() and void show(). The main function need not be written.

Q.5. A super class Stock has been defined to store the details of the stock of a retail

store. Define a subclass Purchase to store the details of the items purchased with

the new rate and updates the stock. Some of the members of the classes are

given below:

Class name : Stock

Data members:

item : to store the name of the item

qty : to store the quantity of an item in stock

rate : to store the unit price of an item

amt : to store the net value of the item in stock

Member functions:

Stock(......) : parameterized constructor to assign values to the data members

void display() : to display the stock details

Class name : Purchase

Data members

pqty : to store the purchased quantity


prate : to store the unit price of the

purchased item

Member functions

Purchase(.....) : parameterized constructor to assign values to the data members of both


classes

void update() : to update stock by adding the previous quantity by the purchased quantity
and replace the rate of item if there is a difference in the purchase rate of the item if there is
a difference in the purchase rate. Also update the current stock value as: (quantity * unit
price)

void display() : to display the stock details before and after updation

Specify the class Stock, giviersion (a version number or a date) , constructor and other
functions. Using the concept of inheritance, specify the class Purchase giving details of the
constructor(…) and other methods. The main function need not be written.
Q.6 A super classBank has been defined to store the details of a customer. Define a sub-
class Accountthat enables transactions for the customer with the bank. The details of both
the classes are given below:
Class name: Bank
Data members/instance variables:
name: stores the name of the customer
accNo: stores the account number
p: stores the principal amount in decimals
Member functions/methods:
Bank(…): parameterized constructor to assign values to the instance variables
void display(): displays the details of the customer
Class name: Account
Data members/instance variables:
amt: stores the transaction amount in decimals
Member functions/methods:
Account(…): parameterized constructor to assign values to the instance variables of both the
classes
void deposit(): accepts the amount and updates the principal as p = p + amt
void withdraw(): accepts the amount and updates the principal as p = p – amt
void display(): displays the details of the customer
Assume that the super classBank has been defined.Using the concept of inheritance, specify
the class Account giving details of the constructor(…), void deposit(), void withdraw() and
void display(). The super class and the main function need not be written.
Q.6A

A library issues books on rental basis at a 2% charge on the cost price of the
bookper day. As per the rules of the library, a book can be retained for 7 days
without any fine. If the book is returned after 7 days, a fine will also be charged for
the excess days as per the chart given below:

Number of excess days Fine per day(Rs.)


1 to 5 2.00
6 to 10 3.00
above 10 days 5.00

Design a class Library and another class Compute to perform the task. The details
of the two classes are given below:
Class name : Library

Data members/instance variables:

name : name of the book


author : author of the book
p : price of the book in decimals

Member functions:

Library(…) : parameterized constructor to assign values to data


members.
void show() : display the book detils.

Class name : Compute

Data members/instance variables:

d : number of days taken in returning the book


f : to store the fine

Member functions:

Compute(…) : parameterized constructor to assign values to data


members of both the classes.
void fine() : calculates the fine for the excess days
void display() : display the book details along with the number of
days, fine and the total amount to be paid.
Total amount is calculated as: (2% of price of book*total
no. of days)+fine.
Specify the class Library giving details of the constructors and void show(). Using
the concept of Inheritance, specify the class Compute giving details of constructor,
void fine() and void display() function.

Q 6B

A super class Worker has been defined to store the details of a worker. Define a subclass
Wages to compute the monthly wages of the worker. The details/specifications of both
classes are given below:
Class Name Worker
Data Members/Instance Variables:
Name Stores the name of the worker.
Basic Stores the basic pay in decimals.
Member Functions:
Worker(…) Parameterised constructor to assign values to data
members.
void display() Displays the worker's details.

Some of the members of the class Wages are given below-


Class Name Wages
Data Members/Instance Variables:
Hrs Stores the hours worked.
Rate Stores the rate per hour.
Wage Stores the overall wage of the worker.

Member Functions:
Wages(…) Parameterised constructor to assign values to data
members of both the classes.
Double overtime() Calculates and returns the overtime amount as
(hours x rate).
void display() To count the frequency of the word "and".

Specify the class Worker, giving details of the constructor and void display(). Using the
concept of inheritance. specify a class Wages giving details of the constructor, double
overtime() and void display().Write an appropriate main() function.

Q 6C. A class Employee contains employee details and another class Salary calculates the
employee’s net salary.

Member functions:

employee( ) : default constructor

Employee( … ) : parametrised constructor to assign values to


employee number, name and designation.

void display ( ) : display the employee details

Class name : Salary

Data member :

basic : float variable to store the basic pay

Member functions:

Salary(…) : parameterized constructor to assign values to data

members.

void calculate( ) : calculate the employee’s net salary

according to following rules;

DA = 10% of basic

HRA = 15% of basic

Salary = basic + DA + HRA

PF = 8% of salary

Net Salary = salary – PF

Display the employee details and the Net salary.

Specify the class Employee giving details of the constructors and member function void
display( ). Using the concept of Inheritance specify the class Salary giving details of
constructors and the member function void calculate( ). The main function need not be
written.

QExtra).Write a program to implement class hierarchy

Circle

Cylinder

Radius is stored in Circle class while height is stored in Cylinder class. Circle class computes
the base area while lateral area and total area are computed in Cylinder class. Create
another class (Main) to implement these.
QExtra).Write a program to implement class hierarchy

Circle

Sphere

The sphere class overrides two methods of Circle class : showCharacteristics() and
calculateArea(), and has an additional method calculateVolume(). Also write a class Test that
has main() method which creates objects of Circle and Sphere classes and tests them.

QExtra).Write a program to implement class hierarchy

Circle

Sphere

The sphere class overrides two methods of Circle class : showCharacteristics() and
calculateArea(), and has an additional method calculateVolume(). Also write a class Test that
has main() method which creates objects of Circle and Sphere classes and tests them.

Topic #7: Object Passing / Object as Parameter - Submission

Date: 10/8/2020

Q10.The co-ordinates of a point P on a two-dimensional plane can be represented by P(x,y)


with x as the x

co-ordinate and y as the y co-ordinate. The co-ordinates of midpoint of two points P1(x1,y1)
and

P2(x2,y2) can be calculated as P(x,y) where:

x1  x 2
x
2 ,
y1  y 2
y
2

Design a class Point with the following e ails:


d t

Class name : Point

Data members

x : stores the x co-ordinate

y : stores the y co-ordinate

Member functions:

Point() : constructor to initialize x=0 and y=0

void readPoint() : accepts the co-ordinates 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 co-ordinates 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.

Q.11 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:
intarr[] : to store the elements of an array
int n : to store the size of the array
Member functions:
Mixer(intnn) : 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 obect array elements with the
parameterized array elements and return the resultant obect
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 obect and call the function
accordingly to enable the task.

Topic #8: Iterations - Submission Date : 10/9/2020

Q12. The International Standard Book Number (ISBN) is a unique numeric book identifier
which is printed on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if
1*digit1 + 2*digit2 + 3*digit3 + 4*digit4 + 5*digit5 + 6*digit6 + 7*digit7 + 8*digit8 + 9*digit9
+ 10*digit10 is divisible by 11.
Example: For an ISBN 1401601499
Sum=1*1 + 2*4 + 0*0 + 4*1 + 5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253 which is divisible by
11.
Write a program to:
(i) input the ISBN code as a 10-digit number
(ii) If the ISBN is not a 10-digit number, output the message “Illegal ISBN” and terminate the
program
(iii) If the number is 10-digit, extract the digits of the number and compute the sum as
explained above.
If the sum is divisible by 11, output the message “Legal ISBN”. If the sum is not divisible by
11, output the message “Illegal ISBN”.
Q.13 Write a Program in Java to input a number and check whether it is a Kaprekar number
or not.

Note: A positive whole number ‘n’ that has ‘d’ number of digits is squared and split into two
pieces, a right-hand piece that has ‘d’ digits and a left-hand piece that has remaining ‘d’ or
‘d-1’ digits.

If the sum of the two pieces is equal to the number, then ‘n’ is a Kaprekar number. The first
few Kaprekar numbers are: 9, 45, 297 ……..
Example 1: 9

92 = 81, right-hand piece of 81 = 1 and left hand piece of 81 = 8

Sum = 1 + 8 = 9, i.e. equal to the number. Hence, 9 is a Kaprekar number.

Example 2: 45

452 = 2025, right-hand piece of 2025 = 25 and left hand piece of 2025 = 20

Sum = 25 + 20 = 45, i.e. equal to the number. Hence, 45 is a Kaprekar number.

Example 3: 297

2972 = 88209, right-hand piece of 88209 = 209 and left hand piece of 88209 = 88

Sum = 209 + 88 = 297, i.e. equal to the number. Hence, 297 is a Kaprekar number.

Q.14Write a Program in Java to input a number and check whether it is a Smith number or
not.

A smith number is a composite number, the sum of whose digits is the sum of the digits of
its prime factors obtained as a result of prime factorization (excluding 1).

The first few such numbers are 4, 22, 27, 58, 85, 94, 121.....

Example 1.

666 Prime factors are 2, 3, 3 and 37

Sum of the digits are (6+6+6) = 18

Sum of the digits of the factors (2+3+3+(3+7) = 18

Sample data:

Input 94 Output SMITH Number


Input 102 Output NOT SMITH Number

Q.15 Write a menu driven Program in Java to input a number and check whether i) it is an
Automorphic number or not and (ii) it is a Disarium number or not and (iii) it is an Armstrong
number or not.

Q.16 Write a Program in Java to find all Twin Primes numbers between 10 and 1000.

Write a Program in Java to print all the Twin Prime numbers within a given range.

Note: Twin Prime numbers are a pair of numbers which are both prime and their difference
is 2.

Example: Twin Prime numbers in the range 1 to 100 are :

(3,5) (5,7) (11,13) (17,19) (29,31) (41,43) (59,61) (71,73)

Q.17 Write a Program in Java to print a diamond pattern with a maximum of 10 *

Q.18 Write a Program in Java to display Pascal’s triangle.

Q.19 Write a Program in Java to input a number and check whether it is a Unique
Number or not.

Note: A Unique number is a positive integer (without leading zeros) with no duplicate
digits. For example 7, 135, 214 are all unique numbers whereas 33, 3121, 300 are not.
Q.20 Write a Program to check whether a number is a Keith number.

Write a Program in Java to input a number and check whether it is a Keith Number
or not.
Note:A Keith Number is an integer N with ‘d’ digits with the following property:

If a Fibonacci-like sequence (in which each term in the sequence is the sum of the ‘d’
previous terms) is formed, with the first ‘d’ terms being the decimal digits of the
number N, then N itself occurs as a term in the sequence.

For example, 197 is a Keith number since it generates the sequence


1, 9, 7, 17, 33, 57, 107, 197, ………..

Some keith numbers are: 14 ,19, 28 , 47 , 61, 75, 197, 742, 1104, 1537……………
Q. 21

A simple encryption system uses a shifting process to hide a message. The value of
the shift can be in the range 1 to 26. For example a shift of 7 means that A = U, B
=V,C = W, etc.i e.
Text : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Code: U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
Fist an extra space is added to the end of the string. To make things little more
difficult, spaces within the original text are replaced with QQ before the text is
encrypted. Double Q (QQ) was selected because no English word ends in Q or
contains QQ.
Additionally the coded message is printed in blocks of six characters separated by
spaces. The last block might not contain six characters. Write a program that takes the
coded text (less than 100 characters), the shift value and prints the decoded original
text.Your program must reject any non-valid value for shift and display an error
message “INVALID SHIFT VALUE)”. Assume all characters are upper case. Test
your program for the following data and some data that you have coded, using the
rules given above:

Q.22

Given a time in numbers we can convert it into words. For example :


5 : 00 —— five o’clock
5 : 10 —— ten minutes past five
5 : 15 —— quarter past five
5 : 30 —— half past five
5 : 40 —— twenty minutes to six
5 : 45 —— quarter to six
5 : 47 —— thirteen minutes to six
Write a program which first inputs two integers, the first between 1 and 12 (both
inclusive) and second between 0 and 59 (both inclusive) and then prints out the time
they represent, in words.
Your program should follow the format of the examples above.
SAMPLE DATA :
1. INPUT :
TIME : 3,0
OUTPUT : 3 : 00 Three o’ clock
2. INPUT :
TIME : 7,29
OUTPUT : 7 : 29 Twenty nine minutes past seven
3. INPUT :
TIME : 6,34
OUTPUT : 6 : 34 Twenty six minutes to seven
4. INPUT :
TIME : 12,1
OUTPUT : 12 : 01 One minute past Twelve
5. INPUT :
TIME : 12,45
OUTPUT : 12 : 45 Quarter to One
6. INPUT :
TIME : 10,59
OUTPUT : 10 : 59 One minute to Eleven
7. INPUT :
TIME : 14,60
OUTPUT : Incorrect Input
Test your program for the data values given in the examples above and some random
data.
Q.23Write a program in Java to input the first 14 digits of an IMEI number and find the
check (last) digit of it.

The IMEI (15 decimal digits: 14 digits plus a check digit) includes information on the origin,
model, and serial number of the device.

The check digit (x) is obtained by computing the sum of digits then computing 9 times that
value modulo 10.

Q.24ACircular Prime is a prime number that remains prime under cyclic shifts of its
digits. When the leftmost digit is removed and replaced at the end of the remaining
string of digits, the generated number is still prime. The process is repeated until the
original number is reached again.
A number is said to be prime if it has only two factors: 1 and itself.
Example:
131
311
113
Hence, 131 is a circular prime.
Accept a positive number N and check whether it is a circular prime or not. The new
numbers formed after the shifting of the digits should also be displayed.

Test your program with the following data and some random data:
Example 1
INPUT: N = 197

OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME.

Example 2
INPUT: N = 1193

OUTPUT:
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME.

Example 3
INPUT: N = 29

OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME.

Q.25 Write a program in Java to display the Floyd’s Triangle as given below, for N number of
rows. Also note that the value of N is to be entered by the user. You may input from the user
using either the java.io package or java.util package. Name the class as
FloydsTriangle.

INPUT:5
OUTPUT:

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Q.26

Consider the sequence of natural numbers:


1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, …
Removing every second number gives a new sequence:
1, 3, 5, 7, 9, 11, 13, 15, …
Removing every third number now gives us another sequence:
1, 3, 7, 9, 13, 15, …
This process continues after indefinitely by removing the 4th, 5th, 6th number, and so
on, until, after a fixed number of steps, certain natural numbers remain indefinitely.
Such numbers are known as Lucky Numbers.

Write a program in Java to generate and print lucky numbers, less than a given
number N, where the value of N is to be entered by the user of the program. If the
user enters the value of N as 10, then we have the following sequence of natural
numbers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Now, removing every 2nd number from this sequence leaves us with:
1, 3, 5, 7, 9
Now removing every 3rd number from the current sequence gives us:
1, 3, 7, 9
Removing every 4th number gives:
1, 3, 7
This sequence now remains constant if you attempt to continue this process.
Hence lucky numbers less than 10 are 1, 3, and 7.

Example:
INPUT: N = 10
OUTPUT: 1, 3, 7

INPUT: N = 25
OUTPUT: 1, 3, 7, 13, 19

Q.27A happy number is a number in which the eventual sum of the square of the digits of
the number is equal to 1.

Example:

28 = ( 2 )^2 + ( 8 )^2 = 4 + 64 = 68

68 = ( 6 )^2 + ( 8 )^2 = 36 + 64 = 100

100 = ( 1 )^2 + ( 0 )^2 + ( 0 )^2= 1 + 0 + 0 = 1


Hence, 28 is a happy number.

Example: 12 = ( 1 )^2 + ( 2 )^2 = 1 + 4 = 5

Hence, 12 is not a happy number.

Design a class happy to check if a given number is a happy number. Some of the members of
the class are given below:

Class name : Happy

Data members/instance variable :

n : stores the number

Member functions :

Happy( ) : constructor to assign 0 to n

void getnum(intnn) : to assign the parameter value to the number n = nn

int sum_sq_digits(int x) : returns the sum of the square of the digits of the number x

void ishappy( ) : checks if the given number is a happy number by calling the function
sum_sq_digits(int) and displays an appropriate message

Specify the class Happy giving details of the constructor( ), void getnum(int),
intsum_sq_digits(int) and void ishappy( ). Also define a main( ) function to create an object
and call the methods to check for happy number.

Q.28

Write a program to input a natural number less than 1000 and display it in words. [Note we
have solved the program for numbers in the range [1-9999]

Test your program for the given sample data and some random data.

Sample Data:

Input: 29

Output: TWENTY NINE


Input: 17001

Output: OUT OF RANGE

Input: 119

Output: ONE HUNDRED AND NINETEEN

Input: 500

Output: FIVE HUNDRED

Q.29

An Emirp number is a number which is prime backwards and forwards. Example: 13 and 31
are both prime numbers. Thus, 13 is an Emirp number.

Design a class Emirp to check if a given number is Emirp number or not. Some of the
members of the class are given below:

Class name :Emirp

Data members/instance variables:

n : stores the number

rev : stores the reverse of the number

f : stores the divisor

Member functions:

Emirp(intnn) : to assign n = nn, rev = 0 and f = 2

intisprime(int x) : check if the number is prime using the recursive technique and return 1 if
prime otherwise return 0

void isEmirp() : reverse the given number and check if both the original number and the
reverse number are prime, by invoking the function isprime(int) and display the result with
an appropriate message.
Specify the class Emirp giving details of the constructor(int), intisprime(int) and void
isEmirp(). Define the main() function to create an object and call the methods to check for
Emirp number.

Q.30

A prime palindrome integer is a positive integer (without leading zeros) which is prime as
well as a palindrome. Given two positive integers m and n, where m < n, write a program to
determine how many prime-palindrome integers are there in the range between m and n
(both inclusive) and output them.

Instance variables: m, n

PalPrime(int mm, int nn)

public static boolean IsPrime(int)

public static boolean IsPal(int)

public static void IsPalPrime(int,int)

public static void main(String[] args)

public static void Gen3DPalPrime() //insert a 1-D palprime number between 11 and test for
primeness. Eg, insertion of 3 and 5 between 11 yields palprimes : 131, 151

public static void Gen4DPalPrime() //insert a 2-D palprime number in place of middle two
zeroes in 1001 and test for primeness.

public static void Gen5DPalPrime() //insert some 3-D palprimes in 11 eg., insertion of
131,383,797 yields these palprime numbers : 11311, 13631, 17971.

The input contains two positive integers m and n where m < 3000 and n < 3000. Display the
number of prime palindrome integers in the specified range along with their values in the
format specified below:

Test your program with the sample data and some random data:

Example 1:
INPUT: m=100

N=1000

OUTPUT: The prime palindrome integers are:

101,131,151,181,191,313,351,373,383,727,757,787,797,919,929

Frequency of prime palindrome integers: 15

Example 2:

INPUT:

M=100

N=5000

OUTPUT: Out of range

Q.31

A Composite Magic number is a positive integer which is composite as well as a magic


number.

Composite number:

A composite number is a number that has more than two factors.

For example: 10

Factors are: 1, 2, 5, 10

Magic number:

A magic number is a number in which the eventual sum of the digits is equal to 1
For example: 28=2+8=10=1+0=1

172=1+7+2=10

10=1+0=1

Instance variable : m, n

Methods:

MagicCompo()

void getnum(int mm, int nn)

int Sum_of_digits(int)

int isPrime(int)

boolean isMagic(int)

void display()

void main()

Accept two positive integers m and n, where m is less than n as user input. Display the
number of Composite magic integers that are in the range between m and n (both inclusive)
and output them along with the frequency, in the format specified below.

Test your program with the sample data and some random data:

Example 1:

INPUT:

m = 10

n = 100

OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE:

10, 28, 46, 55, 64, 82, 91, 100

FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 8

Example 2:

INPUT:

m = 1200

n = 1300

OUTPUT:

THE COMPOSITE MAGIC INTEGERS ARE:

1207, 1216, 1225, 1234, 1243, 1252, 1261, 1270, 1288

FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 9

Example 3:

INPUT:

m = 120

n = 99
OUTPUT:

INVALID INPUT

Q.32

Write a Program in Java to input a number and check whether it is an Evil Number or not.

Evil Number : An Evil number is a positive whole number which has even number of 1’s in its
binary equivalent.

Example: Binary equivalent of 9 is 1001, which contains even number of 1’s.

A few evil numbers are 3, 5, 6, 9….

Design a program to accept a positive whole number and find the binary equivalent of the
number and count the number of 1’s in it and display whether it is a Evil number or not with
an appropriate message. Output the result in format given below:

Example 1

INPUT : 15

BINARY EQUIVALENT : 1111

NO. OF 1’s : 4

OUTPUT : EVIL NUMBER

Example 2

INPUT : 26

BINARY EQUIVALENT : 11010

NO. OF 1’s : 3
OUTPUT : NOT AN EVIL NUMBER

Q.33

A positive natural number, (for e.g. 27), can be represented as follows:

2+3+4+5+6+7

8+9+10

13+14

where every row represents a combination of consecutive natural numbers, which add up to
27.

Write a program which inputs a positive natural number N and prints the possible
consecutive number combinations, which when added give N.

Test your program for the following data and some random data.

SAMPLE DATA

INPUT:

N=9

OUTPUT:

4+5

2 + 3+ 4

INPUT:

N = 15
OUTPUT:

7 +8

1 +2+ 3+ 4+ 5

4 +5+ 6

INPUT:

N = 21

OUTPUT:

10+ 11

1+ 2+ 3+ 4+ 5+ 6

6+ 7+ 8

Topic #9 Arrays - Submission Date : 12/10/2020

Q35. A square matrix [][] where no of rows >2 and < 9. Sort each row in ascending order
using any general sorting algorithm and print the original as well as the changed matrix.

Q35A.

A two-dimensional character array is defined as A[3…6, -2…2]. If the array is stored in Row-
major order, determine the address of A[5, 1], given the base address as 1200.

Q35B.

Given a two-dimensional array 3 x 4 as shown here :


8 6 5 4 
2 1 9 7 
 
3 6 4 2

How would array appear in memory, if : (I) Row-Major technique is implemented. (ii) Column-
major technique is implemented.

Q35C.

X is 2-D array [10 x 5]. Each element of the array is stored in 2 memory locations or requires 2
words of storage space for each element. If X[1, 1] begins at address 150, find the location of X[3,
4]. Use the formula for calculations. (The arrangement is in row-major).

Q35D.

If an integer array Z[-20…20, 10…35] is stored in column major order beginning location 500,
determine the location of Z[0,30].

Q35E.

Each element of an array B[-15…20,20…45] requires one byte of storage. If the array is stored in
column major order and the location of B[0, 40] is 1735, find the address of the beginning
location B[0, 0]

Q.36 A square matrix is said to be a Ma ic Square, if the sum of each row, each column and

g
each diagonal is same. Write a program to enter an integer number ‘n’. Create a magic
square of size ‘n*n’. Finally, print the elements of the matrix as Magic Square.

Note: n <= 5

Sample Input: Enter the size of the matrix : 4


Sample Output: The Magic Matrix of size 4×4 is:

Sample Input: Enter the size of the matrix : 5


SampleOutput: The Magic Matrix of size 5×5 is:
Q.37 Given a 2-D array, write a program to print it out in spiral order. Implement class Spiral
with the following specifications :

Class name: Spiral

Instance Variables

Array a to hold N x N array

int N to hold the value of N

Methods

Constructor method: receives parameter N and creates an N x N array with values 1 to N.

printNormal() : prints the array in normal order

printSpiral() : prints the array in spiral order.

Also create method main() that should obtain the value of N and then create and print the
array.

Q.37A.

Write a program to Spiral Fill a matrix.

Q.38 Write a program to multiply two matrices

Q.39 Write a program to find a) transpose of a matrix b) saddle point of a matrix c)


Symmetric matrix d) Upper triangular matrix e) Lower triangular matrix

Q.40 Write a program to check Diagonal matrix

Q.41 Write a program to a) sort the elements of a 2-D array b) sort the boundary elements
of a matrix c) sort each row of a matrix d) sort each column of a matrix

Q.42 Write a program to fill a matrix with fibonacci numbers as elements

Q. 43 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 order. The details of the
members of the class are given below.

Class name: Composite


Data members/instance variables:
arr[][]: stores the composite numbers column-wise
m: integer variable to store the number of rows
n: integer variable to store the number of columns
Member functions:
Composite(int mm, intnn): to create the matrix of size M x N, making sure that the
dimensions does not exceed 20.
intisComposite(int p): returns 1 if the number is composite. Otherwise it returns 0.
void fill(): to fill the elements of the array with the first M x N composite numbers in
column-wise order.
void display(): displays the array in the matrix form.

Specify the class Composite giving details of the constructor, and other methods.
Also define the main() method to create an object and call the methods accordingly to
enable the task.

Q. 44

A class Shift contains a two-dimensional integer array of order (m x n) where the


maximum values of both m and n is 5. Design the class Shift to shuffle the matrix (i.e.
the first row becomes the last, the second row becomes the first and so on). The
details of the members of the class are given below:
Class name: Shift
Data members/instance variables:
mat[][]: stores the array elements
m: integer to store the number of rows
n: integer to store the number of columns
Member functions/methods:
Shift(int mm, intnn): parameterized 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(): displays the matrix elements

Specify the class Shift giving details of the constructor, void input(), void cyclic(Shift)
and void display(). Define the main() function to create an object and call the
methods accordingly to enable the task of shifting the array elements.

Q.45

Write a program to declare a square matrix A[][] of order (M x M) where ‘M’ must be
greater than 3 and less than 10. Allow the user to input positive integers into this
matrix. Perform the following tasks on the matrix:
(a) Sort the non-boundary elements in ascending order using any standard sorting
technique and rearrange them in the matrix.
(b) Calculate the sum of both the diagonals.
(c) Display the original matrix, rearranged matrix and only the diagonal elements of
the rearranged matrix with their sum.
Test your program with the sample data and some random data:
Example 1
INPUT :M = 4
9 2 1 5

8 13 8 4

15 6 3 11

7 12 23 8

OUTPUT:
ORIGINAL MATRIX
9 2 1 5

8 13 8 4

15 6 3 11

7 12 23 8

REARRANGED MATRIX
9 2 1 5

8 3 6 4

15 8 13 11

7 12 23 8

DIAGONAL ELEMENTS
9 5
3 6
8 13
7 8

SUM OF THE DIAGONAL ELEMENTS = 59

Q.46

Given a square matrix M [ ] [ ] of order ‘n’. The maximum value possible for ‘n’ is 10.
Accept three different characters from the keyboard and fill the array according to the
instruction given below.
Fill the upper and lower elements formed by the intersection of the diagonals by
character 1.
Fill the left and right elements formed by the intersection of the diagonals by
character 2.
Fill both the diagonals by character 3.
Output the result in format given below:
Example 1
ENTER SIZE : 4
INPUT : FIRST CHARACTER : ‘*’
SECOND CHARACTER : ‘?’
THIRD CHARACTER : ‘#’
OUTPUT :
# * *
#
? #
# ?
? #
# ?
# * *
#

Example 2
ENTER SIZE : 5
INPUT : FIRST CHARACTER : ‘$’
SECOND CHARACTER : ‘!’
THIRD CHARACTER : ‘@’
OUTPUT :
@ $ $ $
@
! @ $
@ !
! !
@ ! !
! @ $
@ !
@ $ $ $
@

Example 3
ENTER SIZE : 65
OUTPUT : SIZE OUT OF RANGE

Q.47

Write a program to declare a square matrix A[ ][ ] of order MxM where ‘M’ is the
number of rows and the number of columns, such that M must be greater than 2 and
less than 10. Accept the value of M as user input. Display an appropriate message for
an invalid input. Allow the user to input integers into this matrix. Perform the
following tasks:
(a) Display the original matrix.
(b) Rotate the matrix 90° clockwise as shown below:

(c) Find the sum of the elements of the four corners of the matrix.
Test your program for the following data and some random data:
Example 1
INPUT :
M=3

OUTPUT :
ORIGINAL MATRIX

MATRIX AFTER ROTATION

Sum of the corner elements = 20


Example 2
INPUT :
M=4

OUTPUT :
ORIGINAL MATRIX

MATRIX AFTER ROTATION


Sum of the corner elements = 18
Example 3
INPUT :
M = 14
OUTPUT :
SIZE OUT OF RANGE
Example 4
INPUT :
M = 112
N = 130
OUTPUT :
INVALID INPUT

Q 47B

A class Collection contains an array of 100 integers. Using the following class description
create an array
with common elements from two integer arrays. Some of the members of the class are given
below:

Class name : Collection

Data members

arr[] : integer array

len : length of the array

Member functions

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). You need not write the main Function.

Q47C

A transpose of an array is obtained by interchanging the elements of rows and columns. A


class
Transarray contains a two dimensional integer array of order [ m x 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:
Class name : Transarray
Data members
arr[][] : stores the matrix elements
m : integer to store the number of rows.
n : integer to store the number of columns.
Member functions
Transarray() : default constructor.
Transarray(intmm,intnn) : to inititalize the size of the matrix, m=mm,n=nn.
void fillarray() : to enter elements into the matrix.
void transpose(Transarray A) : to find the transpose of a given matrix.
void disaparray() : displays the array in a matrix form.
Specify the class Transarray giving details of the constructors, void fillarray(), void
transpose(Transarray)
and void disparray(). You need not write the main function
Q47C1.

Write a Java program to transpose a square two-dimensional array in place withouut


creating a second array.

Q 47D

A class PrimeFac contains an array of 50 integers. Some of the members of the class are
given below:
Class name : PrimeFac
Data members
num[] : array to store integers.
freq[] : array to store the frequency of prime factors of numbers.
Member functions
PrimeFac() : constructor to inititalize array elements to 0.
void enter() : to enter values into array num[]
void frefac() : to determine the frequency of prime factors of the numbers stored in num[]
and assign it to freq[].
void disp() : to display both the arrays.
Specify the class PrimeFac giving details of the constructor, void enter(), void frefac() and
void disp().You
need not write the main function.

Q 47D1

Write a Java program that accepts the value of N (an integer) and creates N x N boolean
array a[ ] [ ] such that a[I][j] ids true I I and j are relatively prime (I.e., have no common
factors) and false otherwise. The class specifications are as follows:
Class name : RelPrime
Instance Variables : boolean array of N x N.
Member functions
void create(int n) : create boolean array a[ ][ ] so that
a[I][j]=true, if I,j are relatively prime
=false, otherwise.
int gcd() : determines the greatest common divisor off two numbers.
void disp() : prints the boolean array a[][].
A constructor method to create array.
Also write main() method that accepts value of N(<100) and then implements the above
mentioned functionality.

Q 47D2

Write a Java program to obtain maximum and minimum in a single dimensional

array.

Q 47D3

Write a Java program to perform Bubble Sort in a given 1-D array of integers.

Q 47D4

Write a Java program to perform selection sort in a given 1-D array of integers.

Q 47D5

Write a Java program to perform binary search in a given array of integers.

Q 47D6

Write a Java program to perform linear search in a given array of integers.

Q 47D7

Write a Java program that adds two binary numbers and returns their binary sum as per the
following rules:
0+0=0
0+1=1
1+0=1
1+1=10 (here 1 is carry bit of 10)
1+1+1=11 (here 1 is carry bit of 11)
You can use arrays to hold binary digits. The class specifications are:
Class name : BinNumbers
Methods:
long BinAdd(long A, long B) : adds two binary numbers received in A and B
Write method main()that reads the two binary numbers and invokes BinAdd() to get their
sum.

Q 47D8

Christian Goldback hass conjectures for N < 1014 that every even N>2, can be represented as
sum of two primes. For example, 18=5+13.
Write a Java program that readsN which should be an even number > 2 and represents it as
the sum of two primes.

Q 47D9

Write a Java program to find the longest consecutive sequence of integers with no primes.
The program should accept a number N and print out the largest block of integers between
2 and N with no primes.

Q 47D10

Write a Java program to find the number of prime numbers <= N where accept N from the
user. Use the method Sieve of Erathosthenes to find prime numbers.
To get the prime numbers in the range 2..N, you can use a simple and interesting method
known as Sieve of Erathosthenes. It works as follows :

1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100

Sequentially write down the integers from 2 to the highest number n you wish to include in
the table. Cross out all the numbers >2 which are divisible by 2 (every second number). Find
the smallest remaining number >2. It is 3. So cross out all the numbers > 3which are divisible
by 3 (every third number). Find the smallest remaining number > 3. It is 5. So cross out all
numbers > 5 which are divisible by 5 (every fifth number).

Continue until you have crossed out all numbers divisible by └√n┘,where └x┘ is the floor
function. The numbers remaining are prime. This procedure is illustrated in the above
diagram which sieves up to 50, and therefore crosses out composite numbers up to

└√50┘=7.

Q 47D11

You can generate random numbers in the range 0 to 1 using Math.random() method. If you
want to generate random numbers in a range 7(L) to 23(U) then you can use the method as :
Math.random() * (U-L+1)+L
Where L is the lower limit ie, 7; U is the upper limit ie 23
Using this formula, generate a 1D double type array a in the range 10-50 after asking the
user to specify its length.
Then perform the following actions on the array
(i) Display array elements
(ii) Find maximum element of the array
(iii) Compute array average
(iv) Copy array to another array b
(v) Reverse the second array
(vi) Display second array
(vii) Calculate dot product of two arrays as :

Σa[I]*b[I]

Q 47D12

The B-by-N Hadamard H(N) matrix is a boolean matrix with the remarkable property that
any two rows differ in exacgly N/2 bits.

H(1)
T
H(2)
TT
T0

H(4)
TTTT
T0T0
TT00
T00T

Write a program that takes the value N and prints H(N). Assume that N is a power off 2.
Instance Variable :
boolean[ ][ ] H;
int N;
Methods:
Hadamard(int n)
void createHadamard()
void print();
public static void main(String[ ] args)

Q 47E

Lucky Numbers are those that are generated by a sieving process similar to that of Sieve or
Eratosthenes, consider a list of natural numbers that starts with 1
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 now removing every second element we get
1, 3, 5, 7, 9 now removing every third we get
1, 3, 7, 9 now removing every fourth we get
1, 3, 7 we can no longer remove the fifth so the survivors are 1, 3 and 7 which are Lucky
numbers from 1 to 10.
WAP to implement the same using arrays and display the Lucky numbers from 1 to 10
Q47F The result of a quiz competition is to be prepared as follows:

The quiz has five questions with four multiple choices (A, B, C, D), with each question
carrying 1 mark for the correct answer. Design a program to accept the number of
participants N such that N must be greater than 3 and less than 11. Create a double
dimensional array of size (Nx5) to store the answers of each participant row-wise.
Calculate the marks for each participant by matching the correct answer stored in a single
dimensional array of size 5. Display the scores for each participant and also the participant(s)
having the highest score.

Example: If the value of N = 4, then the array would be:

Note: Array entries are line fed (i.e. one entry per line)
Test your program with the sample data and some random data:

Example 1
INPUT : N = 5
Participant 1 D A B C C
Participant 2 A A D C B
Participant 3 B A C D B
Participant 4 D A D C B
Participant 5 B C A D D
Key: B C D A A

OUTPUT : Scores :
Participant 1 D A B C C
Participant 1 = 0
Participant 2 = 1
Participant 3 = 1
Participant 4 = 1
Participant 5 = 2
Highest score: Participant 5

Example 2
INPUT : N = 4
Participant 1 A C C B D
Participant 2 B C A A C
Participant 3 B C B A A
Participant 4 C C D D B
Key: A C D B B
OUTPUT : Scores :
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest score:
Participant 1
Participant 4
Example 3
INPUT : N = 12
OUTPUT : INPUT SIZE OUT OF RANGE.

Topic #10 Strings - Submission Date : 12/10/2020

Q.48 Design a class Sort which enables a word to be arranged in alphabetical order. The
details of the members of the class are given below :

Class name : Sort

Data members :

Str : stores a word

len : to store the length of the word

Member functions:
Sort () : default constructor

voidreadTxt() : to accept the word

void arrange() : to arrange the word in alphebetical order using any standard
sorting technique.

void display( ) : displays the original word along with the sorted word
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.

Q.48A.

Program to check whether a string is palindrome or not. The program must have the
following functions:

public static void main(String args[]) /* input a string and test to see if it is a palindrome*/

public static void showPalindrome(String s) /*Displays result of testing the string */

public static boolean isPalindrome(String s) /* Returns true if the string is a palindrome */

public static boolean isPalindrome2(String s)/* Returns true if the string is a palindrome
when case is ignored. */

Sample input: mom, dad, radar, Mom

Q.48B.

Implement a class StringS that has a data member as String text. The class also contains a
method extracText() that recceives a word as parameter. The passed word appears at least
two times in the text. Method extracText() finds the first and last occurrence of the passed
word in the text and returns the text from between the two occurrences.

Sample Input/Output

Enter a line of text having two identical words :

This is true that often and mostly true things remain hidden.

Enter the word that has multiple occurrences in the text

true

The text that lies between two ‘trues’s is:

that often and mostly


Q.48C.

Write a Java program to implement a class Strings with the following method swapPairs that
accepts a String as a parameter and returns the String with each pair of adjacent letters
reversed. If the String has an odd number of letters, the last letter is unchanged. For
example, the call swapPairs(“forget”) should return “ofgrte” and the call swapPairs(“hello
there”) should return “ehllo htree”.

The class also has method main() that accepts a string and calls swapPairs() method to swap
pairs of characters in the passed string.

Q.49 Write a program to swap two strings without using third variable.

Q.50 Write a program to remove duplicate characters from a string.

Example:
INPUT: HELLO WORLD
OUTPUT: HELO WRD

Q.51Write a program to remove consecutive repeated characters from a string.

Example:
INPUT: Jaaavvvvvaaaaaaaaaaaa
OUTPUT: Java
INPUT: Heeeeiiiissssggoiingggggggggg
OUTPUT: He is going

Q.52 Write a program to swap strings.

Q.53 Write a program to Print Date in dd/mm/yy format.

Write a Program in Java to input a Date in ddmmyyyy 8-digit format and print it in:
1) dd/mm/yyyy format
2) dd, month name, yyyy format
Input: 01011943
Output:
01/10/1943
1 January, 1943
Q.54Question:

A sentence in the Special Fashion can be printed by taking two integers (not beyond total
number of words in the sentence or less than 1). These integers tell the word number of the
sentence. Replace only those words present at those given integer places by the next
character in a circular fashion according to the English Alphabets. If both the integers are
same then replace only one word. let us consider the following examples:

Input Sentence: He has good Books.

Input Integers: 2, 4

Output Sentence: He ibt good Cpplt.

(i.e. word number 2 and 4 have been replaced by the next characters in a circular fashion)

Input Sentence: Time and tide waits for none.

Input Integers: 3, 3

Output Sentence: Time and ujef waits for none.

Write a case sensitive program that reads a sentence from console (the characters of the
sentence may be capital or small or mixed) and two positive integers and output the same
sentence after replacing those words present at those given integer places by the next
character in a circular fashion according to the English Alphabets.

In the first example given above, word number 2, i.e. has is replaced by next characters and
hence it becomes ibt . Similarly, word number 4, i.e. tide is replaced by next characters and
hence it becomes ujef .

Q.55 A sentence is terminated by either ".", "!" or "?" followed by a space.

Input a piece of text consisting of sentences. Assume that there will be a maximum of 10
sentences in a block.

Write a program to:

(i) Obtain the length of the sentence (measured in words) and the frequency of vowels in
each sentence.

(ii) Generate the output as shown below using the given data

Sample data:

INPUT HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.

OUTPUT

Sentence No. of Vowels No. of words


----------------------------------------------------------

1 2 1

2 5 3

3 8 4

4 3 3

Sentence No. of words/vowels

----------------------------------------------------------

1 VVVVVV

WWW

2 VVVVVVVVVVVVVVV

WWWWWWWWW

3 VVVVVVVVVVVVVVVVVVVVVVVV

WWWWWWWWWWWW

----------------------------------------------------------

Scale used 1:3

Q.56 Input a paragraph containing 'n' number of sentences where (1<=n<=4). The words are
to be separated with single blank space and are in upper case. A sentence may be
terminated either with a full stop (.) or question mark (?). Perform the followings:

(i) Enter the number of sentences, if it exceeds the limit show a message.

(ii) Find the number of words in the paragraph

(iii) Display the words in ascending order with frequency.

Example 1:

INPUT:

Enter number of sentences:

1
Enter sentences:

TO BE OR NOT TO BE.

OUTPUT:

Total number of words: 6

WORD FREQUENCY

OR 1

NOT 1

TO 2

BE 2

(iv) Display the string sorted on word length.

(v) Display the string sorted on words in alphabetical order

(vi) Remove the third word from the sentence

(v) Remove duplicate characters from the sentence

Q.57

A sequence of Fibonacci Strings is generated as follows:

S0 = “a”, S1 = “b”, Sn = S(n-1) + S(n-2) where ‘+’ denotes concatenation. Thus the sequence is:

a, b, ba, bab, babba, babbabab, ………. n terms.

Design a class FiboString to generate Fibonacci strings. Some of the members of the class are
given below:

Class name : FiboString


Data members/instance variables:

x : to store the first string

y : to store the second string

z : to store the concatenation of the previous two strings

n : to store the number of terms

Member functions/methods:

FiboString() : constructor to assign x=”a”, y=”b”, z=”ba”

void accept() : to accept the number of terms ‘n’

void generate() : to generate and print the fibonacci strings. The sum of (‘+’ i.e.
concatenation) first two strings is the third string. Eg. “a” is first string, “b” is second string
then the third string will be “ba” and fourth will be “bab” and so on.

Specify the class FiboString, giving details of the constructor(), void accept() and void
generate(). Define the main() function to create an object and call the functions accordingly
to enable the task.

Output:

1) Enter the number of terms : 2

The Fibonacci String Series is : a, b

2) Enter the number of terms : 5

The Fibonacci String Series is : a, b, ba, bab, babba

Q.58 Input a word in uppercase and check for the position of the first occurring vowel and
perform the

following operation.
i) Words that begin with a vowel are concatenated with “Y” . For example, EUROPE becomes

EUROPEY.

ii) Words that contain a vowel in between should have the first part from the position of the

vowel till end, followed by the part of the string from beginning till position of the vowel and

is concatenated by “C”. For example PROJECT becomes OJECTPRC.

iii) Words which do not contain a vowel are concatenated with “N”. For example, SKY
becomes

SKYN.

Design a class Rearrange using the description of the data members and member functions
given below:

Class name : Rearrange

Data members

Txt : to store a word

Cxt : to store the rearranged word

len : to store the length of the word

Member functions

Rearrange() : constructor to initialize the instance variables

void readword() : to accept the word input in UPPERCASE

void convert() : converts the word into its changed form and stores it in string Txt

void display() : displays the original and the changed word

Specify the class Rearrange giving the details of the constructor(), void readword(), void
convert() and
void display(). Define a main function to create an object and call the function accordingly to
enable the
task.
Q58A

Write a program to search for a string in an ordered array (with elements in ascending order)
using binary search.

Q58A1

For an array containing the terms 2,4,6, and so on up to 28 in that order, draw a trace/dry
run showing which elements are examined if you search for 21 using a binary search.

Q58A2

Write a Java program that accepts a String and prints the letters of the string, separated by
dashes, along with the reversed string, separated by dashes.

Enter String : Useful

U-s-e-f-u-l

l-u-f-e-s--U

Q58A3

Write a Java program that accepts a student’s first name, middle name, last name and age. It
then generates a password as per following specifications:

<first and last letter of lastname> <first digit of age> <first and last letter of firstname>
<second digit of age> <first and last letter of middle name>

ie, for a name “Shama Mohan Bhandari” and age 24, it should generate :

Bi2Sa4Mn

Q58A4

Write a Java program that prompts a user for a mobile number of the form ddd-dddd ddddd,
where d is a digit.

The first three digits signify country-code. Display the phone number in the following format :

(ddd) ddddd-ddddd if the country code is other than 091


0ddddd-ddddd if the country code is 091

Sample Input/Output :

Enter Phone Number : 044-78209 59001

The phone number you entered is : (044) 78209-59001

Q58B

A subsequence of a given sequence is the given sequence with just some elements left
out (order should be from left-to-right, not necessarily consecutive. For example, BCBA is a
subsequence of ABCBDAB. Read in two string sequences and determine whether the first
string sequence is a subsequence of the second string sequence.

Q 58C

A class Modify has been defined with the following details:


Class name : Modify
Data members
St : stores a string
len : to store the length of the string.
Member functions
void read() : to accept the string inuppercase alphabets.
void putin(int , char) : to insert a character at the specified position in the string and display
the
changed string.
void takeout(int) : to remove character from the specified position in the string and display
the
changed string.
void change() : to replace each character in the original string
by the character which is a t a distance of 2
moves ahead. For example:- “ABCD” becomes
“CDEF”, “XYZ” becomes “ZAB”.
Specify the class Modify giving details of the functions void read(), void putin(int,char), void
takeout(int) and void change(). The main function need not be written.

Q 58D

Design a class Alpha which enables a word to be arranged in ascending order accordingly to
its alphabets.
The details of the members of the class are given below :
Class name : Alpha
Data members/ instance variables:
Str : to store a word
Member functions :
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( ) : display the word.
Specify the class Alpha giving details if the constructor and member functions void readword
( ), void
arrange( ), void disp ( ) and defining the main ( ) function 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.

Q58E

A class SortWord has been defined with the following details:


Class name : SortWord
Data members
txt : stores the word.
len : stores the length of the word.
Member functions
SortWord() : default constructor
voidreadTxt() : to accept the word in lower case.
voidsortTxt() : to sort the word in alphabetical order of characters using bubble sort
technique and
display it.
voidchangeTxt() : to change the case of vowels in the word to upper case. For example :-
school becomes
school.
voiddisp() : to display the changed string.
Specify the class SortWord giving the details of the functions constructor, void readTxt(),
void sortTxt(),
void changeTxt() and void disp(). You need not write the main function.

Q58F) Caesar Cipher is an encryption technique which is implemented as ROT13 (‘rotate by


13 places’). It is a simple letter substitution cipher that replaces a letter with the letter 13
places after it in the alphabets, with the other characters remaining unchanged.

Write a program to accept a plain text of length L, where L must be greater than 3 and less
than 100.

Encrypt the text if valid as per the Caesar Cipher.

Test your program with the sample data and some random data:

Example 1
INPUT : Hello! How are you?
OUTPUT : The cipher text is:
Uryyb? Ubj ner lbh?
Example 2
INPUT : Encryption helps to secure data.
OUTPUT : The cipher text is:
Rapelcgvba urycf gb frpher qngn.
Example 3
INPUT : You
OUTPUT : INVALID LENGTH
Topic #11 Recursion - Submission Date: 10/11/2020

Q.61

A class SeriesSum is designed to calculate the sum of the following series:-

Sum= x2/1! + x4/3!+x6/5!+….xn/(n-1)!

Some of the members of the class are given below:

Class name :SeriesSum

Data members

x : to store an integer number

n : to store number of terms

sum : double variable to store the sum of the series

Member functions

Series Sum(intxx,intnn) : constructor to assign x=xx, n=nn

double findfact(int m) : to return the factorial of m using recursive technique

void calculate() : to calculate the sum of the series by invoking the recursive functions
repeatedly

void display() : to display the sum of the series

a) Specify the class SeriesSum, giving details of the constructor(int,int), doublefindfact(int),


double findpower(int,int), void calculate() and void display(). Define the main() function to
create an object and call the functions accordingly to enable the task.

Q.62 Program to print Fibonacci series upto 10 terms using recursion

Q.63 Program to print GCD and LCM of two numbers using recursion.

Q.64 Program to convert Decimal number to Octal using recursion.

Q.65 Design a class Change to perform string related operations.


The details of the class are given below:
Class name : Change
Data members
str : stores the word
newstr : stores the changed word
revstr : stores the reversed word
len : stores the length of the word
Member functions
Change() : default constructor
voidinputword() : to accept a word
charcaseconvert(char ch) : converts the case of the character
and returns it
voidrecchange(int) : extracts characters using recursive
technique and
changes its case using caseconvert() and forms a newword
void recreverse(int) : extracts characters in reverse order
using recursive technique and forms a new word.
void display() : displays all the three words

Q.66A class Admission contains the admission numbers of 100


students. Some of the data members/member functions are given
below:

Class name : Admission

Data member/instance variable:

Adno[] : integer array to store admission numbers

Member functions/methods:

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 binSearch(int, int, int). Define the
main() function to create an object and call the functions
accordingly to enable the task.
Q 66B

The Combination function C(n , k) gives the number of different (unordered ) K – elements
Subsets that can be

found in a given set of n elements.

The function can be computed from the formula:

Design a class Combination to implement this formula. Some of the data members and
member functions are

given below.

Class name: Combination

Data members/instance variables:

n : integer number

k : integer number

Member functions :

Combination ( ) : to initialize the data members n = 0 and k = 0

void read( ) : to accept the value of the data members

int fact(int) : return the factorial of a number using Recursion Technique.

void compute( ) : calculate and display the result

(a) Specify the class Combination, giving details of the Constructor and member functions
void read( ), int

fact(int) and void compute( ). Also write the main( ) function to create an object and call the
member function

accordingly in order to enable the task . [8]

(b) Give any two appropriate differences between recursion and iteration process. [2]
Q66C

Design a class Change to perform string related operations. The details of the class are given
below:

Class Name : Change

Data members/instance variables :

str : stores the word

newstr : stores the changed word

len : stores the length of the word

Member Functions:

Change() : default constructor

void inputword() : to accept a word

char caseconvert(char ch) : converts the case of the character and returns it

void recchange(int) : extracts characters using Recursive Technique and changes


its case using caseconvert() and forms a new word

(a) Specify the class Change, giving details of the constructor, member functions void
inputword(), char caseconvert(char ch), void recchange(int) and void display. Define the
main() function to create an object and call the function accordingly to enable the above
change in the given word.

(b) Differentiate between an infinite and a finite recursion.

Q 66D

Class Convert has been defined to express digits of an integer in words.

The details of the class are given below:

Class Name : Convert

Data members/instance variables :

n : integer whose digits are to be expressed in words.

Member Functions:

Convert() : default constructor

void inputnum() : to accept the value of n

void extdigit(int) : to extract the digits of n using the Recursive technique

void num_to_words(int) : to display the digits of an integer n in words.

(a) Specify the class Convert, giving details of the constructor, member functions void
inputword(), char extdigit(int), void num_to_words(int).The main() function need not be
written.
Q66E

Design a class change to convert a decimal number to its equivalent in base 16 and to
convert it back to

its decimal form. Eg.(i) The decimal number 35 is 23 in base 16. ii) The decimal number 107
is 6B in base

16.

Some of the members of the class are given below:

Class name : change

Data members

a[] : integer type array.

n : integer to be converted to base 16.

Member functions

change() : constructor to assign 0 to instance variables.

void input() : accepts integer to be converted to base 16.

voidhexadeci(int) : to convert decimal integer to hexadecimal form.

voiddecihexa() : to convert hexadecimal number back to decimal form.

Specify the class change giving the details of the constructor and the functions void input(),
void

hexadeci(int) and void decihexa(). The main function need not be written.

QExtra)

Class Binary contains an array of n integers (n<=100) that are already arranged in ascending
order. The

subscripts of the array elements vary from 0 to n-1. The data members and member
functions of class

Binary are given below:


Class name : Binary

Data members

A[] : integer array of 100 elements

n : size of array

l location of the lower bound

u : location of the upper bound

Member functions:

Binary(int nn) : constructor to initialize the size n to nn and the other instance variables.

voidreaddata() : to fill the elements of the array in ascending order.

int binary_search(int v) : returns the location of the value(v) to be searched in the list by
binary search method using the recursive technique. The function returns -1 if the number is
not present in the given list.

a) Specify the class Binary giving details of the constructor, void readdata() and int
binary_search(int). you need not write the main function.

b) State the base case in the recursive technique binary_search().

c) What are the drawbacks of using the recursive technique.

Topic #12 Data Structures Submission Date : 10/11/2020

Q.67 Define a class Repeat which allows the user to add elements from one end (rear)
and remove elements and remove elements from the other end (front) only.

The following details of the class Repeat are given below:

Class name : Repeat

Data members

st[] : an array to hold a maximum of 100 integer

elements
cap : stores the capacity of the array

f : to point to the index of the front

r : to point to the index of the rear

Member functions

Repeat(int m) : constructor to initialize the data members

cap=m, f=0, r=0 and to create the integer array

voidpushvalue(int v) : to add integers from the rear index if possible

else display the message “overflow”

intpopvalue() : to remove and return element from the front, if

array is empty then return -9999

voiddisp() : displays the elements present in the list

a) Specify the class Repeat giving details of the constructor(int), member function
void

pushvalue(int), intpopvalue() and void disp() and main().

Q.68A bookshelf is designed to store the books in a stack with LIFO (Last In First
Out) operation. Define a class Book with the following specifications:
Class name: Book
Data members/instance variables:
name[]: stores the names of the books
point: stores the index of the topmost book
max: stores the maximum capacity of the bookshelf
Methods/Member functions:
Book(int cap): constructor to initialize the data members max = cap and point = -1
void tell(): displays the name of the book which was last entered in the shelf. If there
is no book left in the shelf, displays the message “SHELF EMPTY”
void add(String v): adds the name of the book to the shelf if possible, otherwise
displays the message “SHELF FULL”
void display(): displays all the names of the books available in the shelf Specify
the class Book giving the details of ONLY the functions void tell() and void
add(String). Assume that the other functions have been defined.
The main function need not be written.

Q 69Write a program for Dequeoperations.


Q.70A linked list is formed from the objects of the class Node. The class structure of
the Node is given below:
class Node{
String name;
intitem;
Node next;
}

Write an algorithm or a method to


• search for a given name in the linked list. The method of declaration is given
below:
booleansearchName(Node start, String v)

• add a node at the end of a linked list


• add a node at the start of a linked list
• insert a node in between a linked list
• delete a node at the start of a linked list
• delete a node at the end of a linked list
• delete a node in between a linked list
• traverse and display the nodes in a linked list
• count the number of nodes in a linked list
• sum the integer item in all the nodes in a linked list.
• Concatenate two linked lists
• Create a linked list with 5 nodes
• Find the middle node in the linked list
• To swap first node and last node in the linked list
• To traverse and display linked list in reverse order
• To sort a linked list
• To reverse a linked list
• To split a linked list into two linked lists

Topic #13 Practical Exam Questions - Submission Date :

10/11/2020
[Question 1] ISC 2016 Computer Science Practical

A Circular Prime is a prime number that remains prime under cyclic shifts of its

digits. When the leftmost digit is removed and replaced at the end of the

remaining string of digits, the generated number is still prime. The process is

repeated until the original number is reached again.

A number is said to be prime if it has only two factors 1 and itself.

Example:

131311113
Hence, 131 is a circular prime.

Test your program with the sample data and some random data:

Example 1

INPUT:
N = 197

OUTPUT:197971719197 IS A CIRCULAR PRIME

Example 2

INPUT:
N = 1193

OUTPUT:11931931931131191193 IS A CIRCULAR PRIME

Example 3

INPUT:
N = 29

OUTPUT:299229 IS NOT A CIRCULAR PRIME


[Question 1] ISC 2015 Computer Science Practical

Given two positive numbers M and N, such that M is between 100 and 10000 and

N is less than 100. Find the smallest integer that is greater than M and whose

digits add up to N. For example, if M=100 and N=11, then the smallest integer

greater than 100 whose digits add up to 11 is 119.

Write a program to accept the numbers M and N from the user and print the

smallest required number whose sum of all its digits is equal to N. Also, print

the total number of digits present in the required number. The program should

check for the validity of the inputs and display an appropriate message for an

invalid input.

Test your program with the sample data and some random data:

Example 1

INPUT: M = 100
N = 11
OUTPUT: The required number = 119
Total number of digits = 3

Example 2

INPUT: M = 1500
N = 25
OUTPUT: The required number = 1699
Total number of digits = 4

Example 3

INPUT: M = 99
N = 11
OUTPUT: INVALID INPUT
Example 4

INPUT: M = 112
N = 130
OUTPUT: INVALID INPUT

[Question 1] ISC 2013 Computer Science Practical

An ISBN ( International Standard Book Number) is a ten digit code which

uniquely identifies a book. The first nine digits represent the Group, Publisher

and Title of the book and the last digit is used to check whether ISBN is correct

or not.

Each of the first nine digits of the code can take a value between 0 and 9.

Sometimes it is necessary to make the last digit equal to ten; this is done by

writing the last digit of the code as X. To verify an ISBN, calculate 10 times the

first digit, plus 9 times the second digit, plus 8 times the third and so on until we

add 1 time the last digit. If the final number leaves no remainder when divided

by 11, the code is a valid ISBN.

For example:

1. 02011003311 = 10 x 0 + 9 x 2 + 8 x 0 + 7 x 1 + 6 x 1 + 5 x 0 + 4 x 3 + 3 x 3 + 2 x 1 +
1 x 1 = 55 Since 55 leaves no remainder when divisible by 11, hence it is a valid
ISBN.
2.
007462542X = 10 x 0 + 9 x 0 + 8 x 7 + 7 x 4 + 6 x 6 + 5 x 2 + 4 x 5 + 3 x 4 + 2 x 2 + 1

x 10 = 176 Since 176 leaves no remainder when divided by 11, hence it is a

valid ISBN.
3.
4.
0112112425 = 10 x 0 + 9 x 1 + 8 x 1 + 7 x 2 + 6 x 1 + 5 x 1 + 4 x 1 + 3 x 4 + 2 x 2 + 1

x 5 = 71 Since 71 leaves no remainder when divided by 11, hence it is not a

valid ISBN.

5.
Design a program to accept a ten digit code from the user. For an invalid inout,

display an appropriate message. Verify the code for its validity in the format

specified below:

Test your program with sample data and some random data.

Example 1

INPUT CODE : 0201530821

OUTPUT : SUM = 99

LEAVES NO REMAINDER - VALID ISBN CODE

Example 2

INPUT CODE : 035680324

OUTPUT : INVALID INPUT

Example 3

INPUT CODE : 0231428031

OUTPUT : SUM = 122


LEAVES REMAINDER - INVALID ISBN CODE

[Question 1] ISC 2011 Computer Science Practical

Write a program to input a natural number less than 1000 and display it in

words. Test your program on the sample data and some random data.

Sample input and output of the program.

Examples

Input: 29
Output: TWENTY NINE

Input: 17001
Output: OUT OF RANGE

Input: 119
Output: ONE HUNDRED AND NINETEEN

Input: 500
Output: FIVE HUNDRED

[Question 1] ISC 2010 Computer Science Practical

A bank intends to design a program to display the denomination of an input


amount, upto 5 digits. The available denomination with the bank are of rupees
1000,500,100,50,20,10,5,2 and 1.

Design a program to accept the amount from the user and display the break-up in
descending order of denominations. (i,e preference should be given to the highest
denomination available) along with the total number of notes. [Note: only the
denomination used should be displayed]. Also print the amount in words
according to the digits.
Example 1
INPUT: 14836
OUTPUT: ONE FOUR EIGHT THREE SIX
DENOMINATION:1000 X 14 =14000500 X 1 =500100 X 3 =30050 X 1 =505 X 1 =51 X 1 =1

Example 2
EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT

[Question 1] ISC 2009 Computer Science Practical

Design a program to accept a day number (between 1 and 366), year (in 4 digits)
from the user to generate and display the corresponding date. Also accept 'N'
(1<=N<=100) from the user to compute and display the future date corresponding
to 'N' days after the generated date. Display error message if the value of the day
number, year and N are not within the limit or not according to the condition
specified.

Test your program for the following data and some random data.

Examples
INPUT : DAY NUMBER : 233 YEAR : 2008 DATE AFTER(N) : 17
OUTPUT: 20TH AUGUST 2008 DATE AFTER 17 DAYS : 6TH SEPTEMBER 2008

INPUT : DAY NUMBER : 360 YEAR : 2008 DATE AFTER(N) : 45


OUTPUT: 25TH DECEMBER 2008 DATE AFTER 45 DAYS : 8TH FEBRUARY 2009

[Question 1] ISC 2008 Computer Science Practical

A smith number is a composite number, the sum of whose digits is the sum of the
digits of its prime factors obtained as a result of prime factorization (excluding 1).
The first few such numbers are 4, 22, 27, 58, 85, 94, 121.....

Examples
666 Prime factors are 2, 3, 3 and 37
Sum of the digits are (6+6+6) = 18
Sum of the digits of the factors (2+3+3+(3+7) = 18

Sample data:
Input 94 Output SMITH Number
Input 102 Output NOT SMITH Number

[Question 1] ISC 2007 Computer Science Practical

Write a program to accept a date in the string format dd/mm/yyyy and accept

the name of the day on 1st of January of the corresponding year. Find the day

for the given date. Example:

INPUT Date: 5/7/2001 Day on 1st January : MONDAY


OUTPUT Day on 5/7/2001 : THURSDAY

Test run the program on the following inputs:

INPUT DATE DAY ON 1ST JANUARY OUTPUT DAY FOR INPUT DATE4/9/1998
THURSDAY FRIDAY31/8/1999 FRIDAY TUESDAY6/12/2000
SATURDAY WEDNESDAY

The program should include the part for validating the inputs namely the date

and the day on 1st January of that year.

[Question 1] ISC 2006 Computer Science Practical

A positive natural number, (for e.g.27) can be represented as follows:


2+3+4+5+6+7
8+9+10
13+14

where every row represents a combination of consecutive natural numbers, which


add up to 27.
Write a program which inputs a positive natural number N and prints the possible
consecutive number combinations, which when added give N.

Test your program for the following data and some random data

SAMPLE DATA
INPUT N = 15
OUTPUT 7 8
12345

[Question 1] ISC 2005 Computer Science Practical

Write a program which takes a string (maximum 80 characters) terminated by a

full stop. The words in this string are assumed to be separated by one or more

blanks.

Arrange the words of the input string in descending order of their lengths. Same

length words should be stored alphabetically Each word must start with an

uppercase letter and the sentence should be terminated by a full stop.

Test your program for the following data and some random data.

SAMPLE DATA:

INPUT: "This is human resource department."


OUTPUT: Department Resource Human This Is.
INPUT: "To handle yourself use your head and to handle others use your heart."
OUTPUT: Yourself Handle Handle Others Heart Head Your Your And Use Use

[Question 2] ISC 2006 Computer Science Practical

Write a program that inputs the names of people into two different arrays, A and B.
Array A has N number of names while Array B has M number of names, with no
duplicates in either of them. Merge array A and B into a single array C, such that
the resulting array is sorted alphabetically.

Display all the three arrays, A, B and C, sorted alphabetically. Test your program
for the given data and some random data.

SAMPLE DATA
INPUT

Enter number of names in Array A, N=2


Enter number of names in Array B, M=3

First array:(A) Suman Anil


Second array:(B) Usha Sachin John

OUTPUT

Sorted Merged array:(C)


Anil John Sachin Suman Usha

Sorted first array:(A)


Anil Suman

Sorted Second array:(B)


John Sachin Usha

[Question 2] ISC 2007 Computer Science Practical

The input in this problem will consist of a number of lines of English text

consisting of the letters of the English alphabet, the punctuation marks (')

apostrophe, (.) full stop, (,) comma, (;) semicolon, (:) colon and white space

characters (blank, newline). Your task is to print the words of the text in reverse

order without any punctuation marks other than blanks.

For example consider the following input text:


This is a sample piece of text to illustrate this problem.
If you are smart you will solve this right.

The corresponding output would read as:

right this solve will you smart are you If problem this illustrate to text of piece sample a is This
That is, the lines are printed in reverse order.

Note: Individual words are not reversed.

INPUT FORMAT:

The first line of input contains a single integer N (<=20), indicating the number

of lines in the input. This is followed by N lines of input text. Each line should

accept a maximum of 80 characters.

OUTPUT FORMAT:

Output the text containing the input lines in reverse order without punctuation

except blanks as illustrated above.

[Question 2] ISC 2008 Computer Science Practical

A sentence is terminated by either ".", "!" or "?" followed by a space. Input a piece
of text consisting of sentences. Assume that there will be a maximum of 10
sentences in a block.

Write a program to:

1. Obtain the length of the sentence (measured in words) and the frequency of vowels in
each sentence.
2. Generate the output as shown below using the given data

Examples
INPUT:

HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.


OUTPUT:

Sentence No. of Vowels No. of words----------------------------------------------------------


1 2 1
2 5 3
3 8 4
4 3 3

Sentence No. of words/vowels----------------------------------------------------------1 VVVVVV


WWW2 VVVVVVVVVVVVVVV
WWWWWWWWW3 VVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWW----------------------------------------------------------
Scale used 1:3

[Question 2] ISC 2009 Computer Science Practical

Write a program to declare a matrix A[ ][ ] of order (m*n) where 'm' is the

number of rows and n is the number of columns such that both m and n must

be greater than 2 and less than 20.

Allow the user to input positive integers into this matrix. Perform the following

tasks on the matrix:

1. Sort the elements of the outer row and column elements in ascending order
using any standard sorting technique.
2. Calculate the sum of the outer row and column elements.
3. Output the original matrix, rearranged matrix, and only the boundary
elements of the rearranged array with their sum.
Test your program for the following data and some random data.

Example 1

INPUT : M=3, N=3


1 7 4
8 2 5
6 3 9
OUTPUT :
ORIGINAL MATRIX :
1 7 4
8 2 5
6 3 9

REARRANGED MATRIX :
1 3 4
9 2 5
8 7 6

BOUNDARY ELEMENTS :
1 3 4
9 5
8 7 6

SUM OF OUTER ROW AND OUTER COLUMN = 43

[Question 2] ISC 2011 Computer Science Practical

Encryption is a technique of coding messages to maintain their secrecy. A String


array of size 'n' where 'n' is greater than 1 and less than 10, stores single sentences
(each sentence ends with a full stop) in each row of the array.

Write a program to accept the size of the array.

Display an appropriate message if the size is not satisfying the given condition.

Define a string array of the inputted size and fill it with sentences row-wise.
Change the sentence of the odd rows with an encryption of two characters ahead
of the original character.

Also change the sentence of the even rows by storing the sentence in reverse order.
Display the encrypted sentences as per the sample data given below.

Test your program on the sample data and some random data.

Example 1
INPUT: n = 4
IT IS CLOUDY.
IT MAY RAIN.
THE WEATHER IS FINE.
IT IS COOL.

OUTPUT:
KV KU ENQWFA.
RAIN MAY IT.
VJG YGCVJGT KU HKPG.
COOL IS IT.

[Question 2] ISC 2012 Computer Science Practical

Write a program to accept a sentence as input. The words in the string are to be
separated by a blank. Each word must be in upper case. The sentence is terminated
by either '.','!' or '?'. Perform the following tasks:

1. Obtain the length of the sentence (measured in words)


2. Arrange the sentence in alphabetical order of the words.

Test your program with the sample data and some random data:

Example 1
INPUT: NECESSITY IS THE MOTHER OF INVENTION.
OUTPUT:
Length: 6
Rearranged Sentence:
INVENTION IS MOTHER NECESSITY OF THE

Example 2
INPUT: BE GOOD TO OTHERS.
OUTPUT:
Length: 4
Rearranged Sentence: BE GOOD OTHERS TO

[Question 2] ISC 2013 Computer Science Practical


Write a program to declare a square matrix A[][] of order (M X M) where 'M' is the

number of rows and the number of columns such that M must be greater than 2

and less than 20. Allow the user to input integers into this matrix. Display

appropriate error message for an invalid input. Perform the following tasks:

1. Display the input matrix.


2. Create a mirror image of the inputted matrix.
3. Display the mirror image matrix.
Test your program for the following data and some random data:

Example 1:

INPUT : M = 3

4 16 128 2 146 1 3

OUTPUT :

ORIGINAL MATRIX

4 16 128 2 146 1 3

MIRROR IMAGE MATRIX

12 16 414 2 8
3 1 6

Example 2:

INPUT : M = 22

OUTPUT : SIZE OUT OF RANGE

[Question 2] ISC 2014 Computer Science Practical


Write a program to declare a square matrix A[][] of order MXM where M is an

positive integer and represents row and column. M should be greater than 2

and less than 10.Accept the value of M from user. Display an appropriate

message for invalid input.

Perform the following task:

1. Display the original matrix


2. Check if the given matrix is symmetric or not. If the element of the ith row
and jth column is same as element of the jth row and ith column.
3. Find the sum of the left and right diagonal of the matrix and display them
Example 1:

INPUT: M=31 2 32 4 53 5 6

OUTPUT:
Original matrix1 2 32 4 53 5 6

The given matrix is symmetric


Sum of the left diagonal = 11
Sum of the right diagonal = 10

Example 2:

INPUT: M=4

OUTPUT:
Original matrix:7 8 9 24 5 6 38 5 3 17 6 4 2

The given matrix is not symmetric


Sum of the left diagonal = 17
Sum of the right disgonal = 20

Example 3:

INPUT: M=12
OUTPUT:
Matrix size is out of range
[Question 2] ISC 2015 Computer Science Practical

Write a program to declare a square matrix A[][] of order M×M where ‘M’ is the
number of rows and the number of rows and the number of columns, such that M
must be greater than 2 and less 10. Accept the value M as user input. Display an
appropriate message for an invalid input. Allow the user to input integers into the
matrix. Perform the following tasks:

1. Display the original matrix.


2.
Rotate the matrix 90ᵒ clockwise as shown below:

3.
Original matrix Rotated matrix
1 2 3 7 4 1
4 5 6 8 5 2
7 8 9 9 6 3
4.
5.
Find the sum of the elements of the four corners of the matrix.

6.
Test your program for the following data and some random data:

Example 1
INPUT: M=3
3 4 92 5 81 6 7

OUTPUT:
ORIGINAL MATRIX
3 4 92 5 81 6 7

MATRIX AFTER ROTATION


1 2 36 5 47 8 9

Sum of the corner elements = 20

Example 2
INPUT: M=4
1 2 4 92 5 8 31 6 7 43 7 6 5

OUTPUT:
ORIGINAL MATRIX
1 2 4 92 5 8 31 6 7 43 7 6 5

MATRIX AFTER ROTATION


3 1 2 17 6 5 26 7 8 45 4 3 9

Sum of the corner elements = 18

Example 3
INPUT: M=14
OUTPUT:
SIZE OUT OF RANGE

[Question 2] ISC 2016 Computer Science Practical

Write a program to declare a square matrix A[][] of order (M x M) where ‘M’ must

be greater than 3 and less than 10. Allow the user to input positive integers into

this matrix. Perform the following tasks on the matrix:

1. Sort the non-boundary elements in ascending order using any standard


sorting technique and rearrange them in the matrix.
2. Calculate the sum of both the diagonals.
3. Display the original matrix, rearranged matrix and only the diagonal
elements of the rearranged matrix with their sum.
Test your program with the sample data and some random data:

Example 1

INPUT :M = 4
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8

OUTPUT:
ORIGINAL MATRIX
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8

REARRANGED MATRIX
9 2 1 5
8 3 6 4
15 8 13 11
7 12 23 8

DIAGONAL ELEMENTS
9 5
3 6
8 13 7 8
SUM OF THE DIAGONAL ELEMENTS = 59

Example 2

INPUT :M = 5
7 4 1 9 5 8 2 6 10 1913 1 3 5 110 0 5 12 16 1 8 17 6 8

OUTPUT:

ORIGINAL MATRIX
7 4 1 9
5 8 2 6
10 1913 1 3
5 110 0 5
12 161 8 17 6 8

REARRANGED MATRIX
7 4 1 9 5 8 0 1 2 1913 3 5 5 110 6 10 12 161 8 17 6
8

DIAGONAL ELEMENTS
7 5
0 2
5
6 121 8

SUM OF THE DIAGONAL ELEMENTS = 46

Example 3
INPUT: M = 3
OUTPUT: THE MATRIX SIZE IS OUT OF RANGE.

[Question 3] ISC 2015 Computer Science Practical

Write a program to accept a sentence which may be terminated by either ‘.’ Or ‘?’
only. The words are to be separated by a single blank space. Print an error
message if the input does not terminate with ‘.’ Or ‘?’. You can assume that no
word in the sentence exceeds 15 characters, so that you get a proper formatted
output.

Perform the following tasks:

1. Convert the first letter of each word to uppercase.


2. Find the number of vowels and consonants in each word and diplay them with proper
headings along with the words.

Test your program with the following inputs.

Example 1
INPUT: Intelligence plus character is education.
OUTPUT:
Intelligence Plus Character Is Education.

Word Vowels Consonants


Intelligence 5 7
Plus 1 3
Character 3 6
Is 1 1
Education 5 4

Example 2
INPUT: God is great.

OUTPUT:
God Is Great

Word Vowels Consonants


God 1 2
Is 1 1
Great 2 3
Example 3
INPUT: All The Best!

OUTPUT:
Invalid Input

[Question 3] ISC 2013 Computer Science Practical

A palindrome is a word that may be read the same way in either direction.

Accept a sentence in UPPER CASE which is terminated by either ".", "?", or "!".

Each word of the sentence is separated by a single blank space.

Perform the following taks:

1. Display the count of palindromic words in the sentence.


2. Display the palindromic words in the sentence.
Example of palindromic words:

MADAM, ARORA, NOON

Test your program with the sample data and some random data:

Example 1

INPUT : MOM AND DAD ARE COMING AT NOON


OUTPUT : MOM DAD NOON
NUMBER OF PALINDROMIC WORDS : 3
Example 2
INPUT : HOW ARE YOU?
OUTPUT : NO PALINDROMIC WORDS

[Question 3] ISC 2011 Computer Science Practical


Design a program which accepts your date of birth in dd mm yyyy format.

Check whether the date entered is valid or not.

If it is valid, display "VALID DATE", also compute and display the day number of

the year for the date of birth. If it is invalid, display "INVALID DATE" and then

terminate the program.

Testing of the program

Example 1

INPUT: Enter your date of birth in dd mm yyyy format05012010

OUTPUT: VALID DATE5

Example 2

INPUT: Enter your date of birth in dd mm yyyy format03042010

OUTPUT: VALID DATE93

Example 3

INPUT: Enter your date of birth in dd mm yyyy format34062010

OUTPUT: INVALID DATE

[Question 3] ISC 2010 Computer Science Practical

Input a paragraph containing 'n' number of sentences where (1<=n<=4). The words
are to be separated with single blank space and are in upper case. A sentence may
be terminated either with a full stop (.) or question mark (?).

Perform the following:


1. Enter the number of sentences, if it exceeds the limit show a message.
2. Find the number of words in the paragraph
3. Display the words in ascending order with frequency.

Example 1
INPUT: Enter number of sentences: 1
Enter sentences:
TO BE OR NOT TO BE.

OUTPUT:
Total number of words: 6

WORD FREQUENCY
OR 1
NOT 1
TO 2
BE 2

Example 2
INPUT: Enter number of sentences: 3
Enter sentences:
THIS IS A STRING PROGRAM. IS THIS EASY? YES, IT IS.

OUTPUT:
Total number of words: 11

WORD FREQUENCY
A 1
STRING 1
PROGRAM 1
EASY 1
YES 1
IT 1
THIS 2
IS 3

[Question 3] ISC 2009 Computer Science Practical


Read a single sentence which terminates with a full stop(.). The words are to be

separated with a single blank space and are in lower case. Arrange the words

contained in the sentence according to the length of the words in ascending

order. If two words are of the same length then the word occurring first in the

input sentence should come first. For both, input and output the sentence must

begin in upper case.

Examples

Test your program for the following data and some random data.

INPUT : The lines are printed in reverse order.


OUTPUT : In the are lines order printed reverse.

INPUT : Print the sentence in ascending order.


OUTPUT : In the print order sentence ascending.

[Question 3] ISC 2008 Computer Science Practical

Given a square matrix list [ ] [ ] of order ‘ n ’. The maximum value possible for
‘ n ’ is 20. Input the value for ‘ n ’ and the positive integers in the matrix and
perform the following task:

1. Display the original matrix


2. Print the row and column position of the largest element of the matrix.
3. Print the row and column position of the second largest element of the matrix.
4. Sort the elements of the rows in the ascending order and display the new matrix.

Sample data:
INPUT:
N=3

List [] [ ] = 5 1 3
746
982
OUTPUT:

513
746
982

The largest element 9 is in row 3 and column 1


The second largest element 8 is in row 3 and column 2

Sorted list

135
467
289

You might also like