| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1807 人关注过本帖
标题:C#刚开始学 问问大神们在score属性封装中的if语句为什么没有执行?
取消只看楼主 加入收藏
夏生00
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-11-21
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
C#刚开始学 问问大神们在score属性封装中的if语句为什么没有执行?
public class student
    {
private int Id;
private string name;

public string Name
{
    get { return name; }
    set { name = value; }
}
private DateTime brithday;

public DateTime Brithday
{
    get { return brithday; }
    set { brithday = value; }
}
private int score;

public int Score
{
    get { return score; }
    set { if (score>100) score =100;else if (score>=0) score = value;else score=0 ; }

public string dj;
public student() { }
public student(int xh, string xm)
{ Id = xh; name = xm; }
public student(int xh, string xm, DateTime bri, int cj)
{ Id = xh; name = xm; brithday = bri; cj = score; }
public void inscore()
          {
            Console.Write("学号:");
            Id = int.Parse(Console.ReadLine());
            Console.Write("姓名:");
            name = Console.ReadLine();
            Console.Write("生日:");
            brithday = Convert.ToDateTime(Console.ReadLine());
            Console.Write("总分:");
            score = int.Parse(Console.ReadLine());
           }
public string ScoreDj(int cj)
{
    string dj;
           if (cj>= 90) dj = "优秀";
           else if (cj>= 80) dj = "良好";
           else if (cj>= 70) dj = "中等";
           else if (cj>= 60) dj = "及格";
           else dj = "不及格";
           return dj;
 }

public void Display()
{ Console.WriteLine("   {0},    {1},   {2},   {3},    {4}", Id, name, brithday, score, ScoreDj(score)); }
 }
class Program
    {
const int Max = 100;
static void sort(int n, params student[] p)     //采用冒泡排序法排序
            {
int i, j;
student tmp;
for (i = 0; i< n - 1; i++)
                {
for (j = 0; j < n - i - 1; j++)
if (p[j + 1].Score> p[j].Score)
{ tmp = p[j + 1];                       //p[j+1]<->p[j]
p[j + 1] = p[j];
                            p[j] = tmp;
                      }
   }
 }
static void Main(string[] args)
{  int n, i;
student[] p = new student[Max];     //定义对象引用数组
Console.Write("n:");
                    n = int.Parse(Console.ReadLine());
for (i = 0; i< n; i++)             //创建对象引用的实例
                        p[i] = new student();
for (i = 0; i< n; i++)
                    {
Console.WriteLine("输入第{0}个学生数据:", i + 1);
                        p[i].inscore();
                    }
Console.WriteLine("排序前:");
Console.WriteLine("\t学号\t姓名\t生日\t成绩\t成绩等级");
for (i = 0; i< n; i++)
                    {
Console.Write("序号{0}:", i + 1);
                        p[i].Display();
                    }
sort(n, p);                     //按总分降序排序
Console.WriteLine("排序后:");
Console.WriteLine("\t学号\t姓名\t生日\t成绩\t成绩等级");
for (i = 0; i< n; i++)
                    {
Console.Write("第{0}名:", i + 1);
                        p[i].Display();
                    }
Console.Read();
                }
    }
}
搜索更多相关主题的帖子: private public return 
2016-11-21 16:34
夏生00
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-11-21
收藏
得分:0 
回复 2楼 yhlvht
谢谢版主大神~~~~
2016-11-21 21:11
快速回复:C#刚开始学 问问大神们在score属性封装中的if语句为什么没有执行?
数据加载中...
 
   



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

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