8/20/2019 Project for class 11 ISC
1/36
COMPUTER S CIENCE A SSIGNMENT
1
QUESTION 1
Design a programme to accept a day number (between 1 and 366), year (in 4 digit) from the user togenerate and display the corresponding date. Also accept 'N' (1
8/20/2019 Project for class 11 ISC
2/36
COMPUTER S CIENCE A SSIGNMENT
2
2
ALGORITHM
Algorithm for main() method
1. Start2. Take day as input from console and store it in int variable d13. Take year as input from console and store it in int variable y14. Take N as input from console and store it in int variable n5. Call the function Date as: obj.Date(d1,y1)6. Check if n>=1 and na[i]7. Assign d=d − a[i]8. Increase value of i by 19. Assign j=i10. Repeat step 11 for i=0 till i
8/20/2019 Project for class 11 ISC
3/36
COMPUTER S CIENCE A SSIGNMENT
3
3
SOURCE CODE
import java.io.*;class QUESTION1{
void DATE(int d,int y){
int a[]={31,28,31,30,31,30,31,31,30,31,30,31};if((y%400==0) || (Y%4==0) && (Y%100!=0))a[1]=29;String m[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE",
"JULY","AUGUST","SEPTEMBER","OCTEBER","NOVEMBER","DECEMBER"};int i=0,j=0;String month="";while(d>a[i])
{d=d-a[i];i++;
j=i;}for(i=0;i=1 && n366){
y1+=1;d1-=366;
8/20/2019 Project for class 11 ISC
4/36
COMPUTER S CIENCE A SSIGNMENT
4
4
System.out.print("DATE AFTER "+n+" DAYS ");obj.DATE(d1,y1);
}else if(y1%4!=0 && Y1%400!=0 && d1>365){
y1+=1;d1-=365;System.out.print("DATE AFTER "+n+" DAYS ");obj.DATE(d1,y1);
}else{
System.out.print("DATE AFTER "+n+" DAYS ");obj.DATE(d1,y1);
}
}elseSystem.out.println("OUT OF RANGE");
}}
8/20/2019 Project for class 11 ISC
5/36
COMPUTER S CIENCE A SSIGNMENT
5
5
DATA VARIABLE DESCRIPTION
NAME DATA TYPE DESCRIPTIONd int As an argument for the function Date()y Int As an argument for the function Date()
a[] int array An array to store the number of days of the months of a yearm[] String array An array to store the name of the months of a year
i int To run a loop j int To store the month numberd1 int To store the inputted day numbery1 Int To store the inputted yearn int To store the inputted N
8/20/2019 Project for class 11 ISC
6/36
COMPUTER S CIENCE A SSIGNMENT
6
6
OUTPUT IN THE TERMINAL WINDOW
8/20/2019 Project for class 11 ISC
7/36
COMPUTER S CIENCE A SSIGNMENT
7
7
QUESTION 2
Write a programme to declare a matrix A[][] of order (m X n) where m is the number of rows and n isthe number of columns such that both m and n must be greater than 2 and less than 20. Allow theuser to input positive integer into these matrix. Perform the following tasks on the matrix:
(a)
Sort the elements of the outer row and column in ascending order using any standard sortingtechnique and arrange them in array.(b) Calculate the sum of the outer row and column elements.(c) Output the original matrix and the rearranged matrix.
Example:Input-m=3n=3Original matrix: 1 7 4
8 2 56 3 9
Rearranged matrix: 1 3 49 2 58 7 6
Sum=43
8/20/2019 Project for class 11 ISC
8/36
COMPUTER S CIENCE A SSIGNMENT
8
8
ALGORITHM
1. Start2. Initialise an int variable m with inputted number of rows3. Initialise an int variable n with inputted number of columns
4.
If m=20 or n=20 then print "OUT OF RANGE" and exit from program5. Declare an int array A[][] with dimensions (m X n) as A[][]=new int[m][n]6. Initialise two int variable i=0 and j=07. Repeat steps 7 to 10 till i
8/20/2019 Project for class 11 ISC
9/36
COMPUTER S CIENCE A SSIGNMENT
9
9
Assign t=e[j]Assign e[j]=e[j+1]Assign e[j+1]=t
45. Increase value of j by 146. Increase value of I by 147. Initialise int variable sum=048. Repeat steps 49 and 50 from i=0 till i
8/20/2019 Project for class 11 ISC
10/36
COMPUTER S CIENCE A SSIGNMENT
10
SOURCE CODE
import java.io.*;class QUESTION2{
public static void main(String args[])throws IOException{int m, n, i, j;BufferedReader br=new BufferedReader(new InputStreamReader(System.in));System.out.print("Enter m: ");m=Integer.parseInt(br.readLine());System.out.print("Enter n: ");n=Integer.parseInt(br.readLine());if(m=20 || n=20){
System.out.println("OUT OF RANGE");System.exit(0);
}int A[][]=new int[m][n];for(i=0;i
8/20/2019 Project for class 11 ISC
11/36
COMPUTER S CIENCE A SSIGNMENT
11
for(j=0;j
8/20/2019 Project for class 11 ISC
12/36
COMPUTER S CIENCE A SSIGNMENT
12
2
}i=m-1;for(j=n-2;j>=0;j--){
A[i][j]=e[k];
k++;}
j=0;for(i=m-2;i>0;i--){
A[i][j]=e[k];k++;
}System.out.println("\n");System.out.println("REARRANGED MATRIX");
for(i=0;i
8/20/2019 Project for class 11 ISC
13/36
COMPUTER S CIENCE A SSIGNMENT
13
3
DATA VARIABLE DESCRIPTION TABLE
NAME DATA TYPE DESCRIPTIONm int To store the number of rowsn int To store the number of columnsi int To run loops
j int To run loopsA[][] int array To store the elements inputted by userno int To store the number of boundary elementse[] int array To store the boundary elementsk int To store the number of boundary elementst int To use as a temporary variable during sorting
sum int To store the sum of the boundary element
8/20/2019 Project for class 11 ISC
14/36
COMPUTER S CIENCE A SSIGNMENT
14
4
OUTPUT IN THE TERMINAL WINDOW
8/20/2019 Project for class 11 ISC
15/36
COMPUTER S CIENCE A SSIGNMENT
15
5
QUESTION 3
Read a single sentence which terminates with a full stop (.). The words are to be separated with asingle blank space and are in lower case. Arrange the words contained in the sentence according tothe length of the words in ascending order. If two words are of same length then the word occurring
first in the input sentence should come first. For both input and output, the sentence must begin inupper case.
Test your programme for following data and some random data.
Input 1: The lines are printed in reverse order.Output 1: In the are lines order printed reverse.
Input 2: Print the sentence in ascending order.Output 2: In the print order sentence ascending.
Input 3: I love my country.Output 3: I my love country.
8/20/2019 Project for class 11 ISC
16/36
COMPUTER S CIENCE A SSIGNMENT
16
6
ALGORITHM
1. Start2. Take input from console3. Convert it into lower case
4.
Eliminate last character of the inputted string5. Split the string using split() function and store it in a String array a[]6. Initialise int l with the size of a[] as l=a.length7. Declare String variable temp, int variable i and j8. Repeat steps 9 to 12 from i=0 till i
8/20/2019 Project for class 11 ISC
17/36
COMPUTER S CIENCE A SSIGNMENT
17
7
SOURCE CODE
import java.io.*;class QUESTION3{
public static void main()throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));System.out.println("Enter a sentence:");String s1=(br.readLine()).toLowerCase();s1=s1.substring(0,s1.length()-1);String a[]=s1.split(" ");int l=a.length;String temp;int i,j;for(i=0;i
8/20/2019 Project for class 11 ISC
18/36
COMPUTER S CIENCE A SSIGNMENT
18
8
DATA VARIABLE DESCRIPTION TABLE
NAME DATA TYPE DESCRIPTIONs1 String To store the inputted string
a[] String array To store the words of the stringl int To store the number of wordstemp int Temporary variable to be used during sorting
i int To run a loop j int To run a loop
8/20/2019 Project for class 11 ISC
19/36
COMPUTER S CIENCE A SSIGNMENT
19
9
OUTPUT IN THE TERMINAL WINDOW
8/20/2019 Project for class 11 ISC
20/36
COMPUTER S CIENCE A SSIGNMENT
20
2
QUESTION 4
A bank intends to design a program to display the denomination of an input amount, up to 5 digits.The available denomination with the bank are of rupees 1000, 500, 100, 50, 20, 10, 5, 2 and 1.
Design a program to accept the amount from the user and display the break-up in descending order
of denomination, (i.e., preference should be given to the highest denomination available) along withthe total number of notes. [Note: Only the denomination used should be displayed]. Also print theamount in words according to the digits.
Example 1:INPUT- 14856OUTPUT-ONE FOUR EIGHT FIVE SIXDENOMINATORS:1000X14=14000500X1=500100X3=30050X1=505X1=51X1=1TOTAL NUMBER OF NOTES: 21
Example 2:INPUT- 6043OUTPUT-SIX ZERO FOUR THREEDENOMINATORS:1000X6=600020X2=402X1=21X1=1TOTAL NUMBER OF NOTES: 10
Example 3:INPUT- 235001OUTPUT-Input out of range.
8/20/2019 Project for class 11 ISC
21/36
COMPUTER S CIENCE A SSIGNMENT
21
2
ALGORITHM
1. Start2. Take input from console and store it in int variable amount3. Check if amount>99999, if yes then
Print "INVALID AMOUNT"Exit from program4. Initialise int amt=amount, rev=05. Repeat steps 6 to 8 from i=0 till i
8/20/2019 Project for class 11 ISC
22/36
COMPUTER S CIENCE A SSIGNMENT
22
22
SOURCE CODE
import java.io.*;class QESTION4{
public static void main()throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));int rev=0, amount, amt;System.out.print("Enter the amount:");String a=br.readLine();amount=Integer.parseInt(a);if(amount>99999){
System.out.println("INVALID AMOUNT");System.exit(0);
}amt=amount;for(int i=0;i
8/20/2019 Project for class 11 ISC
23/36
COMPUTER S CIENCE A SSIGNMENT
23
23
case '8':System.out.print("EIGHT");break;case '9':System.out.print("NINE");
}System.out.print(" ");
}int den[]={1000,500,100,50,20,10,5,2,1};int i=0,tot=0;System.out.println();System.out.println("\nDENOMINATION:\n");while(amount!=0){
rev=amount/den[i];
if(rev!=0){
System.out.print("\t\t"+den[i]+"\tX\t"+rev+"\t=\t"+rev*den[i]);System.out.println();tot+=rev;
}amount=amount%den[i];i++;
}System.out.println("\t\tTOTAL\t\t\t=\t"+a);
System.out.println();System.out.println("TOTAL NUMBER OF NOTES\t=\t"+tot);}
}
8/20/2019 Project for class 11 ISC
24/36
COMPUTER S CIENCE A SSIGNMENT
24
24
DATA VARIABLE DESCRIPTION TABLE
NAME DATA TYPE DESCRIPTIONrev int To store the number of notes of a particular denomination
amount int To store the inputted amountamt int Dummy variable
a String To store the inputted amountch char To store the extracted digits of the inputted amount
den[] int array To store the available denominationsi int To run a loop
tot int To store the total number of notes
8/20/2019 Project for class 11 ISC
25/36
COMPUTER S CIENCE A SSIGNMENT
25
25
OUTPUT IN THE TERMINAL WINDOW
8/20/2019 Project for class 11 ISC
26/36
COMPUTER S CIENCE A SSIGNMENT
26
26
QUESTION 5
A positive whole number 'n' having 'd' number of digits is squared and split into two pieces, a right-hand piece that has 'd' digits and a left-hand piece that has remaining 'd' or 'd-1' digits. If the sum ofthe two pieces is equal to the number, then 'n' is a Kaprekar number. The first few Kaprekar numbers
are: 9, 45, 297 . . . . . . . . .Example 1:992=81, right-hand piece of 81=1 and left-hand piece of 81=8Sum=1+8=9, i.e. equal to the number.
Example 2:4545 2=2025, right-hand piece of 2025=25 and left-hand piece of 2025=20Sum=25+20=45, i.e. equal to the number.
Example 3:297297 2=88209, right-hand piece of 88209=209 and left-hand piece of 88209=88Sum=209+88=297, i.e. equal to the number.
Given two positive integers p and q, where p
8/20/2019 Project for class 11 ISC
27/36
COMPUTER S CIENCE A SSIGNMENT
27
27
Algorithm
1. Start2. Take p as input from console and store bit in int variable p3. Take q as input from console and store bit in int variable q
4.
Initialise two int variable as i=0 and c=05. Check if p>5000 or q>5000 or p>q, if yes thenPrint "OUT OF RANGE"
ElseGoto step 6
6. Repeat steps 7 to 12 for i=p till i=q7. Assign int len with the length of i as len=(""+i).length()8. Assign long sq=i*i9. Assign long k=sq%(10^len)10. Assign long s=sq/(10^len)11. Assign long newn=k+s12. Check if newn=I, if yes then
Print iIncrease value of c by 1
13. Print c14. End
8/20/2019 Project for class 11 ISC
28/36
COMPUTER S CIENCE A SSIGNMENT
28
28
SOURCE CODE
import java.io.*;class QUESTION5{
public static void main()throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));System.out.print("p= ");int p=Integer.parseInt(br.readLine());System.out.print("q= ");int q=Integer.parseInt(br.readLine());int i=0,c=0;if(p>5000 || q>5000 || p>q)
System.out.println("OUT OF RANGE");else{
System.out.println("THE KAPREKAR NUMBERS ARE:-");for(i=p;i
8/20/2019 Project for class 11 ISC
29/36
COMPUTER S CIENCE A SSIGNMENT
29
29
DATA VARIABLE DESCRIPTION TABLE
NAME DATA TYPE DESCRIPTIONp int To store the lower limitq int To store the upper limiti int To run a loopc int Counter to count the number of Kaprekar numbers
len long To store the length of each numbersq long To store the square of each numberr long To store the right hand piece of the square of the numberl long To store the left hand piece of the square of the number
newn long To store the new number created by adding r and l
8/20/2019 Project for class 11 ISC
30/36
COMPUTER S CIENCE A SSIGNMENT
30
3
OUTPUT IN THE TERMINAL WINDOW
8/20/2019 Project for class 11 ISC
31/36
8/20/2019 Project for class 11 ISC
32/36
COMPUTER S CIENCE A SSIGNMENT
32
32
ALGORITHM
1. Start2. Take the number of sentences as input from console and store it in int variable n3. Check if n=4, if yes then
Print "Invalid entry"Exit from program4. Take the sentences as input from console and store it in a String variable s5. Convert s to UPPERCASE6. Initialize int i=0, j=0, t=07. Initialize String temp=""8. Replace full stop (.) and question mark (?) in the sentences with a blank space (" ")9. Split the words using split() function and store them in a String array a[]10. Find the number of words and store it in int l as :
l=a.length11. Declare an int array c[] of size l12. Print ("Total number of words: "+l)13. Repeat steps 14 to 18 from i=0 till i
8/20/2019 Project for class 11 ISC
33/36
COMPUTER S CIENCE A SSIGNMENT
33
33
SOURCE CODE
import java.io.*;class QUESTION6{
public static void main()throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));System.out.println("Enter number of sentences.");int n=Integer.parseInt(br.readLine());if(n=4){
System.out.println("Invalid entry");System.exit(0);
}else{
System.out.println("Enter the sentence(s).");String s=(br.readLine()).toUpperCase();int i=0,j=0,t;String temp;s=s.replace('.',' ');s=s.replace('?',' ');String a[]=s.split(" ");int l=a.length;int c[]=new int[l];System.out.println("\nTotal number of words: "+l);System.out.println("WORD"+"\t\t"+"FREQUENCY");for(i=0;i
8/20/2019 Project for class 11 ISC
34/36
COMPUTER S CIENCE A SSIGNMENT
34
34
{if(c[i]
8/20/2019 Project for class 11 ISC
35/36
COMPUTER S CIENCE A SSIGNMENT
35
35
DATA VARIABLE DESCRIPTION TABLE
NAME DATA TYPE DESCRIPTIONn int To store the number of sentencess String To store the sentencesi int To run a loop
j int To run a loopt int Temporary variable used during sorting
temp String Temporary variable used during sortinga[] String array Array to store the wordsl int To store the number of words
c[] int array Array to store the length of each word
8/20/2019 Project for class 11 ISC
36/36
COMPUTER S CIENCE A SSIGNMENT 36
OUTPUT IN THE TERMINAL WINDOW