ISC Computer Science Project 1-10 S

Embed Size (px)

DESCRIPTION

ISC Computer Science Project 1-10 S

Citation preview

Page | 67

ABSTRACT:This is a compilation of the programming assignments done as a part of the essential programming practical work of the Indian School Certificate Examination Computer Science curriculum. Most of the assignments have been taken from the actual previous year Computer Science practical papers and specimen paper of the Council for the Indian School Certificate along with a few important programming assignments for practice. All the programming assignments were written inJava [Java Platform, Standard Edition 8] and compiled on BlueJ IDE. The algorithms for the programming assignments are not written in pseudo code, but in steps which are simple enough to be obviously computable. Each program source code has been written carefully so that it follows the algorithm and is logically and syntactically correct. The source codes are well documented using mnemonic names and comments, identifying and clearly describing the choice of data types and meaning of variables. The comments itself give a brief explanation of the logic used. The programming assignments were test run using the given sample inputs. The outputs thus obtained and the source codes were copied from the terminal window and editor of the BlueJ IDE respectively to Microsoft Office Word and a printout was taken.The common input technique used in all the assignments is Scanner class of java.util package and the output technique is PrintWriter class of java.io package. Since the StringTokenizer class of java.util package is a legacy class and its use is discouraged in new code1, the split() of String class of java.lang package is used to parse Strings into tokens. Wherever the need for the use of sorting is required, the Bubble sort algorithm has been used as it is a simple and easy to understand sorting algorithm. Various classes of the Java API like StringBuffer, Character, etc. have been extensively used for concise and efficient source code.

1 - http://docs.oracle.com/javase/8/docs/api/index.html (Refer to java.utilStringTokenizer)

SUMMARY OF PROGRAMMING ASSIGNMENTS:

PROGRAMMINGASSIGNMENT NO:OBJECTIVE OF PROGRAM:PAGENO:

1To arrange the words of a sentence in descending order of their lengths5

2To check whether a grid of numbers input by the user represents a Wondrous Square or not10

3To generate Anagrams of a word22

4To display the consecutive number combination(s) of a positive natural number28

5To merge two arrays in such a way that the resulting array is alphabetically arranged and to sort the two input arrays33

6To validate a Copyright Protection code according to given instructions40

7To display the day name of a date48

8To display the words of a paragraph of text in reverse order53

9To display Unique-Digit integers along with its frequency58

10To check whether a number is a Smith number or not64

11To display the number of words and vowels present in each sentence in a paragraph70

12To find and display the largest and second largest element of a matrix along with their row and column positions & to sort and display the elements of the rows in ascending order76

13To display the date corresponding to the number of a day in a year83

14To sort the elements of the outer row and column of a matrix in ascending order and to print their sum90

15To arrange the words of a sentence in ascending order of their lengths98

16To display the denominations of an amount103

17To display Kaprekar numbers along with its frequency109

18To display the words of a sentence in ascending order of their frequencies115

19To display a number in words123

20To encrypt the sentences in a paragraph according to given instructions128

21To validate a date134

22To display Prime Palindrome integers along with its frequency139

23To print a sentence in alphabetical order of its words145

24To find and display the largest and smallest element of a matrix along with their row and column positions & to sort and display the elements of the matrix in ascending order150

25To validate an ISBN code159

26To display the mirror image of a matrix166

27To display the Palindromic words present in a sentence along with its frequency172

28To display Composite Magic numbers along with its frequency177

29To check whether a matrix is symmetric or not184

30To delete words in a sentence192

31To generate a Spiral matrix197

32To sort and display the words of each sentence in a paragraph alphabetically and display the words which begin with a vowel203

33To display Lucky numbers along with its frequency210

34To frame a word by combining the first letter of each word in a sentence and to sort the new word and eliminate duplicate characters215

35To validate an IMEI number221

PROGRAMMING ASSIGNMENT 1

Write a program which receives a sentence (maximum 80 characters) terminated by a full stop. The words in this sentence are assumed to be separated by one or more whitespaces.Arrange the words of the input sentence in descending order of their lengths. Same length words should be sorted alphabetically. Each word must start with an uppercase letter and the sentence should be terminated by a full stop.Test you program for the following data and some random data.Sample Data: Input 1:This is human resource department.Output 1: Department Resource Human This Is.Input 2:To handle yourself use your head and to handle others use your heart.Output 2: Yourself Handle Handle Others Heart Head Your Your And Use Use To To.[ISC Computer Science Paper-II (Practical) 2005]

Algorithm:Step 1: Start.Step 2: Accept a sentence.Step 3: Divide the sentence into words and store them in an array.Step 4: Sort the array in descending order using Bubble Sort algorithm by comparing the length of the words contained in the array cells. If the length is equal, the words are compared lexicographically and sorted alphabetically.Step 5: Display the array elements in a single line capitalizing the first letter and terminating with a period.Step 6: Stop.

Source Code:import java.util.Scanner;import java.io.PrintWriter;class PracticalAssignment1{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out,true); String s,t,word[]; int i,j,n; pw.println("Please enter a sentence."); //Prompting the user s=sc.nextLine(); //Accepting the input sentence word=s.split("[. ]"); //Parsing the String (sentence) into tokens (words) and storing in an array n=word.length; //Finding the number of words /*Arranging the words contained in the sentence according to the length of the words in descending order by comparing lengths and using Bubble Sort algorithm. If two words are of the same length, the words are placed in alphabetical order by comparing them in lexicographically.*/ for(i=0;i