PROGRAM TO DEVELOP A CALCULATOR IN C-SHARP BY USING CLASS
BEGIN
using System;
class test
{
public void add()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1+n2);
}
public void sub()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1 - n2);
}
public void mul()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1 * n2);
}
public void div()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1 / n2);
}
public static void Main()
{
Console.WriteLine("1-add 2-sub 3-multiply 4-divide");
int choice = int.Parse(Console.ReadLine());
if (choice == 1)
{
test obj = new test();
obj.add();
}
else if (choice == 2)
{
test obj = new test();
obj.sub();
}
else if (choice == 3)
{
test obj = new test();
obj.mul();
}
else if (choice == 4)
{
test obj = new test();
obj.div();
}
}
}
END
BEGIN
using System;
class test
{
public void add()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1+n2);
}
public void sub()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1 - n2);
}
public void mul()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1 * n2);
}
public void div()
{
Console.WriteLine("enter 2 number");
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
Console.WriteLine(n1 / n2);
}
public static void Main()
{
Console.WriteLine("1-add 2-sub 3-multiply 4-divide");
int choice = int.Parse(Console.ReadLine());
if (choice == 1)
{
test obj = new test();
obj.add();
}
else if (choice == 2)
{
test obj = new test();
obj.sub();
}
else if (choice == 3)
{
test obj = new test();
obj.mul();
}
else if (choice == 4)
{
test obj = new test();
obj.div();
}
}
}
END
0 comments:
Post a Comment