Design a c# console Application that will output the salary sum of two employees
. Your program must do the following :
· Create an abstract data type, Emp. with two private data members Sal. (Type Double) and name (Type String).
· Include a constructor in the Emp class to initialize all private data members with caller-supplied values (in addition to the default constructor!)
· Overload the + operator to return the sum of two Emp objects.
· Your OutPut Should be like:
· Sum of Employees Salary : Shaban, khurrum = 450000.
using System;
namespace ConsoleApplication1
{
internal class Program
{
public static void Main(string[] args)
{
var date1 = new Data(5, 6, 7);
var date2 = new Data(3, 4, 5);
var date3 = date1 + date2;
date3.Display();
}
}
class Data
{
public int Day;
public int Month;
public int Year;
public Data()
{
Day = 0;
Month = 0;
Year = 0;
}
public Data(int d, int m, int y)
{
Day = d;
Month = m;
Year = y;
}
public void Display()
{
Console.WriteLine($"{Day}/{Month}/{Year}");
}
public static Data operator +(Data d1, Data d2)
{
return new Data(d1.Day + d2.Day, d1.Month + d2.Month, d1.Year + d2.Year);
}
}
}
Comments
Leave a comment