Posts

Showing posts from December, 2014

Run length encoding in C++

#include<conio.h> #include<iostream.h> #include<string.h> void main() {  clrscr();  char str[10];  cout<<"\n Enter the word: ";  cin>>str;  cout<<"\n After Run length encoding: \n";  int count=1;  for(int i=0;i<strlen(str);i++)  {     if(str[i]==str[i+1])     {      count+=1;     }     else     {      if(count==1)      {       cout<<str[i];      }      else      {        cout<<str[i]<<count;        count=1;      }     }  }  getch(); }

Entropy code in C++

#include<iostream.h> #include<conio.h> #include<string.h> #include<math.h> void main() { int c; float p[5]; float H=0.0; clrscr(); char str[5]; cout<<"Enter text: "; cin>>str; for(int i=0;i<strlen(str);i++) {   cout<<"\n Enter probabilty of "<<str[i];   cin>>p[i];   H+=(-1)*p[i]*(log(p[i])/log(2.0)); } cout<<"\n Entropy of the given message : "<<H; getch(); }

Average number of bits per codeword in C++

#include<iostream.h> #include<conio.h> #include<math.h> #include<string.h> void main() {   clrscr();   char str[5];   float freq[5];   float code[5];   float avg[5];   cout<<"\n Enter the text: ";   cin>>str;   for(int i=0;i<strlen(str);i++)   {     cout<<"\n Enter frequency of  "<<str[i]<<" ";     cin>>freq[i];     cout<<"\n Enter length  of codeword  "<<str[i]<<" ";     cin>>code[i];     avg[i]=freq[i]*code[i];   }   for(i=0;i<strlen(str);i++)   {       cout<<"\n Average number of bits for "<<str[i]<<" : "<<avg[i];   }   getch(); }

Compression ratio, Compression factor, saving percentage in C++

#include<iostream.h> #include<conio.h> void main() { float ori,aft; float CR,CF,SP; clrscr(); cout<<"\nEnter the size of the source file : "; cin>>ori; cout<<"\nEnter the size of the compressed file : "; cin>>aft; CR=aft/ori; CF=ori/aft; SP=((ori-aft)/ori)*100; cout<<" Compression Ratio = "<<CR; cout<<"\n Compression Factor = "<<CF; cout<<"\n Saving percentage = "<<SP<<" %"; getch(); }

Interface in VB.net

Image
On button click: Public Class Interface_form     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Dim obj As New classInterface         obj.add(TextBox1.Text, TextBox2.Text)     End Sub End Class Create an interface and write the code below: Public Interface Interface1     Sub add(ByVal n1 As Integer, ByVal n2 As Integer) End Interface Public Class classInterface     Implements Interface1     Public Sub add(ByVal n1 As Integer, ByVal n2 As Integer) Implements Interface1.add         MsgBox("Sum is : " & n1 + n2)     End Sub End Class

Exception Handling in VB.net

Image
Source Code: Public Class Form1     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         'Dim str As String = TextBox1.Text         Try             If (TextBox1.Text = "") Then                 Throw (New exc("Empty Values"))             Else                 MsgBox(TextBox1.Text)             End If         Catch ex As exc             MsgBox(ex.Message)         End Try              End Sub End Class Public Class exc : Inherits ApplicationException     Sub New(ByVal msg As String)         MyBase.New(msg)     End Sub En...

Working with database in Vb.net

Image
Fig: Design (grey square is the gridview) Source Code: Imports System.Data Imports System.Data.SqlClient Public Class Database_Connectivity     Dim conn As New SqlConnection("Data Source=.;Initial Catalog=practice ete;Integrated Security=True;Pooling=False") 'Inserting data     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         conn.Open()         Dim str As String = "insert into Table1 values(@id,@name,@age,@phone)"         'Dim str As String = "alter table Table1 add phone int"         Dim comm As New SqlCommand()         comm = New SqlCommand(str, conn)         comm.Parameters.AddWithValue("@id", TextBox1.Text)         comm.Parameters.AddWithValue("@name", TextBox2.Text)         comm.Parameters.AddWithValue("@age", ...

Number and Alphabets Validation in VB.Net

Image
Fig: Design Source Code: Public Class Validation     Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress           If (IsNumeric(e.KeyChar()) Or (Asc(e.KeyChar()) = 8)) Then             e.Handled = False         Else             e.Handled = True             MsgBox("Enter only digits")         End If     End Sub     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         If (String.IsNullOrEmpty(TextBox1.Text)) Then             ErrorProvider1.SetError(TextBox1, "Required field")         End If     End Sub     Privat...