控制台应用程序下的计算器(调用子类)
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double a = 0;
double b = 0;
double c = 0;
Console.WriteLine("请输入第一个数:");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入第二个数:");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入运算符号!");
string hao = Console.ReadLine();
leiku.fulei fl = gethao(hao);
fl.a = a;
fl.b = b;
c = fl.GetC();
Console.WriteLine(c);
Console.ReadKey();
}
private static leiku.fulei gethao(string hao)
{
leiku.fulei fl = null;
switch (hao)
{
case "+":
fl = new leiku.add();
break;
case "-":
fl = new leiku.jian();
break;
case "*":
fl = new leiku.cheng();
break;
case "/":
fl = new leiku.chu();
break;
case "sqrt":
fl = new leiku.sqrt();
break;
case "sin":
fl = new leiku.sin();
break;
}
return fl;
}
}
}