类的封装

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 简易运算
{
class Pack //封装
{
private int x;
private int y;
private string oper;
private int anster = 0;

public int OP
{
set
{
x = value;
}
get
{
return x;
}
}
public int Pt
{
set
{
y = value;
}
get
{
return y;
}
}
public string Oper
{
set
{
oper = value;

}
get
{
return oper;
}
}
public int Aster
{
get
{
return anster;
}
}
public int yusuan()
{
switch (oper)
{
case "+":
anster = x + y;
break;
case "-":
if (x > y)
anster = x - y;
//else
// throw new Exception("被减数不能小于减数,既不能出现负数");
break;
case "*":
anster = x * y;
break;
case "/":
//if (y == 0)
//{
// throw new Exception("被除数不能等于零!");

//}
//else
anster = x / y;
break;
}
return anster;

}
public int fanhui()
{
return anster;
}

}
}

posted @ 2015-12-02 21:45  刘远航  阅读(130)  评论(1编辑  收藏  举报