标题:求指教啊,关于建立学生管理系统
只看楼主
紫色荼蘼812
Rank: 1
等 级:新手上路
帖 子:7
专家分:7
注 册:2011-6-1
结帖率:100%
已结贴  问题点数:10 回复次数:4 
求指教啊,关于建立学生管理系统
我们老师留了个作业,说要建立一个学生管理系统,包括学号,姓名,性别,电话号,地址,要建一个结构体,但是要用arraylist管理,要有添加,删除,排序,查找。
但是从用arraylist管理就不会了啊
搜索更多相关主题的帖子: 管理系统 电话号 结构体 姓名 
2011-06-01 21:43
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:7 
定义一个结构体,把它当成arraylist的成员!

   唯实惟新 至诚致志
2011-06-02 07:14
紫色荼蘼812
Rank: 1
等 级:新手上路
帖 子:7
专家分:7
注 册:2011-6-1
得分:0 
就是不知道怎么把结构体添加到arraylist里面啊
2011-06-02 22:32
紫色荼蘼812
Rank: 1
等 级:新手上路
帖 子:7
专家分:7
注 册:2011-6-1
得分:0 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.OleDb;   

namespace ConsoleApplication作业
{
    //class student : IComparable
    //{
    //   public int nID;
    //   public string szName;
    //   public int nAge;
    //   public string szAddress;
    //   public string szPhoto;

    //   public virtual int CompareTo(object obj)
    //   {
    //       student stu = (student)obj;
    //       if (this.nID > stu.nID)
    //           return -1;
    //       else if (this.nID == stu.nID)
    //           return 0;
    //       else
    //           return 1;
    //   }
    //}

    class student : IComparable
    {
        public int nID;
        public string szName;
        public string szSex;
        public string szNation;
        public string szParty;
        public string szPhone;
        public string szAddress;
        public string szPhoto;


        public virtual int CompareTo(object obj)
        {
            student gradeclass = (student)obj;
            if (this.(gradeclass.nID) < 0)
                return -1;
            else if (this.(gradeclass.nID) == 0)
                return 0;
            else
                return 1;
        }

    }

    class Manager
    {
        private ArrayList stulist = new ArrayList();    //存放学生的集合
        public Manager()
        {
            GetConnect("");
        }

        public int GetNumber()
        {
            return stulist.Count;
        }
        public void Input(student s, int i)
        {
            //  int nLengh = stus.Length;
            //   stus[i] = s;
        }

        private void GetConnect(String szPath)
        {
            string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\2009级地信九班具体信息3.xls; Extended Properties=Excel 8.0";
            OleDbConnection myConn = new OleDbConnection(strCon);
            string strCom = "SELECT* FROM[Sheet1$]";
            myConn.Open();
            OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
            System.Data.DataSet myDataSet;  //读取excel的数据集
            myDataSet = new DataSet();
            myCommand.Fill(myDataSet, "[Sheet1$]");
            myConn.Close();

            //对dataSet中的数据进行处理
            for (int i = 0; i < myDataSet.Tables.Count; i++)
            {
                for (int j = 0; j < myDataSet.Tables[i].Rows.Count - 1; j++)
                {
                    student stu = new student();
                    stu.nID = Convert.ToInt32(myDataSet.Tables[i].Rows[j][0]);
                    stu.szName = myDataSet.Tables[i].Rows[j][1].ToString();
                    stu.szSex = myDataSet.Tables[i].Rows[j][2].ToString();
                    stu.szNation = myDataSet.Tables[i].Rows[j][3].ToString();
                    stu.szParty = myDataSet.Tables[i].Rows[j][4].ToString();
                    stu.szPhone = myDataSet.Tables[i].Rows[j][5].ToString();
                    stu.szAddress = myDataSet.Tables[i].Rows[j][6].ToString();
                    //   stu.szPhoto = myDataSet.Tables[i].Rows[j][7].ToString();
                    stu.szPhoto = Convert.ToString(stu.nID) + ".jpg";
                    stulist.Add(stu);
                }
            }
        }

        public void Sort()
        {
            stulist.Sort();

            //for (int i = 0; i < stulist.Count; i++)
            //{
            //    for (int j = i + 1; j < stulist.Count; j++)
            //    {
            //        if (((student)stulist[j]).nID > ((student)stulist[i]).nID)
            //        {
            //            student temp = (student)stulist[i];
            //            stulist[i] = stulist[j];
            //            stulist[j] = temp;
            //        }
            //    }
            //}
        }
        public void Add()
        {
            student stu = new student();
            Console.WriteLine("请输入要添加几个学生信息:");
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("请输入第{0}个学生的信息:", i + 1);
                Console.WriteLine("请输入学号:");
                stu.nID =Convert .ToInt32  (Console.ReadLine());
                if (stu.nID < 0)
                {
                    Console.WriteLine("输入有误,学号应为正值!");
                }
                Console.WriteLine("请输入姓名:");
                stu.szName = Console.ReadLine();
                Console.WriteLine("请输入性别:");
                stu.szSex = Console.ReadLine();
                Console.WriteLine("请输入地址:");
                stu.szAddress = Console.ReadLine();
                Console.WriteLine("请输入电话号码:");
                stu.szPhone = Console.ReadLine();
                Console.WriteLine("请输入民族:");
                stu.szNation = Console.ReadLine();
                Console.WriteLine("请输入政治面貌:");
                stu.szParty = Console.ReadLine();

                stulist.Add(stu);
                Console.WriteLine("添加成功!");

 
            }
        }
        public void Remove(int num)
        {
            
            int j = 0;
            int index = 0;
            foreach (student  i in stulist )
            {
                j++;
                if (i.nID ==num)
                {
                    index = j;
                }
               
            }
            if (index == 0)
            {
                Console.WriteLine("对不起,没有该学员");
            }
            else
            {
                stulist .RemoveAt(index);
                Console.WriteLine("删除成功");
            }

        }
        public void Contains(int no)
        {
            int j = 0;
            int index = 0;
            foreach (student i in stulist)
            {
                j++;
                if (i.nID == no)
                {
                    index = j;
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7}",i.nID  , i.szName, i.szSex,i.szNation, i.szParty, i.szPhone, i.szAddress, i.szPhoto);
                }

            }
            if (index == 0)
            {
                Console.WriteLine("对不起,没有该学员");
            }
           
        }

        public void select(int i)
        {
            student stu = (student)stulist[i];
            Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7}", stu.nID, stu.szName, stu.szSex, stu.szNation, stu.szParty, stu.szPhone, stu.szAddress, stu.szPhoto);
        }
        public void Print(int i)
        {
            student stu = (student)stulist[i];
            Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7}", stu.nID, stu.szName, stu.szSex, stu.szNation, stu.szParty, stu.szPhone, stu.szAddress, stu.szPhoto);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Manager manger = new Manager();

            manger.Sort();

            for (int i = 0; i < manger.GetNumber(); i++)
            {
                manger.Print(i);
            }

         
            String yesOrNo; ;
            do
            {
                Console.WriteLine("添加按1,删除按2,查询按3,查找按4");

                switch (Console.ReadLine())
                {
                    case "1":
                        manger.Add();
                        break;


                    case "2":
                        Console.WriteLine("请输入要删除学生的学号");
                        int num = int.Parse(Console.ReadLine());
                        manger.Remove(num);
                        break;
                    case "3":
                        for (int i = 0; i < manger.GetNumber(); i++)
                        {
                            manger.select(i);
                        }
                        
                        break;
                    case "4":
                        Console.WriteLine("请输入要查找学生的学号");
                        int no = int.Parse(Console.ReadLine());
                        manger.Contains(no);
                        break;

                }
                Console.WriteLine("是否继续(Y/N)");
                yesOrNo = Console.ReadLine();
            } while (yesOrNo == "Y" || yesOrNo == "y");
        }
    }

}

删除那个函数有些问题啊
2011-06-10 15:56
东南小伙
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-11
得分:0 
你们都太强了,我都看不懂,怎么办!!!!!!!!!!!
2011-06-11 17:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-341672-1-1.html




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

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