| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 581 人关注过本帖, 1 人收藏
标题:求解释哪里错了。
只看楼主 加入收藏
半空的spider
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-4-28
结帖率:100%
收藏(1)
 问题点数:0 回复次数:4 
求解释哪里错了。
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 类
{
      public class student      //定义一个类
        {
            public string name;
            public float score1;
            public float score2;
            public float score3;
            public float sum(float s1, float s2,float s3)
            {this.score1=s1;
                this.score2=s2;
                this.score3=s3;
                return score1+score2+score3;
            }
              public float ave(float s1, float s2,float s3)
            {this.score1=s1;
                this.score2=s2;
                this.score3=s3;
                return (score1+score2+score3)/3;
            }
    public partial class Form1 : Form
    {
      
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            int i = 0;
            float n = 0, m = 0, s1, s2, s3;
            student[] stu = new student[44];
            Random rnd = new Random();
            stu[i].name = ((char)rnd.Next(65, 97)).ToString() + ((char)rnd.Next(65, 97)).ToString() + ((char)rnd.Next(65, 97)).ToString();//姓名
            s1 = (float)rnd.Next(1, 100);// 分数1
            s2 = (float)rnd.Next(1, 100);//分数2
            s3 = (float)rnd.Next(1, 100);//分数3
            n = stu[i].sum(s1, s2, s3);//总分
            m = stu[i].ave(s1, s2, s3);//平均分
            textBox1.Text = Convert.ToString(stu[i].name);
            textBox2.Text = Convert.ToString(s1);
            textBox3.Text = Convert.ToString(s2);
            textBox4.Text = Convert.ToString(s3);
            textBox5.Text = Convert.ToString(n);
            textBox6.Text = Convert.ToString(m);
        }

        }
    }
}
谁能给我正确的写法啊
搜索更多相关主题的帖子: public namespace 
2013-04-30 15:21
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
你的student是个类,Form1也是一个类啊,应该是
public class student
{
}
public partial class Form1 : Form
{
}

而不是
public class student
{
    public partial class Form1 : Form
    {
    }
}
注意一下大括号
2013-04-30 18:24
lxb932979339
Rank: 5Rank: 5
等 级:职业侠客
威 望:4
帖 子:84
专家分:313
注 册:2013-4-24
收藏
得分:0 
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 类
{
    public class student      //定义一个类
    {
        public string name;
        public float score1;
        public float score2;
        public float score3;
        public float sum(float s1, float s2, float s3)
        {
            this.score1 = s1;
            this.score2 = s2;
            this.score3 = s3;
            return score1 + score2 + score3;
        }
        public float ave(float s1, float s2, float s3)
        {
            this.score1 = s1;
            this.score2 = s2;
            this.score3 = s3;
            return (score1 + score2 + score3) / 3;
        }
    }
    partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            int i = 0;
            float n = 0, m = 0, s1, s2, s3;
            student[] stu = new student[44];
            Random rnd = new Random();
            stu[i] = new student();
            stu[i].name = ((char)rnd.Next(65, 97)).ToString()+ ((char)rnd.Next(65, 97)).ToString() + ((char)rnd.Next(65, 97)).ToString();//姓名
            s1 = (float)rnd.Next(1, 100);// 分数1
            s2 = (float)rnd.Next(1, 100);//分数2
            s3 = (float)rnd.Next(1, 100);//分数3
            n = stu[i].sum(s1, s2, s3);//总分
            m = stu[i].ave(s1, s2, s3);//平均分
            textBox1.Text = Convert.ToString(stu[i].name);
            textBox2.Text = Convert.ToString(s1);
            textBox3.Text = Convert.ToString(s2);
            textBox4.Text = Convert.ToString(s3);
            textBox5.Text = Convert.ToString(n);
            textBox6.Text = Convert.ToString(m);
        }
    }
}


[ 本帖最后由 lxb932979339 于 2013-5-1 16:29 编辑 ]
2013-05-01 15:42
csharpluntan
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:7
帖 子:197
专家分:1122
注 册:2013-4-24
收藏
得分:0 
路过

投之以桃,报之以李
2013-05-01 17:27
csharpluntan
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:7
帖 子:197
专家分:1122
注 册:2013-4-24
收藏
得分:0 
ZAI\CI \LU \GUO

投之以桃,报之以李
2013-05-02 11:08
快速回复:求解释哪里错了。
数据加载中...
 
   



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

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