蓝鸥学习枚举和结构体课后题

定义学生结构体,包含名字,学号,语文,数学,英语三科成绩。再定义班级结构体Classs,班级结构体当中包含一个学生数组并且包含了以下功能

(1) 求各门课的平均分; 


(2) 找出三门课平均成绩在85-90分的学生,并输出其学号和姓名

(3) 班级当中的学生通过分数进行降序排序,如果数学成绩相等,按英语成绩排序,如果英语成绩相等,按语文成绩排序

(提示,需要在学生结构体当中定义求平均分的功能,格式为:public void 功能名(){ 功能实现代码 })

using System;


namespace zuoye0102B
{
class MainClass
{
struct Students
{
public string name;
public int number;
public float Chinese_score;
public float Math_score;
public float English_score;
public Students(string name,int number,float Chinese_score,float Math_score,float English_score){
this.name = name;
this.number=number;
this.Chinese_score=Chinese_score;
this.Math_score=Math_score;
this.English_score=English_score;
}


}
struct Class
{
public Students[] student;
public void PJZ()
{
float ChineseSum = 0;
float MathSum = 0;
float EnglishSum = 0;
for (int i = 0; i <student.Length; i++) {
ChineseSum += student [i].Chinese_score;
MathSum += student [i].Math_score;
EnglishSum += student [i].English_score;
}
Console.WriteLine ("语文成绩的平均值为{0},数学成绩的平均值为{1},英语成绩的平均值为{2}",ChineseSum/5,MathSum/5,EnglishSum/5);
}
public void agv()
{

float san = 0;
for (int i = 0; i <student.Length; i++) 
{
san = (student [i].Chinese_score + student [i].Math_score + student [i].English_score) / 3;
if (san>=85&&san<=90) 
{
Console.WriteLine ("姓名:{0},学号:{1}",student[i].name,student[i].number);
}
}
}


public void Sort()
{
for (int i = 0; i < student.Length-1; i++) 
{
for (int j = 0; j < student.Length-1-i; j++) 
{
if (student[j].Math_score<student[j+1].Math_score) 
{
Students temp = student [j];
student [j] = student [j + 1];
student [j + 1] = temp;
}
if (student[j].Math_score==student[j+1].Math_score) 
{
if (student[j].English_score<student[j+1].English_score) 
{
Students temp = student [j];
student [j] = student [j + 1];
student [j + 1] = temp;
}
if (student[j].English_score==student[j+1].English_score) 
{
if (student[j].Chinese_score<student[j+1].Chinese_score) 
{
Students temp = student [j];
student [j] = student [j + 1];
student [j + 1] = temp;
}
}


}
}
}
for (int i = 0; i < student.Length; i++) 
{
Console.WriteLine ("姓名:{0},学号:{1},语文成绩:{2},数学成绩:{3},英语成绩:{4}",
student[i].name,
student[i].number,
student[i].Chinese_score,
student[i].Math_score,
student[i].English_score);
}


}




}
public static void Main (string[] args)
{
Students s1 = new Students ("张三",10,85,77,90);
Students s2 = new Students ("小王",1,80,80,95);
Students s3 = new Students ("尼古拉斯赵四",6,90,77,60);
Students s4 = new Students ("哆啦A梦",9,85,80,95);
Students s5 = new Students ("皮卡丘",2,99,0,96);
Class x = new Class();
x.student = new Students[]{s1,s2,s3,s4,s5};
x.PJZ ();
x.agv ();
x.Sort ();
}
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值