Practical(4 6)
Practical(4 6)
Initialize the
two data members using constructor and store their addition in third data member using function
and display addition.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PRACTICAL4
{
class Distance
{
private int dis1;
private int dis2;
private int dis3;
class Program
{
static void Main(string[] args)
{
Distance d = new Distance(10, 20);
d.calc();
d.display();
Console.ReadKey();
}
}
}
5. Define a class ,,salary" which will contain member variable Basic, TA, DA, HRA. Write a program
using Constructor with default values for D and HRA and calculate the salary of employee.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace practical5
{
class salary
{
private int ta, da, hra, sal;
public salary(int t, int d = 1500, int h = 6000)
{
ta = t;
da = d;
hra = h;
}
class Program
{
static void Main(string[] args)
{
salary s = new salary(1000);
s.calculate();
s.display();
Console.ReadKey();
}
}
}
6. Create a program to create a delegate called TrafficDel and a class called TrafficSignal with the
following delegate methods. Public static void Yellow() { Console.WriteLine("Yellow Light
Signal To Get Ready");} Public static void Green() { Console.WriteLine("Green Light Signal To
Go"); } Public static void Red() { Console.WriteLine("Red Light Signal To Stop"); } Also
include a method IdentifySignal() to initialize an array of delegate with the above methods and a
method show() to invoke members of the above array.
using System;
// Delegate definition
public delegate void TrafficDel();
// TrafficSignal class
public class TrafficSignal
{
// Delegate methods
public static void Yellow()
{
Console.WriteLine("Yellow Light Signal To Get Ready");
}
Output: