Sie sind auf Seite 1von 81

PRESENTING THE NEW UPGRADED ISC COMPUTER PROJECT FOR CLASS XII FOR HELPING

STUDENTS SAVE THEIR TIME FOR STUDYING …..


HOPEFULLY YOU WILL LIKE THIS…………..
EXCLUSIVE FEATURES:->
1>ALL PROGRAM WITH SYNTAX EXECUTED ERROR FREE
2>ALGORITH AVAILABLE
NOTE:-

PLZ EDIT THE COVER

SHARE WITH FRIEND AS MUCH AS POSSIBLE

PAGE NUMBERS MAY VARY ACCORDINGLY.


ARUNAV RAY ISC COMPUTER PROJECT 1
ACKNOWLEDGEMENTS

First of all, I’d like to thank my parents


for helping me out with the project.
Secondly, I’d like to thank our Computer
teachers Archan Sir for helping us with
the programs.
Lastly, I’m really grateful to classmate
Anuj Modi & Nikhil Agarwal whose help was
imperative for myself making this project.

ARUNAV RAY ISC COMPUTER PROJECT 2


CONTENTS

SL NO. TOPIC PAGE NO.

ARRANGE ELEMENTS OF EACH ROW OF A 2D ARRAY IN ASSENDING


1. 2-3
ORDER USING BUBBLE SORT

2. CHECK IF A 2D ARRAY IS SYMMETRIC 4-5

3. PRODUCT OF 2 MATRIX 6-7

ARRANGE ELEMENTS OF EACH ROW OF A 2D ARRAY IN ASSENDING


4. 8-9
ORDER USING BUBBLE SORT

5. MAGIC NUMBER(using RECURSION) 10-11

6. Calculate HCF(using RECURSION) 12-13

7. Armstrong NUMBER (USING RECURSION) 14-15

8. DECIMAL TO BINARY CONVERSION (using RECURSION) 16-17

9. OUTPUT TO A FILE TO STORE 5 NAMES 18-19

10. INPUT NAMES FROM A TEXT FILE 20-21

11. STACK 22-23

12. CIRCULAR QUEUE 24-25

13. WORD PALINDROME 26-27

14. REPLACE VOWELS with the LETTER SUCCEEDING it 28-29

15. DELETE MULTIPLE CHARACTERS FROM A SENTENCE 30-31

ARUNAV RAY ISC COMPUTER PROJECT 3


CONTENTS (cont..)

SL NO. TOPIC PAGE NO.

16. TO FIND PAST DATE 32-33

17. TIME 34-35

TO CALCULATE SUM OF TWO ANGLE USING OBJECT PASSING AND


18. 36-37
OBJECT RETURNING TECHNIQUE

SORTING OF COMMON ELEMENTS OF TWO ARRAY USING OBJECT


19. 38-39
PASSING AND OBJECT RETURNING TECHNIQUE

20. AMECABLE NUMBER 40-41

21. CIRCULAR PRIME NUMBER 42-43

23. TO CALCULATE TELEPHONE BILL USING CONCEPT OF INHERITANCE 44-45

23. TO FIND RADIUS AND AREA OF A CIRCLE USING INHERITANCE 46-47

ARUNAV RAY ISC COMPUTER PROJECT 4


CONTENTS (cont...)

SL
TOPIC PAGE NO.
NO.

24. TO INSERT ELEMENT AT REAR END IN A LINKLIST 55-57

25. TO DELETE ELEMENT AT REAR END IN A LINKLIST 58-61

26. TO DISPLAY UPPER TRIANGULAR OF A SQUARE MATRIX 62-64

ANAGRAMS
27. 65-67

28. TO INCERT AND DELETE ELEMENTS IN DEQUEUE 68-70

29. SORT 2 ARRAYS USING INSERTION SORT. 71-72

30. DISPLAY THE CALENDAR OF A MONTH BY ACCEPTING THE FIRST DAY OF THE 73-76
MONTH.

ARUNAV RAY ISC COMPUTER PROJECT 5


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
import java.util.*;
class Arrange_matrix
{ static void main()
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of array");
int n= sc.nextInt();//accepting size of array
int a[][]=new int[n][n];//declaring array
System.out.println("Enter array elements");
for(int i=0;i<n;i++)//accepting array
for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
for(int i=0;i<n;i++)//sorting array
{ for(int j=0;j<n-1;j++)
{ for(int k=0;k<n-j-1;k++)
if(a[i][k]>a[i][k+1])
{ int temp=a[i][k];
a[i][k]=a[i][k+1];
a[i][k+1]=temp;
}}}
for(int i=0;i<n;i++)//displaying array
{ for(int j=0;j<n;j++)
System.out.print(a[i][j]+"\t");
System.out.println();
}}}

ARUNAV RAY ISC COMPUTER PROJECT 6


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:

ARUNAV RAY ISC COMPUTER PROJECT 7


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 otherwise display array is not symmetric
STEP 13: END
****************
Program: To check if 2D array is symmetric or not

ARUNAV RAY ISC COMPUTER PROJECT 8


Variable description:

Sl. no Variable Name Datatype Purpose


1 N int To store array size
2 a char[][] To store character
3 c,i,j int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 9


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
*****************
Program: To find product of two (n*n)matrix

ARUNAV RAY ISC COMPUTER PROJECT 10


Variable description:

Sl. no Variable Name Datatype Purpose


1 n int To store size of matrix
2 a,b,c int[][] To store number
3 i,j,k int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 11


PROGRAM 4: To arrange elements of each row in ascending
order using bubble sort

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
*****************
Program: To arrange elements of each row in ascending
order using bubble sort

ARUNAV RAY ISC COMPUTER PROJECT 12


Variable description:

Sl. no Variable Name Datatype Purpose


1 n int To store size of matrix
2 a int[][] To store number
3 temp int For calculation
4 i,j,k int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 13


PROGRAM 5: Magic number 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))

*****************
Program: Magic number using recursion

ARUNAV RAY ISC COMPUTER PROJECT 14


Variable description:

Sl. no Variable Name Datatype Purpose


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:

ARUNAV RAY ISC COMPUTER PROJECT 15


PROGRAM 6: Finding HCF Using Recursion
Algorithm
main() 
STEP 1: Accept first number
STEP 2: Accept second number
STEP 3: Calculate HCF
STEP 4: Display HCF
hcf(int a, int b) 
STEP 1: If (a>b)is true then return (hcf(a-b,b))
STEP 2: Otherwise if (b>a) is true then return (hcf(a,b-a))
STEP 3: Otherwise return a
****************

Program: Finding HCF Using Recursion

ARUNAV RAY ISC COMPUTER PROJECT 16


Variable description:

Sl. No Variable Name Datatype Purpose


1 a int To get number
2 b int To get number
3 c int To store hcf

Output:

ARUNAV RAY ISC COMPUTER PROJECT 17


PROGRAM 7: Armstrong Number 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);
*****************

Program: Armstrong Number Using Recursion

ARUNAV RAY ISC COMPUTER PROJECT 18


Variable description:

Sl. no Variable Name Datatype Purpose


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

Output:

ARUNAV RAY ISC COMPUTER PROJECT 19


PROGRAM 8: 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

*****************

Program: Decimal To Binary Conversion Using Recursion

ARUNAV RAY ISC COMPUTER PROJECT 20


Variable description:

Sl. no Variable Name Datatype Purpose


1 a int To get number
2 d int Binary calculation
3 n int User iput

Output:

ARUNAV RAY ISC COMPUTER PROJECT 21


PROGRAM 9: Output to a file to store 5 Names
Algorithm
STEP 1:START
STEP 2: Create a FileWriter stream type object
STEP 3: Link the FileWriter object from STEP 1 with a BufferedWriter object
STEP 4: Link the BufferedWriter object from STEP 2 with a PrintWriter object
STEP 5: for i=0 to 4
STEP 6: Accept name from user
STEP 7: Now write names in the file using PrintWriter object
STEP 8: Close the stream chain by using close()
STEP 9: END

*****************

Program: Output to a file to store 5 Names

ARUNAV RAY ISC COMPUTER PROJECT 22


Variable description:

Sl. no Variable Name Datatype Purpose


1 i int Counter
2 name String Input name from user

Output:

ARUNAV RAY ISC COMPUTER PROJECT 23


PROGRAM 10: Input Names from a text file

Algorithm
STEP 1:START
STEP 2: Create a FileReader stream type object
STEP 3: Link the FileReader object from STEP 1 with a BufferedReader object
STEP 4: Repeat STEP 5 and STEP 6 until readLine() is null
STEP 5: Read text using readLine() from this BufferedReader object and store in a string object
STEP 6: Display the string object
STEP 7: Close the stream chain by using close()
STEP 8: END

*****************

Program: Input Names from a text file

ARUNAV RAY ISC COMPUTER PROJECT 24


Variable description:

Sl. no Variable Name Datatype Purpose


1 i int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 25


PROGRAM 11: Stack
Algorithm
STEP 1: START
/* stack – st[], stack pointer – top*/
Push()
STEP 1: Check for overflow
STEP 2: If STEP 1 is true display “Stack Overflow” otherwise proceed to STEP 3
STEP 3: Increase stack pointer by 1
STEP 4: Push the item
Pop()
STEP 1: Check for underflow
STEP 2: If STEP 1 is true display “Stack Underflow” otherwise proceed to STEP 3
STEP 3: Pop out the item and decrease stack pointer by 1
STEP 4: Display the popped out item
Display()
STEP 1: Check for underflow
STEP 2: If STEP 1 is true display “Stack Underflow” otherwise proceed to STEP 3
STEP 3: for i=top to 0
STEP 4: Display st[i]
*****************
Program: Stack

ARUNAV RAY ISC COMPUTER PROJECT 26


Variable description:

Sl. no Variable Name Datatype Purpose


1 top int Stack pointer
2 size int[][] Size of stack
3 st[][] int To store stack elements
4 n int To store items to be
inserted
5 i int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 27


PROGRAM 12: Circular Queue
Algorithm
STEP 1: START
/* Queue – ar[], pointer – rear,front*/
To insert item 
STEP 1: Check for overflow
STEP 2: Set the pointers
STEP 3: Insert the item
To delete item 
STEP 1: Check for underflow
STEP 2: Delete an item
STEP 3: Set the pointers
Display()
STEP 1: for i=0 to size-1
STEP 2: Display ar[i]
*****************

Program: Circular Queue

ARUNAV RAY ISC COMPUTER PROJECT 28


Variable description:

Sl. no Variable Name Datatype Purpose


1 front,rear int Queue pointer
2 size int[][] Size of the queue
3 ar[] int To store queue
elements
4 n int To store item to be
inserted
5 i int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 29


PROGRAM 13: Palindrome Word

Algorithm
STEP 1: START
STEP 2: Find length of the entered word and store in variable l
STEP 3: for i=l-1 to 0, repeat STEP 4
STEP 4: w=w+s.charAt(i)
STEP 5: If s=w, then display Palindrome otherwise display not palindrome
STEP 6: END

*****************

Program: Palindrome Word

ARUNAV RAY ISC COMPUTER PROJECT 30


Variable description:

Sl. no Variable Name Datatype Purpose


1 s String Store original word
2 w String Store reversed word
3 l int Store number of
character in s
4 i int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 31


PROGRAM 14: Replace all vowels of a sentence with succeeding
letter

Algorithm
STEP 1: START
STEP 2: Find length of the entered word and store in variable l
STEP 3: for i=0 to l-1, repeat STEP 4,5,6
STEP 4: Extract characters of the word and store in variable ch
STEP 5: if ch is a vowel, ch=ch+1
STEP 6: str= str+ch
STEP 7: Display the original word and the new word
STEP 8: END

*****************

Program: Replace all vowels of a sentence with succeeding


letter

ARUNAV RAY ISC COMPUTER PROJECT 32


Variable description:

Sl. no Variable Name Datatype Purpose


1 s String Store original word
2 str String Store the new word
3 l int Store number of
character in s
4 i int Counter
5 ch char Extract character

Output:

ARUNAV RAY ISC COMPUTER PROJECT 33


PROGRAM 15: Delete Multiple Character from a Sentence
Algorithm
STEP 1: START
STEP 2: Covert the string to UPPERCASE
STEP 3: str= the first character of the sentence
STEP 4: Find length of the entered word and store in variable l
STEP 5: for i=0 to l-1, repeat STEP 6-11
STEP 6: Extract characters of the word and store in variable ch
STEP 7: Find length of the entered word and store in variable l 1
STEP 8: for j=0 to l1, repeat STEP 9,10
STEP 9: Extract characters of the word and store in variable ch1
STEP 10: if ch=ch1, is true c=c+1
STEP 11: if c=0, then only add ch to str
STEP 12: Display the original word and the new word
STEP 13: END

*****************
Program: Delete Multiple Character from a Sentence

ARUNAV RAY ISC COMPUTER PROJECT 34


Variable description:

Sl. no Variable Name Datatype Purpose


1 s String Store original word
2 str String Store the new word
3 l,l1 int Store number of
character in string
4 i,j,c int Counter
5 ch,ch1 char Extract character

Output

ARUNAV RAY ISC COMPUTER PROJECT 35


PROGRAM 16: To Find Date on which project was given if
project submission date and number of days
allotted for the project are mentioned by the
user. (PAST DATE)
Example: - Example:-

Entered date 26/02/2000 Entered date 03/01/2000


Days before: - 10 Days before: - 5
Past date 16/02/2000 Past date 29/12/1999

Algorithm
STEP 1: Start
STEP 2: Separating date ,month and year from input
STEP 3: Checking for leap year
STEP 4: Checking for invalid date
STEP 5: Accepting day to calculate past date
STEP 6: Calculating past date
STEP 7: Displaying past date
STEP 8: End

ARUNAV RAY ISC COMPUTER PROJECT 36


Program: TO FIND PAST DATE

import java.util.Scanner;
class pastDate
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
System.out.print("Enter the Submission Date in (dd/mm/yyyy) format: ");
String date=sc.nextLine().trim();
int p,q,count=0;
p=date.indexOf("/");
int d=Integer.parseInt(date.substring(0,p));//EXTRACTING DAYS
q=date.lastIndexOf("/");
int m=Integer.parseInt(date.substring(p+1,q));
int y=Integer.parseInt(date.substring(q+1));
System.out.println("Entered Project Submission Date: "+date);
if((y%400==0) || ((y%100!=0)&&(y%4==0)))//CHECKING LEAP YEAR
month[2]=29;
else
month[2]=28;
if(m<0 || m>12 || d<0 || d>month[m] || y<0 || y>9999)//VALIDATION OF DATE
{
System.out.println("Invalid Date");
}
else
{
System.out.print("Enter number of days alloted for the project: ");
int days=Integer.parseInt(sc.nextLine());
while(count<days)//LOOP TO FIND PAST DATE
{
d--;
count++;
if(d<1)
{
d=month[m-1];//STORING PREVIOUS MONTH NUMBER OF DAYS
m--;
}
if(m<1)
{
y--;
m=12;
d=month[m];
if((y%400==0) || ((y%100!=0)&&(y%4==0))) //CHECKING FOR LEAP YEAR
month[2]=29;
else
month[2]=28;
}
}
System.out.println("Date on which project was given: +d+"/"+m+"/"+y);
}
}
}

ARUNAV RAY ISC COMPUTER PROJECT 37


Variable description:

Sl. no Variable Name Datatype Purpose


1 p,q int To store index number
2 count int Counter
3 i,j,k int Counter
4 month int[] Days of a month
5 d,m,y int To store day ,month ,year
respectively

Output:

ARUNAV RAY ISC COMPUTER PROJECT 38


PROGRAM 17: To Find Sum of two time
Two different time are added as follows:-
Time 1:6 hours 35 minutes
Time 2:3 hours 45 minutes
Sum of Time: 10 hour 20 minutes

Class Name Time


Data Members/Instance Variable
hrs,min Integer variable to store hours and minutes
Member Function/Methods
Time() Constructor to assign 0 to hrs and min
void gettime(int nh,int nm) To store nh in hrs and nm to min
void printTime() To print value of hours and minutes with proper
message
Time sumTime(Time t1,Time t2) To find sum of times from object T1 and T2 by using
above methods of adding time and return the sum of
times

Algorithm
STEP 1: Start
STEP 2: void gettime(int nh,int nm)
Initialization of data members nh to hrs and nm to min
STEP 3: Time sumoftime(Time t1,Time t2)
We take two object in method sum of time as t1 and t2
Create a new object c and declare it min and hrs as sum of min of both the object
t1 and t2.
STEP 4: Return the created object
STEP 5: void display()
Display the hrs and min of the new created object
STEP 6: void main(int hr1,int min1,int hr 2,int min 2 )
Declare object ob1 and ob2
Call Function gettime(hr1,min1) by ob1 and gettime(hr2,min2) by ob2
Call display function using ob1 as well as ob2
Use ob3 object as variable to call function sumoftime(ob1,ob2)
Lastly call display function using ob3
STEP 7: End

ARUNAV RAY ISC COMPUTER PROJECT 39


Program: TO FIND SUM OF TWO TIMES

import java.util.Scanner;
class Time
{
Scanner sc=new Scanner(System.in);
int hrs,min;
Time()
{
hrs=0;
min=0;
}

void gettime(int nh,int mn)


{
hrs=nh;
min=mn;
}

Time sumtime(Time t1,Time t2)


{
Time c=new Time();
c.min=t1.min+t2.min;
c.hrs=t1.hrs+t2.hrs;
c.hrs=c.hrs+(int)(c.min/60);
c.min=c.min%60;
return c;
}

void display()
{
System.out.println(hrs+" hours"+" "+min+" minutes");
}

void main(int h1,int m1,int h2,int m2)


{
Time ob1=new Time();
Time ob2=new Time();
ob1.gettime(h1,m1);
ob2.gettime(h2,m2);
ob1.display();
ob2.display();
Time ob3=sumtime(ob1,ob2);
ob3.display();
}
}

ARUNAV RAY ISC COMPUTER PROJECT 40


Variable description:

Sl. no Variable Name Datatype Purpose


1 hrs,min int To store hour and minute
2 nh,nm int Formal parameter
3 h1,min1,h2,min2 int Actual parameter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 41


PROGRAM 18: To Find Sum of two angle
Two different are are added as follows:-
Let the first angle =20 degrees 45 minutes
Let the second angle = 12 degrees 40 minutes
Sum of Angle will be: 33 degrees 25 minutes (60 minutes=1 Degree)

Class Name Angle


Data Members/Instance Variable
deg,min Integer variable to store degree and minutes
Member Function/Methods
Angle() Constructor to assign 0 to deg and min
void inputangle() To store nh in hrs and nm to min
void displayangle() To print value of deg and minutes with proper
message
Angle sumofangle(Angle t1,Angle t2) To find sum of angles from object T1 and T2 by using
above methods of adding time and return the sum of
angles

Algorithm
STEP 1: Start
STEP 2: void inputangle()
Initialization of data members deg and min
STEP 3: Angle sumofangle (Angle t1,Angle t2)
We take two object in method sum of angle as t1 and t2
Create a new object c and declare its deg & min and hrs as sum of deg&min of
both the object t1 and t2.
STEP 4: Return the created object
STEP 5: void display()
Display the deg and min of the new created object
STEP 6: void main()
Declare object ob1 and ob2
STEP 7: Call Function inputangle()by ob1 and inputangle()by ob2
Call display function using ob1 as well as ob2
Use ob3 object as variable to call function sumofangle(ob1,ob2)
Lastly call display function using ob3
STEP 8: End

ARUNAV RAY ISC COMPUTER PROJECT 42


Program: TO FIND SUM OF TWO ANGLES

import java.util.Scanner;
class Angle
{
Scanner sc=new Scanner(System.in);
int deg,min;
Angle()
{
deg=0;
min=0;
}
void inputangle()
{
System.out.println("enter degree");
deg=sc.nextInt();
System.out.println("enter minutes");
min=sc.nextInt();
}
Angle sumofangle(Angle t1,Angle t2)
{
Angle c=new Angle();
c.min=t1.min+t2.min;
c.deg=t1.deg+t2.deg;
c.deg=c.deg+(int)(c.min/60);
c.min=c.min%60;
return c;
}
void display()
{
System.out.println(deg+" degree"+" "+min+" minutes");
}
void main()
{
Angle ob1=new Angle();
Angle ob2=new Angle();
ob1.inputangle();
ob2.inputangle();
ob1.display();
ob2.display();
Angle ob3=sumofangle(ob1,ob2);
ob3.display();
}
}

ARUNAV RAY ISC COMPUTER PROJECT 43


Variable description:

Sl. no Variable Name Datatype Purpose


1 deg,min int To store degree and
minute

Output:

ARUNAV RAY ISC COMPUTER PROJECT 44


PROGRAM 19: To Sort Common Elements Of Two Array
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.

Algorithm
STEP 1: Start
STEP 2: collection()
Initialization of data members len=0
STEP 3: collection(int a)
STEP 4: Initialization of data members len=a
And declare array of size a
STEP 5: void inparr()
to enter array elements
STEP 6: Collection common (Collection a)
We take object in method common as a
Create a new object b and declare and add the common elemnts of that array and
current array in the new array of the new object
Change the length of the new object accordingly
Return the created object
STEP 7: void arrange()
To sort the common elements in assending order using bubble sort
STEP 8: void display()
Display the sorted array
STEP 9: void main(int l1,int l2)
Declare object ob1 of length l1 and ob2 of length l2 respectively.
STEP 10: Call Function inparr()by ob1 and inparr()by ob2
Use ob3 object as variable to call function common(ob1) using ob2
Lastly call display function using ob3
STEP 11: End

ARUNAV RAY ISC COMPUTER PROJECT 45


Program: TO SORT COMMON ELEMENTS OF TWO ARRAY

import java.util.Scanner;
class collection
Scanner sc=new Scanner(System.in);
int arr[],len;
collection()
{
len=0; }

collection(int a)
{ arr=new int[a];
len=a;
for(int i=0;i<len;i++)
{ arr[i]=0;
} }

void inparr()
{ for(int i=0;i<len;i++)
{ System.out.println("enter");
arr[i]=sc.nextInt(); }
}

collection common(collection a)
{ collection b=new collection(len);
int k=0;
for(int i=0;i<len;i++)
{ for(int j=0;j<a.len;j++)
{ if(arr[i]==a.arr[j])
{ b.arr[k++]=arr[i];
break; }
} }
b.len=k;
return b; }

void arrange()
{ for(int i=0;i<len-1;i++)
{ for(int j=0; j<len-i-1; j++)
{ if(arr[j] > arr[j+1])
{ int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
} } } }
void display()
{
for(int i=0;i<len;i++)
{
System.out.print(arr[i]+" ");
} }
void main(int l1,int l2)
{
collection ob1=new collection(l1);
collection ob2=new collection(l2);
ob1.inparr();
ob2.inparr();
collection ob3=ob2.common(ob1);
ob3.arrange();
ob3.display();
}}

ARUNAV RAY ISC COMPUTER PROJECT 46


Variable description:

Sl. no Variable Name Datatype Purpose


1 arr[] int Integer array
2 len int To store length of array
3 i,j int For loop
4 k int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 47


PROGRAM 20: Amicable Number
A pair of numbers, each of which is the sum of the factors of the other (e.g. 220 and 284).They
are amicable because the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110, of
which the sum is 284; and the proper divisors of 284 are 1, 2, 4, 71 and 142, of which the sum is
220.
Other examples are: - (220, 284), (1184, 1210), (2620, 2924), (5020, 5564)

Algorithm
STEP 1: Start
STEP 2: Take a and b as parameterized input
STEP 3: Declare I,j,c,and d
STEP 4: Run loop i to a and add all factor in c
STEP 5: Run loop j to b and add all factor in d
STEP 6: Check if c is equal to b and d is equal to a
STEP 7: If true then amecable else not
STEP 8: End

Program: AMICABLE NUMBER

ARUNAV RAY ISC COMPUTER PROJECT 48


Variable description:

Sl. no Variable Name Datatype Purpose


1 a,b int Parameterized input
2 c,d int To store sum of factors
3 i,j int For loop

Output:

ARUNAV RAY ISC COMPUTER PROJECT 49


PROGRAM 21: Circular Prime Number

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 I and itself.
Example:
131
311
113
Hence, 131 is a circular prime.

Algorithm

STEP 1: Start
STEP 2: Take a and b as parameterized input
STEP 3: Declare I,j,c,and d
STEP 4: Run loop i to a and add all factor in c
STEP 5: Run loop j to b and add all factor in d
STEP 6: Check if c is equal to b and d is equal to a
STEP 7: If true then amecable else not
STEP 8: End

ARUNAV RAY ISC COMPUTER PROJECT 50


Program: CIRCULAR PRIME NUMBER
import java.util.*;
class CircularPrimeNumber
{
boolean isPrime(int n)
{
int c = 0;
for(int i = 1; i<=n; i++)
{
if(n%i == 0)
c++;
}
if(c == 2)
return true;
else
return false;
}

int circulate(int n)
{
String s = Integer.toString(n);
String p = s.substring(1)+s.charAt(0);
int a = Integer.parseInt(p);
return a;
}

void isCircularPrime(int n)
{
int f = 0,a = n;
do
{
System.out.println(a);
if(isPrime(a)==false)
{
f = 1;
}
a = circulate(a);
}while(a!=n);

if(f==1)
System.out.println(n+" IS NOT A CIRCULAR PRIME");
else
System.out.println(n+" IS A CIRCULAR PRIME");
}

public static void main(String args[])


{
CircularPrimeNumber ob = new CircularPrimeNumber();
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int n = sc.nextInt();
ob.isCircularPrime(n);
}
}

ARUNAV RAY ISC COMPUTER PROJECT 51


Variable description:

Sl. no Variable Name Datatype Purpose


1 n int Parameterized input
2 c int Counter
3 i int For loop
4 s,p String To store string and
modify it
5 f int Checking condition
6 a int Acting as temporary
variable

Output:

ARUNAV RAY ISC COMPUTER PROJECT 52


PROGRAM 22: TO CALCULATE TELEPHONE BILL USING CONCEPT OF
INHERITANCE

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 Of Calls Rate
1 – 100 Only Rental charge
101 – 200 60 paisa per call + rental charge
201 – 300 80 paisa per call + rental charge
Above 300 1 rupee per call + rental 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().

Algorithm
SUPER CLASS
STEP 1: Start
STEP 2: Accept personal details
STEP 3: Print them in display
STEP 4: End
BASE CLASS
STEP 1: Start
STEP 2: Assign value to super class variable using super keyword
STEP 3: Calculating amount to be paid as per number of calls
STEP 4: Printing details
STEP 5: End

ARUNAV RAY ISC COMPUTER PROJECT 53


Program: TO CALCULATE TELEPHONE BILL USING CONCEPT OF
INHERITANCE
import java.io.*;
class Detail //superclass
{
String name, address;
long telno;
double rent;

Detail(String n1, String a1, long t1, double r1)


{
name = n1;
address = a1;
telno = t1;
rent = r1;
}

void show()
{
System.out.println("Name of customer = "+name);
System.out.println("Address = "+address);
System.out.println("Telephone Number = "+telno);
System.out.println("Monthly Rental = Rs. "+rent);
}
} //end of superclass Detail
class Bill extends Detail //subclass
{ int n;
double amt;

Bill(String n1, String a1, long t1, double r1, int c)


{
super(n1,a1,t1,r1); //initializing data members of superclass by
calling its constructor
n = c;
amt = 0.0;
}
void cal()
{
if(n>=1 && n<=100)
amt = rent;
else if(n>=101 && n<=200)
amt = 0.6*n + rent;
else if(n>=201 && n<=300)
amt = 0.8*n + rent;
else
amt = 1*n + rent;
}
void show()
{
super.show(); //calling the superclass function show()
System.out.println("No. of calls = "+n);
System.out.println("Amount to be paid = Rs. "+amt);
}
} //end of subclass Bill

ARUNAV RAY ISC COMPUTER PROJECT 54


Variable description:

Sl. no Variable Class Datatype Purpose


Name
1 n1,a1 detail String Parameterized input name and address
2 t1 detail long Telephone number
3 r1 detail double rent
4 n bill int Number of calls made
5 amt bill double For calculating payable amount
6 a bill int Acting as temporary variable

Output:

ARUNAV RAY ISC COMPUTER PROJECT 55


Class Name Point
Data Members:
x1,x2 stores x- coordinate
y1,y2 stores y- coordinate
Member Functions:
Point(…) To assign values to data members.
void display() Displays the coordinates.

PROGRAM 23: TO FIND RADIUS OF A CIRCLE USING INHERITANCE

Class Name Circle


Data Members:
r Stores the radius
Member Functions:
Circle(…) To assign values to data
void calDistance() Calculates the distance between the
coordinates and stores in r
void display() displaying the radius along with points.

Specify the class Point, giving details of the constructor and void display(). Using the
concept of inheritance. specify a class Circle giving details of the constructor, void
calDistance() and void display().Do not write main() function.

Algorithm
SUPER CLASS
STEP 1: Start
STEP 2: Parameterized constructor to initialize the point coordinates
STEP 3: Displaying the points
STEP 4: End

BASE CLASS
STEP 1: Start
STEP 2: Parameterized constructor to initialize the variables by invoking the constructor of
the parent class
STEP 3: CalDistance function to calculate the distance between two points and storing in r
STEP 4: Calling the display func of parent class and displaying the radius
STEP 5: End

ARUNAV RAY ISC COMPUTER PROJECT 56


Program: TO FIND RADIUS OF A CIRCLE USING INHERITANCE

class Point
{
int x1,x2,y1,y2;
Point(int a,int b,int c,int d)
{
x1=a;
x2=b;
y1=c;
y2=d;
}
void display()
{
System.out.println("The coordinates are - ("+x1+","+y1+") and
("+x2+","+y2+")");
}
}
public class circle extends Point
{
double r;
circle(int a,int b,int c,int d)
{
super(a,b,c,d);
r=0.0;
}
public void calDistance()
{
r=Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
}
void display()
{
super.display();
System.out.println("The length of the radius = "+r+" units");
}}

ARUNAV RAY ISC COMPUTER PROJECT 57


Variable description:

Sl. no Variable Class Datatype Purpose


Name
1 x1,x2,y1,y2 Point int Storing coordinates
2 a,b,c,d Point int For calculation
3 r Circle double To store Radius

Output:

ARUNAV RAY ISC COMPUTER PROJECT 58


PROGRAM 24: TO INSERT ELEMENT AT REAR END IN A LINKLIST

Algorithm
STEP 1 : START
STEP 2 : [Create the first list of the structure]
Accept(start->temp)
start->link=NULL
STEP 3 : [Initialize the temporary objects]
ptr=start
STEP 4 : [Input number of nodes to be created]
Accept(“Numbers of nodes-”,n)
count=0
STEP 5 : [Create other nodes of the linked list structure and connect them]
Repeat through steps 6 and 7 while(c<n)
STEP 6 : [Create a temporary node]
Accept(temp->data)
temp->link=NULL
STEP 7 : [Connect the temporary list in existing linked list]
ptr->link=temp
ptr=ptr->link
c=c+1
temp=NULL
ar[rear]=n
STEP 8 : [Withdraw temporary pointer ptr]
ptr=NULL
STEP 9 : [Create a single list]
Accept(temp->data)
STEP 10 : [Initialize ptr object to refer first list]
ptr=start
STEP 11 : [Locate the last link of the linked list structure]
while(ptr->link!=NULL)
ptr=ptr->link
endwhile
STEP 13 : [Insert the list]
ptr->link=temp
STEP 14 : END

ARUNAV RAY ISC COMPUTER PROJECT 59


Program: TO INSERT ELEMENT AT REAR END IN A LINKLIST

import java.util.*;
class node
{ int data;
node link;
void create()//creating a linked list
{ Scanner OB= new Scanner(System.in);
System.out.println("Enter the first data-");
this.data= OB.nextInt();
System.out.println("Enter number of nodes to be
created-");
int n=OB.nextInt();
node temp;
node ptr=this;
for(int i=1; i<n;i++)
{ temp= new node();
System.out.println("Enter next data");
temp.data= OB.nextInt();
temp.link= null;
ptr.link= temp;
temp=null;
ptr=ptr.link; }}
void insertend(node start, int x)//inserting a list
{ node temp= new node();
temp.data=x;
node ptr=start;
while(ptr.link!=null)
{ ptr=ptr.link; }
ptr.link=temp; }
void display()//displaying the elements
{ System.out.println("Linked list-");
node ptr=this;
while(ptr!=null)
{ System.out.println(ptr.data);
ptr=ptr.link; }}
static void main()
{ Scanner OB = new Scanner(System.in);
System.out.println("Enter the no. to be inserted");
int k = OB.nextInt();
node first = new node();
first.create();
first.insertend(first,k);
first.display(); }}//end of class

ARUNAV RAY ISC COMPUTER PROJECT 60


Variable description:
Sl. no Variable Name Datatype Purpose

1 data int Accepting value

2 n int Accepting value

3 i int Counter

4 x int To store value

5 k int Accepting values

Output:

ARUNAV RAY ISC COMPUTER PROJECT 61


PROGRAM 25: TO DELETE ELEMENT AT REAR END IN A LINKLIST

Algorithm
STEP 1 : START
STEP 2 : [Create the first list of the structure]
Accept(start->temp)
start->link=NULL
STEP 3 : [Initialize the temporary objects]
ptr=start
STEP 4 : [Input number of nodes to be created]
Accept(“Numbers of nodes-”,n)
count=0
STEP 5 : [Create other nodes of the linked list structure and connect them]
Repeat through steps 6 and 7 while(c<n)
STEP 6 : [Create a temporary node]
Accept(temp->data)
temp->link=NULL
STEP 7 : [Connect the temporary list in existing linked list]
ptr->link=temp
ptr=ptr->link
c=c+1
temp=NULL
ar[rear]=n
STEP 8 : [Withdraw temporary pointer ptr]
ptr=NULL
STEP 9 : [Initialize Ptr and ptr1 objects referring Start]
Ptr=Start
Ptr1=Start
STEP 10 : [Initialize the counter]
Count=0
STEP 11 : [Locate nth node to be deleted]
Repeat while (Count<n)
Ptr1=Ptr
Ptr=Ptr->link
Count=Count+1
Endwhile
STEP 12 : [Delete the list]
Ptr1->link=Ptr->link
Ptr->link=NULL
STEP 13 : [Withdraw the temporary pointers]
Ptr=NULL
Ptr1=NULL
STEP 14 : return
STEP 15 : END

ARUNAV RAY ISC COMPUTER PROJECT 62


Program: TO DELETE ELEMENT AT REAR END IN A LINKLIST

import java.util.*;
class nodal
{ int data;
nodal link;
public nodal()
{
data=0;
link=null; }
public static void main()
{
Scanner sc= new Scanner(System.in);
nodal ob=new nodal();
int ch,n,k,e,s=1;
do {
System.out.println("Enter 1 to create List");
System.out.println("Enter 2 to delete element");
System.out.println("Enter 3 to to display List");
System.out.println("Enter your choice");
ch=sc.nextInt();
switch(ch)
{
case 1:ob.create();
break;
case 2:System.out.println("Enter the node number you want to delete");
n=sc.nextInt();
ob.delete(ob,n);
break;
case 3:ob.display();
break;
default : System.out.println("Wrong choice");
}
System.out.println("Do you want to continue?(1/0)");
s=sc.nextInt();
}
while(s!=0);
}

void create()//creating a linked list


{ Scanner sc= new Scanner(System.in);
System.out.println("Enter the first data-");
this.data= sc.nextInt();
System.out.println("Enter number of nodes to be created-");
ARUNAV RAY ISC COMPUTER PROJECT 63
int n=sc.nextInt();
nodal temp;
nodal ptr=this;
for(int i=1; i<n;i++)
{ temp= new nodal();
System.out.println("Enter next data");
temp.data= sc.nextInt();
temp.link= null;
ptr.link= temp;
temp=null;
ptr=ptr.link;
}
}

public void delete(nodal start, int n)//inserting a list


{ nodal ptr= start;
nodal ptr1= ptr;
int c=0;
while(c<=n)
{
ptr1=ptr;
ptr=ptr.link;
c++;
}
ptr1.link=ptr.link;
ptr.link=null;
ptr=ptr1=null;
}

void display()//displaying the elements


{
System.out.println("Linked list-");
nodal ptr=this;
while(ptr!=null)
{ System.out.println(ptr.data);
ptr=ptr.link;
}
}

}//end of class

ARUNAV RAY ISC COMPUTER PROJECT 64


Variable description:
Sl. no Variable Name Datatype Purpose

1 data int Accepting value

2 n int Accepting value

3 i int Counter

4 Ptr,Ptr1 int To store value

5 link int To link cells of linklist

6 ch int Switch variable

7 s int checker

Output:

ARUNAV RAY ISC COMPUTER PROJECT 65


PROGRAM 26: TO DISPLAY UPPER TRIANGULAR OF A SQUARE MATRIX

Algorithm
STEP 1 : START
STEP 2 : Define array a
STEP 3 : Accept row and coloumn from user and check if square matrix or not
STEP 4 : Repeat i from 0 to n an j from 0 to n and take input in array
STEP 5 : Repeat i from 0 to n an j from 0 to n and display the inputted array
STEP 6 : Repeat i from 0 to n an j from 0 to n and check condition if i<=j true or not
if true print else leave free space
STEP 7 : If row number and coloumn number is different then print suitable
message
STEP 8 : END

Variable description:

Sl. no Variable Name Datatype Purpose


1 a[] int Integer array
2 n,m int Accepting value
3 i,j int Counter

ARUNAV RAY ISC COMPUTER PROJECT 66


Program: TO INSERT ELEMENT AT REAR END IN A LINKLIST
import java.util.Scanner;
public class Upper_Triangular
{ public static void main(String args[])
{ int a[][];
System.out.println("Enter the order of your Matrics ");
System.out.println("Enter the rows:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("Enter the columns:");
Scanner s = new Scanner(System.in);
int m = s.nextInt();
a=new int[n][m];
if(n == m)
{ System.out.println("Enter your elements:");
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
Scanner ss = new Scanner(System.in);
a[i][j] = ss.nextInt();
System.out.print(" "); }
}
System.out.println("You have entered:");
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
System.out.print(a[i][j] + " ");
}
System.out.println("");
}
System.out.println("The Upper Triangular Matrices is:");
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(i <= j)
{
System.out.print(a[i][j] +" ");
}
else
{
System.out.print("0"+" ");
} }
System.out.println(""); } }
else
{
System.out.println("you have entered improper order");
} }
}

ARUNAV RAY ISC COMPUTER PROJECT 67


Output:

ARUNAV RAY ISC COMPUTER PROJECT 68


PROGRAM 27: ANAGRAMS

Algorithm
STEP 1 : START

STEP 2 : Accept the word from the user


STEP 3 : Send the entered word along with a blank space to STEP 4
STEP 4 : If the length of the entered word is 1 display the same word otherwise
gotoSTEP 5
STEP 5 : run a loop i from 0 to length
STEP 6 : break the word into 3 parts and send 1 string and 2 strings together to
STEP3.
STEP 7 : END

Variable description:

Sl. no Variable Name Datatype Purpose

1 c int Counter
2 s String Accepting value

3 s1,s2 String Parameterized input

4 x,y,z String To form anagram String editing

ARUNAV RAY ISC COMPUTER PROJECT 69


Program: ANAGRAMS

import java.util.*;
class Anagrams
{ int c = 0;
void input()throws Exception
{ Scanner sc = new Scanner(System.in);
System.out.print("Enter a word : ");
String s = sc.next();
System.out.println("The Anagrams are : ");
display("",s);
System.out.println("Total Number of Anagrams =
"+c);
}
void display(String s1, String s2)
{
if(s2.length()<=1)
{
c++;
System.out.println(s1+s2);
}
else
{
for(int i=0; i<s2.length(); i++)
{
String x = s2.substring(i, i+1);
String y = s2.substring(0, i);
String z = s2.substring(i+1);
display(s1+x, y+z); }
}
}
public static void main(String args[])throws
Exception
{
Anagrams ob=new Anagrams();
ob.input();
}
}

ARUNAV RAY ISC COMPUTER PROJECT 70


Output:

ARUNAV RAY ISC COMPUTER PROJECT 71


PROGRAM 28: TO INCERT AND DELETE ELEMENTS IN DEQUEUE

Algorithm
STEP 1 : START
STEP 2 : [Check for the underflow]
if(front=NULL and rear=NULL)
Display(“Queue Underflow”)
STEP 3 : [Delete an element at the front end]
Display(“Deleted-”, ar[front])
if(front =rear)
front=NULL and rear= NULL
else
front++
STEP 4 : [Delete an element at the rear end]
Display(“Deleted-”, ar[rear])
if(front =rear)
front=NULL and rear= NULL
else
rear--
STEP 5 : [Set the pointer if Underflow]
if(front =NULL and rear= NULL)
front=0 and rear=0
[insert the first element]
ar[front]=n
STEP 6 : [Insert the element in the Dqueue at rear end]
if(rear=size-1)
Display(“Queue overflow at rear end”)
else
rear++
ar[rear]=n
STEP 7 : [Insert the element in the Dqueue at front end]
if(front=0)
Display(“Queue overflow at front end”)
else
--front
ar[front]=n
STEP 8 : Display the elements form front to rear
STEP 9 : END

ARUNAV RAY ISC COMPUTER PROJECT 72


Program: TO INCERT AND DELETE ELEMENTS IN DEQUEUE

import java.util.*;
class DeQueue
{ int size=5,front=-1,rear=-1;
int ar[]= new int[size];
void front_delete()//delete element function
{ if(front==-1 && rear==-1)//checking if queue is empty
System.out.println("Queue Underflow");
else
{ System.out.println("\nDeleted- |"+ar[front]+"| ");
if(front==rear)
front=rear=-1;
else
front++; }}
void rear_delete()//delete element function
{ if(front==-1 && rear==-1)//checking if queue is empty
System.out.println("Queue Underflow");
else
{ System.out.println("\nDeleted- |"+ar[rear]+"| ");
if(front==rear)
front=rear=-1;
else
rear--; }}
void rear_insert(int n)//insert element function
{ if(rear==size-1)
System.out.println("Queue overflow at rear end");
else
{ if(front==-1 && rear==-1)
front=rear=0;
else
rear++;
ar[rear]=n; }}
void front_insert(int n)//insert element function
{ if(front==0)
System.out.println("Queue overflow at front end");
else
{ if(front==-1 && rear==-1)
front=rear=0;
else
--front;
ar[front]=n; }}
void display()//display queue function
{ if(front==-1&&rear==-1)
System.out.println("Dequeue empty");
else
{
for(int i=front;i<=rear;i++)
System.out.print("|"+ar[i]+"| "); }}}

ARUNAV RAY ISC COMPUTER PROJECT 73


Variable description:

Sl. no Variable Name Datatype Purpose

1 front int Queue pointer

2 rear int Queue pointer

3 size int Store Value

4 ar[] int Store Values

5 n int Accepting value

6 i int Counter

Output:
 Entering values in rear 5,4,3,2 & calling display function
 Removing value from front (5) & calling display function
 Entering value at front (6) & calling display function
 Removing value from rear(2) & calling display function

ARUNAV RAY ISC COMPUTER PROJECT 74


PROGRAM 29: SORT 2 ARRAYS USING INSERTION SORT.

Algorithm
Step 1- START
Step 2- store a highly negative number in the initial cell
Step 3-Sort the elements. Repeat Step 6 for (i=1,2,3…….n)
Step 4- initialize temporary variables
Step 5- Compare the elements backwards.
Step 6- insert the element entered by the user
Step 7- END.

Variable description:

Sl. no Variable Name Datatype Purpose

1 l1 int Store size of array

2 a int[] Store elements

3 i Int Counter

4 temp,ptr int For Calculation

ARUNAV RAY ISC COMPUTER PROJECT 75


Program: SORT 2 ARRAYS USING INSERTION SORT.

import java.util.*;
class Insertion_sort
{ static void main()//main function
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array");
int l1=sc.nextInt(),temp=0,ptr=0;
int a[]=new int[l1+1];//declaring array
a[0]=-999;//Highly negative number in initial cell
System.out.println("Enter array elements");
for(int i=1;i<=l1;i++)//accepting array
a[i]=sc.nextInt();
//sorting of array
for(int i=1;i<=l1;i++)
{
temp=a[i];
ptr=i-1;
while(a[ptr]>temp)
{
a[ptr+1]=a[ptr];
ptr--;
}
a[ptr+1]=temp;
}
for(int i=1;i<=l1;i++)//displaying array
System.out.print(a[i]+" ");
}
}

Output:

ARUNAV RAY ISC COMPUTER PROJECT 76


PROGRAM 30: DISPLAY THE CALENDAR OF A MONTH
BY ACCEPTING THE FIRST DAY OF THE MONTH.

Algorithm

STEP 1: START
STEP 2: Declare an array to store the names of the month, days, dates and calendar
respectively
STEP 3: Accept year, month and days
STEP 4: if leap year adjust the days of February
STEP 5: Find the day and month entered by the user to make the calendar
STEP 6: for i=0 to 4,
STEP 7: for j=0 to 6,
STEP 8: Enter the date in a[i,j]
STEP 9: if the date entered reached the number of days in a month, r=1 and goto
STEP 11 otherwise increase date by 1 and goto step 7 with j=j+1
STEP 10: if dates cannot be added further i=-1 and goto step 6 with i=i+1
STEP 11: Display the array a
STEP 12: END

ARUNAV RAY ISC COMPUTER PROJECT 77


Program: DISPLAY THE CALENDAR OF A MONTH
BY ACCEPTING THE FIRST DAY OF THE MONTH.

import java.util.*;
class Calendar_Print
{
static void main()
{
String
days[]={"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRID
AY","SATURDAY"};
String
months[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JUL
Y","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER",};
int dates[]={31,28,31,30,31,30,31,31,30,31,30,31};
int a[][]= new int[5][7];
Scanner sc = new Scanner(System.in);
System.out.println("Enter the year,month and the first
day of the month");
int y=sc.nextInt();//accepting year
String m= sc.next(),d=sc.next();//accepting month and
1st day
if(y%4==0)//checking for leap year
dates[1]++;
int c=0,r=0,s=0,date=1;
for(int i=0;i<12;i++)
{
if(m.equalsIgnoreCase(months[i]))//finding the month
entered
s=i;
}
for(int i=0;i<7;i++)
{
if(d.equalsIgnoreCase(days[i]))//finding the day
entered
c=i;
}
for(int i=0;i<5;i++)
{
int p=0;
for(int j=c;j<7;j++)
{
a[i][j]=date;
if(date<dates[s])//finding if more dates to
enter
{
p++;
date++;

ARUNAV RAY ISC COMPUTER PROJECT 78


}
else//calender full
{ r++;
break;
}
}
c=0;
if(i==4 && p==7 && r==0)//if last row is reached but
more dates to display
i=-1;
if(r==1)//calender full
break;
}
//displaying calender
System.out.println("\t\t\t"+m+" "+y);
for(int i=0;i<7;i++)
System.out.print(days[i]+" ");
System.out.println();
for(int i=0;i<5;i++)
{
for(int j=0;j<7;j++)
{
c=a[i][j];
if(c!=0)
System.out.print(" "+c+"\t");
else
System.out.print(" \t");
}
System.out.println();
}
}
}

ARUNAV RAY ISC COMPUTER PROJECT 79


Variable description:

Sl. no Variable Name Datatype Purpose

1 days String[] Store name of days

2 months String[] Store name of months

3 dates int[] Store number of days

4 a int[][] Store the calendar

5 y int Accept the year

6 m String Accept the month

7 d String Accepts the first day of the month

8 c,r,s,p int For calculation

9 date,i,j int Counter

Output:

ARUNAV RAY ISC COMPUTER PROJECT 80

Das könnte Ihnen auch gefallen