RAKSHITHA-VB2[2]
RAKSHITHA-VB2[2]
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
PROGRAM 1: Design a VB form to accept a number and display its
factorial. Input is to be accepted using textbox and the output can be
displayed using textbox or label. Perform validation for empty input, non-
numeric input, as well as negative input and display error message
accordingly using a message box.
DESIGN VIEW:
PROGRAM CODE:
1
a = Val(TextBox1.Text)
If a < 0 Then
MessageBox.Show("Enter only positive number")
Else
For i = 1 To a
fact = fact * i
Next
Label1.Visible = True
Label1.Text = "Factorial of" & a & "is:" & fact.ToString()
End If
End If
End Sub
OUTPUT:
2
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
DESIGN VIEW:
PROGRAM CODE:
3
If (DateTime.Now.TimeOfDay.Hours >= 12 And
DateTime.Now.TimeOfDay.Hours <= 15) Then
Txtgreeting.Text = "GOOD AFTERNOON"
ElseIf (DateTime.Now.TimeOfDay.Hours > 15 And
DateTime.Now.TimeOfDay.Hours <= 20) Then
Txtgreeting.Text = "GOOD EVENING"
ElseIf (DateTime.Now.TimeOfDay.Hours > 20 And
DateTime.Now.TimeOfDay.Hours <= 24) Then
Txtgreeting.Text = "GOOD NIGHT"
Else
Txtgreeting.Text = "GOOD MORNING"
End If
End Sub
4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
End
End Sub
End Class
OUTPUT:
5
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
DESIGN VIEW:
PROGRAM CODE:
6
MsgBox("No Items")
End If
End Sub
Public Function check(ByVal a As String) As Boolean
If ComboBox1.Items.Contains(a) Then
Return True
Else
Return False
End If
End Function
7
OUTPUT:
8
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
DESIGN VIEW:
PROGRAM CODE:
9
MsgBox("Non numeric input.please enter number")
TxtNum1.Clear()
TxtNum1.Focus()
Exit Sub
End If
If Val(TxtNum1.Text) < 0 Then
MsgBox("Enter a positive number")
TxtNum1.Clear()
TxtNum1.Focus()
Exit Sub
End If
If Val(TxtNum2.Text) < 0 Then
MsgBox("Enter a positive integer")
TxtNum2.Clear()
TxtNum2.Focus()
Exit Sub
End If
Dim a, b, prod, lcm As Integer
a = Val(TxtNum1.Text)
b = Val(TxtNum2.Text)
prod = a * b
While a <> b
If a > b Then a = a - b
If b > a Then b = b - a
End While
lcm = prod / a
Label5.Text = a
Label6.Text = lcm
End Sub
10
Label5.Text = " "
Label6.Text = " "
End Sub
OUTPUT:
11
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prime_number
{
class Program
{
static void Main(string[] args)
{
int num, i, f = 0;
Console.Write("Enter a number.");
num = int.Parse(Console.ReadLine());
for (i = 1; i <= num; i++)
{
if (num % i == 0)
{
f++;
}
}
if (f == 2)
{
Console.WriteLine("Number is prime.");
}
else
{
Console.WriteLine("Number is not prime.");
int factor;
12
for(factor=1;factor<=num;factor++)
{
if(num%factor==0)
{
Console.Write(factor+",");
}
}
}
Console.ReadLine();
}
}
}
OUTPUT:
13
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace salary
{
class Program
{
public class salary
{
int emp_no;
string emp_name;
string dob;
double basic;
double da, hra, pf, pt, gross, netpay;
public salary(int no, string name, string db, double salary)
{
emp_no = no;
emp_name = name;
basic = salary;
dob = db;
da = 0;
14
hra = 0;
pf = 0;
pt = 0;
gross = 0;
netpay = 0;
}
void calculate(double basic)
{
if (basic <= 20000)
{
da = basic * 40 / 100;
hra = basic * 10 / 100;
gross = basic + da + hra;
pf = gross * 12 / 100;
pt = 100;
netpay = gross - pt - pf;
}
else if (basic > 20000)
{
da = basic * 50 / 100;
hra = basic * 15 / 100;
gross = basic + da + hra;
pf = gross * 12 / 100;
pt = 150;
netpay = gross - pt - pf;
}
}
void display()
{
Console.WriteLine("Employee Number:" + emp_no);
Console.WriteLine("Employee Name:" + emp_name);
Console.WriteLine("Date of birth:" + dob);
Console.WriteLine("salary:" + basic);
Console.WriteLine("dearness allowances:" + da);
Console.WriteLine("house rent allowance:" + hra);
Console.WriteLine("provident fund:" + pf);
Console.WriteLine("gross salary:" + gross);
Console.WriteLine("professional tax:" + pt);
Console.WriteLine("net salary:" + netpay);
}
15
static void Main(string[] args)
{
int empno;
string empname, dob;
double salary;
Console.WriteLine("enter your employee no:");
empno = int.Parse(Console.ReadLine());
Console.WriteLine("enter your name");
empname = Console.ReadLine();
Console.WriteLine("enter your date of birth dd-mm-yy:");
dob = Console.ReadLine();
Console.WriteLine("enter your salary:");
salary = double.Parse(Console.ReadLine());
salary sal = new salary(empno, empname, dob, salary);
sal.calculate(salary);
sal.display();
System.Console.ReadLine();
}
}
}
}
OUTPUT:
16
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace complex
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the first real and imaginary number");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the second real and imaginary number");
int c = int.Parse(Console.ReadLine());
int d = int.Parse(Console.ReadLine());
complex c1 = new complex(a, b);
complex c2 = new complex(c, d);
complex c3 = new complex();
c3 = c1 + c2;
c3.Display();
complex c4 = new complex();
c4 = c1 * c2;
c4.Display();
Console.ReadKey();
}
}
public class complex
17
{
int real;
int img;
public complex(int r=0,int i=0)
{
real=r;
img=i;
}
public static complex operator+(complex c1,complex c2)
{
complex c3=new complex();
c3.real=c1.real+c2.real;
c3.img=c1.img+c2.img;
return c3;
}
public static complex operator*(complex c1,complex c2)
{
complex c3=new complex();
c3.real=c1.real*c2.real-c1.img*c2.img;
c3.img=c1.real*c2.img+c1.img*c2.real;
return c3;
}
public void Display()
{
Console.WriteLine(real+"+i"+img);
}
}
}
OUTPUT:
18
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
DESIGN VIEW:
PROGRAM CODE:
19
If flag = True Then
TextBox1.Text = Button1.Text
flag = False
Else
TextBox1.Text &= Button1.Text
End If
End Sub
20
Else
TextBox1.Text &= Button5.Text
End If
End Sub
21
TextBox1.Text = Button9.Text
flag = False
Else
TextBox1.Text &= Button9.Text
End If
End Sub
22
TextBox1.Text &= Button13.Text
End If
End Sub
23
End Select
TextBox1.Text = result
flag = True
End Sub
OUTPUT:
24
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
DESIGN VIEW:
PROGRAM CODE:
25
Else
GroupBox2.Visible = False
GroupBox3.Visible = True
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
GroupBox1.Visible = False
End Sub
26
RadioButton4.Text = "Integrating development environment"
cans(i) = 3
End Sub
27
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
i=4
changestatus()
clicked = sender
Label2.Text = "5.Keyboard shortcut key to select the entire document in
ms word"
With ComboBox1.Items
.Add("ctrl+c")
.Add("ctrl+v")
.Add("ctrl+A")
.Add("ctrl+k")
End With
cans(i) = 3
End Sub
28
Dim os As Integer
If i < 4 Then
If RadioButton1.Checked Then os = 1
If RadioButton2.Checked Then os = 2
If RadioButton3.Checked Then os = 3
If RadioButton4.Checked Then os = 4
Else : os = ComboBox1.SelectedIndex + 1
End If
If cans(i) = os Then
score = score + 20
End If
End Sub
End Class
OUTPUT:
29
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
When the Add button is clicked, one row gets added to the table. When the
preview button is pressed data from the table is to be displayed in a grid
view.
DESIGN VIEW:
PROGRAM CODE:
Imports System.Text.RegularExpressions
Imports System.Data.SqlClient
End Sub
31
Else
gender = "female"
End If
If (CheckBox1.Checked) Then hobbies = "Reading"
If CheckBox2.Checked Then hobbies += "Painting"
If CheckBox3.Checked Then hobbies += "Singing"
con.Open()
com = New SqlCommand("insert into student values('" + TextBox1.Text +
"','" + DateTimePicker1.Value.Date + "','" + gender + "','" + TextBox2.Text + "','"
+ ComboBox1.SelectedItem + "','" + hobbies + "')", con)
com.ExecuteNonQuery()
MsgBox("STUDENT DETAILS INSERTED TO DATABASE")
con.Close()
End Sub
32
CheckBox2.Checked = False
CheckBox3.Checked = False
End Sub
End Class
OUTPUT:
33
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
DESIGN VIEW:
PROGRAM CODE:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds, ds1 As New DataSet
Dim bds As New BindingSource
Dim dr As SqlDataReader
Dim str As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
34
Dim constr As String = "Data
Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\BCA-LAB.BCA-
LAB030\Documents\author.mdf;Integrated Security=True;Connect
Timeout=30"
con.ConnectionString = constr
da = New SqlDataAdapter("select* from Book", con)
da.Fill(ds, "table1")
bds.DataSource = ds
bds.DataMember = "table1"
TextBox1.DataBindings.Add("text", bds, "Author'sName")
TextBox2.DataBindings.Add("text", bds, "Title")
TextBox3.DataBindings.Add("text", bds, "Price")
End Sub
35
If bds.Position = 0 Then
MsgBox("first record")
End If
End Sub
36
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
con.Close()
str = InputBox("Enter the title to be deleted")
cmd.CommandText = "select*from Book where title=' " + str + " '"
cmd.Connection = con
con.Open()
dr = cmd.ExecuteReader()
dr.Read()
If dr.HasRows Then
con.Close()
cmd.CommandText = "delete from Book where title=' " + str + " ' "
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("record deleted")
Else
MsgBox("no record")
End If
End Sub
37
OUTPUT:
38
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
DESIGN VIEW:
PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
39
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
40
OUTPUT:
41
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
PROGRAM 6: Create a web application to insert records into a database
table having the following fields ( EmpId, EmpName, DeptName, Salary).
Update any employee's salary and increment it to 15% of the present
salary. Perform the delete operation on 1 row of the database table.
DESIGN VIEW:
PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace EMPLOYEE1
{
public partial class WebForm1 : System.Web.UI.Page
{
42
{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\v11.0;AttachDbFilename=C:\Rakshitha\EMPLOYEE1\EMPLO
YEE1\App_Data\DatabaseEMP.mdf;Integrated Security=True");
SqlCommand cmd;
string str = "insert into emp values('" + TextBox1.Text + "','" +
TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + ")";
cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Label1.Text = "User Added";
GridView1.DataBind();
}
}
}
43
OUTPUT:
44
****************************************************************
NAME : RAKSHITHA
REG NO : U05SP22S0032
****************************************************************
Example1)
i/p) abcdefcdhycd,cd
o/p) befhy
Example2)
i/p) kumarkumar,kum
o/p) ara
45
PROGRAM CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Text.RegularExpressions;
namespace Search
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
46
textOutput.Text = sb.ToString();
}
47
OUTPUT:
48