_.Net Lab File
_.Net Lab File
SUBMITTED BY :
NAME – POOJA
ROLL NO. – 22001602041
COURSE – MCA 2ND YEAR
SUBMITTED TO :
Ms. Garima
INDEX
S NO PROGRAMS TEACHER’S
SIGN
PROGRAM 1 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to class");
}
}
}
Output :
PROGRAM 2 :
using P = System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_2
{
internal class Program
{
static void Main(string[] args)
{
P.WriteLine("Hello World");
}
}
}
Output :
PROGRAM 3 :
Write a program to take the username as input and greet them using the input
name.
using P = System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_3
{
internal class Program
{
static void Main(string[] args)
{
P.WriteLine("Enter your name :");
string name = P.ReadLine();
P.WriteLine("Hello " + name);
}
}
}
Output :
PROGRAM 4 :
WAP to create class within the same program and access the another class using
object.
using P = System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_3
{
internal class Program
{
static void Main(string[] args)
{
P.WriteLine("Enter your name :");
string name = P.ReadLine();
P.WriteLine("Hello " + name);
P.WriteLine("-----------***************-----------");
Class1 obj = new Class1();
obj.func1();
}
}
}
namespace Pooja_3
{
internal class Class1
{
public void func1()
{
double n1, sq_rt;
Console.WriteLine("Enter a number : ");
string no = Console.ReadLine();
n1 = double.Parse(no);
sq_rt = Math.Sqrt(n1);
Console.WriteLine("Square Root : " + sq_rt);
}
}
}
Output :
PROGRAM 5 :
using P = System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_4
{
internal class Program
{
static void Main(string[] args)
{
P.WriteLine("System arg = " + args[0] + " " + args[1] + "
" + args[2] + " " + args[3]);
}
}
}
Output :
PROGRAM 6 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("First class main");
}
}
}
namespace Pooja_1
{
internal class Program1
{
static void Main(string[] args)
{
Console.WriteLine("Second Class Main");
}
}
}
Output :
PROGRAM 7 :
WAP that takes command-line arguments, performs square root and power
calculations on them using for loop and displays the results.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_5
{
internal class Program
{
static void Main(string[] args)
{
double n1, sq, power;
Console.WriteLine("System Arg = " + args[0] + " " +
args[1] + " " + args[2] + " " + args[3]);
for(int i = 0; i < args.Length; i++)
{
n1 = Double.Parse(args[i]);
sq = Math.Sqrt(n1);
Console.WriteLine("Square root : " + sq);
}
for (int i = 0; i < args.Length; i+=2)
{
power = Math.Pow(Double.Parse(args[i]),
Double.Parse(args[i+1]));
Console.WriteLine("Power : " + power);
}
}
}
}
Output :
PROGRAM 8 :
WAP to enter a character from the user and checks whether it is a vowel or not
using switch statement and the program continues running until the user decides
to quit.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja_6
{
internal class Program
{
static void Main(string[] args)
{
char ch;
string input;
do
{
Console.WriteLine("Enter a character (q to quit): ");
input = Console.ReadLine();
if (input.Length == 1)
{
ch = input[0];
switch (ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
Console.WriteLine("{0} is a vowel", ch);
break;
default:
Console.WriteLine("{0} is not a vowel",
ch);
break;
}
}
else if (input.ToLower() == "q")
{
Console.WriteLine("Quitting the program.");
break;
}
else
{
Console.WriteLine("Invalid input. Please enter a
single character.");
}
} while (true);
}
}
}
Output :
PROGRAM 9 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja7
{
internal class JaggedArray
{
public static void Main()
{
int sum = 0;
int[][] arr = new int[3][];
arr[0] = new int[3];
arr[1] = new int[5];
arr[2] = new int[2];
for(int i = 0; i<arr.Length; i++)
{
Console.WriteLine("Enter the size of the inner array "
+ (i + 1) + " : ");
arr[i] = new int[int.Parse(Console.ReadLine())];
Console.WriteLine("Enter elements for inner array "
+arr[i].Length + " : ");
for (int j = 0; j < arr[i].Length; j++)
{
arr[i][j] = int.Parse(Console.ReadLine());
sum += arr[i][j];
}
}
Console.WriteLine("The Sum is : " + sum);
Console.ReadKey();
}
}
}
Output :
PROGRAM 10 :
using System;
namespace Pooja8
{
internal class Boxing_Unboxing
{
static void box(object obj)
{
Console.WriteLine("value =" + obj);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pooja9
{
internal class Complex
{
double x; //real part
double y; //imaginary part
public Complex()
{}
public Complex(double real, double imag)
{
x = real;
y = imag;
}
public static Complex operator +(Complex c1, Complex c2)
{
Complex c3 = new Complex();
c3.x = c1.x + c2.x;
c3.y = c1.y + c2.y;
return c3;
}
public void Display()
{
Console.Write(x);
Console.Write(" + j" + y);
Console.WriteLine();
}
}
class ComplexTest
{
public static void Main()
{
Complex a, b, c;
a = new Complex(2.5, 3.5);
b = new Complex(1.6, 2.7);
c = a + b;
Console.Write("a = ");
a.Display();
Console.Write("b = ");
b.Display();
Console.Write("c = ");
c.Display();
Console.ReadKey();
}
}
}
Output :
PROGRAM 12 :
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 Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string CalTotal;
int num1;
int num2;
string option;
int result;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button1.Text;
}
if (option.Equals("+"))
{
result = num1 + num2;
}
if (option.Equals("-"))
{
result = num1 - num2;
}
if (option.Equals("*"))
{
result = num1 * num2;
}
if (option == "/")
{
if (num2 == 0)
{
MessageBox.Show("Divide by 0 Error. enter
denominator again");
}
result = num1 / num2;
}
textBox1.Text = result + "";
}
}
}
OUTPUT :
PROGRAM 13 :
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 Registration_Form
{
public partial class RegistrationForm : Form
{
public RegistrationForm()
{
InitializeComponent();
}
}
private void label3_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
Gender = "Male";
else
Gender = "Female";
if (radioButton2.Checked)
Gender = "Male";
else
Gender = "Female";
if (checkBox1.Checked)
Qual = Qual + " 10th";
if (checkBox2.Checked)
Qual = Qual + " 12th";
if (checkBox1.Checked)
Qual = Qual + " Graduation";
string sp = comboBox1.Text;
}
}
}
Output Form1 :
Form 2.cs
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 Registration_Form
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}
Output Form2 :