using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("第一个数:");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("输入运算符(+—*/)");
// c=Console.ReadLine();
char str=Convert.ToChar(Console.ReadLine());
Console.WriteLine("第er个数:");
int b = Int32.Parse(Console.ReadLine());
//int c = a + b;
//Console.WriteLine("两个数和为:{0}",c);
switch (str) {
case '+':
Console.WriteLine("两个数和为:{0}", a+b);
break;
case '-':
Console.WriteLine("两个数差为:{0}", a-b);
break;
case '*':
Console.WriteLine("两个数积为:{0}", a*b);
break;
case '/':
Console.WriteLine("两个数商为:{0}", a/b);
break;
case '%':
Console.WriteLine("两个数余数为:{0}", a % b);
break;
default:
Console.WriteLine("输入正确的运算符!!");
break;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("第一个数:");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("输入运算符(+—*/)");
// c=Console.ReadLine();
char str=Convert.ToChar(Console.ReadLine());
Console.WriteLine("第er个数:");
int b = Int32.Parse(Console.ReadLine());
//int c = a + b;
//Console.WriteLine("两个数和为:{0}",c);
switch (str) {
case '+':
Console.WriteLine("两个数和为:{0}", a+b);
break;
case '-':
Console.WriteLine("两个数差为:{0}", a-b);
break;
case '*':
Console.WriteLine("两个数积为:{0}", a*b);
break;
case '/':
Console.WriteLine("两个数商为:{0}", a/b);
break;
case '%':
Console.WriteLine("两个数余数为:{0}", a % b);
break;
default:
Console.WriteLine("输入正确的运算符!!");
break;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Cauculator
{
static void Main(string[] args)
{
Console.WriteLine("请输入两个数:");
Console.WriteLine("add="+Add.add(Int32.Parse( Console.ReadLine()),Int32.Parse( Console.ReadLine())));
Console.WriteLine("请输入两个数:");
Console.WriteLine("less=" + Less.less(Int32.Parse(Console.ReadLine()), Int32.Parse(Console.ReadLine())));
Console.WriteLine("请输入两个数:");
Console.WriteLine("Multiply="+Multiply.multiply (Int32.Parse( Console.ReadLine()),Int32.Parse( Console.ReadLine())));
Console.WriteLine("请输入两个数:");
Console.WriteLine("Divided="+Divided.divided (Int32.Parse( Console.ReadLine()),Int32.Parse( Console.ReadLine())));
Console.ReadLine();
}
}
}
class Add
{
public static int add(int a, int b)
{
return (a + b);
} } class Less
{
public static int less(int a, int b)
{
return (a - b);
} }
class Multiply
{
public static int multiply(int a, int b)
{
return (a * b);
} }
class Divided
{
public static int divided(int a, int b)
{
return (a / b);
} }
告诉你为什么写成4个类,分开写成四个类是完全秉承了写代码要讲求高内聚低耦合的思想!
.不懂你为什么要写成四个类,.我写了一个all类.里面包括这四个功能.你说的我也写了.
//写的有什么不对的请指点.vs2005 开发.http://www.lzexe.com/HelpWord/Cauculator.rar