Answer to Question #256565 in C# for shaves

Question #256565

Write a program in C# to implement the operator overloading for the greater than (>) and assignment (=) operators


1
Expert's answer
2021-10-25T14:49:50-0400
using System;
using System.Collections.Generic;


namespace App
{


    class Number
    {
        private double number;


        public double DoubleNumber
        {
            get { return number; }
            set { number = value; }
        }




        public Number() { }


        public Number(double number)
        {
            this.number = number;
        }
        public static bool operator <(Number otherNumber1, Number otherNumber2)
        {
            return (otherNumber1.DoubleNumber < otherNumber2.DoubleNumber);
        }
        public static bool operator >(Number otherNumber1, Number otherNumber2)
        {
            return (otherNumber1.DoubleNumber > otherNumber2.DoubleNumber);
        }


    }


    class Program
    {


        static void Main(string[] args)
        {
            Console.Write("Enter number 1: ");
            double number1 = double.Parse(Console.ReadLine());
            Console.Write("Enter number 2: ");
            double number2 = double.Parse(Console.ReadLine());


            Number n1 = new Number(number1);
            Number n2 = new Number(number2);




            Console.WriteLine("n1 > n2 = {0}", (n1 > n2));
            n2 = n1;
            Console.WriteLine("n2 = {0}", n2.DoubleNumber);


            Console.ReadLine();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS