answersLogoWhite

0

Why are tackpads used on laptops?

User Avatar

Anonymous

13y ago
Updated: 8/20/2019

K u v e m p u U n i v e r s i t y

Laboratory Assignments

Subject: Basics of .NET

Subject Code: BSIT - 61 L

1. Write a program in C# using command line arguments to display a welcome

message. The message has to be supplied as input in the command line.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_1

{

class Program

{

static void Main(string[] args)

{

for (int i = 0; i < args.Length; i++)

{

Console.Write(args[i] + " ");

}

Console.ReadLine();

}

}

}

2. Write a program in C# to find the area of a circle, given its radius.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_2

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Enter the radius of Circle to find its area");

double radius =double.Parse(Console.ReadLine());

double area = Math.PI * radius * radius;

Console.WriteLine("The area of circle for given radius is : " + area);

Console.ReadLine();

}

}

}

3. Write a program in C# to find the area of polygon - triangle and rectangle by

using multiple constructors.

using System;

using System.Collections.Generic;

class rkm

{

public rkm(double basse,double height) //constructor for triangle

{

double b = basse;

double h = height;

double tri_area = (0.5) * b * h;

Console.WriteLine("Area of Triange:- " + tri_area);

}

public rkm(float width, floatheight) //constructor for Rectangle

{

float w = width;

float h = height;

float rec_area = w * h;

Console.WriteLine("Area of Rectangle:- "+ rec_area);

}

public static void Main()

{

Console.WriteLine("============For Triangle==============");

Console.WriteLine("Enter the base of triangle:-");

double tri_base =Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Enter the height of triangle:-");

double tri_height =Convert.ToDouble(Console.ReadLine());

Console.WriteLine("============For Rectangle==============");

Console.WriteLine("Enter the width of rectangle:-");

float rec_width = (float)(Convert.ToDouble(Console.ReadLine()));

Console.WriteLine("Enter the height of rectangle:-");

float rec_height = (float)(Convert.ToDouble(Console.ReadLine()));

Console.WriteLine("================Result=================");

rkm th1 = new rkm(tri_base, tri_height);

rkm th2 = new rkm(rec_width, rec_height);

Console.ReadLine();

}

}

4. Write a program in C# to add and multiply two numbers and display the results.

Demonstrate the use of ref and out parameters in this program.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_4

{

class Program

{

public static int ADD(ref int x,ref int y)

{

int res = x + y;

return res;

}

public static int Multiply(int x,int y, out int res1)

{

res1 = x * y;

return res1;

}

static void Main(string[] args)

{

Console.WriteLine("Enter First Number");

int n1 =Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter Second Number");

int n2 =Convert.ToInt32(Console.ReadLine());

int Res = Program.ADD(refn1, ref n2);

Console.WriteLine("Sum of Two Number is : "+ Res);

Program.Multiply(n1, n2, outRes);

Console.WriteLine("Multiply of Two Number is : " + Res);

Console.ReadLine();

}

}

}

5. Using foreach looping statement, write a program in C# to display all the

elements of string array.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_5

{

class Program

{

static void Main(string[] args)

{

string[] str = { "I","Love", "My", "India"};

foreach (string s instr)

{

Console.WriteLine(s);

}

Console.ReadLine();

}

}

}

6. Write a program in C# to create a string array to store 10 employees name.

Display the employees name to the console by passing array as a parameter to

the display function.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_6

{

class Program

{

public static void Display(Arrayarr)

{

foreach (string a inarr)

{

Console.WriteLine(a);

}

}

static void Main(string[] args)

{

string[] arr = new string[10];

for (int i = 0; i < arr.Length; i++)

{

Console.WriteLine("Enter " + (i + 1) + " Emplyee Name");

string str = Console.ReadLine();

arr.SetValue(str, i);

}

Console.WriteLine("The Names you have Entered is given below ");

Console.WriteLine();

Display(arr);

Console.ReadLine();

}

}

}

7. Write a program in C# to demonstrate the usage of checked and unchecked

statements.

using System;

class rkm

{

public static void Main()

{

int i = Int32.MaxValue;

Console.WriteLine("Simple: " + (i + 1));

unchecked

{

Console.WriteLine("Unchecked: " + (i + 1));

}

checked

{

try

{

Console.WriteLine(i + 1);

}

catch (Exception ee)

{

Console.WriteLine("Error in Checked Block");

Console.ReadLine();

}

}

}

}

8. Write a class called rectangle which consists of members side_1, side_2 and

displayArea(). Write another class square which inherits class rectangle. Take

side of square as input and display the area of square on console.

using System;

using System.Collections.Generic;

using System.Text;

public class RKM

{

public double side_1;

public double side_2;

public void displayArea()

{

double area = side_1 * side_2;

Console.WriteLine("Area is:- " + area);

}

}

class Square : RKM

{

public static void Main()

{

Square sq = new Square();

Console.WriteLine("Enter the side of Square:-");

sq.side_1 =Convert.ToDouble(Console.ReadLine());

sq.side_2 = sq.side_1;

sq.displayArea();

Console.ReadLine();

}

}

9. Write a program to sort 20 decimal numbers in decreasing order and print the

result.

using System;

using System.Collections.Generic;

using System.Text;

class RKM

{

public static void Main(string[] args)

{

decimal[] arr = { 12.3m, 45.2m, 5.4m, 23.44m, 43.21m, 31.34m, 4.3m, 21.3m,

34.2m, 32.1m, 44.2m, 6.4m, 64.3m, 3.4m, 5.32m, 32.345m, 4.34m, 23.4m,

45.234m, 5.31m };

for (int i = 0; i < arr.Length; i++)

{

Console.WriteLine(arr[i]);

}

Console.WriteLine("\n--Number in decreasing order--\n");

int count = 0;

while (count < arr.Length - 1)

{

if (arr[count] < arr[count + 1])

{

decimal temp = arr[count];

arr[count] = arr[count + 1];

arr[count + 1] = temp;

count = 0;

continue;

}

count++;

}

foreach (double i inarr)

{

Console.WriteLine(i);

Console.ReadLine();

}

}

}

10. Write a program for matrix multiplication in C#.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_10

{

class Program

{

static void Main(string[] args)

{

int[,] x ={ { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

int[,] y ={ { 11, 12, 13 }, { 14, 15, 16 }, { 17, 18, 19 } };

Console.WriteLine("----First Matrix--------");

for (int i = 0; i < 3; i++)

{

for (int j = 0; j < 3; j++)

Console.Write(x[i, j] + " ");

Console.WriteLine();

}

Console.WriteLine("----Second Matrix--------");

for (int i = 0; i < 3; i++)

{

for (int j = 0; j < 3; j++)

Console.Write(y[i, j] + " ");

Console.WriteLine();

}

Console.WriteLine("Multilpilcation of Two Matrix (Matrix1 * Matrix2) ");

for (int i = 0; i < 3; i++)

{

for (int j = 0; j < 3; j++)

Console.Write(x[i, j] * y[i, j] + " ");

Console.WriteLine();

}

Console.ReadLine();

}

}

}

11. Write a program in C# to sort the students list based on their names. The

students list is stored in a string array.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_11

{

class Program

{

public static void Display(Arrayarr)

{

foreach (string s inarr)

{

Console.WriteLine(s);

}

}

static void Main(string[] args)

{

Console.WriteLine("Enter the No of Student");

int n =Convert.ToInt16(Console.ReadLine());

string[] arr = new string[n];

for (int i = 0; i < arr.Length; i++)

{

Console.WriteLine("Enter " + (i + 1) + " Student Name");

string str = Console.ReadLine();

arr.SetValue(str, i);

}

Console.WriteLine("\nThe Names you have Entered i Sort order is given

below ");

Console.WriteLine();

Array.Sort(arr);

Display(arr);

Console.ReadLine();

}

}

}

12. Write a program in C# to demonstrate operator overloading.

using System;

class rkm

{

int a;

public rkm()

{

a = 10;

}

public static rkm operator-(rkm obj)

{

obj.a = -obj.a;

return obj;

}

public void display()

{

Console.WriteLine("Number is {0}", a);

}

public static void Main()

{

rkm aa = new rkm();

aa.display();

aa = -aa;

aa.display();

Console.ReadLine();

}

}

13. Write a program in C# to demonstrate boxing and unboxing opertation.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_13

{

class Program

{

static void Main(string[] args)

{

int i = 10;

Console.WriteLine("Value of i : " + i);

object obj = (object)(i+1); // boxing Convert int to object

Console.WriteLine("Value of obj :"+ obj);

i = (int)obj;

Console.WriteLine("Value of i after unbox "+i);

Console.ReadLine();

}

}

}

14. Write a program in C# to throw and catch any arithmetic exception.

using System;

using System.Collections.Generic;

using System.Text;

namespace Exercise_14

{

class Program

{

static void Main(string[] args)

{

try

{

int n1 =10;

int n = 0;

int res;

res = n1 / n;

Console.WriteLine(res);

}

catch (ArithmeticException ex)

{

Console.WriteLine(ex.Message.ToString());

}

Console.ReadLine();

}

}

}

15. Write a program to demonstrate the usage of threads in C#.

using System;

using System.Threading;

class rkm

{

public void get1()

{

for (int i = 0; i <= 10; i++)

{

Console.WriteLine("Welcome");

Thread.Sleep(1000);

}

}

public void get2()

{

for (int j = 0; j <= 10; j++)

{

Console.WriteLine("India");

Thread.Sleep(1000);

}

}

public static void Main()

{

rkm ff = new rkm();

ThreadStart ts1 = newThreadStart(ff.get1);

ThreadStart ts2 = newThreadStart(ff.get2);

Thread t1 = newThread(ts1);

Thread t2 = newThread(ts2);

t1.Start();

Thread.Sleep(500);

t2.Start();

} }

User Avatar

Wiki User

13y ago

What else can I help you with?