| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1277 人关注过本帖
标题:C#中构造函数怎么使用?
取消只看楼主 加入收藏
liangshizhuo
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-5
结帖率:100%
收藏
已结贴  问题点数:2 回复次数:5 
C#中构造函数怎么使用?
1.设计一个学生成绩类,数据成员包括:班级,姓名,英语成绩、c#成绩、数据库;
方法成员包括:有参构造函数(参数为:班级,姓名,英语成绩、c#成绩、数据库),
计算总分,计算平均分,判断等级(平均在85,且各科成绩在75分以上为“优秀”
平均在75,且各科成绩在70分以上为“良好”其它“合格”)
2.采用WinForm形式设计程序,界面根据需要自行设计(考虑输入与输出),所有方法都要使用。
搜索更多相关主题的帖子: 英语成绩 设计程序 数据库 
2012-09-11 23:04
liangshizhuo
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-5
收藏
得分:0 
实例化class student=new class();是这样吗?求继续赐教!
2012-09-12 13:19
liangshizhuo
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-5
收藏
得分:0 
{
            string grade = Convert.ToString(textBox1.Text.Trim());
            string name = Convert.ToString(textBox2.Text.Trim());
            double sql = Convert.ToDouble(textBox3.Text.Trim());
            double english = Convert.ToDouble(textBox4.Text.Trim());
            double csharp = Convert.ToDouble(textBox5.Text.Trim());
            student h = new student(  grade,name,sql,english,csharp);
            label6.Text = Convert.ToString(h.zongfen(english, csharp,sql));
           

        }
        class student
        {
            string grade;
            string name;
            double sql;
            double english;
            double csharp,pj;
            public student(string grade, string name, double sql, double english, double csharp)
            {
                this.grade = grade;
                this.name = name;
                this.sql = sql;
                this.english = english;
                this.csharp = csharp;
            }
            public double zongfen(double english, double csharp,double sql)
            {
                return english + csharp+sql ;
            }
            public double average(double english, double csharp,double sql)
            {
                return pj = (english + csharp+sql) / 3;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string grade = Convert.ToString(textBox1.Text.Trim());
            string name = Convert.ToString(textBox2.Text.Trim());
            double  sql = Convert.ToDouble(textBox3.Text.Trim());
            double english = Convert.ToDouble(textBox4.Text.Trim());
            double csharp = Convert.ToDouble(textBox5.Text.Trim());
            student h = new student(grade, name, sql, english, csharp);
            label7.Text = Convert.ToString(h.average(english, csharp,sql));
        }
还可以怎么改进?肚子里的墨水太少,初次接触c#,另外判断等级的带码不怎么会写。求赐教!
2012-09-13 10:59
liangshizhuo
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-5
收藏
得分:0 
回复 4楼 ZWYyj
{
            string grade = Convert.ToString(textBox1.Text.Trim());
            string name = Convert.ToString(textBox2.Text.Trim());
            double sql = Convert.ToDouble(textBox3.Text.Trim());
            double english = Convert.ToDouble(textBox4.Text.Trim());
            double csharp = Convert.ToDouble(textBox5.Text.Trim());
            student h = new student(  grade,name,sql,english,csharp);
            label6.Text = Convert.ToString(h.zongfen(english, csharp,sql));
           

        }
        class student
        {
            string grade;
            string name;
            double sql;
            double english;
            double csharp,pj;
            public student(string grade, string name, double sql, double english, double csharp)
            {
                this.grade = grade;
                this.name = name;
                this.sql = sql;
                this.english = english;
                this.csharp = csharp;
            }
            public double zongfen(double english, double csharp,double sql)
            {
                return english + csharp+sql ;
            }
            public double average(double english, double csharp,double sql)
            {
                return pj = (english + csharp+sql) / 3;
            }
            public string dengji(double english, double csharp, double sql)
            {
                if (pj >= 85 && english > 75 && csharp > 75 && sql > 75)
                {
                    return "优秀";
                }
                else if (pj >= 75 && english > 70 && csharp > 70 && sql > 70)
                {
                    return "良好";
                }
                else
                {
                    return "合格";
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string grade = Convert.ToString(textBox1.Text.Trim());
            string name = Convert.ToString(textBox2.Text.Trim());
            double  sql = Convert.ToDouble(textBox3.Text.Trim());
            double english = Convert.ToDouble(textBox4.Text.Trim());
            double csharp = Convert.ToDouble(textBox5.Text.Trim());
            student h = new student(grade, name, sql, english, csharp);
            label7.Text = Convert.ToString(h.average(english, csharp,sql));
        }
      
        private void button3_Click(object sender, EventArgs e)
        {
           string grade = Convert.ToString(textBox1.Text.Trim());
            string name = Convert.ToString(textBox2.Text.Trim());
            double  sql = Convert.ToDouble(textBox3.Text.Trim());
            double english = Convert.ToDouble(textBox4.Text.Trim());
            double csharp = Convert.ToDouble(textBox5.Text.Trim());
            student h = new student(grade, name, sql, english, csharp);
            label8.Text = Convert.ToString(h.dengji(english, csharp,sql));
        }
      
            




    }
}
为什么无论我输入多少分成绩都是显示为合格的?显示不了优秀或良好的,到底哪里出错了?求大神指教!!!感激不尽!!
2012-09-13 15:32
liangshizhuo
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-5
收藏
得分:0 
回复 10楼 sunxuan007
这个方法不行啊
2012-09-16 23:10
liangshizhuo
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-5
收藏
得分:0 
回复 11楼 sunxuan007
谢谢啦!!!
2012-09-16 23:18
快速回复:C#中构造函数怎么使用?
数据加载中...
 
   



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

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