BCA III sem-C# & .NET Framework-Lab programs
BCA III sem-C# & .NET Framework-Lab programs
In-charge
EVELIN JACOB
using System;
namespace ConditionalStatementsDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Conditional Statements Demo in C#");
if (isNumber)
{
// if-else statement
if (number > 0)
{
Console.WriteLine("The number is positive.");
}
else if (number < 0)
{
Console.WriteLine("The number is negative.");
}
else
{
Console.WriteLine("The number is zero.");
}
// switch statement
switch (number)
{
case 1:
Console.WriteLine("The number is one.");
break;
case 2:
Console.WriteLine("The number is two.");
break;
case 3:
Console.WriteLine("The number is three.");
break;
default:
Console.WriteLine("The number is not one, two, or three.");
break;
}
}
else
{
Console.WriteLine("Invalid input! Please enter a valid integer.");
}
// End of program
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
2. Develop a C# .NET console application to demonstrate the control statements.
using System;
namespace ControlStatementsDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Control Statements Demo in C#");
// End of program
Console.WriteLine("\nPress any key to exit.");
Console.ReadKey();
}
}
}
3. Develop an application in C#.NET that demonstrates the windows controls
using System;
using System.Windows.Forms;
namespace WindowsControlsDemo
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
using System;
using System.Threading;
namespace MultithreadedProgrammingDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Multithreaded Programming Demo in C#");
namespace SubroutinesAndFunctionsDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Subroutines and Functions Demo in C#");
Here is an example of the code that demonstrates various built-in functions in VB.NET:
' Round
Dim rounded As Double = Math.Round(number)
MessageBox.Show("Rounded Value: " & rounded, "Math Operations")
To develop an MDI (Multiple Document Interface) application for Employee Payroll transactions in
VB.NET, you can follow these steps. This example will create a basic MDI application where you can
manage employee information and payroll transactions.
- In the `MDIParentForm` code, add event handlers for the menu items to open the child forms. Here’s an
example:
```vb
Public Class MDIParentForm
Private Sub NewEmployeeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
NewEmployeeToolStripMenuItem.Click
' Open the EmployeeForm as a child form
Dim empForm As New EmployeeForm()
empForm.MdiParent = Me
empForm.Show()
End Sub
End Class
```
1. **EmployeeForm:**
- Design the form with labels and text boxes for employee details such as Employee ID, Name,
Department, etc.
- Add buttons for saving and closing the form.
2. **PayrollForm:**
- Design the form with labels, text boxes, and combo boxes for payroll details such as Employee ID,
Salary, Tax deductions, etc.
- Add buttons for processing the payroll and closing the form.
This basic MDI application structure provides a foundation for developing a more complex Employee
Payroll system in VB.NET.
8. Construct a console application to demonstrate the OOP Concepts
To demonstrate Object-Oriented Programming (OOP) concepts in a C# console application, we'll create a
simple application that models an Employee and a Payroll system. The application will cover the four key
OOP concepts: **Encapsulation, Inheritance, Polymorphism,** and **Abstraction**.
1. **Encapsulation**: We'll encapsulate the employee's data within the `Employee` class, making the data
accessible only through public methods.
2. **Inheritance**: We'll create a `FullTimeEmployee` and a `PartTimeEmployee` class that inherit from
the `Employee` base class.
3. **Polymorphism**: We'll use method overriding to demonstrate polymorphism, where the same
method behaves differently in derived classes.
4. **Abstraction**: We'll use an abstract class `Employee` to force derived classes to implement specific
methods.
```csharp
using System;
namespace OOPConceptsDemo
{
// Abstraction: Abstract class Employee
abstract class Employee
{
// Encapsulation: Private fields
private int id;
private string name;
private string department;
// Constructor
public Employee(int id, string name, string department)
{
this.id = id;
this.name = name;
this.department = department;
}
// Constructor
public FullTimeEmployee(int id, string name, string department, double annualSalary)
: base(id, name, department)
{
this.annualSalary = annualSalary;
}
// Constructor
public PartTimeEmployee(int id, string name, string department, double hourlyRate, int
hoursWorked)
: base(id, name, department)
{
this.hourlyRate = hourlyRate;
this.hoursWorked = hoursWorked;
}
class Program
{
static void Main(string[] args)
{
// Create instances of FullTimeEmployee and PartTimeEmployee
FullTimeEmployee ftEmployee = new FullTimeEmployee(1, "John Doe", "Engineering", 120000);
PartTimeEmployee ptEmployee = new PartTimeEmployee(2, "Jane Smith", "Marketing", 40, 120);
### Explanation
1. **Encapsulation**:
- The `Employee` class encapsulates data by making fields private and exposing them through
properties. This protects the data from unauthorized access and modification.
2. **Abstraction**:
- The `Employee` class is an abstract class that defines common properties and methods for all
employees. It forces derived classes to implement the `CalculateSalary` method, which is specific to the
type of employee.
3. **Inheritance**:
- The `FullTimeEmployee` and `PartTimeEmployee` classes inherit from the `Employee` base class. They
reuse the properties and methods defined in `Employee` and add their own specific logic.
4. **Polymorphism**:
- The `DisplayEmployeeInfo` method is overridden in both `FullTimeEmployee` and
`PartTimeEmployee`. Despite being called the same way on both classes, it behaves differently based on
the object type.
2. **Output**:
- The output will display the employee details, showcasing the OOP concepts in action.
This application provides a clear demonstration of the key OOP concepts in C#. Each concept is applied in
a practical context, making it easier to understand how these principles can be used to structure and
organize code effectively.
9. Develop a web application in VB.NET for dynamic Login Processing
Creating a web application in VB.NET for dynamic login processing involves several steps, including
setting up the project, designing the user interface, and implementing the logic for authentication. Below
is a step-by-step guide to developing a simple login web application.
```html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Login</h2>
<asp:Label ID="lblUsername" runat="server" Text="Username:"></asp:Label>
<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox><br /><br />
<asp:Label ID="lblPassword" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox><br
/><br />
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" /><br
/><br />
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label>
</div>
</form>
</body>
</html>
```
```vb
Partial Class Login
Inherits System.Web.UI.Page
Example `Home.aspx`:
```html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Home</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Welcome to the Home Page!</h2>
</div>
</form>
</body>
</html>
```
To make the login dynamic, you should store usernames and passwords in a database. Here's a basic
outline of how to implement this:
1. **Set Up a Database:**
- Create a database (e.g., `UserDB`) in SQL Server.
- Create a table named `Users` with columns `Username` and `Password`.
```xml
<connectionStrings>
<add name="UserDBConnectionString"
connectionString="Data Source=.;Initial Catalog=UserDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
```
```vb
Imports System.Data.SqlClient
### Conclusion
This guide provides a fundamental example of how to create a dynamic login processing web application
in VB.NET. You can expand upon this by implementing more advanced features such as password hashing,
user roles, session management, and more robust error handling.
10. Develop a Windows application with database connectivity for core-banking transactions
Creating a Windows application in VB.NET for core-banking transactions with database connectivity
involves several steps. Below is a step-by-step guide to help you build a simple banking application that
allows users to perform basic banking operations like depositing and withdrawing funds, and viewing
account balances.
**Technologies Used:**
- VB.NET
- Windows Forms
- SQL Server (for database)
**Core Features:**
- User login
- Account balance inquiry
- Deposit funds
- Withdraw funds
1. **Create a Database:**
- Open SQL Server Management Studio (SSMS).
- Create a new database named `BankDB`.
- Create a table named `Accounts` with the following columns:
- `AccountID` (Primary Key, INT, Identity)
- `AccountNumber` (VARCHAR(20))
- `AccountHolderName` (VARCHAR(100))
- `Balance` (DECIMAL(18, 2))
USE BankDB;
1. **LoginForm Design:**
- Add `TextBox` controls for entering `AccountNumber`.
- Add a `Button` for login.
- Add a `Label` for displaying error messages.
' ... Designer code for text boxes, labels, and buttons ...
End Class
```
2. **LoginForm Code-Behind:**
- Add code to authenticate the user based on the `AccountNumber`.
End Class
```
2. **MainForm Code-Behind:**
- Implement the logic to handle button clicks, opening the transaction form, and displaying account
balance.
1. **TransactionForm Design:**
- Add `TextBox` controls for entering the transaction amount.
- Add a `Button` to submit the transaction.
' ... Designer code for text boxes, labels, and buttons ...
End Class
```
2. **TransactionForm Code-Behind:**
- Implement the logic for handling deposits and withdrawals.
2. **Test Scenarios:**
- Try logging in with a valid and invalid `AccountNumber`.
- Perform deposit and withdrawal transactions.
- Check if the balance updates correctly after each transaction.
### Conclusion
This Windows Forms application provides a basic implementation of core banking transactions. It
includes a login system, balance inquiry, deposit, and withdrawal functionality, all connected to a SQL
Server database. You can expand upon this by adding more features like transaction history, user
authentication, account creation, and more robust error handling.
Evaluation Scheme for Lab Examination:
Assessment Criteria Marks
Writing 2 Programs 10
Execution of 1 Program 10
Viva and Record 05
Total 25