You are on page 1of 6

PRACTICAL 3

using System;
namespace staff
{
class staff
{
string name, post;
public void getdata()
{
Console.Write("Enter name and post:");
name = Console.ReadLine();
post = Console.ReadLine();
}
public void display()
{
Console.WriteLine(name + "\t\t" + post);
}
public string getPost()
{
return post;
}
}
class program
{
static void Main(string[] args)
{
staff[] objStaff = new staff[5];
int i;
for (i = 0; i < 5; i++)
{
objStaff[i] = new staff();
objStaff[i].getdata();
}
Console.WriteLine("Name \t\t Post");
for (i = 0; i < 5; i++)
{
if (objStaff[i].getPost() == "HOD")
objStaff[i].display();
}
}
}
}
PRACTICAL 4

using System;
namespace distanceclass
{
class Distance
{
int dist1,dist2,dist3;
public Distance(int dist1,int dist2)
{
this.dist1=dist1;
this.dist2=dist2;
}
public void addition()
{
dist3=dist1+dist2;
}
public void display()
{
Console.WriteLine("Distance1:"+ dist1);
Console.WriteLine("Distance1:"+ dist2);
Console.WriteLine("Distance1:"+ dist3);
}}
class program
{
static void Main(string[] args)
{
Distance objDistance = new Distance(10, 20);
objDistance.addition();
objDistance.display();
}}}

PRACTICAL 5

using System;

public class Salary

// Member variables

private double Basic;

private double TA;

private double DA;

private double HRA;

// Constructor with default values for DA and HRA

public Salary(double basic, double ta, double da = 0, double hra = 0)

Basic = basic;

TA = ta;

DA = da;
HRA = hra;

// Method to calculate total salary

public double CalculateTotalSalary()

// Total salary = Basic + TA + DA + HRA

return Basic + TA + DA + HRA;

class Program

static void Main(string[] args)

// Create a Salary object with default values for DA and HRA

Salary employeeSalary = new Salary(50000, 20000);

// Calculate and display the total salary

Console.WriteLine("Total salary of the employee: " + employeeSalary.CalculateTotalSalary());

Practical 6
using System;

// Define the delegate


public delegate void TrafficDel();

// Define the TrafficSignal class


public class TrafficSignal
{
// 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");
}

// Method to initialize an array of delegate with the above methods


public TrafficDel[] IdentifySignal()
{
// Initialize an array of delegates
TrafficDel[] signals = new TrafficDel[3];

// Assign delegate methods to array elements


signals[0] = Yellow;
signals[1] = Green;
signals[2] = Red;

return signals;
}

// Method to invoke members of the array of delegates


public void Show()
{
TrafficDel[] signals = IdentifySignal();

// Invoke each delegate method in the array


foreach (TrafficDel signal in signals)
{
signal();
}
}
}

class Program
{
static void Main(string[] args)
{
TrafficSignal trafficSignal = new TrafficSignal();

// Invoke the Show method to display the traffic signals


trafficSignal.Show();
}
}

PRACTICAL 7

You might also like