Facebook Badge

Vinod Singh | Create Your Badge

Wednesday, July 30, 2014

ISC COMPUTER SCIENCE PRACTICAL Solved ~ 2004


The computer department of the Agency of International Espionage is trying to decode intercepted messages. The agency's spies have determined that the enemy encodes messages by first converting all characters to their ASCII values and then reversing the string.
For example, consider A_z ( the underscore is just to hightlight the space). The ASCII values of A, <space>, z are 65,32,122 respectively. Concatenate them to get 6532122, then reverse this to get 2212356 as the coded message.
Write a program which reads a coded message and decodes it. It will contain only alphabets (A......Z, and a........z) and spaces. ASCII values of A.......Z are 65........90 and those of a.....z are 97......122. Test your program for the following data and some random data.

SAMPLE DATA:
INPUT:
Encoded Message: 2312179862310199501872379231018117927
OUTPUT:
The Decoded Message: Have a Nice Day

import java.util.*;
import java.io.*;
public class EncryptionAscii {
    public static void main(String[] args) throws IOException
        {
        String msg;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   
        System.out.println(" Enter the sentence (Encoded Message):");
        msg = br.readLine();   
        Decrypt ob = new Decrypt(msg);
        ob.reverseString();
        System.out.println("OUTPUT The Decoded Message: ");
        ob.decryptCode();       
        }
    }
class Decrypt {
    Decrypt(String msg) {
        Decryptmsg = msg;
        codeValues = new int[Decryptmsg.length()];
        }
    public void reverseString() {
        int j = 0;
        for ( int i = Decryptmsg.length()-1; i >= 0; i--) {
            codeValues[j++] = Decryptmsg.charAt(i)-48;
            }
        }   
    public void decryptCode() {
        byte tmp = 0;
        int i = 0;
        flag = false;
        charCount = 0;
        ascii = new byte[Decryptmsg.length()];
        while ( i < Decryptmsg.length() ) {
            tmp += codeValues[i++]*10;
            tmp += codeValues[i++];
            if ( 10 <= tmp && tmp <= 12 ) {
                tmp *= 10;
                tmp += codeValues[i++];
                ascii[charCount++] = tmp;//System.out.println(String.valueOf(tmp));
                tmp=0;
                }       
            else {
                ascii[charCount++] = tmp;//System.out.println(String.valueOf(tmp));
                tmp = 0;
                }   
            }
        String S = new String(ascii);
        System.out.println(S);   
        }   
    private String Decryptmsg;   
    private int[] codeValues;
    private int charCount;
    private byte[] ascii;
    private boolean flag;
    }   

Monday, July 28, 2014

ISC COMPUTER SCIENCE PRACTICAL 2014~ COMPOSITE MAGIC

/*
A Composite Magic number is a positive integer which is composite as well as a magic number.
Composite number : A composite number is a number which has more than 2 factors.
For example : 10
Factors are : 1,2,5,10.
Magic number : A magic number is a number in which the eventual sum of the
digits is equal to 1.
For example:- 28 = 2+ 8 =10 = 1+0=1
Accept 2 positive integers m and n, where m is less than n as user input. Display the number of
composite magic integers that are in the range between m and n (both inclusive) and output them
along with the frequency, in the format specified below.
Test your program with the sample data and some random data:

Example 1:
INPUT:
m=10
n=100
OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE :
10,28,46,55,64,82,91,100
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS :8

Example 2:INPUT:
m=1200
n=1300
OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE :
1207,1216,1225,1234,1243,1252,1261,1270,1288
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS :9

Example 3:
INPUT:
m=120
n=99
OUTPUT:
INVALID INPUT
*/

/* ISC COMPUTER SCIENCE PRACTICALS SOLVED, 2014 */
import java.util.*;
public class CompositeMagic {
    public static void main(String[] args) {
        int m,n;
        Scanner in = new Scanner(System.in);
        System.out.println("INPUT THE VALUE OF m & n:");
        m = in.nextInt();
        n = in.nextInt();
        while( m > n || n < 1 || m < 1) {
            System.out.println("INVALID CHOICE:");
            m = in.nextInt();
            n = in.nextInt();
            }
        CheckCompositeMagic cm = new CheckCompositeMagic(m,n);
        System.out.println("THE COMPOSITE MAGIC NUMBERS ARE:");
        cm.checkComposite();
        System.out.println("FREQUENCY OF COMPOSITE MAGIC INTEGERS IS:"+cm.fCount());
        System.out.println();
        }
    }
class CheckCompositeMagic {
    CheckCompositeMagic (int m, int n) {
        M = m; N = n;
        freqCompositeMagic = 0;
        }
    public int fCount() {
        return     freqCompositeMagic;
        }
    public void checkComposite() {
        for ( int i = M; i <= N ;i++) {
            flag = false;
            for ( int j = 2; j <= Math.sqrt(i); j++) {
                if( i%j == 0) {
                    flag = true;
                    break;
                    }
                }
            if(flag == true) {
                 checkMagic(i);
                 if(fg == true)   
                     System.out.println(i);
                 }   
            }
        }    
    private void checkMagic(int mg) {
        fg = false;
        int tmp,rem;
        tmp = mg;
        sum = 0;
        while( tmp > 0) {
            rem = tmp % 10;
            sum += rem;
            tmp = tmp/10;
            }
        if( sum == 1 ) {
            freqCompositeMagic++;
            fg = true;
            }   
        else {
            if(sum < 10)
                fg = false;
            else
                checkMagic(sum);
            }   
           
        }   
    private int M;
    private int N;   
    private int freqCompositeMagic;
    private int sum;
    private boolean flag,fg;
    }   

ISC Computer Science Practical 2014 solved



/*
Question 3.
Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only. Any
other character may be ignored. The words may be separated by more than one blank space and are
in UPPER CASE.
Perform the following tasks:
a) Accept a sentence and reduce all the extra blank space between 2 words to a single blank space.
b) Accept a word from the user which is a part of the sentence along with its position number
and delete the word and display the sentence.

Test your program for the following data and some random data.:

Example 1
INPUT: A   MORNING WALK IS A BLESSING FOR   THE    WHOLE DAY.
WORD TO BE DELETED : IS
WORD POSITION IN THE SENTENCE : 4
OUTPUT: A MORNING WALK A BLESSING FOR THE WHOLE DAY.

Example 2
INPUT: AS YOU SOW, SO SO YOU REAP.
WORD TO BE DELETED : SO
WORD POSITION IN THE SENTENCE : 4
OUTPUT: AS YOU SOW, SO YOU REAP.

Example 3
INPUT: STUDY WELL ##.
OUTPUT: INVALID INPUT.
/*

/* ISC COMPUTER SCIENCE PRACTICAL~2014 */
import java.util.*;
import java.io.*;
public class SpaceWord {
    public static void main(String[] args) throws IOException
        {
        String msg;
        String wordDelete;
        int pos;
        Scanner in = new Scanner(System.in);
        System.out.println("WORD POSITION IN THE SENTENCE:");
        pos = in.nextInt();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   
        System.out.println(" Enter the sentence:");
        msg = br.readLine();
        br.close();
        OutputString os = new OutputString(msg);
        if(os.validInvalid() == false)
            System.out.println("INVALID INPUT");
        else    {
            os.extraSpaceDeletion();
            os.wordDeletion(pos);
            }
               
        }
    }
class OutputString {
    OutputString(String mg) {
        msg = mg;
        lengthMsg = msg.length();
        outputmsg = "";
        }
    public boolean validInvalid() {
        return (msg.charAt(lengthMsg-1) == '.'  ? true : msg.charAt(lengthMsg-1) == '!' ? true : msg.charAt(lengthMsg-1) == '?' ? true : false);
        }   
    public void extraSpaceDeletion() {
        for ( int i = 0; i < lengthMsg; i++) {
            if(msg.charAt(i) != ' ') {
                outputmsg += msg.charAt(i);
                }
            else {
                outputmsg += msg.charAt(i);
                while(msg.charAt(i) == ' ' && i < lengthMsg)
                    i++;
                i--;   
                }   
            }
        System.out.println();   
        }   
    public void wordDeletion(int pos) {
        int tmp = 0;
        for ( int i = 0; i < outputmsg.length(); i++) {
            if(outputmsg.charAt(i) == ' ')
                tmp++;
            if(tmp == pos-1) {
                while(outputmsg.charAt(i+1) != ' ' && i < outputmsg.length())
                    i++;
                }   
            else
            System.out.print(outputmsg.charAt(i));   
            }
        System.out.println();
        }   
    private String msg;
    private String outputmsg;
    private int lengthMsg;
    }       

Sunday, July 27, 2014

CBSE ~ COMPUTER SCIENCE ~ CLASS XI ~ CHAPTER 3


CBSE ~ COMPUTER SCIENCE ~ CLASS XI ~ CHAPTER 3 #Python

1. Create following Variables
i) “mystring” to contain “hello‟
ii) “myfloat‟ to contain “2.5‟
iii) “myint‟ to contain “10‟
Answer: mystring = 'hello'
myfloat = 2.5
myint = 10

2. Write the value justification
i) 2*(3+4) ii) 2*3+4 iii) 2+3*4
Answer: 14,10,14

3. What is the type of the following result:
i) 1+2.0+3
Answer: float, adding/subtracting/multiplying/dividing an integer with a float type results in float.

4. Which of the following is the valid variable name:
i) global ii) 99flag iii) sum iv) an$wer
Answer: sum

5. True of False
i) Character Data type values should be delimited by using the single quote.
ii) None is one of the data type in python
iii) The += operator is used to add the right hand side value to the left hand side
variable.
iv) The data type double is not a valid python data type.
v) Python does not have any keywords
vi) The equal to condition is written by using the == operator

Answer: False,True,False,True,False,True

6. Check all syntactically correct statements
a) Which input statements are correct
i) a = raw_input ( )
ii) a = raw_input (“enter a number”)
iii) a = raw_imput (enter your name)
Answer: Only iii) is incorrect

b) Which print statements are correct?
i) _print “9” + “9”
ii) _print int(“nine”)
iii) _print 9+9
iv) print 9
Answer: iv)

c) Which are correct arithmetical operations?
i) a = 1*2
ii) 2 = 1+1
iii) 5 + 6 = y
iv) Seven = 3 * 4
Answer: i) and iv)

d) Which are correct type conversions?
i) int (7.0+0.1)
ii) str (1.2 * 3.4)
iii) float (“77”+“.0”)
iv) str ( 9 / 0 )
Answer: i) and ii)

e) Which operations result in 8?
i) 65 // 8
ii) 17 % 9
iii) 2 * * 4
iv) 64 * * 0.5

Answer: 8,8,16,8.0

f) Which lines are commented?
i) “””This is a comment”””
ii) # This is a comment
iii) // this is a comment
iv) '''This is a comment'''

Answer: i) & ii)

g) Find the matching pairs of expressions and values.
i) 1023 boolean
ii) None int
iii) [2, 4, 8, 16] tuple
iv) True list
v) 17.54 str
vi) ('Roger', 1952) NoneType
vii) “my fat cat” float

Answer: 1023-int, None-NoneType, [2,4,8,16]-list,True-boolean, 17.54-float, ('Roger', 1952)-tuple,”my fat cat”-str

7. MCQ
i) The __________ data type allows only True/False values [bool]

ii) If the value of a = 20 and b = 20, then a+=b will assign ________ to a [40]

iii) The ____________ operator is used to find out if division of two number
yields any remainder [%]

8. When will following statement in interpreter result into error:
>>> B+4

Answer: when B is not defined before hand or B+4 is not being assigned to any other variable

9. How can we change the value of 6*1-2 to -6 from 4?

Answer: 6*(1-2)

10. Is python case sensitive?

Answer: YES

11. What does 'immutable' mean; which data type in python are immutable.

Answer: Integer & Long , Float/floating point , Complex

Thursday, May 8, 2014

ISC Computer Science Practicals: Solved


Write a program to declare a matrix A [][] of order (MXN)
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:

1. Display the input matrix
2. Find the maximum and minimum value in the matrix and display
them along with their position.
3. Sort the elements of the matrix in ascending order using any
standard sorting technique and rearrange them in the matrix.

Output the rearranged matrix.

Sample input Output
INPUT:
M=3
N=4
Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4
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

Monday, May 5, 2014

open GL Programming in LINUX


To compile a program (using open GL graphics library) in Linux, go to the current directory where the program is residing say test.c. type the following command gcc -o xyz test.c -lglut -lGLU -lGL -lGLU make sure you have the open GL library installed! After the execution of the command a output file with name xyz will be created in the current directory. To run the output file type in the following command ./xyz

To sum up consider a program vinod.c in the folder Graphics, to execute it perform the following steps.
administrator@ubuntu:~/Graphics$ gcc -o vin vinod.c -lglut -lGLU -lGL -lGLU
administrator@ubuntu:~/Graphics$ ./vin


Here is an example of a simple program which will just create a window with a text

#include <GL/glut.h>
void
display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("MY FIRST GRAPHICS PROGRAM");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Sunday, April 20, 2014

Pascal trialngle



CODE

import java.io.*;
import java.util.*;
public class Pascal {
    public static void main(String[] args) {
        int rows;
        Stack<Integer> s1 = new Stack<Integer>();
        Stack<Integer> s2 = new Stack<Integer>();
        s1.push(1);
        s1.push(1);
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the number of rows:");
        rows = in.nextInt();
        System.out.println("Pascal Traingle:");
        for(int i = 1; i <= rows; i++) {
            if(i==1 || i==2) {
                if(i==1)
                    System.out.println("1");
                else {
                    System.out.println();
                    System.out.println("1  1");
                    }
                }
            else {
            System.out.println();
            int p = s1.pop();
            System.out.print(p+" ");
            s2.push(p);
            while(s1.empty() == false) {
                    int q = s1.pop();
                    int next = p+q;
                    System.out.print(next+" ");
                    s2.push(next);
                    p = q;
                    }
            System.out.println(" 1 ");
            s2.push(1);
            while(s2.empty() == false) {
                    s1.push(s2.pop());
                    }
                }
            } // end of i loop
        }
    }