C#.Net Lab Report
C#.Net Lab Report
S COLLEGE OF ENGINEERING
(Autonomous College under VTU)
Bull Temple Road, Bangalore-560019
Lab report on
Windows Application Development
with C#.NET (18MCA5PCWP)
Submitted by:
SHUBHRA DEBNATH (1BF19MCA15)
CERTIFICATE
This is to certify that SHUBHRA DEBNATH(1BF19MCA15) has
satisfactorily Windows Application Development with C#.NET
(18MCA5PCWP) completed the requirements Laboratory Report prescribed
by 5th semester MCA course, BMS College of Engineering during the year
2021-2022.
2. Program to demonstrate the sum of all the elements present in a jagged array of
3 inner arrays.
namespace P1_Lab1
{
class Program
{
static void Main(string[] args)
{
}
}
}
OUTPUT:
PROGRAM2: Program to demonstrate the sum of all the elements present in a jagged
array of 3 inner arrays
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program_Lapprogram2
{
class Program
{
static void Main(string[] args)
{
int r = 3,sum=0;
Console.WriteLine("Sum of all the elements present in a jagged array of 3 inner arrays");
//r=Convert.ToInt32(Console.ReadLine());
int[][] arr = new int[r][];
for (int i = 0; i < r; i++)
{
Console.WriteLine("How many number of elements");
int m = Convert.ToInt32(Console.ReadLine());
arr[i] = new int[m];
Console.WriteLine("Enter" + m + "elements");
for (int j = 0; j < m; j++)
{
arr[i][j] = int.Parse(Console.ReadLine());
sum = sum + arr[i][j];
}
}
Console.WriteLine("The sum of elements in a jagged array of 3 inner arrays are " +
sum);
}
}
}
OUTPUT:
Program 3: Programs to demonstrate Classes and Objects.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program_Labprogram3
{
class Program
{
int insuranceId, carnum;
String carname, color;
void getCarDetails()
{
Console.WriteLine("Enter the insuranceId,car number,color,name");
insuranceId = Convert.ToInt32(Console.ReadLine());
carnum = Convert.ToInt32(Console.ReadLine());
color = Console.ReadLine();
carname = Console.ReadLine();
}
void Display()
{
Console.WriteLine("Car Details");
Console.WriteLine(" ");
Console.WriteLine("Car InsuranceID: " + insuranceId);
Console.WriteLine("Car Number: "+carnum);
Console.WriteLine("Car Color: " + color);
Console.WriteLine("Car Name: "+carname);
}
static void Main(string[] args)
{
Program p = new Program();
Console.WriteLine("Classes and objects");
p.getCarDetails();
p.Display();
}
}
}
OUTPUT:
PROGRAM4: Program to illustrate the use of different properties in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program_Labprogram4
{
class Program
{
public String carname;
private int insuranceId=0;
private static int count=0;
public string Car
{
get
{
return carname;
}
set
{
carname = value;
}
}
public override string ToString()
{
}
public int Insurance
{
get
{
return insuranceId;
}
}
public Program()
{
count++;
}
public static int Carnum
{
get
{
return count;
}
set
{
count = value;
}
}
private string[] names = new string[2];
public string this[int i]
{
get
{
return names[i];
}
set
{
names[i] = value;
}
}
static void Main(string[] args)
{
Console.WriteLine("Different properties in C#");
Console.WriteLine(" ");
Program p = new Program();
p.carname = "FORD";
Console.WriteLine("GETTER AND SETTER METHODS");
Console.WriteLine(p);
Console.WriteLine(" ");
Console.WriteLine("ReadOnly Property");
Program p1 = new Program(1234);
Console.WriteLine("Car InsuranceId: " + p1.insuranceId);
Console.WriteLine(" ");
Console.WriteLine("Static Property");
Program p2 = new Program();
Program p3 = new Program();
Console.WriteLine("Number of Objects of Program class using Static property:{0}" +
Program.Carnum);
Console.WriteLine(" ");
Console.WriteLine("Indexer Property");
Program p4 = new Program();
p4[0] = "Rakshitha";
p4[1] = "MCA,BMSCE";
for (int i = 0; i < 2; i++)
{
Console.WriteLine(p4[i]);
}
}
}
}
OUTPUT:
5. Programs to demonstrate Exploring Structs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PROGRAM_LAB5
{
struct area
{
public int l;
public int b;
public area(int l,int b)
{
this.l = l;
this.b = b;
}
public int display()
{
return l * b;
}
};
class Program
{
static void Main(string[] args)
{
area m = new area();
Console.WriteLine("Enter breadth and length of rectangle");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
m.l = a;
m.b = b;
Console.WriteLine("Area of rectangle is {0}", m.display());
}
}
}
OUTPUT:
6. Programs to demonstrate Exception Handling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationExceptionHandling
{
class DivByZero : Exception
{
// Constructor
public DivByZero()
{
Console.Write("Exception has occurred : ");
}
}
class Program
{
public double DivisionOperation(double numerator,
double denominator)
{
// throw exception when denominator
// value is 0
if (denominator == 0)
throw new DivByZero();
OUTPUT:
7.Program to demonstrate inheritance covering the concepts of Sealed Classes, Sealed
Methods, Extension Methods
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationSealed
{
// C# program to
// define Sealed Class
using System;
class Printer
{
// Display Function
public virtual void print()
{
Console.WriteLine("printer printing....\n");
}
}
// inheriting class
class LaserJet : Printer
{
// Function to override
// Print() function
override public void print()
{
Console.WriteLine("Laserjet printer printing....\n");
}
}
// Driver Class
class Program
{
// Driver Code
static void Main(string[] args)
{
Printer p = new Printer();
p.show();
p.print();
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationExtensionMethod
{
// Here Geek class contains three methods
// Now we want to add two more new methods in it
// Without re-compiling this class
class Geek
{
// Method 1
public void M1()
{
Console.WriteLine("Method Name: M1");
}
// Method 2
public void M2()
{
Console.WriteLine("Method Name: M2");
}
// Method 3
public void M3()
{
Console.WriteLine("Method Name: M3");
}
}
// This class contains M4 and M5 method
// Which we want to add in Geek class.
// NewMethodClass is a static class
static class NewMethodClass
{
// Method 4
public static void M4(this Geek g)
{
Console.WriteLine("Method Name: M4");
}
// Method 5
public static void M5(this Geek g, string str)
{
Console.WriteLine(str);
}
}
// Now we create a new class in which
// Geek class access all the five methods
class Program
{
static void Main(string[] args)
{
Geek g = new Geek();
g.M1();
g.M2();
g.M3();
g.M4();
g.M5("Method Name: M5");
Console.ReadLine();
}
}
}
OUTPUT:
8. Programs to demonstrate Abstract Classes and Interfaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationAbstractClassInterface
{
abstract class Area
{
protected float r, s;
public abstract float area();
}
interface Perimeter
{
float perimeter();
}
class Circle : Area
{
public void input()
{
Console.Write("Enter the value of Radius : ");
r = float.Parse(Console.ReadLine());
}
public override float area()
{
return 3.14F * r * r;
}
}
class Square : Area, Perimeter
{
public void input2()
{
Console.Write("Enter the value of Square Side : ");
s = float.Parse(Console.ReadLine());
}
public override float area()
{
return s * s;
}
public float perimeter()
{
return 4 * s;
}
}
class Program
{
static void Main(string[] args)
{
Circle c = new Circle();
Console.WriteLine("--------Area of Circle---------------");
c.input();
Console.WriteLine("Area : {0}", c.area());
Square s = new Square();
Console.WriteLine("\n-------Area and Perimeter of Square-----------");
s.input2();
Console.WriteLine("Area : {0}", s.area());
Console.WriteLine("Perimeter:{0}", s.perimeter());
Console.Read();
}
}
}
OUTPUT:
9. Programs to demonstrate Polymorphism covering the concepts of Overloading,
Overriding, Virtual and Override keywords
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationOverloadOverride
{
class area
{
public virtual void calcarea(int s) { }
public virtual void calcarea(int l, int b) { }
}
class square : area
{
public override void calcarea(int s)
{
Console.WriteLine("Area of Square : "+(s*s));
}
}
class rectangle : area
{
public override void calcarea(int l, int b)
{
Console.WriteLine("Area of Rectangle : " + (l*b));
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("Enter side of square : ");
int s=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter sides of rectangle : ");
int l = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
area a = new square();
a.calcarea(s);
a = new rectangle();
a.calcarea(l, b);
Console.ReadLine();
}
}
}
OUTPUT:
10.Programs to demonstrate Operator Overloading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationOperatorOverloading
{
class Cuboid
{
private double length;
private double breadth;
private double height;
public double getVolume()
{
return length * breadth * height;
}
public void setLength(double len)
{
length = len;
}
public void setBreadth(double bre)
{
breadth = bre;
}
public void setHeight(double hei)
{
height = hei;
}
public static Cuboid operator +(Cuboid b, Cuboid c)
{
Cuboid Cuboid = new Cuboid();
Cuboid.length = b.length + c.length;
Cuboid.breadth = b.breadth + c.breadth;
Cuboid.height = b.height + c.height;
return Cuboid;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Volumne of Cuboid Using operator Overloading");
Cuboid Cuboid1 = new Cuboid();
Cuboid Cuboid2 = new Cuboid();
Cuboid Cuboid3 = new Cuboid();
double volume = 0.0;
Console.WriteLine("Enter dimensions of cuboid1 : ");
double a=double.Parse(Console.ReadLine());
double b=double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
Console.WriteLine("Enter dimensions of cuboid2 : ");
double x = double.Parse(Console.ReadLine());
double y = double.Parse(Console.ReadLine());
double z = double.Parse(Console.ReadLine());
Cuboid1.setLength(a);
Cuboid1.setBreadth(b);
Cuboid1.setHeight(c);
Cuboid2.setLength(x);
Cuboid2.setBreadth(y);
Cuboid2.setHeight(z);
volume = Cuboid1.getVolume();
Console.WriteLine("Volume of Cuboid1 : {0}", volume);
volume = Cuboid2.getVolume();
Console.WriteLine("Volume of Cuboid2 : {0}", volume);
Cuboid3 = Cuboid1 + Cuboid2;
volume = Cuboid3.getVolume();
Console.WriteLine("Volume of Cuboid3 : {0}", volume);
Console.ReadKey();
}
}
}
OUTPUT:
namespace Program_Lab11
{
public class Program
{
public delegate void DelegateEventHandler();
public static double previous_amount;
public static void Deposit()
{
OUTPUT:
namespace ConsoleApplicationLINQ
{
class Program
{
static void Main(string[] args)
{
try {
Console.WriteLine("\n\tUsage of LINQ");
int a;
Console.Write("Enter the size of marks board : ");
a = int.Parse(Console.ReadLine());
int[] marks = new int[a];
Console.WriteLine("Enter the marks : ");
for (int i = 0; i < marks.Length; i++)
{
marks[i] = Convert.ToInt32(Console.ReadLine());
}
IEnumerable<int> marksQuery = from score in marks where
score > 80 select score;
Console.Write("Marks above 80 ");
foreach (int i in marksQuery)
{
Console.Write(i + " ");
}
Console.WriteLine("\n\n***************************\n\n");
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}
OUTPUT: