Click here to Skip to main content
15,904,653 members
Home / Discussions / C#
   

C#

 
AnswerRe: TripleDES encryption. Anyone want to help? Pin
Colin Angus Mackay17-Jan-06 23:03
Colin Angus Mackay17-Jan-06 23:03 
GeneralRe: TripleDES encryption. Anyone want to help? Pin
jbergetun18-Jan-06 7:48
jbergetun18-Jan-06 7:48 
GeneralRe: TripleDES encryption. Anyone want to help? Pin
Colin Angus Mackay18-Jan-06 11:39
Colin Angus Mackay18-Jan-06 11:39 
GeneralRe: TripleDES encryption. Anyone want to help? Pin
jbergetun19-Jan-06 10:21
jbergetun19-Jan-06 10:21 
QuestionWaiting for Event to fire Pin
Bralyan17-Jan-06 12:29
Bralyan17-Jan-06 12:29 
Questioncalculating fraction in c# Pin
two_man_only17-Jan-06 12:02
two_man_only17-Jan-06 12:02 
AnswerRe: calculating fraction in c# Pin
Christian Graus17-Jan-06 14:03
protectorChristian Graus17-Jan-06 14:03 
GeneralRe: calculating fraction in c# Pin
two_man_only24-Jan-06 12:02
two_man_only24-Jan-06 12:02 
Hi, Christian Graus i`m realy apperciateLaugh | :laugh: your replay and i think that i found the code i need.Cool | :cool:



using System;

namespace Point_project
{
public class Fraction
{
private int up, down;
public Fraction()
{}
public Fraction( int m, int n)
{
Up = m;
Down = n;
}
public override string ToString()
{
return Up+""+" / "+Down;
}

public int Up
{
get
{
return up;
}
set
{
up = value;
}
}
public int Down
{
get
{
return down;
}
set
{
down = value;
}
}

public static Fraction operator + (Fraction x, Fraction y)
{
int r1 = (x.Down * y.Up) + (y.down * x.Up);
int r2 = x.Down * y.down;
return new Fraction( r1, r2);
}
public static Fraction Add( Fraction x, Fraction y)
{
return x + y;
}

public static Fraction operator - (Fraction x, Fraction y)
{
int r1 = (y.down * x.Up)-(x.Down * y.Up) ;
int r2 = x.Down * y.down;
return new Fraction( r1, r2);
}
public static Fraction Sub( Fraction x, Fraction y)
{
return x - y;
}

public static Fraction operator * (Fraction x, Fraction y)
{
return new Fraction( x.Up * y.Up, x.Down * y.Down);
}
public static Fraction Multiply( Fraction x, Fraction y)
{
return x * y;
}

public static Fraction operator / ( Fraction x, Fraction y)
{
int r1 = x.Up * y.Down;
int r2 = x.Down * y.Up;
return new Fraction( r1, r2);
}
public static Fraction Division ( Fraction x, Fraction y)
{
return x / y;
}

public static int GCD(int left, int right)
{
if (left < 0)
left = - left;

if (right < 0)
right = - right;

if (left < 2 || right < 2)
return 1;

if(left == right)return left;

do
{
if (left < right)
{
int temp = left;
left = right;
right = temp;
}

left %= right;

} while (left != 0);

return right;
}
public void simplify()
{
int g=GCD(down,up);
down/=g;
up/=g;
}
}
public class FractionTeast
{
static void Main()
{
Fraction w = new Fraction();
Fraction x = new Fraction();
Fraction y = new Fraction();
Fraction z = new Fraction();

Console.Write("Numerator1 =");
x.Up = Convert.ToInt32(Console.ReadLine());

Console.Write("denominator1 =");
x.Down = Convert.ToInt32(Console.ReadLine());
while(x.Down == 0)
{
Console.Write("Invalid value REENTER denominator1 =");
x.Down = Convert.ToInt32(Console.ReadLine());
}
Console.Write("\nNumerator2 =");
y.Up = Convert.ToInt32(Console.ReadLine());

Console.Write("denominator2 =");
y.Down = Convert.ToInt32(Console.ReadLine());
while(y.Down == 0)
{
Console.Write("Invalid value REENTER denominator1 =");
y.Down = Convert.ToInt32(Console.ReadLine());
}
Console.Write("\nSelect the calculation type (1:Addtion, 2:Subtraction, 3:Multiplication, 4:Division, Or 0:ToTerminate)==>");
sbyte e = Convert.ToSByte(Console.ReadLine());

while(e != 0)
{
if(e < 0 || e > 4)
{
Console.Write("\nInvalid number PLEASE Select the calculation type (1:Addtion, 2:Subtraction, 3:Multiplication, 4:Division, Or 0:ToTerminate)==>");
e = Convert.ToSByte(Console.ReadLine());
}

if( e == 1)
{
z = (x+y);
z.simplify();
if(z.Down == 1)
{
Console.WriteLine(x.Up+"/"+x.Down+" + "+y.Up+"/"+y.Down+" = "+z.Up);
}
else if(z.Up == 0)
{
Console.WriteLine(x.Up+"/"+x.Down+" + "+y.Up+"/"+y.Down+" = 0");
}
else
{
Console.WriteLine(x.Up+"/"+x.Down+" + "+y.Up+"/"+y.Down+" = "+z);
}

Console.Write("\nSelect the calculation type (1:Addtion, 2:Subtraction, 3:Multiplication, 4:Division, Or 0:ToTerminate)==>");
e = Convert.ToSByte(Console.ReadLine());
}
if( e == 2)
{
z = (x-y);
z.simplify();

if(z.Down == 1)
{
Console.WriteLine(x.Up+"/"+x.Down+" - "+y.Up+"/"+y.Down+" = "+z.Up);
}
else if(z.Up == 0)
{
Console.WriteLine(x.Up+"/"+x.Down+" - "+y.Up+"/"+y.Down+" = 0");
}
else
{
Console.WriteLine(x.Up+"/"+x.Down+" - "+y.Up+"/"+y.Down+" = "+z);
}

Console.Write("\nSelect the calculation type (1:Addtion, 2:Subtraction, 3:Multiplication, 4:Division, Or 0:ToTerminate)==>");
e = Convert.ToSByte(Console.ReadLine());
}
if( e == 3)
{
z = (x*y);
z.simplify();

if(z.Down == 1)
{
Console.WriteLine(x.Up+"/"+x.Down+" X "+y.Up+"/"+y.Down+" = "+z.Up);
}
else if(z.Up == 0)
{
Console.WriteLine(x.Up+"/"+x.Down+" X "+y.Up+"/"+y.Down+" = 0");
}
else
{
Console.WriteLine(x.Up+"/"+x.Down+" X "+y.Up+"/"+y.Down+" = "+z);
}

Console.Write("\nSelect the calculation type (1:Addtion, 2:Subtraction, 3:Multiplication, 4:Division, Or 0:ToTerminate)==>");
e = Convert.ToSByte(Console.ReadLine());
}
if( e == 4)
{
z = (x/y);
z.simplify();

if(z.Down == 1)
{
Console.WriteLine(x.Up+"/"+x.Down+" / "+y.Up+"/"+y.Down+" = "+z.Up);
}
else if(z.Up == 0)
{
Console.WriteLine(x.Up+"/"+x.Down+" / "+y.Up+"/"+y.Down+" = 0");
}
else
{
Console.WriteLine(x.Up+"/"+x.Down+" / "+y.Up+"/"+y.Down+" = "+z);
}

Console.Write("\nSelect the calculation type (1:Addtion, 2:Subtraction, 3:Multiplication, 4:Division, Or 0:ToTerminate)==>");
e = Convert.ToSByte(Console.ReadLine());
}
}
if( e == 0)
{
Console.WriteLine("\nPress ENTER toterminate");
Console.ReadLine();
}
}
}
}

casue i'm the man withno lose
GeneralRe: calculating fraction in c# Pin
Christian Graus24-Jan-06 12:04
protectorChristian Graus24-Jan-06 12:04 
GeneralRe: calculating fraction in c# Pin
two_man_only25-Jan-06 1:11
two_man_only25-Jan-06 1:11 
QuestionGracefully shutting down threads Pin
User 665817-Jan-06 11:44
User 665817-Jan-06 11:44 
AnswerRe: Gracefully shutting down threads Pin
CWIZO17-Jan-06 21:15
CWIZO17-Jan-06 21:15 
GeneralRe: Gracefully shutting down threads Pin
User 665818-Jan-06 2:12
User 665818-Jan-06 2:12 
GeneralRe: Gracefully shutting down threads Pin
CWIZO18-Jan-06 3:01
CWIZO18-Jan-06 3:01 
QuestionVS 2005 UK edition Pin
pieterman17-Jan-06 11:44
pieterman17-Jan-06 11:44 
AnswerRe: VS 2005 UK edition Pin
Christian Graus17-Jan-06 14:03
protectorChristian Graus17-Jan-06 14:03 
GeneralRe: VS 2005 UK edition Pin
pieterman18-Jan-06 7:03
pieterman18-Jan-06 7:03 
QuestionTry/Catch Variable Scoping Pin
RobertF5717-Jan-06 11:34
RobertF5717-Jan-06 11:34 
AnswerRe: Try/Catch Variable Scoping Pin
Guffa17-Jan-06 11:50
Guffa17-Jan-06 11:50 
GeneralRe: Try/Catch Variable Scoping Pin
RobertF5717-Jan-06 11:55
RobertF5717-Jan-06 11:55 
AnswerRe: Try/Catch Variable Scoping Pin
Guffa17-Jan-06 12:14
Guffa17-Jan-06 12:14 
GeneralRe: Try/Catch Variable Scoping Pin
RobertF5717-Jan-06 12:38
RobertF5717-Jan-06 12:38 
QuestionSetup Project - Getting the user selected install directory Pin
dotnetprgrmmr17-Jan-06 11:28
dotnetprgrmmr17-Jan-06 11:28 
AnswerRe: Setup Project - Getting the user selected install directory Pin
Sasuko17-Jan-06 11:48
Sasuko17-Jan-06 11:48 
GeneralRe: Setup Project - Getting the user selected install directory Pin
dotnetprgrmmr17-Jan-06 12:00
dotnetprgrmmr17-Jan-06 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.