Posts

Showing posts from June, 2022

Frequency Program ISC Computer Science 2011 Theory

Input a sentence from the user and count the number of times the words "an" and "and" are present in the sentence. Design a class Frequency using the description below: Class name : Frequency Data members/variables : text: stores the sentence countAnd: to store the frequency of the word "and" countAn: to store the frequency of the word "an" len: stores the length of the string Member functions/methods : Frequency(): constructor to initialize the instance variables void accept(String n): to assign n to text, where the value of the parameter n should be in lowercase. void checkAndFreq(): to count the frequency of "and" void checkAnFreq(): to count the frequency of "an" void display(): to display the number of "and" and "an" with appropriate messages. Specify the class Frequency giving details of the constructor, void accept(String), void checkAndFreq(), void checkAnFreq() and void display(). Also define the

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

Maximum and Minimum Value in Matrix ISC Computer Science 2012 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 20. Allow the user to input integers into this matrix. Perform the following tasks on the matrix: (a) Display the input matrix. (b) Find the maximum and minimum value in the matrix and display them along with their position. (c) Sort the elements of the matrix in ascending order using any standard sorting technique and rearrange them in the matrix. (d) Output the rearranged matrix. Test your program with the sample data and some random data: Example 1 INPUT: M = 3 N = 4 8 7 9 3 -2 0 4 5 1 3 6 -4 OUTPUT: ORIGINAL MATRIX 8 7 9 3 -2 0 4 5 1 3 6 -4 LARGEST NUMBER: 9 ROW = 0 COLUMN = 2 SMALLEST NUMBER: -4 ROW = 2 COLUMN = 3 REARRANGED MATRIX -4 -2 0 1 3 3 4 5 6 7 8 9 Example 2 INPUT: M = 3 N = 22 OUTPUT: SIZE OUT OF RANGE import java.util.Scanner; class Matrix{     public static void main(Strin

Arrange Words ISC Computer Science 2012 Practical

Write a program to accept a sentence as input. The words in the string are to be separated by a blank. Each word must be in uppercase. The sentence is terminated by either ".", "!" or "?". Perform the following tasks: (a) Obtain the length of the sentence (measured in words) (b) Arrange the sentence in alphabetical order of the words. Test your program with the sample data and some random data: Example 1 INPUT: NECESSITY IS THE MOTHER OF INVENTION. OUTPUT: LENGTH: 6 REARRANGED SENTENCE: INVENTION IS MOTHER NECESSITY OF THE Example 2 INPUT: BE GOOD TO OTHERS. OUTPUT: LENGTH: 4 REARRANGED SENTENCE BE GOOD OTHERS TO import java.util.Scanner; class Arrange{     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         System.out.print("Enter the sentence: ");         String s = in.nextLine().toUpperCase();         char last = s.charAt(s.length() - 1);         if(".?!".indexOf(last) == -1){             Sys

Prime Palindrome ISC Computer Science 2012 Practical

A prime palindrome integer is a positive integer (without leading zeros) which is prime as well as a palindrome. Given two integers m and n, where m < n, write a program to determine how many prime-palindrome integers are there in the range between m and n (both inclusive) and output them. The input contains two positive integers m and n where m < 3000 and n < 3000. Display the number of prime-palindrome integers in the specified range along with their values in the format specified below: Test your program with the sample data and some random data: Example 1 INPUT: m = 100 N = 1000 OUTPUT: THE PRIME PALINDROME NUMBERS ARE: 101, 131, 151, 181, 191, 313, 353, 373, 383, 727, 757, 787, 797, 919, 929 FREQUENCY OF PRIME PALINDROME INTEGERS: 15 Example 2 INPUT: m = 100 n = 5000 OUTPUT: OUT OF RANGE import java.util.Scanner; class PrimePalindrome{     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         System.out.print("m = ");    

Detail Inheritance ISC Computer Science 2012 Theory

A super class Detail has been defined to store the details of a customer. Define a sub class 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 paise per call + rental charge 201 - 300 80 paise 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 details 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

Link Queue ISC Computer Science 2012 Theory

Link is an entity which can hold a maximum of 100 integers. Link enables the user to add elements from the rear end and remove integers from the front end of the entity. Define a class Link with the following details: Class name : Link Data members/instance variables : lnk[]: entity to hold the integer elements max: stores the maximum capacity of the entity begin: to point to the index of the front end end: to point to the index of the rear end Member functions : Link(int m): constructor to initialize max = m, begin = 0, end = 0 void addLink(int v): to add an element from the rear index if possible otherwise display the message "OUT OF SIZE" int delLink(): to remove and return an element from the front index, if possible otherwise display the message "EMPTY" and return -99 void display(): displays the elements of the entity (a) Specify the class Link giving details of the constructor, void addLink(int), int delLink() and void display(). The main() function and algo

Vowel Word ISC Computer Science 2012 Theory

Design a class VowelWord to accept a sentence and calculate the frequency of words that begin with a vowel. The words in the input string are separated by a single blank space and terminated by a full stop. The description of the class is given below: Class name : VowelWord Data members/instance variables : str: to store a sentence freq: store the frequency of the words beginning with a vowel Member functions : VowelWord(): constructor to initialize data members to legal initial values void readStr(): to accept a sentence void freqVowel(): counts the frequency of the words that begin with a vowel void display(): to display the original string and the frequency of the words that begin with a vowel Specify the class VowelWord giving details of the constructor, void readStr(), void freqVowel() and void display(). Also define the main() function to create an object and call the methods accordingly to enable the task. import java.util.Scanner; class VowelWord{     String str;     int freq

Combine Arrays ISC Computer Science 2012 Theory

A class Combine contains an array of integers which combines two arrays into a single array including the duplicate elements, if any, and sorts the combined array. Some of the members of the class are given below: Class name : Combine Data members/instance variables : com[]: integer array size: size of the array Member functions/methods : Combine(int num): parameterized constructor to assign size = num void inputArray(): to accept array elements void sort(): sorts the elements of combined array in ascending order using the selection sort technique void mix(Combine a, Combine b): combines the parameterized object arrays and stores the result in the current object array along with duplicate elements, if any void display(): displays the array elements Specify the class Combine giving details of the constructor, void inputArray(), void sort(), void mix(Combine, Combine) and void display(). Also define the main() function to create an object and call the methods accordingly to enable the

Palindrome Words ISC Computer Science 2013 Practical

A palindrome is a word that may be read the same way in either direction. Accept a sentence in uppercase which is terminated by either ".", "?" or "!". Each word of the sentence is separated by a single blank space. Perform the following tasks: (a) Display the count of palindromic words in the sentence. (b) Display the palindromic words in the sentence. Example of palindromic words: MADAM, ARORA, NOON Test your program with the sample data and some random data: Example 1 INPUT: MOM AND DAD ARE COMING AT NOON. OUTPUT: MOM DAD NOON NUMBER OF PALINDROMIC WORDS: 3 Example 2 INPUT: NITIN ARORA USES LIRIL SOAP. OUTPUT: NITIN ARORA LIRIL NUMBER OF PALINDROMIC WORDS: 3 Example 3 INPUT: HOW ARE YOU? OUTPUT: NO PALINDROMIC WORDS import java.util.Scanner; class Palindrome{     public static void main(String[] args){         Scanner in = new Scanner(System.in);         System.out.print("Enter the sentence: ");         String s = in.nextLine().toUpperCase();

Matrix Mirror Image ISC Computer Science 2013 Practical

Write a program to declare a square matrix a[][] of order (M × M) where 'M' is the number of rows and the number of columns such that M must be greater than 2 and less than 20. Allow the user to input integers into this matrix. Display appropriate error message for an invalid input. Perform the following tasks: (a) Display the input matrix. (b) Create a mirror image of the inputted matrix. (c) Display the mirror image matrix. Test your program for the following data and some random data: Example 1 INPUT: M = 3 4 16 12 8 2 14 6 1 3 OUTPUT: ORIGINAL MATRIX 4 16 12 8 2 14 6 1 3 MIRROR IMAGE MATRIX 12 16 4 14 2 8 3 1 6 Example 2 INPUT: M = 22 OUTPUT: SIZE OUT OF RANGE import java.util.Scanner; class Mirror{     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         System.out.print("M = ");         int m = Integer.parseInt(in.nextLine());         if(m < 3 || m > 19){

ISBN Number ISC Computer Science 2013 Practical

An ISBN (International Standard Book Number) is a ten-digit code which uniquely identifies a book. The first nine digits represent the Group, Publisher and Title of the book and the last digit is used to check whether ISBN is correct or not. Each of the first nine digits of the code can take a value between 0 and 9. Sometimes it is necessary to make the last digit equal to ten; this is done by writing the last digit of the code as X. To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third and so on until we add 1 time the last digit. If the final number leaves no remainder when divided by 11, the code is a valid ISBN. For example: 1. 0201103311 = 10 × 0 + 9  ×  2 + 8  ×  0 + 7  ×  1 + 6  ×  1 + 5  ×  0 + 4  ×  3 + 3  ×  3 + 2  ×  1 + 1  ×  1 = 55 Since 55 leaves no remainder when divided by 11, hence it is a valid ISBN. 2. 00746254X =  10  ×  0 + 9  ×  0 + 8  ×  7 + 7  ×  4 + 6  ×  6 + 5  ×  2 + 4  ×  5 + 3  ×  4 + 2  ×  2 + 1  ×  1

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:     print('1. PUSH ELEMENT')     print('2. POP ELEMENT')     print('3. PEEK STACK')     print('4. DISPLAY ELEMENTS')     choice = int(input('ENTER YOUR CHOICE: '))     if choice == 1:         element = int(input('Element to be pushed: '))