C# Lab Pgms
C# Lab Pgms
LAB 1A: Write a C# program to show the machine details like machine
name, Operating System, Version, Physical Memory and calculate
time since the Last Boot Up.
using System;
namespace LabPgm1
{
class Program
{
static void Main(string[] args)
{
}
}
}
OUTPUT
using System;
namespace LabPgm2
{
class Program
{
static void Main(string[] args)
{
string str;
int alp, digit, splch, i, l;
alp = digit = splch = i = 0;
l = str.Length;
while (i < l)
{
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
{
alp++;
}
else if (str[i] >= '0' && str[i] <= '9')
{
digit++;
}
else
{
splch++;
}
i++;
}
Console.ReadLine();
}
}
}
OUTPUT
using System;
namespace LabPgm3
{
class Program
{
static public int calc_sum(int n)
{
int s=0,m;
while (n > 0)
{
m = n % 10;
s = s + m;
n = n / 10;
}
return s;
}
static void Main(string[] args)
{
int n, sum = 0, m;
Console.Write("Enter a number: ");
n = int.Parse(Console.ReadLine());
sum = calc_sum(n);
OUTPUT
LAB 4A: Draw a square with sides 100 pixels in length. Then inscribe a
circle of radius 50 inside the square. Position the square and the
inscribed circle in middle of the screen.
STEPS:
Go to File -> Click on New -> Project -> Select Windows Forms Application -> Click
OK
Once Windows Form Created
Go to Properties Table -> Click on Events -> Double Click on Paint -> Write 5 Lines
code as given
below in source code.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace LabPgm4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OUTPUT
using System;
namespace LabPrm5
{
public class Brand
{
public string Name;
public void GetName()
{
Console.WriteLine("Mobile Name:{0}", Name);
}
}
class Program
{
static void Main(string[] args)
{
Price p = new Price();
Console.WriteLine("Enter Model:");
p.Mod = Console.ReadLine();
Console.WriteLine("........................");
Console.WriteLine("Mobile details are:");
p.GetName();
p.GetModel();
p.GetPrice();
Console.ReadLine();
}
}
}
OUTPUT
........................
Mobile details are:
Mobile Name:Samsung
Mobile Model=Galaxy A14
Total Amount=18989
using System;
namespace LabPgm6
{
class Program
{
static void Main(string[] args)
{
int Number1, Number2, Result=0;
try
{
Console.WriteLine("Enter First Number");
Number1 = int.Parse(Console.ReadLine());
catch (DivideByZeroException)
{
Console.WriteLine("\nSecond Number Should Not Be Zero");
}
catch (Exception)
{
Console.WriteLine("\nGeneric Catch Block...");
}
finally
{
Console.WriteLine("\nResult:" + Result);
}
Console.ReadKey();
}
}
}
OUTPUT
Enter First Number
4
Enter Second Number
2
Result: 2
using System;
namespace LabPgm7
{
class Bank
{
public int balance(int amount)
{
Console.WriteLine("\n* * * * *YOUR CURRENT BALANCE IS Rs :
{0}",amount);
return amount;
}
public int deposit(int amount)
{
Console.Write("\n* * * * *ENTER THE DEPOSIT AMOUNT: ");
int deposit = int.Parse(Console.ReadLine());
amount = amount + deposit;
Console.WriteLine("\n\n* * * * *YOUR TOTAL BALANCE IS Rs : {0}\n",
amount);
return amount;
}
public int withdraw(int amount)
{
Console.Write("* * * * *ENTER THE WITHDRAW AMOUNT: ");
int withdraw = int.Parse(Console.ReadLine());
if (withdraw <= 100)
{
Console.WriteLine("\n\n* * * * *PLEASE ENTER THE AMOUNT IN ABOVE
100");
}
switch (choice)
{
case 1: amount = obj.balance(amount);
break;
case 2:
amount = obj.withdraw(amount);
break;
case 3:
amount = obj.deposit(amount);
break;
case 4:
Console.WriteLine("thank you \n");
break;
default:
Console.WriteLine("\nInvalid choice\n");
break;
}
}while (choice != 4);
}
}
}
OUTPUT
*******MENU********
WELCOME TO BANK
1. Current Balance
2. Withdraw
3. Deposit
4. Exit
***************
*******MENU********
WELCOME TO BANK
1. Current Balance
2. Withdraw
3. Deposit
4. Exit
***************
*******MENU********
WELCOME TO BANK
1. Current Balance
2. Withdraw
3. Deposit
4. Exit
***************
*******MENU********
WELCOME TO BANK
1. Current Balance
2. Withdraw
3. Deposit
JAIN COLLEGE OF BBA, BCA AND COMMERCE, BELAGAVI Page:
USN No. _________________________ Subject: C# & Dot Net Framework Lab
4. Exit
***************
*******MENU********
WELCOME TO BANK
1. Current Balance
2. Withdraw
3. Deposit
4. Exit
***************
*******MENU********
WELCOME TO BANK
1. Current Balance
2. Withdraw
3. Deposit
4. Exit
***************
using System;
namespace LabPgm8
{
public struct Complex
{
public int real;
public int imaginary;
class Program
{
static void Main()
{
int r1, i1, r2, i2;
i1 = int.Parse(Console.ReadLine());
OUTPUT
FORM1:
using System;
using System.Windows.Forms;
namespace LabPgm9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
FORM2:
using System;
using System.Windows.Forms;
namespace LabPgm9
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}
OUTPUT
using System;
using System.Drawing;
using System.Windows.Forms;
namespace LabPgm10
{
public partial class Form1 : Form
{
private MainMenu mainMenu;
public Form1()
{
InitializeComponent();
File.MenuItems.Add(new MenuItem("&New"));
File.MenuItems.Add(new MenuItem("&Open"));
File.MenuItems.Add(new MenuItem("&Exit"));
this.Menu = mainMenu;
this.Menu = mainMenu;
mainMenu.GetForm().BackColor = Color.Indigo;
}
}
}
OUTPUT