1. 创建一个接口Person,包含两个属性PerName,PerAge,一个方法Sort(Person []p);
2. 创建Person接口的实现类Student,包含两个成员变量perName,perAge,实现Person接口中的两个属性,实现对该类中的两个成员变量进行存取;实现Sort()方法,实现对所有的学生按照年龄进行升序显示。
3. 创建Person接口的实现类Employee,包含两个成员变量perName,perAge,实现Person接口中的两个属性,实现对该类中的两个成员变量进行存取;添加empSalary成员变量,表示员工的工资,为该变量添加属性访问器;实现Sort()方法,对所有员工按照工资降序显示
在Main()方法中,创建长度为5的Student类的对象数组,分别从控制台接收数据给该数组赋值,显示出5个学生的信息,并调用Sort()方法,实现按照年龄排序的功能。再创建一个长度为5的Employee类的对象数组,完成同样功能。

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 学生管理系统
    {
        public partial class Form22 : Form
        {        //插入学生信息用到的数据
            public string studnetno;
            public string studentname;
            public string sex;
            public string ative;
            public string address;
            public string birth;
            using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 学生管理系统
    {
        public partial class Form22 : Form
        {        //插入学生信息用到的数据
            public string studnetno;
            public string studentname;
            public string sex;
            public string ative;
            public string address;
            public string birth;using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 学生管理系统
    {
        public partial class Form22 : Form
        {        //插入学生信息用到的数据
            public string studnetno;
            public string studentname;
            public string sex;
            public string ative;
            public string address;
            public string birth;
     ////插入班级信息,确认按钮消息相应函数
            private void button11_Click(object sender, EventArgs e)
            {
                //班级号不为空
                if (textBox5.Text != "")
                {
                    classno = textBox5.Text;
                    depart = textBox6.Text;
                    specical = textBox9.Text;
                    studyears = textBox8.Text;
                    entertime = dateTimePicker2.Value.ToString("yyyy-MM-dd");
                    Classinfo cla = new Classinfo();
                    cla.insert(classno, depart, specical, studyears, entertime);
                    textBox5.Text = "";
                    textBox6.Text = "";
                    textBox9.Text = "";
                    textBox8.Text = "";
                    // dateTimePicker2.Text = "";
                }
                else
                {
                    MessageBox.Show("请填写班级号!");
                }
            }
    …………
    insert方法:
    public void insert(string studentno, string studentname, string studentsex, string studentbirth, string studentnative, string studentaddress)
            {
              
                cmd.CommandText = "insert into student values(" + "'" + studentno + "','" + studentname + "','" + studentsex + "','" + studentbirth + "','" + studentnative + "','" + studentaddress + "')";
                cmd.Connection = conn;
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("添加成功");
                }
                catch
                {
                    MessageBox.Show("格式错误,,添加此信息失败!");
                }
            }
      

  2.   

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 学生管理系统
    {
      public partial class Form22 : Form
      {  //插入学生信息用到的数据
      public string studnetno;
      public string studentname;
      public string sex;
      public string ative;
      public string address;
      public string birth;
     ////插入班级信息,确认按钮消息相应函数
      private void button11_Click(object sender, EventArgs e)
      {
      //班级号不为空
      if (textBox5.Text != "")
      {
      classno = textBox5.Text;
      depart = textBox6.Text;
      specical = textBox9.Text;
      studyears = textBox8.Text;
      entertime = dateTimePicker2.Value.ToString("yyyy-MM-dd");
      Classinfo cla = new Classinfo();
      cla.insert(classno, depart, specical, studyears, entertime);
      textBox5.Text = "";
      textBox6.Text = "";
      textBox9.Text = "";
      textBox8.Text = "";
      // dateTimePicker2.Text = "";
      }
      else
      {
      MessageBox.Show("请填写班级号!");
      }
      }
    …………
    //数据库连接
    strCon = "server=localhost;database=zt;uid=sa;pwd=";
                conn = new SqlConnection(strCon);
                cmd = new SqlCommand();
    insert方法:
    public void insert(string studentno, string studentname, string studentsex, string studentbirth, string studentnative, string studentaddress)
      {
        
      cmd.CommandText = "insert into student values(" + "'" + studentno + "','" + studentname + "','" + studentsex + "','" + studentbirth + "','" + studentnative + "','" + studentaddress + "')";
      cmd.Connection = conn;
      try
      {
      conn.Open();
      cmd.ExecuteNonQuery();
      MessageBox.Show("添加成功");
      }
      catch
      {
      MessageBox.Show("格式错误,,添加此信息失败!");
      }
      }