Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: January 2021

Friday, January 22, 2021

ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 11

 Question 11

A linear data structure enables the user to add address from rear end and remove address

from front. Define a class Diary with the following details:

Class name                                                                 : Diary

Data members / instance variables:

Q[ ]                                                                              : array to store the addresses

Size                                                                             : stores the maximum capacity of the

array

start                                                                             : to point the index of the front end

end                                                                              : to point the index of the rear end

Member functions:

Diary (int max)                                                            : constructor to initialize the data

member size=max, start=0 and end=0

void pushadd(String n)                                               : to add address in the diary from the

rear end if possible, otherwise display

the message “ NO SPACE”

String popadd( )                                                          : removes and returns the address from

the front end of the diary if any, else

returns “?????

void show( )                                                                : displays all the addresses in the diary

 

(a) Specify the class Diary giving details of the functions void pushadd(String) and

String popadd( ). Assume that the other functions have been defined.

The main function and algorithm need NOT be written.

 (b) Name the entity used in the above data structure arrangement : Answer QUEUE


In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. By convention, the end of the sequence at which elements are added is called the back, tail, or rear of the queue, and the end at which elements are removed is called the head or front of the queue, analogously to the words used when people line up to wait for goods or services.

The operation of adding an element to the rear of the queue is known as enqueue, and the operation of removing an element from the front is known as dequeue. Other operations may also be allowed, often including a peek or front operation that returns the value of the next element to be dequeued without dequeuing it.

import java.util.*;
public class ISC2019Q11 {
       public static void main(String[] args) {
       int max;
       int choice = -1;
       Scanner input = new Scanner(System.in);
       System.out.println("Enter the maximum strength of the diary:");
       max = input.nextInt();
       Diary obj = new Diary(max);
       System.out.println("Enter 0 to exit:");
       System.out.println("Enter 1 to add:");
       System.out.println("Enter 2 to remove:");
       System.out.println("Enter 3 to display:");
       do {
           System.out.println("Enter your choice:");
           choice = input.nextInt();
           switch(choice) {
           case 0:
               break;
           case 1:     
               String n;
               System.out.println("Enter the address to add:");
               n = input.next();
               obj.pushAdd(n);
               break;
           case 2:
               System.out.println(obj.popAdd());
               break;
           case 3:
               obj.show();
               break;
               
           }
                            
       }while(choice !=0);
       input.close();
       }
}
class Diary {
    public void show() {
        for(int i = start; i<end; i++)
            System.out.println("Address at "+(i+1)+" is: "+Q[i]);
    }
    public String popAdd() {
        String frontValue;
        if ( end == start)
            return ("QUEUE IS EMPTY");
        else { 
            frontValue = Q[start];
            for(int i = 0; i < end-1 ;i++)
                Q[i]=Q[i+1];
            end--;
            return (frontValue);
        }
    }
    public void pushAdd(String n) {
        if (end < size) {
            Q[end] = n;
            end++;
        }
        else
            System.out.println("NO SPACE:"); 
    }
    Diary (int max){
        this.size = max;
        this.start = 0;
        this.end = 0;
        Q = new String[this.size];
    }
    private String[] Q;
    private int size;
    private int start;
    private int end;
}

Monday, January 18, 2021

ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 10

 Definitions: A class that is derived from another class is called a subclass (also a derived class, extended class, or child class).

 The class from which the subclass is derived is called a superclass (also a base class or a parent class).Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object.Classes can be derived from classes that are derived from classes that are derived from classes, and so on, and ultimately derived from the topmost class, Object. Such a class is said to be descended from all the classes in the inheritance chain stretching back to Object.

The idea of inheritance is simple but powerful: When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class. 

 In doing this, you can reuse the fields and methods of the existing class without having to write (and debug!) them yourself.A subclass inherits all the members (fields, methods, and nested classes) from its superclass. 

Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass

ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 10 - SECTION C

A super class Record contains names and marks of the students in two different single

dimensional arrays. Define a sub class Highest to display the names of the students

obtaining the highest mark.

The details of the members of both the classes are given below:

     


Class name : Record

Data member/instance variable:

n[ ]                                                                    : array to store names

m[ ]                                                                  : array to store marks

size                                                                   : to store the number of students

Member functions/methods:

Record(int cap)                                               : parameterized constructor to initialize the data

  member size = cap

void readarray()                                              : to enter elements in both the arrays

void display( )                                                 : displays the array elements

 

Class name: Highest

Data member/instance variable:

index                                                               : to store the index

Member functions/methods:

Highest(…)                                                     : parameterized constructor to initialize the data

  members of both the classes

void find( )                                                      : finds the index of the student obtaining the

                                                                        highest mark and assign it to ‘index

void display( )                                                 : displays the array elements along with the    names and marks of the students who have obtained the highest mark

Assume that the super class Record has been defined. Using the concept of inheritance,

specify the class Highest giving the details of the constructor(…),void find( ) and

void display( ).


import java.util.*;
public class ISC2019Q10 {
       public static void main(String[] args) {
       int cap;
       Scanner input = new Scanner(System.in);
       System.out.println("Enter the strength of students");
       cap = input.nextInt();
       Highest obj = new Highest(cap);
       obj.readArray();
       obj.findHighestMarks();
       obj.display();
       input.close();
       }
}
class Highest extends Record {
    public void display() {
        super.display();
        System.out.println("Highest marks is obatained by "+names[index]+" with "+marks[index]+" as total marks.");
    }
    public void findHighestMarks() {
        // for simplicity I have assumed that there is not tie for the highest marks
        int highest = 0;
        forint i =0; i < size; i++) {
            if( highest < marks[i]) {
                index = i;
                highest = marks[i];
                }
        }
    }
    Highest(int cap){
        super(cap);
        this.index = 0;
        }
    private int index;
    }
class Record {
    protected void display() {
        System.out.println("Entered details are as follows:");
        for(int i = 0; i < size; i++) {
            System.out.println(names[i]+" has obtained "+marks[i]+" marks.");
        }
    }
    public void readArray() {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the details of the students:");
        for(int i=0;i<size;i++) {
            if((i+1)%10 == 1) {
                System.out.println("Enter the name of the "+(i+1)+"st student:");
                names[i] = input.next();
                System.out.println("Enter the marks of the "+(i+1)+"st student:");
                marks[i] = input.nextInt();
            }
            else if((i+1)%10==2) {
                System.out.println("Enter the name of the "+(i+1)+"nd student:");
                names[i] = input.next();
                System.out.println("Enter the marks of the "+(i+1)+"nd student:");
                marks[i] = input.nextInt();
            }
            else if((i+1)%10==3) {
                System.out.println("Enter the name of the "+(i+1)+"rd student:");
                names[i] = input.next();
                System.out.println("Enter the marks of the "+(i+1)+"rd student:");
                marks[i] = input.nextInt();
            }
            else {
                System.out.println("Enter the name of the "+(i+1)+"th student:");
                names[i] = input.next();
                System.out.println("Enter the marks of the "+(i+1)+"th student:");
                marks[i] = input.nextInt();
            }
        } 
        input.close();
    }
    Record (int cap) {
        this.size = cap;
        names = new String[size];
        marks = new int[size];
        }
    protected String[] names;
    protected int[] marks;
    protected int size;
}

ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 9

 



A class Rearrange has been defined to modify a word by bringing all the vowels in the

word at the beginning followed by the consonants.

Example: ORIGINAL becomes OIIARGNL

Some of the members of the class are given below:


Class name                                                     : Rearrange

Data member/instance variable:

wrd                                                                 : to store a word

newwrd                                                          : to store the rearranged word

Member functions/methods:

Rearrange( )                                                    : default constructor

void readword( )                                             : to accept the word in UPPER case

void freq_vow_con( )                                     : finds the frequency of vowels and consonants

                                                                        in the word and displays them with an

                                                                        appropriate message

void arrange( )                                                : rearranges the word by bringing the vowels at

                                                                        the beginning followed by consonants

void display( )                                                 : displays the original word along with the

                                                                        rearranged word

Specify the class Rearrange, giving the details of the constructor( ), void readword( ),

void freq_vow_con( ), void arrange( ) and void display( ). Define the main( ) function to

create an object and call the functions accordingly to enable the task.

import java.util.*;
public class ISC2019Q9 {
       public static void main(String[] args) {
       Rearrange obj = new Rearrange();
       obj.readWord();
       obj.vowelCount();
       obj.rearrangeWord();
       obj.display();
     }
}
class Rearrange {
    public void display() {
        System.out.println("ORIGINAL WORD:"+word);
        System.out.println("REARRANGED WORD:"+word_final);
    }
    public void rearrangeWord() {
        String vowels_beg ="";
        String conso_end ="";
        boolean flag;
        for (int i = 0;i<word.length();i++) {
            flag = false;
            for (int j =0;j<5;j++)
                if(word.charAt(i) == vowels[j]) {
                    flag = true;
                    break;
                }
            if (flag == true)
                vowels_beg += word.charAt(i);
            else
                conso_end +=word.charAt(i);
        }
        word_final = vowels_beg+conso_end;
    }
    public void vowelCount() {
        for (int i = 0;i<word.length();i++) {
            for (int j =0;j<5;j++)
                if(word.charAt(i) == vowels[j])
                    frequency_vowel_count++;
        }
        System.out.println("Number of vowels isn the word "+word+" is:"+frequency_vowel_count);
    }
    public void readWord() {
        Scanner input = new Scanner(System.in);
        boolean flag = true;
        do {
            System.out.println("Enter the word in upper case:");
            word = input.next();
            for(int i = 0;i<word.length();i++) {
                flag = Character.isUpperCase(word.charAt(i));
                if (flag == false ) {
                    System.out.println("You have not entered the word in upper case, try again:");
                    break;
                }
            }
        } while(flag == false);
        input.close();
    }
    Rearrange(){
        this.word = "";
        this.word_final ="";
        this.frequency_vowel_count = 0;
    }
    static char[] vowels = new char[] {'A','E','I','O','U'}; 
    private String word;
    private String word_final;
    private int frequency_vowel_count;
}

Saturday, January 16, 2021

INCOME TAX CALCULATOR (Real life) : OLD & NEW TAX REGIME

INCOME TAX CALCULATOR - OLD & NEW TAX REGIME

Enter your name:

Enter your gross salary in ₹

Enter your total Professional Tax (P.Tax) in ₹

Enter your savings a/c interest (cumulative of all banks)in ₹

Enter your total income from other sources (Dividend, Interest on FDs, Bond Income) in ₹

Enter the Gross Annual Rent ( put 0 for self occupied property) in ₹:

Enter the Municipal Taxes ( put 0 for self occupied property) in ₹:

Enter total interest paid on Home loan in ₹:

Enter the interest during construction in ₹ (put 0 if house is old than 5 years):

Divide the total interest paid during construction period by 5, as this deduction can be availed only for 5 years after the completion/acquisition of house in equal parts

Enter total deductions u/s 80C: (Housing Loan Principla,LIC,PLI,PPF,EPF,ELSS,NPS,Tax Saving FDs/Bonds..) in ₹

Enter contribution to NPS, additional deduction u/s 80CCD upto ₹50000:

Enter contribution to medical insurance, u/s 80D:

Enter deductions u/s 80EEA (Interest on loan for first residential house under affordable housing- additional deduction 1.5 lacs above 2 lacs under section 24, cannot be availed if deduction already taken in section 80EE last year or loan value is greater that 35 lacs):

Enter deduction under section 80G (donations):

Enter deduction under section 80GG (Rent Paid):

Enter deduction under section 80U (person with 40% disability can claim upto ₹75,000 while with severe disabilty (80% or above) can claim a tax deduction upto ₹1.25 lacs):




Saturday, January 9, 2021

INCOME TAX CALCULATOR: NEW TAX REGIME


INCOME TAX CALCULATOR - NEW REGIME

CALCULATE YOUR INCOME TAX UNDER NEW REGIME HERE: 

Enter your gross salary in ₹

Enter your total income from other sources (Savings Interest, Dividend, Interest on FDs) in ₹

Enter your total Professional Tax (P.Tax) in ₹


Compare with the Old Tax Regime


Up to Rs 3,00,000Exempt from tax
Rs 3,00,000 to Rs 6,00,0005% (5% of Rs 6,00,000 less Rs 3,00,000)
Rs 6,00,000 to Rs 9,00,00010% (10% of Rs 9,00,000 less Rs 6,00,000)
Rs 9,00,000 to Rs 12,00,00015% (15% of Rs 12,00,000 less Rs 9,00,000)
Rs 12,00,000 to Rs 15,00,00020% (20% of Rs 15,00,000 less Rs 12,00,000)
More than Rs Rs 15,00,00030% (30% of Rs 20,42,000 less Rs 15,00,000)
Cess4% of total tax 

ICSE JAVA PROGRAMS 2019: SECTION B QUESTION 6

 

Bubble Sort: JAVA Code

/*Question 5.

Write a program to input n integer elements in an array and sort them in ascending 
order using the bubble sort technique */

import java.util.*;
public class ICSEB6 {
       public static void main(String[] args) {
           int number_of_elements;
           Scanner input = new Scanner(System.in);
           System.out.println("Enter the number of elements in the array");
           number_of_elements = input.nextInt();
           bubbleSort obj = new bubbleSort(number_of_elements);
           obj.inputArrayElements();
           obj.bubbleSortMethod();
           obj.display();
           input.close();          
     }
}
class bubbleSort {
    public void display() {
        System.out.println("Array after bubble sort:");
        for(int i=0;i< number_of_elements;i++) 
            System.out.println(array[i]+ " ");
    }
    public void bubbleSortMethod() {
        for (int i = 0; i < number_of_elements-1; i++) 
            for (int j = 0; j < number_of_elements-i-1; j++) 
                if (array[j] > array[j+1]) 
                    { 
                    // swap array[j+1] and array[j] 
                    int temp = array[j]; 
                    array[j] = array[j+1]; 
                    array[j+1] = temp; 
                    }
    }
    public void inputArrayElements() {
        Scanner input = new Scanner(System.in);
        for(int i=0;i< number_of_elements;i++) {
            System.out.println("Enter the element at the position: "+(i+1));
            array[i] = input.nextInt();
        }
        input.close();
        System.out.println("Array before bubble sort:");
        for(int i=0;i< number_of_elements;i++) 
            System.out.println(array[i]+" ");
    }
    bubbleSort(int number_of_elements){
        this.number_of_elements = number_of_elements;
        array = new int[number_of_elements];
    }
    int []array;
    int number_of_elements;
}