C#Program
C#Program
PROGRAM LIST
PART A
1. Develop a C# .NET console application to demonstrate the conditional statements
2. Develop a C# .NET console application to demonstrate the control statements
3. Develop an application in C#. NET that demonstrates the window controls
4. Demonstrate Multithreaded Programming in C#.NET
5. Demonstrate subroutines and functions in C#.Net
6. Develop an application for deploying various built-in functions in VB .Net
7. Develop an MDI application for Employee Pay-roll transactions in VB.NET
8. Construct a console application to demonstrate the OOP Concepts
9. Develop a web application in VB.NET for dynamic Login Processing
10. Develop a Windows application with database connectivity for core-banking
transactions
PART B
1. C# console program to check whether the number is palindrome or not
2. C# console program to display Factorial of a number
3. Write a C# Program for Dental Payment Form. Calculate total on selected options
from check boxes.
4. Write a C# Program to display the reverse of a given number using function. (Accept
number through textbox and display result using message box)
8. Write a VB.Net program to calculate the sum of all elements of an integer array
9. Write a Vb.net program to accept a string from keyboard and count the number of
vowels
10. Create a windows Login application with database connectivity in C#.
2
PART A
1. Develop a C# .NET console application to demonstrate the
conditional statements
using System;
namespace pg1
{
class Program
{
static void Main(string[] args)
{
case 2:
case 3:
default:
Console.WriteLine("invalid");
break;
}
}
}
4
2. Develop a C# .NET console application to demonstrate the
control statements
using System;
namespace pg2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter your choice to demonstrate");
Console.WriteLine("1:while \t 2: do-while \t 3:for 4:foreach");
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
break;
case 2:
Console.WriteLine("Demonstrating do while :display numbers 1 to
5");
int x = 1;
do
{
Console.WriteLine("i = {0}", x);
x++;
} while (x <=5);
break;
case 3:
case 4:
Console.WriteLine("Demonstrating foreach loop :read and sum the
elements in an array");
int[] b = new int[5];
int sum = 0;
Console.WriteLine("Enter 5 elements into array");
foreach (int j in b)
{
b[j] = Convert.ToInt32(Console.ReadLine());
sum += b[j];
}
Console.WriteLine(" the sum of elements of array are" + sum);
break;
default:
Console.WriteLine("invalid");
break;
}
}
}
}
6
3. Develop an application in C# . NET that demonstrates the
window controls
7
4. Demonstrate Multithreaded Programming in C#.NET
using System;
using System.Threading;
class Program {
ThreadObject2.Start();
Console.WriteLine("Thread1 Started");
Console.WriteLine("Thread1 Executing");
Thread.Sleep(5000); //Sleep is used to pause a thread and 5000 is MilliSeconds that means 5 Seconds
Console.WriteLine("Thread2 Started");
Console.WriteLine("Thread2 Executing");
Thread.Sleep(5000);
Output:
8
5. Demonstrate subroutines and functions in C#.Net
using System;
public class A
{
public static void Main(string[] args)
{
A ob=new A();
int sum;
ob.greetme(); // calls subroutine
Console.WriteLine ("Enter 2 numbers to add");
int a=Convert.ToInt32(Console.ReadLine());
int b=Convert.ToInt32(Console.ReadLine());
sum=ob.add(a,b); //calls function
Console.WriteLine ("sum is {0}",sum);
}
public void greetme() //This is a subroutine
{
Console.WriteLine ("Hello World");
}
public int add(int x, int y) // This is a function
{
int total=x+y;
return total;
}
}
9
6. Develop an application for deploying various built-in
functions in VB .Net
End Sub
10
MsgBox(i)
End Sub
11
7. Develop an MDI application for Employee Pay-roll
transactions in VB.NET
Add menu strip to the form, add the sub menus required.
To add new forms go to solution explorer right click on project name, click on add, then forms, create.
13
tax = ans * 0.15
TextBox5.Text = tax
phil = ans * 0.05
TextBox6.Text = phil
s = ans * 0.11
TextBox7.Text = s
deduc = tax + phil + s
TextBox8.Text = deduc
TextBox10.Text = deduc
}
}
class Pqr : abc
{
public override void operation(int a, int b)
{
int total;
total = a + b;
Console.WriteLine("OPERATION IS ADDITIION {0}+{1}={2}", a, b, total);
base.operation(a, b);
}
}
Class program
14
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Enter 2 numbers ");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
Pqr ob1 = new Pqr();
ob1.operation(a,b);
}
}
15
9. Develop a web application in VB.NET for dynamic Login
Processing
End If
End Sub
End Class
16
Part B
1. C# console program to check whether the
number is palindrome or not
using System;
public class Palindrome
{
public static void Main(string[] args)
{
int n,r,sum=0,temp;
Console.Write("Enter the Number: ");
n = Convert.ToInt32(Console.ReadLine());
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10) +r;
n=n/10;
}
if(temp==sum)
Console.Write("Number is Palindrome.");
else
Console.Write("Number is not Palindrome");
}
}
Output:
Enter the Number=121
Number is Palindrome.
Enter the number=113
Number is not Palindrome
17
2. C# console program to display Factorial of a number
using System;
public class Factorial
{
public static void Main(string[] args)
{
int i,fact=1,number;
Console.Write("Enter any Number: ");
number= Convert.ToInt32(Console.ReadLine());
for(i=1;i<=number;i++){
fact=fact*i;
}
Console.Write("Factorial of " +number+" is: "+fact);
}
}
18
3. Write a C# Program for Dental Payment Form. Calculate
total on selected options from check boxes.
label3.Text = sum.ToString();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace traffic
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button4.Visible = true; //button 4 is red
button5.Visible = false; // button 5 is yellow
button6.Visible = false; // button 6 is green
}
22
Along with car image
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Visible = true;
button2.Visible = false;
button3.Visible = false;
23
}
}
else if (button2.Visible ==true )
{
button1.Visible = true ;
button2.Visible = false;
button3.Visible = false ;
}
else if (button3.Visible ==false && button2 .Visible ==true )
{
pictureBox1.Left = pictureBox1.Left + 2 ;
24
}
else if (button2.Visible ==false && button1.Visible ==true)
{
pictureBox1.Left = pictureBox1.Left + 0; ;
}
}
25
Public Class Form1
Dim Operand1 As Double
Dim Operand2 As Double
Dim op As String
Operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
op = "+"
End Sub
'C to clear
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
TextBox1.Text = ""
End Sub
End Sub
Operand2 = Val(TextBox1.Text)
Select Case op
Case "+"
Result = Operand1 + Operand2
TextBox1.Text = Result
Case "-"
Result = Operand1 - Operand2
TextBox1.Text = Result
Case "/"
Result = Operand1 / Operand2
TextBox1.Text = Result
Case "*"
Result = Operand1 * Operand2
TextBox1.Text = Result
End Select
End Sub
End Clas
27
7)Write a VB Program to accept birth date from user and
calculate age.
28
8) Write a VB.Net program to calculate the sum of all
elements of an integer array
Module Module1
Sub Main()
Dim arr As Integer() = New Integer(5) {}
Dim sum As Integer = 0
End Module
Output:
29
Public Class Form1
End Sub
vowel = vowel + 1
End If
Next i
TextBox2.Text = vowel
End Sub
30
10. Create a windows Login application with database
connectivity.
Windows application with database connectivity steps
31
Step 2: Design Login form
Button
32
Create database
Click on new database
33
Save the table (press ctrl+s to save
table)
34
Go to View -Open
server explorer
Click on change
select Microsoft
sql server -click
ok
35
Enter server name and
select database from
dropdown list-click ok
namespace log
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
36
SqlDataAdapter sda = new SqlDataAdapter("SELECT COUNT(*) FROM [logintable] WHERE
username='" + textBox1.Text + "' AND password='" + textBox2.Text + "'", con);
}
}
}
37