Part A PrintOut
Part A PrintOut
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
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
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
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
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
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
Page No:
III SEM BCA C# and .NET Framework Lab - PART A
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:
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
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;
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
Page No:
III SEM BCA C# and .NET Framework Lab - PART A
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)
{
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()
{
Page No:
III SEM BCA C# and .NET Framework Lab - PART A
}
public static Complex operator *(Complex ob1, Complex ob2)
{
c3 = c1 + c2;
c4 = c1 * c2;
c4.Print();
Console.ReadLine();
}
}
Page No:
III SEM BCA C# and .NET Framework Lab - PART A
Output:
Page No: