Monday, February 27, 2017

Networking Devices

Networking Devices are components used to connect computers or other devices together so that they can share files or resources like printers .Devices may be used to setup a LAN network or in connecting different LAN Networks.


1.Network Interface Card(Lan Adapter):

2.Hub:

3.Switches:









4.Router:
5.Bridges:
6.Host:
7.Repeaters:
8.Modem:

Saturday, February 25, 2017

Pythagorean Triplets Java

A Pythagorean Triplet is a set of 3 values a, b and c such that the sum of squares of a and b is equal to  square of c.
(a*a) + (b*b)  = (c*c)
Following Program Displays the Pythagorean Triplets upto a user desired value.

import java.util.Scanner;
public class Triplets {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int a, b, c;
        System.out.println("Enter the value of n: ");
        int n = in.nextInt();
        System.out.println("Pythagorean Triplets upto " + n + " are:\n");
        for (a = 1; a <= n; a++) {
            for (b = a; b <= n; b++) {
                for (c = 1; c <= n; c++) {
                    if (a * a + b * b == c * c) {
                        System.out.print(a + ", " + b + ", " + c);
                        System.out.println();
                    }
                   
                    else
                        continue;                  
                }
            }
        }
    }
}




Friday, February 24, 2017

Inclusion Exclusion Principle

Inclusion Exclusion Principle is Used to Calculate Cardinality of Union or Intersection of Sets

For Example:
n(a or b)=n(a)+n(b)-n(a&b)

Following Code will calculate the Intersection of Sets Using Inclusion Exclusion Principle

Code:

//Program to Calculate Cardinality of Intersection of sets Using Inclusion Exclusion Principle
import java.util.*;
public class IncExcP 
{
    public static void main(String[] nt) 
    {
        Scanner in=new Scanner (System.in);
        System.out.print("Enter Number of sets: ");
        int n=in.nextInt();
        int [][] s=new int[n][];
        System.out.println("Enter Cardinality Type Wise (i.e:Singles,Pairs,Triples etc): ");
        for(int i=1;i<n;i++)
        {  s[i]=new int[choose(n,i)];
            for(int j=0;j<choose(n,i);j++)
            {
                s[i][j]=in.nextInt();
            }
            if(i==n-1)
            {
                break;
            }
            System.out.println("Enter Next Type");
        }
        System.out.print("Enter Value of Union:");
        int u=in.nextInt();
        int [] sum=new int[n];
        for(int i=1;i<n;i++)
        {
            for(int j=0;j<choose(n,i);j++)
            {
                sum[i]=sum[i]+s[i][j];
            }
        }
        int x=u;
        for(int i=1;i<n;i=i+2)
        {
            x=x-sum[i];
        }
        for(int i=2;i<n;i=i+2)
        {
            x=x+sum[i];
        }
        if(n%2==0)
        {
            x=-x;
        }
        System.out.println("Intersection: "+x);
    }
    public static int choose(int n,int i)
    {   int result=1;
        for(int j=1;j<=i;j++)
        {
            result=result*(n-j+1)/j;
        }
        return result;
    }
}

Output:
For example:


Thursday, February 16, 2017

Telephone Database (Persistent Variables) Python

Following Code will help in maintaining a telephone database including following commands

1.whois phonenumber -tell the details of a particular Number

2. add phonenumber information-add the new number with the information

3.search keyword-return all numbers having keyword in their information

4.delete-deleting any number from database

5.quit-Halt the application

Code::

import string
import shelve

database=shelve.open("information.db")
print("Commands are: whois,add,search,delete or quit")
c=0
line=input("Command: ")
while line!='quit':
    words=line.lower().split()
    if line=="":
        print("Commands are: whois,add,search,delete or quit")
    elif words[0] =='whois':
        if words[1] in database:
            print(words[1],":",string.capwords(database[words[1]]))
        else:
            print("Not Found Try again!!")
    elif words[0]=='add':
        if words[1] in database:
            print("Already Present")
        else:
            database[words[1]]=" ".join(words[2:])
    elif words[0]=='search':
        for e in database:
            if database[e].find(words[1])!=-1:
                c=1
                print(e,":",string.capwords(database[e]))
                
        if c==0:
            print("Keyword Not found Try again!!")
    elif words[0]=="delete":
        if words[1] in database:del database[words[1]]
        else:print("Not Found Try again!!")
    else:
        print("Command Not Found Please Try again!!")
    line=input("Command: ")
database.close()

Output::

 

Wednesday, February 15, 2017

A Concordance Python

A concordance is an alphabetical listing of the words in a text String,along with the line numbers on which each word occurs.

Code::

def count(line,dct,linenumber):
    for word in line.split():
        lst=dct.get(word,[])
        lst.append(linenumber)
        dct[word]=lst

line=input("Enter text,quit to end: ")
linenumber=0
dct={}
while line!='quit':
    linenumber+=1
    count(line,dct,linenumber)
    line=input()
for el in sorted(dct.keys()):
    print(el,":",dct[el])

Output::

Tuesday, February 14, 2017

Tabulating Club Dues Python

Following Code will tabulate the dues of Members of Club :

Code::

def main():
    fre={}
    print("Enter Dues ,enter quit to end")
    while True:
        line=input()
        if(line=='quit'):break
        words=line.split(':')
        fre[words[0]]=fre.get(words[0],0)+int(words[1])
    for name in fre:
        print(name+" has Paid Rs",fre[name],"in dues")

main()

Output::

Word Frequency Python

Following code will give the frequency of occurrence of words in text:

Code::

def main():
    fre={}
    print("Enter Text ,enter quit to end the text")
    while True:
        line=input()
        if(line=='quit'):break
        for el in line.split():
            fre[el]=fre.get(el,0)+1
    print (fre)

main()

    
Output::