Tuesday, 28 May 2019

Operator Overloading C# program Source Code


Operator Overloading
using System;
namespace OperatorOverloading
{
    class Box
    {
        double lenght, breadth, height;

        public double getVolume()
        {

            return lenght * breadth * height;
        }

        public void setLenght(double len)
        {
            lenght = len;
        }
        public void setBreadth(double bre)
        {
            breadth = bre;
        }
        public void setheight(double hei)
        {
            height = hei;
        }
        public static Box OperatorOverloading(Box b,Box c)
        {
            Box box = new Box();
            box.lenght = b.lenght + c.lenght;
            box.breadth = b.breadth + c.breadth;
            box.height = b.height + c.height;

            return box;
        }

      }

    class Program
    {
        static void Main(string[]args)
        {

            Box Box1 = new Box();
            Box Box2 = new Box();
            Box Box3 = new Box();
            double volume = 0.0;

            Box1.setLenght(6.0);
            Box1.setBreadth(7.0);
            Box1.setheight(5.0);

            Box2.setLenght(12.0);
            Box2.setBreadth(13.0);
            Box2.setheight(10.0);


            volume = Box1.getVolume();
            Console.WriteLine("Volume of the Box1={0}",volume);
            volume = Box2.getVolume();
            Console.WriteLine("Volume of the Box2={0}", volume);
          
            volume = Box3.getVolume();
            Console.WriteLine("Volume of the box3={0}",volume);
            Console.ReadKey();
       }
   }
}

No comments:

Post a Comment