Sunday, 29 January 2017

Python Programs

PYTHON PROGRAM
Aim:
To write each and every given python program and execute it.
Program 1:
#!/usr/bin/python
#program to select odd number from the list
a=[11,12,13,14,15,16,17,18,19,20,21,31,44,45,10];
print("List is:",a);
n=len(a);
print("length:",n);
i=0;
print("Odd number");
for i in range(len(a)):
  if(a[i]%2==1):
      print(a[i]);
Output:
[root@fosslab html]# python odd.py
('List is:', [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 31, 44, 45, 10])
('length:', 15)
Odd number
11 13 15 17 19 21 31 45

Program 2: Program to display the celsius value\
#!/usr/bin/python
a=input("enter the celsius value:")
f=(a*1.8)
b=f+32;
print b
Output:
[fosslab@fosslab ~]$ python celsius.py
enter the celsius value:23
73.4


Program 3: Program to display the fibonacciseries values
#!/usr/bin/python
a, b = 0, 1
while b < 200:
       print b,
       a, b = b, a+b
Output:
[fosslab@fosslab ~]$ python  fibanoo.py
1 1 2 3 5 8 13 21 34 55 89 144

Program 4: Program to display odd or even numbers.
#!/usr/bin/python
a = int(raw_input("Please enter an integer: "));
if (a % 2 == 1):
   print 'a' + ' is odd.'
else:
    print 'a' + ' is even.'
Output:
[fosslab@fosslab ~]$ python odd.py
Please enter an integer: 23
a is odd.
                   
Program 5: String Concatenation in python programming
#String concatenation
worda='computer';
wordb='science';
print("worda is ",worda);
print("wordb is",wordb);
wordc=worda+" " +wordb;
print("wordc is",wordc);
wordd=worda*3;
print("wordd is ",wordd);
str = 'HelloWorld!'
length=len(str);
print ("str :",str);
print("length:",length);
print ("first character is",str[0]);
print ("print character from 2rd to 6th :", str[2:7] );
print ("Prints string starting from 3rd character:",str[2:]);
print ("Prints string two times",str * 2);
print ("Prints concatenated string :",str + "TEST" );
print(str[-1]); #print last character
print(str[-6]);#print character from last 6th position
print(str[:-2]);# Everything except the last two characters

OUTPUT:
(‘word a is’,’computer’)
(‘word b is’,’science’)
(‘word c is’,’computer science’)
(‘word d is’,’computer computer computer’)
(‘str:’,’HelloWord!’)
(‘length:’,11)
(‘first character is’,’H’)
(‘Print character from 2rd to 6th :’,’llowo’)
(‘Prints string starting from 3rd character:’,’lloWord!’)
(‘Prints string two times’,’HelloWorld! HelloWorld!’)
(‘Prints concatenated string :’,’HelloWorld! TEST’ )
!
W
HelloWord
>>>

Program 6: Write a python program to perform function in Lists
#Python Lists
#!/usr/bin/python
print("\t \t \t Python Lists");
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
print("Prints complete list:",list);
print("Prints first element of the list : ",list[0]);
print("Prints elements starting from 2nd to 4th:",list[1:3]);
print("Prints elements starting from 3rd element:",list[2:]);
print("Prints list two times:",tinylist * 2);
print("Prints concatenated lists: ", list + tinylist );
#modify the 4th elements in the list
print("Before modifying the 4th element in list :",list[4]);
list[4]='efgh';
print("4th element in list :",list[4]);
print(" complete list:",list);
#Appending new elements
list.append('ijkl');
print("After appending list:",list);
#deleting an element in list
del list[2];
print("List :",list);

OUTPUT:
(‘Prints complete list:’,[‘abcd’,786,2.23,’john’,70.2])
(‘Prints first element of the list : ‘,’abcd’)
(‘Prints elements starting from 2nd to 4th:’,[786,2.23])
(‘Prints elements starting from 3rd element:’,[2.23,’john’,70.2])
(‘Prints list two times:’,[123,’john’,123,’john’])
(‘Prints concatenated lists: ‘,[‘abcd’,786,2.23,’john’,70.2,123,’john’])
(‘Before modifying the 4th element in list:’,70.2)
(‘4th element is list:’,’efgh’)
(‘complete list:’,[‘abcd’,786.2.23,’john’,’efgh’])
(‘After appending list:’[‘abcd’,786,2.23,’john’,’efgh’,’ijkl’])
(‘List:’[‘abcd’,786,2.23,’john’,’efgh’,’ijkl’])

Program 7: Write a python Program to select odd number from the lists
#!/usr/bin/python
#program to select odd number from the list
a=[11,12,13,14,15,16,17,18,19,20,21,31,44,45,10];
print("List is:",a);
n=len(a);
print("length:",n);
i=0;
print("Odd number");
for i in range(len(a)):
if(a[i]%2==1):
print(a[i]);

OUTPUT:
11
13
15
17
19
21
31
45

Program 8: For Statement in Python
>>> # Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>>> for x in a:
... print x, len(x)
cat 3
window 6

OUTPUT
cat
window
defenestrate
Program 9: The Range() and Len() in Python
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
... print i, a[i]
...
OUTPUT:
0 Mary
1 had
2 a
3 little
4 lamb

Program 10: Prime Number using Python.
>>> for n in range(2, 10):
... for x in range(2, n):
... if n % x == 0:
... print n, 'equals', x, '*', n/x
... break
... else:
... # loop fell through without finding a factor
... print n, 'is a prime number'
OUTPUT:
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3

Linux Command

File Commands

Perform the following file related operations at the shell prompt.

Create file named linux_distros.txt Add the names of the linux distributions you know.

Display the content of the file linux_distros.txt.

Copy the file linux_distros.txt to a new file list_of_linux_distributions.txt.

Rename the file list_of_linux_distributions.txt to linux.txt.

Delete the file linux.txt.

Directory Commands

Perform the following directory related operations at the shell prompt.

Get a list of files in the current directory.

Create a directory called foss.

Delete the directory foss

Create the following directory structure with a single command: one/two/three.

Delete the directory one with all its sub directories.
      
Print the path of current working directory

Program:
$ cat > linux_distros.txt debian

fedora ubuntu slackware centos OpenSuSE
^D

$ cat linux_distros.txt debian

fedora ubuntu slackware centos OpenSuSE

$ cp linux_distros.txt list_of_linux_distributions.txt

$ mv list_of_linux_distributions.txt linux.txt

$ rm linux.txt






Hidden files

Perform the following hidden files related operations at the shell prompt.

Create a hidden file called .a.

Create a hidden directory called .config.

List all the files in the current directory including hidden files.

Program:
$ touch .a

$ mkdir .config

$ ls -a

. .. .a .config

Tuesday, 17 January 2017

STUDENT RECORD USING ADO.NET

PROGRAM:


Imports System.Data.SqlClient
Public Class Form1
    Dim sqlconn As New SqlConnection()
    Dim sqlcomm As New SqlCommand()
    Dim sqldaat As New SqlDataAdapter()
    Dim ds As New DataSet()
    Private Sub StdBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles StdBindingNavigatorSaveItem.Click
Me.Validate()
Me.StdBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.VickyDataSet)
    End Sub
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'VickyDataSet2.std' table. You can move, or remove it, as needed.
Me.StdTableAdapter1.Fill(Me.VickyDataSet.std)
    End Sub
    Private Sub insert_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
sqlconn = New SqlConnection("Data Source=PRINCES\QLEXPRESS;InitialCatalog=vicky;Integrated Security=True")
sqlcomm = New SqlCommand("dbo.StoredProcedure1", sqlconn)
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@name", TextBox1.Text)
sqlcomm.Parameters.AddWithValue("@regno", TextBox2.Text)
sqlcomm.Parameters.AddWithValue("@dept", TextBox3.Text)
sqlconn.Open()
sqlcomm.ExecuteNonQuery()
sqlconn.Close()
MessageBox.Show("inserted",”Data Inserted”)
    End Sub

    Private Sub delete_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
sqlconn = New SqlConnection("Data Source=PRINCE\SQLEXPRESS;InitialCatalog=vicky;Integrated Security=True")
sqlcomm = New SqlCommand("dbo.StoredProcedure3", sqlconn)
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@name", TextBox1.Text)
sqlconn.Open()
sqlcomm.ExecuteNonQuery()
sqlconn.Close()
MessageBox.Show("deleted",”Record Deleted”)
    End Sub
Private Sub update_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
sqlconn = New SqlConnection("Data Source=PRINCE\SQLEXPRESS;InitialCatalog=vicky;Integrated Security=True")
sqlcomm = New SqlCommand("dbo.StoredProcedure5", sqlconn)
sqlcomm.CommandType = CommandType.StoredProcedure
sqlconn.Open()
sqlcomm.Parameters.AddWithValue("@name", TextBox1.Text)
sqlcomm.Parameters.AddWithValue("@regno", TextBox2.Text)
sqlcomm.Parameters.AddWithValue("@dept", TextBox3.Text)
        Try
sqlcomm.ExecuteNonQuery()
        Catch ex As SqlException
        Catch ex As Exception
        Finally
            If IsNothing(sqlcomm) = False Then
sqlcomm.Dispose()
sqlcomm = Nothing
            End If
sqlconn.Close()
        End Try
MessageBox.Show("Updated", "Record Updated")
    End Sub
End Class
   Private Sub select_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
sqlconn = New SqlConnection("Data Source=PRINCE\SQLEXPRESS;InitialCatalog=vicky;Integrated Security=True")
sqlcomm = New SqlCommand("dbo.StoredProcedure6", sqlconn)
sqlcomm.CommandType = CommandType.StoredProcedure
sqlconn.Open()
sqldaat.SelectCommand = sqlcomm
sqldaat.Fill(ds, "dbo.StoredProcedure6")
sqlconn.Close()
    End Sub
Private Sub exit_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        End
    End Sub
Create Database:
Create database student;
Create Table:
Create table std(name nvarchar(50), regnoint, deptnvarchar(50));
STORED PROCEDURE:
Insert:
ALTER PROCEDURE dbo.StoredProcedure1
            @name nvarchar(50),@regnoint,@deptnvarchar(50)
AS
insert into std values(@name,@regno,@dept)
            RETURN

Delete:

ALTER PROCEDURE dbo.StoredProcedure3
            @name nvarchar(50)
AS
delete from std where @name=name
            RETURN

Update:
ALTER PROCEDURE dbo.StoredProcedure5
            @name nvarchar(50),@regnoint,@deptnvarchar(50)
AS
updatestd set name=@name,regno =@regno,dept=@dept where name=@name
            RETURN

Select:
ALTER PROCEDURE dbo.StoredProcedure6
            @name nvarchar(50)
AS
select* from std where name=@name

            RETURN

PAYMENT DETAIL USING ASP.NET

PROGRAM:

HTML Codes:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>PAYMENT DETAILS</h1>
</div>
<div>
 Name<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Quantity<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
 Rate<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
Gross Amount<asp:TextBox ID="TextBox4"runat="server"></asp:TextBox>
<br />
<br />
        Discount<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<br />
<br />
 Net Amount <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="Calculate" />
</div>
</form>
</body>

</html>

C# Code:

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
    {
    }
protected void Button1_Click(object sender, EventArgs e)
    {
int a, b, c;
float x, y;
        a = Convert.ToInt32(TextBox2.Text);
        b = Convert.ToInt32(TextBox3.Text);
        c = a * b;
        x = c * 10 / 100;
        y = c - x;
        TextBox4.Text = c.ToString();
        TextBox5.Text = x.ToString();
        TextBox6.Text = y.ToString();
    }
}

VOTERS (EXCEPTION HANDLING)

PROGRAM:

Module Module1

    Sub Main()
        Dim vname As String
        Dim age As Integer
        Try
            Console.Write("Enter your Name:")
            vname = Console.ReadLine()
            Console.Write("Enter your Age:")
            age = Int32.Parse(Console.ReadLine())
            If (age >= 18) Then
                MsgBox("Hi Your age is greater than 18, so you are eligible for vote")
            Else
                MsgBox("Sorry  Your age is less than 18, so you are not eligible for vote")
            End If
        Catch ex As Exception
            Console.WriteLine("Exception is:" & ex.Message)
            Console.ReadLine()
        End Try
               

    End Sub


End Module

EMPLOYEE DETAILS USING VB.NET

PROGRAM:

Public Class Form1
    Private Sub Label5_Click(sender As Object, e As EventArgs) Handles Label5.Click
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox7.Text = (Val(TextBox5.Text) - (Val(TextBox6.Text)))
MsgBox("Hi! " & TextBox1.Text &" your Net Salary is Rs" & TextBox7.Text)
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
        TextBox5.Text = (Val(TextBox2.Text) + (Val(TextBox3.Text) + (Val(TextBox4.Text))))
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        End
    End Sub

End Class

DESIGN A CALCULATOR USING VB.NET

PROGRAM:

Declaration command
Public Class Form1

    Inherits System.Windows.Forms.Form
    Dim num1 As Double
    Dim num2 As Double
    Dim result As Double
    Dim add As Boolean
    Dim sb As Boolean
    Dim mul As Boolean
    Dim div As Boolean


Form command

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = " "
        add = sb = mul = div = False

    End Sub

Buttons command

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        TextBox1.Text = TextBox1.Text + Button1.Text
        num1 = TextBox1.Text

    End Sub

    Private Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        TextBox1.Text = TextBox1.Text + Button4.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        TextBox1.Text = TextBox1.Text + Button2.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        TextBox1.Text = TextBox1.Text + Button3.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button7.Click
        TextBox1.Text = TextBox1.Text + Button7.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
        TextBox1.Text = TextBox1.Text + Button5.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button8.Click
        TextBox1.Text = TextBox1.Text + Button8.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button6.Click
        TextBox1.Text = TextBox1.Text + Button6.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button9_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button9.Click
        TextBox1.Text = TextBox1.Text + Button9.Text
        num1 = TextBox1.Text
    End Sub

    Private Sub Button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button11.Click
        TextBox1.Text = TextBox1.Text + Button11.Text
        num1 = TextBox1.Text
    End Sub


OFF Button
    Private Sub Button12_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button12.Click
        TextBox1.Text = " "
        num1 = 0
        result = 0
        add = False
        sb = False
        mul = False
        div = False
        num2 = 0
    End Sub

Equal button

    Private Sub Button17_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button17.Click
        If add Then
            result = num1 + num2
        End If
        If sb Then
            result = num2 - num1
        End If
        If mul Then
            result = num1 * num2
        End If
        If div Then
            result = num2 / num1
        End If
        TextBox1.Text = result
        num1 = result
    End Sub

Div button

    Private Sub Button16_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button16.Click
        div = True
        num2 = num1
        num1 = 0
        TextBox1.Text = " "
    End Sub

Add button
    Private Sub Button13_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button13.Click
        add = True
        num2 = num1
        TextBox1.Text = " "
    End Sub

Sub button

    Private Sub Button14_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button14.Click
        sb = True
        num2 = num1
        num1 = 0
        TextBox1.Text = " "
    End Sub

Mul button

    Private Sub Button15_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button15.Click
        mul = True
        num2 = num1
        num1 = 0
        TextBox1.Text = " "
    End Sub


AC Button
    Private Sub Button10_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button10.Click
        TextBox1.Text = " "
        num1 = 0
        result = 0
        add = False
        sb = False
        mul = False
        div = False
        num2 = 0
    End Sub


End Class