C# 模拟电子计算器的功能,编写一个类,实现两个整数的加减乘除运算
展开全部
public class Calculator
{
//加法运算
public int Add(int a,int b)
{
return a+b;
}
//减法运算
public int Sub(int a,int b)
{
return a-b;
}
//乘法运算
public int Mul(int a,int b)
{
return a*b;
}
//除法预算
public int Div(int a,int b)
{
if(b!=0) //判断分母不能为0
{
return a/b;
}
return 0;
}
}
比较简易的算法,复杂点可以使用多态!
2017-08-18 · 知道合伙人互联网行家
关注
展开全部
class cal{
public double cal(double num1,double num2,string oper){
double result = 0;
switch(oper){
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "+":
result = num1 * num2;
break;
case "+":
result = num1 / num2;
break;
}
retrun result;
}
}
public double cal(double num1,double num2,string oper){
double result = 0;
switch(oper){
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "+":
result = num1 * num2;
break;
case "+":
result = num1 / num2;
break;
}
retrun result;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class cal{
public double cal(double num1,double num2,string oper){
double result = 0;
switch(oper){
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "+":
result = num1 * num2;
break;
case "+":
result = num1 / num2;
break;
}
retrun result;
}
}
public double cal(double num1,double num2,string oper){
double result = 0;
switch(oper){
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "+":
result = num1 * num2;
break;
case "+":
result = num1 / num2;
break;
}
retrun result;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询