Professional Documents
Culture Documents
Isc Computer Project
Isc Computer Project
18. TO CALCULATE SUM OF TWO ANGLE USING OBJECT PASSING AND 36-37
OBJECT RETURNING TECHNIQUE
CONTENTS (cont...)
30. DISPLAY THE CALENDAR OF A MONTH BY ACCEPTING THE FIRST DAY OF THE 73-76
MONTH.
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();
}}}
VARIABLE LISTING
Output:
Variable description:
Output:
Variable description:
Output:
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
Variable description:
Output:
*****************
Program: Magic number using recursion
Variable description:
Output:
Output:
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);
*****************
Output:
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
*****************
Output:
*****************
Output:
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
*****************
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
Output:
Output:
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
*****************
Output:
*****************
Variable description:
*****************
Program: Delete Multiple Character from a Sentence
Output
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
32
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);
}
}
}
Output:
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
Variable description:
Output:
ARUNAV RAY ISC COMPUTER PROJECT
36
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)
Algorithm
STEP 1: Start
STEP 2: void inputangle()
Initialization of data members deg and min
Variable description:
Output:
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
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;
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();
}}
Variable description:
Output:
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
Variable description:
Output:
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
{ 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)
Variable description:
Output:
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
Program: TO CALCULATE TELEPHONE BILL USING CONCEPT OF
INHERITANCE
import java.io.*; class
Detail //superclass
{
String name,
address; long telno;
double rent;
Variable description:
Output:
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.
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
{ super.display(
);
System.out.println("The length of the radius = "+r+" units");
}}
Variable description:
Output:
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
3 i int Counter
Output:
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
ARUNAV RAY ISC COMPUTER PROJECT
57
STEP 15 : END
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);
}
{ ptr1=ptr;
ptr=ptr.link;
c++;
}
ptr1.link=ptr.link;
ptr.link=null;
ptr=ptr1=null;
}
}//end of class
Variable description:
Sl. no Variable Name Datatype Purpose
3 i int Counter
7 s int checker
Output:
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:
Algorithm
STEP 1 : START
Variable description:
1 c int Counter
2 s String Accepting value
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();
}
}
Output:
ARUNAV RAY ISC COMPUTER PROJECT 65
28:
PROGRAM TO INCERT AND DELETE ELEMENTS IN DEQUEUE
ARUNAV RAY ISC COMPUTER PROJECT 66
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
Variable description:
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
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
Variable description:
3 i Int Counter
{ 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:
Algorithm
STEP 1: START
{ Stri
ng
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
ARUNAV RAY ISC COMPUTER PROJECT 72
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++; }
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");
}
ARUNAV RAY ISC COMPUTER PROJECT 73
System.out.println();
}
} }
Variable description:
Output: