class Calculator
{
public void Sum(int num1, int num2)
{
return num1+num2;
}
public void Diff(int num1, int num2)
{
return num1-num2;
}
public void Product(int num1, int num2)
{
return num1*num2;
}
public void Div(int num1, int num2)
{
return num1/num2;
}
}
class Calculator
{
public int Sum(int num1, int num2)
{
return num1+num2;
}
public int Diff(int num1, int num2)
{
return num1-num2;
}
public int Product(int num1, int num2)
{
return num1*num2;
}
public int Div(int num1, int num2)
{
return num1/num2;
}
}
class Caculator
{
public int Summation(int r, int r1)
{
Console.WriteLine();
int s = r + r1;
Console.WriteLine(r + "+" + r1 + "=" + s);
return r + r1;
}
public int different(int r, int r1)
{
Console.WriteLine();
int s = r - r1;
Console.WriteLine(r + "-" + r1 + "=" + s);
return r - r1;
}
public int Product(int r, int r1)
{
Console.WriteLine();
double s = r * r1;
Console.WriteLine(r + "*" + r1 + "=" + s);
return r * r1;
}
public int Division(int r, int r1)
{
Console.WriteLine();
double s = r / r1;
Console.WriteLine(r + "/" + r1 + "=" + s);
return r1 / r1;
}
}
}
ส่วนอันนี้คือ code ที่ให้มันอ่านตัวค่าของ class Caculator
Code (C#)
class Program
{
static void Main()
{
int r, r1;
Console.Write("enter number1 :");
r = int.Parse(Console.ReadLine());
Console.Write("enter number2 :");
r1 = int.Parse(Console.ReadLine());
Caculator m = new Caculator();
m.Summation(r, r1);
m.different(r, r1);
m.Product(r, r1);
m.Division(r, r1);
Console.ReadLine();
}
}
}