Friday, 28 October 2016

ISC Computer 2016 Theory Part II : Section B Fully Solved

Section B : 2016 Solved Theory


Question : 7

Disarium Number Using recursive technique.

Sample Input : 135

135 = 1¹ + 3² + 5³ = 1 + 9 + 25 = 135

Sample Output : 135 is a Disarium Number.

import java.util.*;
public class Disarium
{
    int num,size;
    Disarium(int nn)
    {
        num=nn;
        size=0;
    }
    void countDigit()
    {
        int t;
        t=num;
        for(;t!=0;)
        {
            t=t/10;
            size++;
        }
    }
    int sumOfDigits(int n,int p)
    {
        int r;
        r=(int)(Math.pow(n%10,p));
        p--;
        n=n/10;
        if(p==0)
        {
            return (r);
        }
        else
        {
            return (r+sumOfDigits(n,p));
        }
    }
    void check()
    {
        int d;
        d=sumOfDigits(num,size);
        if(d==num)
        {
            System.out.println(num+" is Desarium Number.");
        }
        else
        {
            System.out.println(num+" is not a Desarium Number.");
        }
    }
    public static void main()
    {
        Scanner in=new Scanner(System.in);
        int no;
        System.out.println("Enter a number to check if it is Desarium Number : ");
        no=in.nextInt();
        Disarium ob=new Disarium(no);
        ob.countDigit();
        ob.check();
    }
}
  

Question :8

Shift Matrix row : 1st to 2nd, last to 1st and so on.

Sample Input : 

1      2      3

4      5      6

7      8      9

Sample Output :

7      8      9

1      2      3

4      5      6

import java.util.*;
public class Shift
{
    int mat[][]=new int[5][5];
    int m,n;
    Shift(int mm,int nn)
    {
        m=mm;
        n=nn;
    }
    void input()
    {
        Scanner in=new Scanner(System.in);
        int i,j;
        System.out.println("Enter elements in matrix of size "+m+" X "+n+" : ");
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                mat[i][j]=in.nextInt();
            }
        }
        System.out.println("Matrix Formed :");
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                System.out.print(mat[i][j]+"\t");
            }
            System.out.println();
        }
    }
    void cyclic(Shift P)
    {
        int i,j,t;
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                P.mat[(i==(m-1))?0:(i+1)][j]=mat[i][j];
            }
        }
    }
    void display()
    {
        int i,j;
        System.out.println("Shifted Matrix : ");
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                System.out.print(mat[i][j]+"\t");
            }
            System.out.println();
        }
    }
    public static void main()
    {
        Scanner in=new Scanner(System.in);
        int r,c;
        System.out.println("Enter number of rows : ");
        r=in.nextInt();
        System.out.println("Enter number of columns : ");
        c=in.nextInt();
        Shift ob=new Shift(r,c);
        ob.input();
        Shift ob1=new Shift(r,c);
        ob.cyclic(ob1);
        ob1.display();
    }
}

Question :9

Change all the consonants to upper case and arrange it at the starting of the word followed by vowel.

Sample Input : shubham

Sample Output : SHBHMum

import java.util.*;
public class ConsChange
{
    String word;
    int len;
    ConsChange()
    {
        word="";
        len=0;
    }
    void readWord()
    {
        Scanner in=new Scanner(System.in);
        System.out.println("Enter a word in lower case : ");
        word=in.nextLine();
        len=word.length();
    }
    void shiftCons()
    {
        char c;
        int i;
        String cons="",vol="";
        for(i=0;i<len;i++)
        {
            c=word.charAt(i);
            if((c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u'))
            {
                vol=vol+c;
            }
            else
            {
                cons=cons+c;
            }
        }
        System.out.println("Shifted Word : "+(cons+vol));
    }
    void changeWord()
    {
        char c;
        int i;
        String cons="",vol="";
        for(i=0;i<len;i++)
        {
            c=word.charAt(i);
            if((c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u'))
            {
                vol=vol+c;
            }
            else
            {
                cons=cons+Character.toUpperCase(c);
            }
        }
        System.out.println("Changed Word : "+(cons+vol));
    }
    void show()
    {
        System.out.println("Original Word : "+word);
        shiftCons();
        changeWord();
    }
    public static void main()
    {
        ConsChange ob=new ConsChange();
        ob.readWord();
        ob.show();
    }
}
 
 

ISC Computer 2016 Theory Part II : Section C Fully Solved

Section C : 2016 Solved Theory


Question :10

Inheritance From Account to Bank 

public class Bank
{
    String name;
    long accno;
    double p;
    Bank(String n,long a,double s)
    {
        name=n;
        accno=a;
        p=s;
    }
    void display()
    {
        System.out.println("Customer's Name : "+name);
        System.out.println("Customer's Account Number : "+accno);
        System.out.println("Customer's Principal Ammount : "+p);
    }
}


public class Account extends Bank
{
    double amt;
    Account(double a,String na,long no,double sm)
    {
        super(na,no,sm);
        amt=a;
    }
    void deposit()
    {
        p=p+amt;
    }
    void withdraw()
    {
        if(p>=amt)
        {
            p=p-amt;
            if(p<500)
            {
                p=p-(500-p)/10;
            }
        }
        else
        {
            System.out.println("INSUFFICIENT BALANCE");
        }
    }
    void display()
    {
        System.out.println("Customer's Name : "+name);
        System.out.println("Customer's Account Number : "+accno);
        System.out.println("Customer's Principal Ammount : "+p);
    }
}


Question :11

Stack programming using LIFO : Book Shelf 

public class Book
{
    String name[]=new String[100];
    int point,max;
    Book(int cap)
    {
        max=cap;
        point=-1;
    }
    void tell()
    {
        if(point==-1)
        {
            System.out.println("SHELF EMPTY");
        }
        else
        {
            System.out.println(name[point]+" is last book entered at "+(point+1)+".");
        }
    }
    void add(String v)
    {
        if((point+1)==max)
        {
            System.out.println("SHELF FULL");
        }
        else
        {
            name[++point]=v;
        }
    }
    void display()
    {
        int i;
        System.out.println("POSITION\t\tNAME OF THE BOOKS");
        System.out.println("--------------------------------------------------------------------");
        for(i=0;i<=point;i++)
        {
            System.out.println((i+1)+".\t\t\t"+name[i]);
        }
    }
}
   

Thursday, 27 October 2016

ISC Computer 2015 Theory Part II : Section B Fully Solved



Section B : 2015 Solved Theory


Question :8
A class Admission contains…………..enable the task.
//ISC 2015 Theory Question 8
//A Program by Shubham Kumar Sharma
import java.util.*;
public class Admission
{
intAdno[]=new int[100];
Admission()
    {
inti;
        for(i=0;i<100;i++)
        {
Adno[i]=0;
        }
    }
    void fillArray()
    {
        Scanner in=new Scanner(System.in);
inti;
System.out.println("Enter Admission Numbers in ascending order : ");
        for(i=0;i<100;i++)
        {
Adno[i]=in.nextInt();
        }
    }
intbinSearch(intl,intu,int v)
    {
intmid,r;
        mid=(l+u)/2;
        if(Adno[mid]==v)
        {
            r=1;
        }
        else if(l>u)
        {
            r=-1;
        }
        else if(Adno[mid]>v)
        {
            r=binSearch(l,mid-1,v);
        }
        else
        {
            r=binSearch(mid+1,u,v);
        }
        return (r);
    }
    public static void main()
    {
        Scanner in=new Scanner(System.in);
        Admission ob=new Admission();
intx,y;
ob.fillArray();
System.out.println("Enter the Admission number to be searched : ");
        x=in.nextInt();
        y=ob.binSearch(0,99,x);
        if(y==1)
        {
System.out.println("Admission number exist");
        }
        else
        {
System.out.println("Admission number does not exist");
        }
    }
}


Question : 9
A class Merger concatenates…………enable the task.
Sample Input : 11 and 1998
Sample Output :111998
import java.util.*;
public class Merger
{
    long n1,n2,mergNum;
Merger()
    {
        n1=0;
        n2=0;
mergNum=0;
    }
    void readNum()
    {
        Scanner in=new Scanner(System.in);
System.out.println("Enter first number : ");
        n1=in.nextLong();
System.out.println("Enter second number : ");
        n2=in.nextLong();
    }
    void joinNum()
    {
mergNum=Long.parseLong(Long.toString(n1)+Long.toString(n2));
    }
    void show()
    {
System.out.println("First Number : "+n1);
System.out.println("Second Number : "+n2);
System.out.println("Merged Number : "+mergNum);
    }
    public static void main()
    {
        Merger ob=new Merger();
ob.readNum();
ob.joinNum();
ob.show();
    }
}


Question : 10
A class TheString accepts a string………………..enable the task.
Sample Input :Shubham reads computer science
Sample Output :
Number of Words : 4
Number of Consonants : 27

import java.util.*;
public class TheString
{
    String str;
intlen,wordcount,cons;
TheString(String ds)
    {
str=ds;
    }
    void countFreq()
    {
        String s[];
inti;
        char c;
len=str.length();
        s=str.split(" ");
wordcount=s.length;
        for(i=0;i<len;i++)
        {
            c=str.charAt(i);
            if(Character.isLetter(c))
            {
                if((c!='A')||(c!='E')||(c!='I')||(c!='O')||(c!='U')||(c!='a')||(c!='e')||(c!='i')||(c!='o')||(c!='u'))
                {
                    cons++;
                }
            }
        }
    }
    void display()
    {
System.out.println("Original String : "+str);
System.out.println("Number of Words : "+wordcount);
System.out.println("Number of Consonents : "+cons);
    }
    public static void main()
    {
        Scanner in=new Scanner(System.in);
        String s;
System.out.println("Enter your string : ");
        s=in.nextLine();
TheStringob=new TheString(s);
ob.countFreq();
ob.display();
    }
}

ISC Computer 2015 Theory Part II : Section C Fully Solved



Section C : 2015 Solved Theory


Question : 11
WordPile is an entity ……………..not be written.
public class WordPile
{
    char ch[]=new char[20];
    int capacity,top;
    WordPile(int cap)
    {
        capacity=cap;
        top=-1;
    }
    void pushChar(char v)
    {
        if((top+1)==capacity)
        {
            System.out.println("WordPile is full");
        }
        else
        {
            ch[++top]=v;
        }
    }
    char popChar()
    {
        if(top==-1)
        {
            return ('\\');
        }
        else
        {
            return (ch[top--]);
        }
    }
}


Question : 12
A line on a plane can……………………….not be written.
public class Plane
{
    int x1,y1;
    Plane(int nx,int ny)
    {
        x1=nx;
        y1=ny;
    }
    void show()
    {
        System.out.println("Coordinate : ("+x1+","+y1+")");
    }
}



public class Circle extends Plane
{
    int x2,y2;
    double radius,area;
    Circle(int ax,int ay,int bx,int by)
    {
        super(ax,ay);
        x2=bx;
        y2=by;
    }
    void findRadius()
    {
        radius=(Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2)))/2;
    }
    void findArea()
    {
        area=(22/7)*(Math.pow(radius,2));
    }
    void show()
    {
        System.out.println("Coordinates : ("+x1+","+y1+") and ("+x2+","+y2+")");
        System.out.println("Radius : "+radius);
        System.out.println("Area : "+area);
    }
}