Professional Documents
Culture Documents
AWP Worksheet - Practical - 2
AWP Worksheet - Practical - 2
Practical #2
Name Rahul Dilip Rajdeo Roll Number 21302B0018
Subject/Course: Advanced Web Programming
Topic Working with Object Oriented C#
a. Create simple application to perform following operations i. Finding factorial Value ii. Money Conversion iii.
Quadratic Equation iv. Temperature Conversion
FACTORIAL MAIN FILE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp12
{
class Program
{
static void Main(string[] args)
{
Factorial f = new Factorial();
Console.WriteLine("enter a number");
int n = Convert.ToInt32(Console.ReadLine());
f.getFact(6);
}
}
}
FACTORIAL CLASS:
using System;
namespace ConsoleApp12
{
class Factorial
{
public void getFact(int n)
{
int f = 1;
for (int i = 1; i <= n; i++)
{
f = f * i;
}
Console.WriteLine("factorial=" + f);
Console.Read();
}
}
}
B]Conversion:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
conversion t = new conversion();
Console.WriteLine("enter dollars");
int n = Convert.ToInt32(Console.ReadLine());
t.dollartoRs(n);
Console.WriteLine("enter rupees");
int a = Convert.ToInt32(Console.ReadLine());
t.RsToDollar(a);
Console.ReadLine();
}
}
}
Conversion Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class conversion
{
public void dollartoRs(int d)
{
double r = d * 82.32;
Console.WriteLine(d + "dollars:" + "Rs." + r);
}
public void RsToDollar(int r)
{
double d = r / 82.32;
Console.WriteLine("Rs." + r + "=$" + d);
}
}
}
}
FunctionOverloadingClass:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class FunctionOverloading
{
Vidyalankar School of Information Technology
public void Add(int n)
{
Console.WriteLine("Result a=" + (n + 20));
}
public void Add(int a, int b)
{
Console.WriteLine("Result b=" + (a + b));
}
public void Add(int a, int b, int c)
{
Console.WriteLine("Result c=" + (a + b + c));
}
}
}
OUTPUT:
2]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter length and breadth of rectangle:");
int l = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
Rectangle r1 = new Rectangle();
Rectangle r2 = new Rectangle(l, b);
Rectangle r3 = new Rectangle(r2);
r1.Display();
r2.Display();
r3.Display();
Console.ReadKey();
}
}
}
RECTANGLE CLASS:-
using System;
using System.Collections.Generic;
Vidyalankar School of Information Technology
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Rectangle
{
int length, breadth; //instance variables
public Rectangle() //default Construtor
{
length = 10;
breadth = 20;
}
//parametrized Constructor
public Rectangle(int length, int breadth)
{
this.length = length;
this.breadth = breadth;
}
//copy Constructor
public Rectangle(Rectangle r)
{
this.length = r.length;
this.breadth = r.breadth;
}
static Rectangle()
{
Console.WriteLine("static Constructor ");
}
public void Display()
{
Console.WriteLine("area of rectangle" + (length * breadth));
}
}
}
OUTPUT:-
Inheritance
namespace Furniture
{
public class Furniture
{
public string material;
public double price;
public table(string material, double price, double height, double surface_area) : base(material, price)
{
this.height = height;
this.surface_area = surface_area;
this.material = material;
this.price = price;
}
}
}
class Program
{
static void Main(string[] args)
{
table t = new table("wood", 12000, 12, 100);
t.display();
Console.ReadKey();
}
}
}
Interface:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp6
interface Gross
void gross_sal();
class Employee
this.name = name;
return b;
this.hra = hra;
public int TA
set { ta = value; }
public int DA
set { da = value; }
Console.WriteLine("HRA:" + hra);
Console.WriteLine("TA:" + TA);
Console.WriteLine("DA:" + DA);
class Program
s.TA = 5000;
s.DA = 25000;
s.gross_sal();
Console.ReadLine();
Output:
namespace ConsoleApp6
{
public delegate void delmethod(string name);
class EventEx
{
public event delmethod myevent;
public void Raise_Event(string msg)
{
if(myevent != null)
{
myevent(msg);
}
}
public void getMessage(string name)
{
Console.WriteLine(name);
}
}
class Program
{
static void Main(string[] args)
{
EventEx ex = new EventEx();
delmethod d1 = ex.getMessage;
ex.myevent += d1;
ex.Raise_Event("My Event Raised");
Console.ReadKey();
}
}
}
Output: