| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2625 人关注过本帖
标题:如何定义类?
取消只看楼主 加入收藏
hailingmm
Rank: 2
等 级:论坛游民
帖 子:96
专家分:15
注 册:2009-10-15
结帖率:91.67%
收藏
已结贴  问题点数:20 回复次数:5 
如何定义类?
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();
        }

怎么把上面的用类定义出来,哪位大侠帮帮忙!
搜索更多相关主题的帖子: 定义 
2010-05-20 11:31
hailingmm
Rank: 2
等 级:论坛游民
帖 子:96
专家分:15
注 册:2009-10-15
收藏
得分:0 
回复 楼主 hailingmm
我想把下面的定义成类,看了一些资料,但是不会啊!
2010-05-20 11:35
hailingmm
Rank: 2
等 级:论坛游民
帖 子:96
专家分:15
注 册:2009-10-15
收藏
得分:0 
回复 3楼 hailingmm
我试了怎么有问题啊?
2010-05-20 13:59
hailingmm
Rank: 2
等 级:论坛游民
帖 子:96
专家分:15
注 册:2009-10-15
收藏
得分:0 
回复 3楼 hailingmm
重新定义一个类放进去老是出现这样的错误:找不到类型或命名空间名称PointF,是否缺少using指令或程序集应用。
2010-05-20 14:03
hailingmm
Rank: 2
等 级:论坛游民
帖 子:96
专家分:15
注 册:2009-10-15
收藏
得分:0 
回复 3楼 hailingmm
定义了之后怎么调用类啊?
2010-05-20 14:08
hailingmm
Rank: 2
等 级:论坛游民
帖 子:96
专家分:15
注 册:2009-10-15
收藏
得分:0 
回复 9楼 adu_to
明白了,谢谢!
2010-05-21 08:40
快速回复:如何定义类?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035421 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved