0% found this document useful (0 votes)
6 views28 pages

_.Net Lab File

Dotnet file

Uploaded by

xejod11748
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
6 views28 pages

_.Net Lab File

Dotnet file

Uploaded by

xejod11748
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 28

J.C.

Bose University of Science and Technology,YMCA, Faridabad

.NET PRACTICAL 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 :

Write a program to display welcome message to the user.

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 :

Write a program to display welcome message to the user using alias.

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();
}
}
}

Class within the same program i.e. Pooja_3


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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 :

WAP to create command line arguments.

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 :

WAP to create two main classes within the same program.

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 :

WAP of Jagged Array.

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 :

WAP of Boxing and Unboxing.

using System;

namespace Pooja8
{
internal class Boxing_Unboxing
{
static void box(object obj)
{
Console.WriteLine("value =" + obj);
}

public static void Main()


{
Object o;
int a = 10;
double d = 4.4;
o = a;
Console.WriteLine("Passing integer");
box(a);
Console.WriteLine("Passing object");
box(o);
int x = (int)o;
Console.WriteLine("Unboxing");
Console.WriteLine("a = " + x);
o = d;
Console.WriteLine("Passing double");
box(d);
Console.WriteLine("Passing object");
box(o);
double dd = (double)o;
Console.WriteLine("Unboxing");
Console.WriteLine("d = " +dd);
Console.ReadKey();
}
}
}
Output :
PROGRAM 11 :

WAP to overload binary operator (+).

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 :

Windows Form Calculator

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 Form1_Load(object sender, EventArgs e)


{

private void textBox1_TextChanged(object sender, EventArgs e)


{

}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button1.Text;
}

private void button2_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button2.Text;
}

private void button3_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button3.Text;
}

private void button4_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button4.Text;
}

private void button5_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button5.Text;
}

private void button6_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button6.Text;
}

private void button7_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button7.Text;
}

private void button8_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button8.Text;
}

private void button9_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + button9.Text;
}

private void button10_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "0";
}

private void button11_Click(object sender, EventArgs e)


{
option = "+";
num1 = int.Parse(textBox1.Text);
textBox1.Clear();

private void button12_Click(object sender, EventArgs e)


{
option = "-";
num1 = int.Parse(textBox1.Text);
textBox1.Clear();
}

private void button13_Click(object sender, EventArgs e)


{
option = "*";
num1 = int.Parse(textBox1.Text);
textBox1.Clear();
}

private void button14_Click(object sender, EventArgs e)


{
option = "/";
num1 = int.Parse(textBox1.Text);
textBox1.Clear();
}
private void button16_Click(object sender, EventArgs e)
{
num2 = int.Parse(textBox1.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 + "";
}

private void button15_Click(object sender, EventArgs e)


{
textBox1.Clear();
result = 0;
num1 = 0;
num2 = 0;
}

}
}
OUTPUT :
PROGRAM 13 :

Windows Form Registration Form

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 RegistrationForm_Load(object sender, EventArgs e)


{

private void label1_Click(object sender, EventArgs e)


{

private void textBox1_TextChanged(object sender, EventArgs e)


{

private void label2_Click(object sender, EventArgs e)


{

private void textBox2_TextChanged(object sender, EventArgs e)


{

private void groupBox1_Enter(object sender, EventArgs e)


{

private void groupBox2_Enter(object sender, EventArgs e)


{

}
private void label3_Click(object sender, EventArgs e)
{

private void listBox1_SelectedIndexChanged(object sender,


EventArgs e)
{
listBox1.Text = listBox1.SelectedItem.ToString();
listBox1.Enabled = true;
}
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{

private void checkBox1_CheckedChanged(object sender, EventArgs


e)
{

private void checkBox2_CheckedChanged(object sender, EventArgs


e)
{

private void checkBox3_CheckedChanged(object sender, EventArgs


e)
{

private void checkBox4_CheckedChanged(object sender, EventArgs


e)
{
listBox1.Enabled = true;
}

private void button1_Click(object sender, EventArgs e)


{
string Qual = "", Gender = "";

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;

Form2 objPreview = new Form2();


objPreview.SetValues(textBox1.Text, textBox2.Text, Gender,
Qual,listBox1.Text, sp);
objPreview.Show();
}

private void radioButton1_CheckedChanged(object sender,


EventArgs e)
{

private void radioButton2_CheckedChanged(object sender,


EventArgs e)
{

}
}
}

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();
}

private void label10_Click(object sender, EventArgs e)


{

private void label1_Click(object sender, EventArgs e)


{

private void label2_Click(object sender, EventArgs e)


{

private void label3_Click(object sender, EventArgs e)


{

private void label4_Click(object sender, EventArgs e)


{

private void label5_Click(object sender, EventArgs e)


{

public void SetValues(string Name, string Class, string Gender,


string
Qual, string AfterPG, string sp)
{
label6.Text = Name;
label7.Text = Class;
label8.Text = Qual;
label9.Text = Gender;
label10.Text = AfterPG;
label12.Text = sp;
}

}
}

Output Form2 :

You might also like