如何安排第1,第2,第3位置 [英] How do I arrange position like 1st, 2nd, 3rd

查看:76
本文介绍了如何安排第1,第2,第3位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建学校管理系统。我已经达到了这样的程度,我希望用户输入所有科目的学生所达到的分数,之后只需按一下按钮就会将第1个位置分配给分数最高的学生,第2个分配给ID,并获得次高分按顺序排在第3位,直到最低数字。



我尝试了什么:



我显示了学生,科目和专栏的名称,以输入datagridview中每个数字的分数

Am creating a school management system. And I've got to a point where I want the user to enter scores attained by students in all subjects and after that just a button click will assign positions like 1st to the the student with highest score, 2nd to ID with the next highest score and 3rd in that order till the lowest number.

What I have tried:

I displayed the name of students, subject and columns to enter the scores for each number in the datagridview

推荐答案

按分数排序。

你究竟是如何做到这一点将取决于你如何组织你的数据:如果你把学生和他们的分数一起放入一个班级,我会使用Array.Sort方法,并通过实现可比较的界面(系统) [ ^ ] e class。

但是......你可能还没有接口,所以现在可能对你来说太高级了。

所以相反,想想关于编写一个简单的冒泡排序,它可以重新排序一系列学生姓名和一组独立的分数。每次通过气泡时,顶部的项目都是最高,因此您打印并排序所有其他项目。当你的物品用完时,你就完成了。
Sort them by score.
Exactly how you do this will depend on how you organise your data: if you put students into a class together with their score, I'd do it using the Array.Sort method, and by implementing the IComparable Interface (System)[^] for the class.
But...you probably haven't got to interfaces yet, so that's likely to be too advanced for you for the moment.
So instead, think about writing a simple bubble sort which reorders an array of your student names and a separate array of their scores together. Each time you pass through the "bubble", the item at the top is the "highest", so you print it and sort all the others. When you run out of items, you are done.


这篇关于如何安排第1,第2,第3位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆