0% found this document useful (0 votes)
24 views21 pages

Part A PrintOut

Bigg Boss season la ya ellam pota tym iruke la pinna ethuke dii inike onum illa

Uploaded by

ramsheet74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views21 pages

Part A PrintOut

Bigg Boss season la ya ellam pota tym iruke la pinna ethuke dii inike onum illa

Uploaded by

ramsheet74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

III SEM BCA C# and .

NET Framework Lab - PART A

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 Text Box/Label. Perform validation for empty
input, non-numeric input, as well as negative input and display error message, accordingly
using a message box

To Start Visual Studio -> Create New Project -> Visual Basic -> Windows Forms
Application

Design:

Properties:
Control Property Value

Name TxtNum
TextBox1
Text “”

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Label2 Name LblFact

Name BtnFact
Button1
Text Factorial

Name BtnClear
Button2
Text Clear

Name BtnExit
Button3
Text Exit

Code:Form1.vb
Public Class Form1
Private Sub BtnExit_Click(sender AsObject, e AsEventArgs) Handles BtnExit.Click
End
End Sub

Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click


TxtNum.Text = ""
LblFact.Text = Nothing
End Sub

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


LblFact.Visible = False
End Sub
Private Sub BtnFact_Click(sender As Object, e As EventArgs) Handles BtnFact.Click
Dim a, i A sInteger
Dim fact As Long = 1
'Validations
If TxtNum.Text = "" Then
MessageBox.Show("Textbox is empty", "Error", MessageBoxButtons.OK)
Else If IsNumeric(TxtNum.Text) = False Then
MessageBox.Show("Please enter only a number", "Error",
MessageBoxButtons.OK)
Else
a = Val(TxtNum.Text)
If a < 0 Then
MessageBox.Show("Enter only positive number", "Error",
MessageBoxButtons.OK)
Else
' Calculate the factorial
For i = 1 To a
fact = fact * i

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Next
' Display the result
LblFact.Visible = True
LblFact.Text = "Factorial of "& a &" is: "& fact.ToString()
End If
End If
End Sub
End Class

Output

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

2. Design a VB interface containing

a. A picture box whose picture should be changed every 5 second (use 5 pictures).
b. Textboxes to display date & time and day greeting based on time. Time has to be
changed every second automatically.
c. Use scrollbars to change the font size and background color (RGB) of the textbox
that shows the greeting. [Use timer, scrollbars]

To Start Visual Studio -> Create New Project -> Visual Basic -> Windows Forms Application

Design:

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Properties
Control Property Value

Name TxtTime
TextBox1
Text “”

Name TxtDay
TextBox2
Text “”

Name TxtGreeting
TextBox3
Text “”

Name HScrollRed
HScrollBar1 Minimum 0
Maximum 255
Name HScrollGreen
HScrollBar2 Minimum 0
Maximum 255
Name HScrollBlue
HScrollBar3 Minimum 0
Maximum 255
Name VScrollFont
VScrollBar1 Minimum 8
Maximum 24
Interval 5000
Timer1
Enabled True
Interval 1000
Timer2
Enabled True
Picture1 SizeMode StretchImage
ImageList1 Image Add five images
Name BtnExit
Button1
Text Exit

Code:Form1.vb
Public Class Form1
Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
End
End Sub

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

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

TxtDay.Text = Today
TxtTime.Text = TimeOfDay
Dim t As Integer
t = Date.Now.ToString("HH")
If (t >= 1 And t < 12) Then
TxtGreeting.Text = "GOOD MORNING"
Else If (t >= 12 And t < 16) Then
TxtGreeting.Text = "GOOD AFTERNOON"
Else If (t >= 16 And t < 20) Then
TxtGreeting.Text = "GOOD EVENING"
Else
TxtGreeting.Text = "GOOD NIGHT"
End If
Timer1.Start()

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


Static i As Integer
If i < ImageList1.Images.Count - 1 Then
i=i+1
Else
i =0
End If
PictureBox1.Image = ImageList1.Images(i)
End Sub

Private Sub HScrollRed_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollRed.Scroll


TxtGreeting.BackColor = Color.FromArgb(HScrollRed.Value, HScrollGreen.Value,
HScrollBlue.Value)
End Sub

Private Sub HScrollGreen_Scroll(sender As Object, e As ScrollEventArgs) Handles


HScrollGreen.Scroll
TxtGreeting.BackColor = Color.FromArgb(HScrollRed.Value, HScrollGreen.Value,
HScrollBlue.Value)
End Sub

Private Sub HScrollBlue_Scroll(sender As Object, e As ScrollEventArgs) Handles


HScrollBlue.Scroll
TxtGreeting.BackColor = Color.FromArgb(HScrollRed.Value, HScrollGreen.Value,
HScrollBlue.Value)
End Sub

Private Sub VScrollFontSize_Scroll(sender As Object, e As ScrollEventArgs) Handles


VScrollFontSize.Scroll
TxtGreeting.Font = New Font(TxtGreeting.Font.FontFamily,

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

VScrollFontSize.Value)
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
TxtTime.Text = TimeOfDay.ToString("hh:mm:ss tt")

End Sub
End Class

Output:

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

3. Design a VB interface to add, remove, search, and clear the items in a combo box. The item
name to be added, removed, or searched can be accepted through the input box. Use a general
procedure to find the existence of an item before deleting or while searching.

To StartVisual Studio -> Create New Project -> Visual Basic -> Windows Forms Application

Design

Properties
Control Property Value

Name CmbItem

ComboBox1 Text “”

DropDownStyle Simple

Name BtnAdd
Button1
Text Add

Name BtnRemove
Button2
Text Remove

Name BtnSearch
Button3
Text Search

BtnClear
Button4
Text Clear

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Name BtnExit
Button5
Text Exit

Code: Form1.vb
Public Class Form1
Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click
Dim newitem As String
newitem = Trim(InputBox("Enter the Item to be added"))
If String.IsNullOrEmpty(newitem) Then
MessageBox.Show("Item cannot be empty")
Else
If Not Check_Item(newitem) Then
CmbItem.Items.Add(newitem)
Else
MessageBox.Show("Item already exist")
End If
End If
End Sub

Function Check_Item(ByVal i As String) As Boolean


Return CmbItem.Items.Contains(i)
End Function

Private Sub BtnSearch_Click(sender As Object, e As EventArgs) Handles BtnSearch.Click


Dim i As String
i = Trim(InputBox("Enter the Item to be searched"))
If Check_Item(i) Then
MessageBox.Show("Item is found in the combo box")
Else
MessageBox.Show("Item not found in the combo box")
End If
End Sub

Private Sub BtnRemove_Click(sender As Object, e As EventArgs) Handles BtnRemove.Click


Dim i As String
i = Trim(InputBox("Enter the Item to be removed/deleted"))
If Check_Item(i) Then
CmbItem.Items.Remove(i)
MessageBox.Show("Item deleted sussessfully")
Else
MessageBox.Show("Item not found in the combo box")
End If
End Sub

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click


End
End Sub

Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click


CmbItem.Items.Clear()
End Sub
End Class
Output

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

4. Write a VB program to find the GCD and LCM of two numbers. Accept input through the
textbox and display the results in a label. Also validate for invalid input such as empty input,
nonnumeric, and negative integer.

To Start Visual Studio -> Create New Project -> Visual Basic -> Windows Forms
Application
Design :

Properties:

Control Property Value

Name TxtNum1
TextBox1
Text “”

Name TxtNum2
TextBox1
Text “”

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Name LblGCD
Label1
Text First Number

Name LblLCM
Label2
Text Second Number

Name BtnCalc
Button1
Text Calculate

Name BtnClear
Button2
Text Clear

Name BtnExit
Button3
Text Exit

Code:Form1.vb

Public Class Form1


Private Sub BtnExit_Click(sender As Object, e As EventArgs) HandlesBtnExit.Click
End
End Sub
Private Sub BtnCalc_Click(sender As Object, e As EventArgs) Handles BtnCalc.Click
Dim a, b, i, gcd, lcm As Integer
If IsNumeric(Txtnum1.Text) = False Or IsNumeric(Txtnum2.Text) = False Or
Txtnum1.Text = " " Or Txtnum2.Text = "" Then
MessageBox.Show("Textbox should not be empty And Please enter only number ",
"Important note", MessageBoxButtons.OK)
Else
a = Convert.ToInt32(Txtnum1.Text)
b = Convert.ToInt32(Txtnum2.Text)
If a <= 0 Or b <= 0 Then
MessageBox.Show("Please enter only positive number", "Important note",
MessageBoxButtons.OK)
Else
i=1
If a = 0 Or b = 0 Then
gcd = 0
LblGCD.Text = "GCD:" + CStr(gcd)
Exit Sub
End If
Do While ((i <= a) Or (i <= b))
If ((a Mod i) = 0) And ((b Mod i) = 0) Then
gcd = i
End If
i=i+1

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Loop
LblGCD.Text = "GCD:" + CStr(gcd)
lcm = (a * b) / gcd
LblLCM.Text = "LCM:" + CStr(lcm)
End If
End If
End Sub
Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
Txtnum1.Text = ""
Txtnum2.Text = ""
LblGCD.Text = ""
LblLCM.Text = ""
End Sub
End Class

Output:

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

5. Write a Program in C# to check a number if it is Prime; otherwise display the factor of that
number.

To Start Visual Studio -> Create New Project -> C# -> Console Application

Code:

using System;
usingSystem.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Prime
{
Internal class Program
{
ptatic void Main(string[] args)
{
int n;
bool isPrime = true;
Console.WriteLine("Enter a number");
n = int.Parse(Console.ReadLine());
if (n < 2)
Console.WriteLine("Given number is not a prime number");
else
{
for(int i=2; i<=Math.Sqrt(n); i++)
{
if (n % 2 == 0)
{
isPrime = false;
break;

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

}
if (isPrime)
Console.WriteLine("Given number is a prime number");
else
{
Console.WriteLine("Given number is not a prime number\nIt's factors are");
Console.Write(1);
for(int i=2; i<=n/2; i++)
{
if (n % i == 0)
Console.Write(" "+i);

}
}

}
Console.ReadKey();
}
}}

Output

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

6. Write a Program in C# define a Class “Salary” which will contain member variables
Emp_no, Emp_name, Dob, and Basic Write a program using a constructor and method to
calculate the DA, HRA, PF, IT, GROSS, and NETPAY using appropriate condition.
If Basic <= 20000 D.A is 40% Basic H.R.A is 10% Basic.
P.F 12% of Gross; PT is Rs .100
If Basic.> 20000 D.A is 50% Basic. H.R.A 15% Basic. P.F
12% of Gross ; PT is Rs.150
Gross = Basic.+ D.A +HRA and Net = Gross -PT –PF

To Start Visual Studio -> Create New Project -> C# -> Console Application

Code:
namespace Employee
{
Internal class Salary
{
private int Emp_no;
private string Emp_name;
private string Dob;
private double Basic;

// Constructor to initialize member variables


public Salary(int empNo, string empName, string dob, double basic)
{
Emp_no = empNo;
Emp_name = empName;
Dob = dob;

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Basic = basic;
}
private void Calculate()
{
double da_pay, hra_pay, grosspay, pf, pt, netpay;
if (Basic <= 20000)
{
da_pay = 0.4 * Basic;hra_pay = 0.1 * Basic;
grosspay = Basic + da_pay + hra_pay;
pf = 0.12 * grosspay;
pt = 100;
netpay = grosspay - pf - pt;
}
else
{
da_pay = 0.5 * Basic;
hra_pay = 0.15 * Basic;
grosspay = Basic + da_pay + hra_pay;
pf = 0.12 * grosspay;
pt = 150;
netpay = grosspay - pf - pt;
}
Console.WriteLine("==================================");
Console.WriteLine(" Salary Details ");
Console.WriteLine("==================================");
Console.WriteLine("EmpID : "+ Emp_no);
Console.WriteLine("EmpName : "+ Emp_name);
Console.WriteLine("Basic Pay : "+ Basic);
Console.WriteLine("DA : "+ da_pay);
Console.WriteLine("HRA : "+ hra_pay);
Console.WriteLine("Gross Pay : "+ grosspay);
Console.WriteLine("PT : "+ pt);
Console.WriteLine("PF : "+ pf);
Console.WriteLine("NetPay : " + netpay);

}
// Main method for testing
static void Main(string[] args)
{
Console.Write("Employee ID : ");
int empid = int.Parse(Console.ReadLine());
Console.Write("Employee Name : ");
string empname = Console.ReadLine();
Console.Write("Employee DOB: ");
string empdob = Console.ReadLine();
Console.Write("Basic Pay: ");
double empsal = double.Parse(Console.ReadLine());

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Salary emp1 = new Salary(empid,empname,empdob,empsal);


emp1.Calculate();
Console.ReadKey();
}
}

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

7. Write a Program in C# to find addition and Multiplication operations on two complex


numbers using operator overloading.

To Start Visual Studio -> Create New Project -> C# -> Console Application

Code:
\
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Complex
{
public int real;
public int img;
public void Value(Complex a,Complex b)
{

Console.WriteLine("Enter real and an imaginary part of two complex number ..");

a.real = int.Parse(Console.ReadLine());
a.img = int.Parse(Console.ReadLine());
b.real = int.Parse(Console.ReadLine());
b.img = int.Parse(Console.ReadLine());

}
public Complex()
{

public static Complex operator +(Complex ob1, Complex ob2)


{

Complex temp = new Complex();


temp.real = ob1.real + ob2.real;
temp.img = ob1.img + ob2.img;
return temp;

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

}
public static Complex operator *(Complex ob1, Complex ob2)
{

Complex temp = new Complex();


temp.real = (ob1.real * ob2.real) - (ob1.img * ob2.img);
temp.img = (ob1.real * ob2.img) + (ob1.img * ob2.real);
return temp;
}

public void Print()


{
Console.WriteLine("{0}+{1}i", real, img);
}

public static void Main()


{

Complex c1 = new Complex();


Complex c2 = new Complex();

Complex c3, c4;


c1.Value(c1, c2);

c3 = c1 + c2;

c4 = c1 * c2;

Console.Write(" Sum of two Complex Number is : ");


c3.Print();
Console.Write(" Multiplication of two Complex Number is : ");

c4.Print();

Console.ReadLine();
}
}

Page No:
III SEM BCA C# and .NET Framework Lab - PART A

Output:

Page No:

You might also like