constructor overloading method in c#

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//constructor overloading

using System;

using System.Collections.Generic;

using System.Text;

namespace over

{

class con

{

void check(int d)

{

string[] n ={“one”,“two”,“three”,“four”,“five”,“six”,“seven”,“eight”,“nine”};

Console.Write(n[d-1]);

}

//123= one two three

con(int a)

{

int[] rem=new int[10];

int i=0;

while(a!=0)

{

i++;

rem[i] = a % 10;

a = a / 10;

}

for (int j = i; j > 0; j–)

{

check(rem[j]);

Console.Write(” “);

}

}

//123= one hundred twenty three

con(int b, int x)

{

Console.WriteLine(” “);

int[] rem = new int[10];

int i = 0;

int ck = 0, ck1 = 0;

while (b != 0)

{

i++;

rem[i] = b % 10;

b = b / 10;

if (i == 5)

ck = 1;

if (i == 7)

ck1 = 1;

}

for (int j = i; j > 0; j–)

{

if (rem[j] != 0)

{

check(rem[j]);

check2(j, ck, ck1);

}

}

}

//roman

con(int a, int x, int y)

{

string[] m ={ “I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX” };

Console.WriteLine(“”);

while (a >= 10)

{

if (a >= 500)

{

Console.Write(” C “);

a = a – 500;

}

if (a >= 100 && a < 500)

{

a = a – 100;

Console.Write(” M “);

}

if (a >= 50 && a < 100)

{

a = a – 50;

Console.Write(” L “);

}

if (a >= 10 && a < 50)

{

a = a – 10;

Console.Write(” X “);

}

}

Console.Write(m[a-1]);

}

void check2(int f,int c,int c1)

{

if (f == 2)

Console.Write(“ty “);

else if (f == 3)

Console.Write(” hundred “);

else if (f == 4)

Console.Write(” thousand “);

else if (f == 6)

Console.Write(” lakhs “);

else if (f == 5)

{

if (c != 1)

Console.Write(” lakhs “);

Else

Console.Write(“ty”);

}

else if (f == 7)

{

if (c1 != 1)

Console.Write(” thousand “);

else

Console.Write(“ty”);

}

}

static void Main(string[] args)

{

Console.WriteLine(“Enter any number”);

int num;

num=int.Parse(Console.ReadLine());

con p = new con(num);

con q = new con(num,1);

con r = new con(num,1,2);

Console.ReadLine();

}

}

}

/***********OUTPUT**********

Enter any number

586

five eight six

five hundred eightty six

D L X X X VI

Leave a Reply

Your email address will not be published. Required fields are marked *