如何定义类?
class cp{
public double sum(double[] t)
{
double result = 0;
foreach (double i in t)
{
result = result + i;
}
return result;
}
cp mycp = new cp();
PointF[] p = new PointF[8];
double a, b, c, u, q;
private double sumx(PointF[] tp)//求X的和
{
double[] temp = new double[tp.Length];
for (int i = 0; i < tp.Length; i++)
{
temp[i] = tp[i].X;
}
return mycp.sum(temp);
}
private double sumy(PointF[] tp)//Y的和
{
double[] temp = new double[tp.Length];
for (int i = 0; i < tp.Length; i++)
{
temp[i] = tp[i].Y;
}
return mycp.sum(temp);
}
private double sumx2(PointF[] tp)//求X2的和
{
double[] temp = new double[tp.Length];
for (int i = 0; i < tp.Length; i++)
{
temp[i] = Math.Pow(tp[i].X, 2);
}
return mycp.sum(temp);
}
private double sumx3(PointF[] tp)//求X3和
{
double[] temp = new double[tp.Length];
for (int i = 0; i < tp.Length; i++)
{
temp[i] = Math.Pow(tp[i].X, 3);
}
return mycp.sum(temp);
}
private double sumx4(PointF[] tp)//求X4的和
{
double[] temp = new double[tp.Length];
for (int i = 0; i < tp.Length; i++)
{
temp[i] = Math.Pow(tp[i].X, 4);
}
return mycp.sum(temp);
}
private double sumxy(PointF[] tp)//求XY的和
{
double[] temp = new double[tp.Length];
for (int i = 0; i < tp.Length; i++)
{
temp[i] = tp[i].X * tp[i].Y;
}
return mycp.sum(temp);
}
private double sumx2y(PointF[] tp)//求X2Y的和
{
double[] temp = new double[tp.Length];
for (int i = 0; i < tp.Length; i++)
{
temp[i] = Math.Pow(tp[i].X, 2) * tp[i].Y;
}
return mycp.sum(temp);
}
private void calculate()
{
int n = tidu.Length;
double d, e, f, g, h;
d = n * sumx2(p) - sumx(p) * sumx(p);
e = n * sumx2y(p) - sumx2(p) * sumy(p);
f = n * sumxy(p) - sumx(p) * sumy(p);
g = n * sumx3(p) - sumx2(p) * sumx(p);
h = n * sumx4(p) - sumx2(p) * sumx2(p);
a = (d * e - f * g) / (h * d - g * g);
b = (f - g * a) / d;
c = (sumy(p) - a * sumx2(p) - b * sumx(p)) / n;
u = -(b / (2 * a));
q = Math.Sqrt(-1 / (2 * a));
this.label4.Text = "a=" + a.ToString() + "\r\nb=" + b.ToString() + "\r\nc=" + c.ToString() + "\r\nu=" + u.ToString() + "\r\nq=" + q.ToString();
}
怎么把上面的用类定义出来,哪位大侠帮帮忙!