zoukankan      html  css  js  c++  java
  • 0906小练习

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Collections;

    namespace 练习0906
    {
    class Program
    {
    struct student
    {
    public int num;
    public string code;
    public string name;
    public decimal score;
    }
    public string pdc(string a)
    {
    if (a != null)
    { return a; }
    else
    { return "f";}
    }
    public string pdn(string a)
    {
    if (a != null)
    { return a; }
    else
    { return "f"; }
    }
    public decimal pds(decimal a)
    {
    if (a>=0&&a<=100)
    { return a; }
    else
    { return -1; }
    }
    static void Main(string[] args)
    {
    Program hanshu=new Program();
    ArrayList st = new ArrayList();
    student student =new student();
    Console.Write("请输入班级人数:");
    int n = int.Parse(Console.ReadLine());
    int num = 1;
    for (int i = 0; i < n; i++)
    {
    student.num = num;
    Console.Write("请输入第" + (i + 1) + "个学生的学号:");
    student.code=Console.ReadLine();
    for (; ; )
    {
    if (hanshu.pdc(student.code) == "f")
    {
    Console.Write("序号不能为空,请重新输入第" + (i + 1) + "个学生的学号:");
    student.code = Console.ReadLine();
    }
    else
    {
    break;
    }
    }
    Console.Write("请输入第" + (i + 1) + "个学生的名字:");
    student.name=Console.ReadLine();
    for (; ; )
    {
    if (hanshu.pdn(student.name) == "f")
    {
    Console.Write("姓名不能为空,请重新输入第" + (i + 1) + "个学生的名字:");
    student.name = Console.ReadLine();
    }
    else
    {
    break;
    }
    }
    Console.Write("请输入第" + (i + 1) + "个学生的成绩:");
    try
    {
    student.score = decimal.Parse(Console.ReadLine());
    for (; ; )
    {
    if (hanshu.pds(student.score) == -1)
    {
    Console.Write("成绩输入有误,请重新输入第" + (i + 1) + "个学生的成绩:");
    student.score = decimal.Parse(Console.ReadLine());
    }
    else
    {
    break;
    }
    }
    }
    catch { Console.WriteLine("成绩输入必须为数字!"); }
    num++;
    st.Add(student);
    Console.WriteLine("-------------------------------");
    }
    Console.Write("输入完毕请按回车键打印学生信息:");
    Console.ReadLine();
    for (int i = 0; i < n-1; i++)
    {
    for (int j = i+1; j < n; j++)
    {
    student a = (student)(st[i]);
    student b = (student)(st[j]);
    if (a.score< b.score)
    {
    object zhong = st[i];
    st[i] = st[j];
    st[j] = zhong;
    }
    }
    }
    Console.WriteLine("==============学生成绩展示=================");
    Console.WriteLine("序号" + " "+" "+"学号"+" "+" "+"姓名" + " "+" "+"成绩");
    for (int i = 0; i < n;i++)
    {
    student a = (student)(st[i]);
    Console.Write(a.num);Console.Write(" ");Console.Write(" ");
    Console.Write(a.code);Console.Write(" ");Console.Write(" ");
    Console.Write(a.name);Console.Write(" ");Console.Write(" ");
    Console.Write(a.score);Console.Write(" ");Console.Write(" ");
    Console.WriteLine();
    }
    Console.ReadLine();
    }
    }
    }

  • 相关阅读:
    Myflight航班查询系统
    《java语法实例2~15章》
    第九章
    第八章
    第六章
    第五章
    第四章
    php_mvc实现步骤十
    php_mvc实现步骤九(登录验证码,退出-登录标记)
    php_mvc实现步骤八
  • 原文地址:https://www.cnblogs.com/xiaobao5161/p/5845166.html
Copyright © 2011-2022 走看看