Posts

Showing posts from June, 2022

Class 8 Algorithms and Flowcharts

Image
A Fill in the blanks with the correct words. 1. The start and stop symbols are oval in shape. 2. The parallelogram symbol is used for input/output in flowchart. 3. The decision symbol has two outputs for true and false conditions. 4. It is a good practice to write algorithm first and then write the code of a program. 5. A flowchart should flow from top to bottom and from left to right. B Write T for the true statement and F for the false one. Correct the false statement(s). 1. There can be more than one start symbol in a flowchart. ( F - because there can only be one start symbol in a flowchart ) 2. You cannot draw a flowchart in more than one page. ( F - because we can draw a flowchart in more than one page by using the off-page connectors ) 3. The arrow lines show the flow of steps. ( T ) 4. The order of instructions in an algorithm is not important. ( F - the order of instructions in an algorithm is important ) 5. You can use the parallelogram symbol for calculations in a flowc...

Singly Linked List Program in Java

What is a Linked List? A Linked List is a linear data structure. It is a collection of nodes such that each node points to the next node. The size of a linked list isn't fixed as the nodes can be added or removed as and when required. The nodes are created by allocating space from the heap memory, using the new keyword. A singly linked list is one in which each node is only capable to point to the next node. A doubly linked list is one in which each node is capable of pointing to the previous as well as the next node. Basic Operations in a Linked List (a) Insertion : We can insert a node in a linked list. A node can be inserted at the beginning, or at the end, or anywhere in-between the list. (b) Deletion : We can delete a node in a linked list. Firstly, we search for the node to be deleted. If found, the deletion takes place and the linked list is readjusted. If not found, then the deletion operation is cancelled. (c) Traversal : We can traverse a linked list, meaning that we can ...

Data Structures - Stacks and Queues in Python

Implementing Stack in Python using a List def push(stack, element):     stack.append(element)     top = len(stack) - 1 def pop(stack):     if stack == []:         return 'UNDERFLOW'     element = stack.pop()     if len(stack) == 0:         top = None     else:         top = len(stack) - 1     return element def peek(stack):     if stack == []:         return 'UNDERFLOW'     top = len(stack) - 1     return stack[top] def display(stack):     if stack == []:         print('STACK EMPTY')     else:         top = len(stack) - 1         print(str(stack[top]) + "<--top")         for i in range(top - 1, -1, -1):             print(stack[i]) stack = [] top = None while True:     p...

Sort Matrix ISC Computer Science 2021 Practical

Write a program to declare a matrix A[][] of order (M × N) 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 8. Allow the user to input integers into the matrix. Perform the following tasks on the matrix: (a) Sort the matrix elements in descending order using any standard sorting technique. (b) Calculate the sum of the boundary elements of the matrix before sorting and after sorting. (c) Display the original matrix and the sorted matrix along with the sum of their boundary elements respectively. Test your program for the following data and some random data: Example 1 INPUT: M = 3 N = 4 ENTER ELEMENTS OF MATRIX 11 2 -3 5 1 7 13 6 0 4 9 8 OUTPUT: ORIGINAL MATRIX 11 2 -3 5 1 7 13 6 0 4 9 8 SUM OF THE BOUNDARY ELEMENTS (UNSORTED) = 43 SORTED MATRIX 13 11 9 8 7 6 5 4 2 1 0 -3 SUM OF THE BOUNDARY ELEMENTS (SORTED) = 52 Example 2 INPUT: M = 3 N = 3 ENTER ELEMENTS OF MATRIX 6 2 5 14 1...

Common Words ISC Computer Science 2021 Practical

Write a program to accept a paragraph containing two sentences only. The sentences may be terminated by either '.', '?' or '!' only. Any other character may be ignored. The words are to be separated by a single blank space and must be in uppercase. Perform the following tasks: (a) Check for the validity of the accepted paragraph for the number of sentences and for the terminating character. (b) Separate the two sentences from the paragraph and find the common words in the two sentences with their frequency of occurrence in the paragraph. (c) Display both the sentences separately along with the common words and their frequency, in the format given below. Test your program for the following data and some random data: Example 1 : INPUT: IS IT RAINING? YOU MAY GET WET IF IT IS RAINING. OUTPUT: IS IT RAINING? YOU MAY GET WET IF IT IS RAINING. COMMON WORDS FREQUENCY IS 2 IT 2 RAINING 2 Example 2 : INPUT: INDIA IS MY MOTHERLAND AND I AM PROUD OF MY MOTH...

Fascinating Number ISC Computer Science 2021 Practical

A Fascinating number is one which when multiplied by 2 and 3 and then, after the results are concatenated with the original number, the new number contains all the digits from 1 to 9 exactly once. There can be any number of zeroes and are to be ignored. Example : 273 273 × 1 = 273 273  × 2 = 546 273  × 3 = 819 Concatenating the result we get, 273546819 which contains all digits from 1 to 9 exactly once. Thus, 273 is a Fascinating number. Accept two positive integers m and n, where m must be less than n and the values of both 'm' and 'n' must be greater than 99 and less than 10000 as user input. Display all fascinating numbers that are in the range between m and n (both inclusive) and output them along with the frequency, in the format given below: Example 1 : INPUT: m = 100 n = 500 OUTPUT: THE FASCINATING NUMBERS ARE: 192 219 273 327 FREQUENCY OF FASCINATING NUMBERS IS: 4 Example 2 : INPUT: m = 900 n = 5000 OUTPUT: THE FASCINATING NUMBERS ARE: 1902 1920 2019 2190 2703 ...

Banner Program ISC Computer Science 2018 Practical

The names of the teams participating in a competition should be displayed on a banner vertically, to accommodate as many teams as possible in a single banner. Design a program to accept the names of N teams, where 2 < N < 9 and display them in vertical order, side by side with a horizontal tab (i.e. eight spaces). Test your program for the following data and some random data: Example 1: INPUT: N = 3 Team 1: Emus Team 2: Road Rols Team 3: Coyote OUTPUT: E R C m o o u a y s d o t R e o l s Example 2: INPUT: N = 4 Team 1: Royal Team 2: Mars Team 3: De Rose Team 4: Kings OUTPUT: R M D K o a e i y r n a r R g l s o s s e Example 3: INPUT: N = 10 OUTPUT: INVALID INPUT import java.util.Scanner; class Banner{     public static void main(String[] arg...

Recursion in Python

Recursion is an approach to solve a problem which involves a function calling itself either directly or indirectly. Such a function is known as a recursive function. Every recursive method must have a base case which would stop calling the function again and again indefinitely, because the function stack has a limit, which is platform dependent. A Python program to print a string backwards using a recursive function. def reverse(s, n):     if n > 0:         print(s[n], end = '')         reverse(s, n - 1)     elif n == 0:         print(s[0]) s = input('Enter the string: ') reverse(s, len(s) - 1) A Python program to calculate a b using a recursive function. def power(a, b):     if b == 0:         return 1     else:         return a * power(a, b - 1) a = int(input('a = ')) b = int(input('b = ')) p = power(a, b) print('a to the power b: ' + str(p)...

Capital Word ISC Computer Science 2018 Theory

A class Capital has been defined to check whether a sentence has words beginning with a capital letter or not. Some of the members of the class are given below: Class name : Capital Data members/instance variables : sent: to store a sentence freq: stores the frequency of words beginning with a capital letter Member functions/methods : Capital(): default constructor void input(): to accept the sentence boolean isCap(String w): checks and returns true if word begins with a capital letter, otherwise returns false void display(): displays the sentence along with the frequency of the words beginning with a capital letter Specify the class Capital, giving details of the constructor, void input(), boolean isCap(String) and void display(). Define the main() function to create an object and call the functions accordingly to enable the task. import java.util.Scanner; import java.util.StringTokenizer; class Capital{     String sent;     int freq;     public Capital(...

Equal Matrix ISC Computer Science 2018 Theory

Two matrices are said to be equal if they have the same dimension and their corresponding elements are equal. For example the two matrices A and B given below are equal: Matrix A 1 2 3 2 4 5 3 5 6 Matrix B 1 2 3 2 4 5 3 5 6 Design a class EqMat to check if two matrices are equal or not. Assume that the two matrices have the same dimension. Some of the members of the class are given below: Class name : EqMat Data members/instance variables : a[][]: to store integer elements m: to store the number of rows n: to store the number of columns Member functions/methods : EqMat(int mm, int nn): parameterized constructor to initialize the data members m = mm and n = nn void readArray(): to enter elements in the array int check(EqMat p, EqMat q): checks if the parameterized objects p and q are equal and returns 1 if true, otherwise returns 0 void print(): displays the array elements Define the class EqMat giving details of the constructor, void readArray(), int check(EqMat, EqMat) and void print(...

Convert to Palindrome ISC Computer Science 2019 Practical

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 and are in uppercase. Perform the following tasks: (a) Check for the validity of the accepted sentence. (b) Convert the non-palindrome words of the sentence into palindrome words by concatenating the word by its reverse (excluding the last character). Example: The reverse of the word HELP would be LEH (omitting the last alphabet) and by concatenating both, the new palindrome word is HELPLEH. Thus, the word HELP becomes HELPLEH. Note: The words which end with repeated alphabets, for example ABB would become ABBA and not ABBBA and XAZZZ becomes XAZZZAX. Palindrome words: Spells same from either side. Example: DAD, MADAM, etc. (c) Display the original sentence along with the converted sentence. Test your program for the following data and some random data: Example 1 : INPUT: THE BIRD IS FLYING. OUTPUT: THE BIRD IS FLYING...

Fill Matrix ISC Computer Science 2019 Practical

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: (a) Sort the elements of the single dimensional array in ascending order using any standard sorting technique and display the sorted elements. (b) 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: 1 2 5 8 1 2 5 1 1 2 1 2 1 1 2 5 (c) Display the filled matrix in the above 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 1 3 7 1 3 1 1 1 3 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 ARR...

Date Program ISC Computer Science 2019 Practical

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 an 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 with 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 Example 4 : INPUT: DAY NUMBER: 150 YEAR: 2018 DATE AFTER (N DAYS): 330 OUTPUT: DATE AFTER (N DAYS) OUT OF RAN...