Tuesday, November 11, 2014

SOME SIMPLE SOURCE CODES THAT I DEVELOPED IN C#.NET AFTER REFERRING FEW BOOKS FEEL FREE TO POINT OUT ERRORS IF ANY

SOURCE CODE #1
using System;
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello C#");
        }
    }

OUTPUT OF SOURCE CODE #1



SOURCE CODE #2:
using System;
namespace ConsoleApplication2
{
    public class Fraction
    {
        public Fraction(int numerator, int denominator)
        {
            this.numerator = numerator;
            this.denominator = denominator;
        }
        public void Add(Fraction rhs)   
        {
            if(rhs.denominator != this.denominator)
            {
                throw new ArgumentException("Denominators must match");
            }
            //return new Fraction(this.numerator+rhs.numerator, this.denominator);
            Console.WriteLine("The sum of the two fractions is " + (this.numerator + rhs.numerator) + " / " + this.denominator);
        }
        public override string ToString()
        {
            return numerator + "/" + denominator;
        }
        private int numerator;
        private int denominator;
        public static void Main (String []args)
        {
            Fraction frac = new Fraction(2,3);
            Fraction frac1 = new Fraction(4,3);
            frac1.Add(frac);
        }
    }
}

OUTPUT FOR SOURCE CODE #2:




No comments:

Post a Comment