0% found this document useful (0 votes)
21 views81 pages

Computer Project

Uploaded by

ashishmurya02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views81 pages

Computer Project

Uploaded by

ashishmurya02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 81

ISC COMPUTER PROJECT

2023-24

SUBMITTED BY
SOHAM
SUBMITTED TO
MAM GANGA DEVI
ACKNOWLWDGEMENT
First of all, I would like to thank my
parents for helping me out with the
project.

Secondly I would like to thank our


Computer teacher Mam Ganga Devi
for helping us with the programs.

Lastly, I’m really grateful to my


classmates, whose help was
imperative for me in making this
project.

Thank You ALL !


INDEX
1. Arrange all the elements of row of n*n
NO. matrix in ascending order

To check if 2D array is symmetric or


2. not
3. To find product of two (n*n)matrix
4. Magic number by using recursion
5. Sort the elements of the single-
dimensional array in ascending order
and fill the square matrix b[][] in the
following format: If the array a[] =
{5, 2, 8, 1} then, after sorting a[]
= {1, 2, 5, 8} Then, the matrix b[][]
would fill as below:

6. Armstrong Number by Using Recursion


7. Decimal To Binary Conversion Using
Recursion
8. Accept two positive integers m and n,
and Display all Prime-Adam integers
that are in
the range between m and n (both
inclusive)
9. To accept an even integer 'N' where N
> 9 and N < 50. Find all the odd
prime pairs whose
sum is equal to 'N'
10. To accept the number of sentences,
find the number of words in the whole
paragraph and display the words in
ascending order of their
frequency
11. To find the transpose of a given matrix
12. To compute the total amount paid by
the
retailer with or without fine along
with service tax.
13. To calculate the fine books issued from
library by using inheritance
14. To display the details of the student by
using
inheritance
15. To create super class to store the
details of the stock of a retail store
and a subclass to store the details of
the items purchased with the
new rate and updates the stock
16. To accept the numbers M and N from
the user
and print the smallest required number
whose sum of the digits is equal to N
17. To find the maximum and minimum
value in the matrix and display them
along with their position, sort the
elements of the matrix in ascending
order using any standard sorting
technique and rearrange them in the
matrix
18. To find the number of vowels and
consonants and display them with
proper headings along
with the words.
19. To display the count of palindromic words
and display them in the sentence.
20. To Obtain the length of the sentence
(measured in words) and arrange the
sentence in alphabetical order of the
words
21. To print the Fibonacci series up to a limit
22. To create a super class Detail to store
the details of a customer and a
subclass Bill to
compute the monthly telephone
charge of the customer
23. To create a super class Plane to a
represent line and a subclass Circle to
find the length of the radius and the
area of Circle by using the
required data members of super class.
24. 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
25. To accept elements in a Double-
Dimensional
Array of N x N order and print the
sum of the elements of Left as well as
Right Diagonal.
26. To find the sum of all even
numbers and product of all odd
numbers of the elements
stored in 2D array
27. To calculate and print the mid-point of
two
coordinates in a two dimensional plane
28. To create a double dimensional array
of size n x m. Input the numbers in
first (n-1) x (m-1) cells. Find and place
the sum of each row and each column
in corresponding cells of last
column and last row respectively
29. To create a 4 x 4 matrix , swap the
PROGRAM 1: Arrange all the elements of row of n*n matrix
in ascending order.
ALGORITHM
STEP 1: START
STEP 2: Accept value of n
STEP 3: for i=0 to n, repeat
STEP 4 STEP 4: for j=0 to n,
repeat STEP 5 STEP 5: read
a[i,j]
STEP 6: for i=0 to n, repeat STEP
7 STEP 7: for j=0 to n-1, repeat
STEP 8 STEP 8: for k=0 to n-j-1,
repeat STEP 9
STEP 9: if (a[i][k]>a[i][k+1]) is true switch the
numbers STEP 10: for i=0 to n, repeat STEP 11
STEP 11: for j=0 to n, repeat STEP
12 STEP 12: Display c[i,j]
STEP 13: END
SOLUTION:
VARIABLE LISTING:
SL NO. NAME TYPE METHOD DESCRIPTION
1 n int main() Store size of
matrix
2 a int[][] main() Store
numbers
3 temp int main() For
calculation
4 i,j,k int main() counter

Output:
PROGRAM 2: To check if 2D array is symmetric or
not
ALGORITHM
STEP 1: START
STEP 2: Accept value of n
STEP 3: for i=0 to n, repeat
STEP 4 STEP 4: for j=0 to n,
repeat STEP 5 STEP 5: read
a[i,j]
STEP 6: for i=0 to n, repeat
STEP 7 STEP 7: for j=0 to n-1,
repeat STEP 8 STEP 8: if a[i,j]
≠a[j,i] is true, c=c+1 STEP 9:
for i=0 to n, repeat STEP 10
STEP 10: for j=0 to n, repeat
STEP 11 STEP 11: Display c[i,j]
STEP 12: if c=0 is true then display Array is symmetric is not
symmetric STEP 13: END
VARIABLE DESCRIPTION:
Sl. no Variable Datatype Purpose
Name
1 N int To store
array size
2 a char[][] To store
character
3 c,i,j int Counter

OUTPUT:
PROGRAM 3: To find product of two (n*n)matrix
ALGORITHM
STEP 1: START
STEP 2: Accept value of n
STEP 3: for i=0 to n, repeat
STEP 4 STEP 4: for j=0 to n,
repeat STEP 5 STEP 5: read
a[i,j]
STEP 6: for i=0 to n, repeat
STEP 7 STEP 7: for j=0 to n,
repeat STEP 8 STEP 8: read
b[i,j]
STEP 9: for i=0 to n, repeat
STEP 10 STEP 10: for j=0 to n,
repeat STEP 11 STEP 11: for
k=0 to n, repeat STEP 12 STEP
12: c[i,j] = a[i,j]* b[i,j] + c[i,j]
STEP 13: for i=0 to n, repeat
STEP 14 STEP 14: for j=0 to n,
repeat STEP 15 STEP 15:
Display c[i,j]
STEP 16: END

SOLUTION:
VARIABLE DESCRIPTION:
Sl. no Variable Datatype Purpose
Name
1 n int To store
size
of
matri
x
2 a,b,c int[][] To store
number
3 i,j,k int Counter

OUTPUT:
PROGRAM 4: Magic number by using recursion
ALGORITHM
main() 
STEP 1: Accept number and store in variable a
STEP 2: Repeat STEP 3 until a>9
STEP 3: Calculate magic number
STEP 4: Check for magic number
STEP 5: If STEP 4 is true, display Magic number OTHERWISE display
not a magic number
sum_digit(int n) 
STEP 1: Extract digits from the number and store in variable r
STEP 2: if (n=0) is true then return 0
STEP 3: Otherwise return (r+sum_digit(n/10))

SOLUTION:
VARIABLE DESCRIPTION:

Sl. no Variable Datatype Purpose


Name
1 a int Accept and
store
number to
check
2 n int Store
number
to find
sum of
digit
3 r int Extract
digit

OUTPUT:
PROGRAM 5:Write a program to declare a single-
dimensional array a[] and a square matrix b[][] of size N, where
N > 2 and N < 10. Allow the
user to input positive integers into the single dimensional array.

Perform the following tasks on the matrix:


1. Sort the elements of the single-dimensional array in
ascending order using any standard sorting technique and
display the sorted elements.

2.Fill the square matrix b[][] in the following format: If the


array a[] = {5, 2, 8, 1} then, after sorting a[] = {1, 2, 5, 8}
Then, the matrix b[][] would fill as below:

3.Display the filled matrix in the given format

Test your program for the following data and some random data:
Example 1
INPUT: N = 3 ENTER ELEMENTS OF SINGLE DIMENSIONAL
ARRAY: 3 1 7
OUTPUT: SORTED ARRAY: 1 3 7 FILLED MATRIX

Example 2
INPUT: N =
13
OUTPUT: MATRIX SIZE OUT OF RANGE

Example 3
INPUT: N = 5 ENTER ELEMENTS OF SINGLE
DIMENSIONAL ARRAY: 10 2 5 23 6
OUTPUT: SORTED ARRAY: 2 5 6 10 23 FILLED MATRIX
SOLUTION:
OUTPUT:
PROGRAM: 6
Armstrong Number by Using Recursion
(153 =>13+53+33=153)
ALGORITHM
main() 
STEP 1: Accept number and store in variable a
STEP 2: Repeat STEP 3 until a>9
STEP 3: Calculate magic number
STEP 4: Check for magic number
STEP 5: If STEP 4 is true, display Magic number OTHERWISE display not a
magic number
checknum(int n) 
STEP 1: Receive actual parametric value in variable n
STEP 2: if (n=0) is true then return 0
STEP 3: Otherwise (int)Math.pow(n%10,3)+ checknum(n/10);
SOLUTION:
VARIABLE DESCRIPTION:

Sl. no Variable Datatype Purpose


Name
1 n int To get
number
2 m int To store
value of
return
sum
of digits

OUTPUT:
PROGRAM 7: Decimal To Binary Conversion Using Recursion
(10=>1010)

ALGORITHM:
main() 
STEP 1: Accept number
task(int n) 
STEP 1: Proceed if n>2
STEP 2: store remainder in variable d when n is divided by 2
STEP 3: task(n/2)
STEP 4: Display d backwards in horizontal line
SOLUTION:

VARIABLE DESCRIPTION:
Sl. no Variable Datatype Purpose
Name
1 a int To get
number
2 d int Binary
calculation
3 n int User iput

OUTPUT:
A Prime-Adam integer is a positive integer (without leading zeros) which is a
prime as well as an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number
itself.
Example: 2, 3, 5, 7 … etc.
Adam number: The square of a number and the square of its reverse are
reverse to each other.
Example: If n = 13 and reverse of 'n' = 31, then,
(13)2 = 169
(31)2 = 961 which is reverse of
169 thus 13, is an Adam
number.
PROGRAM 8:Accept two positive integers m and n, where m is less than n
as user input. Display all Prime-Adam integers that are in the range
between m and n (both inclusive) and output them along with the
frequency, in the format given below:
Test your program with the following data and some random data:
Example 1
INPUT:
m=5
n = 100
OUTPUT:
THE PRIME-ADAM INTEGERS
ARE: 11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 2
INPUT:
m = 100
n = 200
OUTPUT:
THE PRIME-ADAM INTEGERS
ARE: 101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 3
INPUT:
m = 50
n = 70
OUTPUT:
THE PRIME-ADAM INTEGERS
ARE: NIL
FREQUENCY OF PRIME-ADAM INTEGERS IS: 0
Example 4
INPUT:
m = 700
n = 450
OUTPUT:
INVALID INPUT
SOLUTION:

import
java.util.Scanner;
public class
PrimeAdam
{
public static int reverse(int
num) { int rev = 0;

while (num != 0)
{ int d = num %
10; rev = rev *
10 + d; num /=
10;
}

return rev;
}

public static boolean isAdam(int


num) { int sqNum = num *
num;
int revNum = reverse(num);
int sqRevNum = revNum *
revNum; int rev =
reverse(sqNum);

return rev == sqRevNum;


}

public static boolean isPrime(int


num) { int c = 0;

for (int i = 1; i <= num;


i++) { if (num % i ==
0) {
c++;
}
}

return c == 2;
}

public static void main(String args[])


{ Scanner sc= new
Scanner(System.in);
System.out.print("Enter the value of
m: "); int m =sc.nextInt();
System.out.print("Enter the value
of n: "); int n = sc.nextInt();
int count = 0;
if (m >= n) {
System.out.println("INVALID
INPUT"); return;
}

System.out.println("THE PRIME-ADAM INTEGERS


ARE:"); for (int i = m; i <= n; i++) {
boolean adam =
isAdam(i); if (adam) {
boolean prime =
isPrime(i); if (prime) {
System.out.print(i + " ");
count++;
}
}
}

if (count == 0) {
System.out.print("NIL");
}

System.out.println();
System.out.println("FREQUENCY OF PRIME-ADAM INTEGERS IS: " +
count);
}}

OUTPUT:
A Goldbach number is a positive even integer that can be expressed
as the sum of two odd primes.
Note: All even integer numbers greater than 4 are Goldbach numbers.
Example:
6=3+3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two
odd prime pairs, i.e. 3 and 7, 5 and 5.
PROGRAM 9:
Write a program to accept an even integer 'N' where N > 9 and
N < 50. Find all the odd prime pairs whose sum is equal to the
number 'N'.
Test your program with the following data and some random data:
Example 1
INPUT:
N = 14
OUTPUT:
PRIME PAIRS ARE:
3, 11
7, 7
Example 2
INPUT:
N = 30
OUTPUT:
PRIME PAIRS ARE:
7, 23
11, 19
13, 17
Example 3
INPUT:
N = 17
OUTPUT:
INVALID INPUT. NUMBER IS ODD.
Example 4
INPUT:
N = 126
OUTPUT:
INVALID INPUT. NUMBER IS OUT OF RANGE.
SOLUTION:

OUTPUT:
PROGRAM 10:
Input a paragraph containing 'n' number of sentences where (1 < = n <
4). The words are to be separated with a single blank space and are in
UPPERCASE. A sentence may be terminated either with a full stop '.' Or a
question mark '?' only. Any other character may be ignored. Perform the
following operations:

 Accept the number of sentences. If the number of sentences


exceeds the limit, an appropriate error message must be
displayed.
 Find the number of words in the whole paragraph.
 Display the words in ascending order of their frequency.
Words with same frequency may appear in any order.
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
Example 3
Input:
Enter number of
sentences. 5: Output :
Invalid Entry
import java.util.Scanner;

public class word


{
public static void main(String
args[]) { Scanner sc= new
Scanner(System.in);
System.out.println("Enter number of
sentences."); int n = in.nextInt();
in.nextLine();

if (n < 1 || n > 3) {
System.out.println("Invalid
Entry"); return;}
System.out.println("Enter
sentences."); String ipStr =
sc.nextLine();
ipStr = ipStr.toUpperCase();

StringTokenizer st = new
StringTokenizer(ipStr, " .?"); int wordCount =
st.countTokens();

System.out.println();
System.out.println("Total number of words: " + wordCount);

String wordArr[] = new


String[wordCount]; int wordFreq[] =
new int[wordCount];
int idx = 0;

for (int i = 0; i < wordCount; i++) {

String word =
st.nextToken(); int j = 0;

for (j = 0; j < idx; j++) {


if (wordArr[j].equals(word))
{ wordFreq[j]++;
break;}
} if (j ==
idx) {
wordArr[idx] =
word;
wordFreq[idx]+
+; idx++;}}
//Sort Word Frequency in ascending
order for (int i = 0; i < idx - 1; i++)
{
for (int j = 0; j < idx - i - 1; j++) {
if (wordFreq[j] > wordFreq[j +
1]) { int t = wordFreq[j];
wordFreq[j] =
wordFreq[j+1];
wordFreq[j+1] = t;

String temp =
wordArr[j]; wordArr[j]
= wordArr[j+1];
wordArr[j+1] = temp;
}}

//Display the words and frequencies


System.out.println("Word\
tFrequency"); for (int i = 0; i < idx;
i++) {
System.out.println(wordArr[i] + "\t" + wordFreq[i]);
}}}
PROGRAM 11:
A Transpose of an array is obtained by interchanging the elements of the
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/instance variables :
arr[] : stores the matrix elements
M : integer to store the number of rows
N : integer to store the number of columns
Member functions :
Transarray() : default constructor
Transarray(int mm, int nn) : to initialize the size of the matrix,
m=mm, n=nn void fillarray() : to enter the elements of the matrix
void transpose(Transarray A) : to find the transpose of a
given matrix void disparrary() : displays the array in a
matrix form

Specify the class Transarray giving the details of the constructors, and
fuctions void fillarray(), void transpose(Transarray) and void disparray().
SOLUTION:
OUTPUT:
PROGRAM 12:A superclass Product has been defined to store the details of a
product sold by a wholesaler to a retailer. Define a subclass Sales to
compute the total amount paid by the retailer with or without fine along
with service tax.
Some of the members of both classes are given below:
Class name: Product
Data members/instance variables:
name: stores the name of the
product code: integer to store the
product code
amount: stores the total sale amount of the product (in decimals)

Member functions/methods:
Product (String n, int c, double p): parameterized constructor to assign data
members: name = n, code = c and amount = p
void show(): displays the details of the data members

Class name: Sales


Data members/instance variables:
day: stores number of days taken to pay the sale
amount tax: to store the service tax (in decimals)
totamt: to store the total amount (in decimals)
Member functions/methods:
Sales(….): parameterized constructor to assign values to data members of both
the classes void compute(): calculates the service tax @ 12.4% of the actual sale
amount calculates the fine @ 2.5% of the actual sale amount only if the amount
paid by the retailer to the wholesaler exceeds 30 days calculates the total amount
paid by the retailer as (actual sale amount + service tax + fine)
void show (): displays the data members of the superclass and the total amount
Assume that the superclass Product has been defined. Using the concept of
inheritance, specify
the class Sales giving the details of the constructor (…), void compute() ) and void
show(). The
superclass, main function and algorithm need NOT be written.
SOLUTION:
PARENT CLASS:
CHILD CLASS:

OUTPUT:
PROGRAM 13: A library issues books on a rental basis at a 2% charge on
the cost price of the book per 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
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 2 classes
are given below:
Class name: Library
Data members:
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 details
Class name: Compute
Data members:
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 class void fine() : calculate the fine for excess days.
void display() : displays the book details along with the number of days, fine and
total
amount to be paid. The amount is calculated as: (2% of price of book*total no. of
days)+ fine.
Specify the class Library giving details of the constructor all the member
function of both the classes

ALGORITHM:
1. Start.
2. A base class library is created with given parameter of details.
3. All the parameters are initialized in the constructor.
4. Another class named compute is created which inherits its properties
from the base class library.
5. The derived class gets it’s variables initialized alo nwgit h the variables of the super
class.
6. The keyword super is used to call the constructor of the super class and
pass values to the respective variables.
7. The calculation of the fine is done in void fine() function with the provided conditions.
8. Then the final amount is printed with all the information in void show().
9. Another class is created to create main for ease of access.
10. Object of class compute is created and the required
functions are called. 11.Stop
PARENT CLASS

CHILD CLASS
OUTPUT:

VARIABLE DESCRIPTION:
Variable Type Description
name String To store name of the
book
author String To store author of the
book
p Double To store price of the
book
in decimals
f Double To store the calculated
fine
d Int To store number of days
taken in returning the
book.
sc Object variable To accept a value from
console
nr String To store name of the
book
pr Double To store price of the
book
in decimals
ar String To store author of the
book
dr Int To store number of days
taken in returning the
book.
PROGRAM 14: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 / instance variables:
name : variable to store the name
sex : character variable to store sex ‘F’ or ‘M’
age : integer variable to store the age
Member functions/methods
Student(……) : parameterised constructor
void inpdetailS() : to accept values for
data members void studDisplay () : to display
personal data of student

Class name : Marks


Data members/instance variables:
subject : variable to store the subject
regno : integer variable to store register
number mark : variable to store marks
Member functions/methods
Marks(….) : parameterised constructor
void inpdetailM() : to accept values for data members
void markDisplay () : to display exam details of Student and
Marks Specify the class Student giving details of
the constructor, void impdetailS() and void studDisplay (). Using the concept
of inheritance specify the class Marks, giving details of the constructor
function void inpdetailM() and void markDisplay (). Also define
the main() function.
PARENT CLASS:
CHILD CLASS:

OUTPUT:
PRORAM 15: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/instance variables:
item : to store the name of the item
qt : 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/instance variables:
pqty : to store the purchased quantity
prate : to store the unit price of the purchased item
Member functions/ methods:
Purchase(…) : parameterized conustcrtor 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 the item if there is a
difference in
purchase rate. Also, update the current stock
the (quantity
value as price)
* unit
void display() : to display the stock details before and after
updation. Specify the class Stock, giving details of the
constructor() and void display(). Using the concept of inheritance,
specify the class Purchase, giving details of the constructor(), void
update() and void display().
The main function and algorithm need not be written.
PARENT CLASS:

CHILD CLASS:
PROGRAM 16: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 the 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 Example 3
Input: M = 100 Input: M=99
N = 11 N = 11
Output: The required number Output: Invalid
= 119 Total number Input
of digits = 3
Example 2 Example 4
Input: M = 1500 Input: M=112
N = 25 N=130
Output: The required number = 1699 Output: Invalid
Input Total number of digits = 4
SOLUTION:
OUTPUT:
PROGRAM 17: Write a program to declare a matrix A [][] of order (MXN)
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 integers into this matrix.
Perform the following tasks on the matrix:
(a) Display the input matrix
(b) Find the maximum and minimum value in the matrix and display
them along with their position.
(c) Sort the elements of the matrix in ascending order using any standard
sorting
technique and rearrange them in the
matrix. (d)Output the rearranged
matrix.
Test your program with following data values and also some random data:

Example 1

INPUT:
M=3
N=4

Entered values: 8, 7, 9, 3, -2, 0, 4, 5, 1, 3, 6, -4

Original matrix:
8 7 93
-2 0 4 5
1 3 6 -4

Largest Number: 9
Row: 0
Column: 2

Smallest Number:
-4 Row=2
Column=3

Rearranged matrix:
-4 -2 0 1
3 3 4 5
6 7 8 9
SOLUTION:
OUTPUT:
PROGRAM 18:
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:

(i) Convert the first letter of each word to uppercase.

(ii) Find the number of vowels and consonants in each word and
display 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

Example 2:

INPUT: God is great.


OUTPUT: God Is Great
Word Vowels Consonan
ts
God 1 2
Is 1 1
Great 2 3

Example 3

INPUT: All The Best!


OUTPUT: Invalid Input
SOLUTION:
OUTPUT:
PROGRAM 19: 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 tasks:
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
SOLUTION:

OUTPUT:
PROGRAM 20: 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

SOLUTION:
OUTPUT:
POGRAM 21: A class Recursion has been defined to find the Fibonacci series
upto a limit. Some of the members of the class are given below:
Class Name :Recursion
DataMembers/instance variables : a, b, c, limit (all integers)
Member functions/methods :
Recursion ( ) : constructor to assign a,b,c with
appropriate values. void input ( ) : to accept the limit of
the series.
int fib(int n): to return the nth Fibonacci term using recursive technique.
void generate_fibseries() : to generate the Fibonacci series upto the given
limit, using recursive function int fib( ).
Specify the class Recursion giving details of constructor, fib( ),
voidgenerate_fibseries( ).
SOLUTION:

OUTPUT:
PROGRAM 22: A super class Detail has been defined to store
the details of a customer. Define a subclass Bill to compute the
monthly telephone charge of the customer as per the chart
given below:
Number Rate
Of Calls
1 – 100 Only Rental charge
101 – 60 paisa per call + rental
200 charge 80 paisa per call +
201 – rental charge
300
Above 1 rupee per call + rental
300 charge

The details of both the classes are given below:


Class Name : Detail
Data members / Instance variables:
name : to store the name of the
customer. address : to
store the address of the customer.
telno : to store the phone number of the
customer. rent : to store the
monthly rental charge Member functions:
Detail(…) : parameterized constructor to assign values to data
members. void show() : to display the detail of the customer.

Class Name : Bill


Data members / Instance variables:
n : to store the number of calls.
amt : to store the amount to be paid by the customer.
Member functions:
Bill(…) : parameterized constructor to assign values to data
members of both classes
and to initialize amt = 0.0.
void cal() : calculates the monthly telephone charge as per the
charge given above.
void show() : to display the detail of the customer and
amount to be paid. Specify the class Detail giving details of the
constructor( ) and void show(). Using the concept of inheritance,
specify the class Bill giving details of the constructor( ),void cal()
and void show(). Do not write the super class, main() function and
algorithm.
PARENT CLASS:

CHILD CLASS:
PROGRAM 23: A line on a plane can be represented by
coordinates of the two-end points p1 and p2 as p1(x1,y1) and
p2(x2,y2).
A super class Plane is defined to represent a line and a subclass Circle to
find
the length of the radius and the area of Circle by using the required
data members of super class.
Some of the members of both the classes are given below:
Class name : Plane
Data members/instance variables:
x1 : to store the x-coordinate of the first
end point y1 : to store the y-coordinate of
the first end point Member functions/methods:
Plane(int nx,int ny) : parameterized constructor to assign the
data members x1=nx
and y1=ny
void Show() : to display the coordinates
Class name : Circle
Data members/instance variables:
x2 : to store the x-coordinate of the second
end point y2 : to store the y-coordinate
of the second end point radius : double
variable to store the radius of the circle area
: double variable to store the area of
the circle Member functions / methods:
Circle(…) : parameterized constructor to assign values to data
members of both the
classes
void findRadius( ) : to calculate the length of radius using the
formula:
(𝑥2−𝑥1) 2 +
(𝑦2−𝑦1) 2
assuming that x1, x2, y1, y2 are
2
the coordinates of the two ends of the diameter of a circle.
void findArea( ) : to find the area of circle using formula: π𝑟2.
The value of π or 3.14
is 22
7
void Show( ) : to display both the coordinates along with the
length of the radius and
area of the circle.
Specify the class Plane giving details of the constructor and void
Show(). Using the concept of inheritance, specify the class Circle
giving details of the constructor, void findRadius(), void findArea()
and void Show().
The main function and algorithm need not be written.
PARENT CLASS:

CHILD CLASS:
PROGRAM 24: 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.
Example 1
INPUT:
DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22
OUTPUT:
DATE: 12TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4TH OCTOBER, 2018

Example 2
INPUT:
DAY NUMBER: 360
YEAR: 2018
DATE AFTER (N DAYS): 45
OUTPUT:
DATE: 26TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9TH FEBRUARY, 2019

Example 3
INPUT:
DAY NUMBER: 500
YEAR: 2018
DATE AFTER (N DAYS): 33
OUTPUT: DAY NUMBER OUT OF RANGE
SOLUTION:
OUTPUT:
PROGRAM 25:
To accept elements in a Double-Dimensional Array of N x N order
and print the sum of the elements of Left as well as Right
Diagonal.

Here, diaonal1 is left diagonal and diagonal2 is right


diagonal. Following is a test-case of this program:
Input:
Enter the size of the square
matrix: 3
123
456
789

Output:
Left Diagonal Sum
=15 Right Diagonal
Sum =10

SOLUTION:
OUTPUT:
PROGRAM 26: A double dimensional array is defined as N[4][4]
to store numbers. Write a program to find the sum of all even
numbers and product of all odd numbers of the elements stored
in Double Dimensional Array (DDA). Sample Input:
12 10 15 17
30 11 32 71
17 14 29 31
41 33 40 51

Sample Output:
Sum of all even numbers: ……….
Product of all odd numbers: ……….

SOLUTION:
OUTPUT:
PROGRAM 27: The coordinates of a point P on a two-dimensional plane
can be represented by P(x, y) with x as the x-coordinate and y as the y-
coordinate. The coordinates of the midpoint of two points P1(x1, y1) and
P2(x2, y2) can be calculated as P(x, y) where:

Design a class Point with the following details:


Class name: Point
Data Members/instance variables:
x : stores the x-
coordinate y : stores
the y-coordinate
Member functions:
Point () : constructor to initialize x = 0, y = 0
void readpoint () : accepts the coordinates x and y of a point
Point midpoint (Point A, Point B) : calculates and returns the midpoint of the
two
points A and B
void displaypoint () : displays the coordinates of
a point
Specify the class Point giving details of the constructor (), member functions
void readpoint ( ), Point midpoint (Point, Point) and void displaypoint () along with
the main () function to create an object and call the functions accordingly
to calculate the midpoint between any two given points.
SOLUTION:
OUTPUT:
PROGRAM 28: Write a program to create a double dimensional array of size
nx
m. Input the numbers in first (n-1) x (m-1) cells. Find and place the sum of
each row and each column in corresponding cells of last column and last
row respectively. Finally, display the array elements along with the sum
of rows and columns.

Sample Input

10 15 16 18

15 14 12 11

11 12 16 17

12 10 14 16

Sample output:

10 15 16 18 59

15 14 12 11 52

11 12 16 17 56

12 10 14 16 52

48 51 58 62
SOLUTION:
OUTPUT
PROGRAM 29:Write a program in Java to create a 4 x 4 matrix. Now,
swap the elements of 0th row with 3rd row correspondingly. Display the
result after swapping. Sample Input
55 33 26 14
81 86 31 10
58 64 17 12
22 14 23 25
Sample Output
22 14 23 25
81 86 31 10
58 64 17 12
55 33 26 14

SOLUTION:
OUTPUT:
PROGRAM 30: Write a program in Java to enter natural numbers in
a double dimensional array m x n (where m is the number of rows
and n is the number of columns). Display the new matrix in such
a way that the new matrix is the mirror image of the original
matrix.
Sample Input
8 15 9 18
9 10 7 6
10 8 11 13
12 16 17 19
Sample Output
18 9 15 8
6 7 10 9
13 11 8 10
19 17 16 12

SOLUTION
OUTPUT:
BIBLIOGRAPHY
For completing this project, I have taken help from :
 Understanding I.S.C. Computer Science (Java
with Blue J) Class- XII

 Guided Computer Science (Java) Practical


Programming Work- Book ISC Class 11-12

 Our Subject teacher: MAM GANGA DEVI


 My Classmates
 Google

You might also like