| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 611 人关注过本帖
标题:大家能帮我改改着程序吗?
取消只看楼主 加入收藏
heqinwu8
Rank: 2
来 自:黄土高坡
等 级:论坛游民
帖 子:65
专家分:58
注 册:2009-7-11
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
大家能帮我改改着程序吗?
学生管理系统的,实现功能添加、删除、修改、查询功能,但是这个程序没应用OOP思想,都是些比较低级编程思想,现在想使用接口、继承、多态的一些特性修改这个程序,让这个程序更简洁明了
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    public class Student
    {
        public Student(int _number,string _name)
        {
            number = _number;
            name = _name;
        }
        public int number = 0;
        public string name = "";
    }
    class Program
    {
        public static List<Student> stu = new List<Student>();
        public static void Create()   //添加函数
        {
            bool flag=true;
            char a;
            int m;
            string n;
                while (flag)
                {
                    Console.WriteLine("请输入您要添加的数据(按s开始输入数据,按e结束输入数据,学号和姓名用回车键隔开):");
                    a = char.Parse(Console.ReadLine());
                    switch (a)
                    {
                        case 's':
                            bool t=true;
                            while (t)
                            {
                                Console.WriteLine("开始输入:");
                                m = int.Parse(Console.ReadLine());
                                n = Console.ReadLine();
                                bool c = false;
                                if (m == 0 && n == "")
                                {
                                    Console.WriteLine("您输入的格式有误,请重新输入!");
                                }
                                else
                                {
                                foreach (Student s in stu)
                                {
                                    if (s.number == m && s.name == n)
                                    {
                                    Console.WriteLine("您添加的数据已存在!");
                                    c = true;
                                    break;
                                    }
                                 }
                                    if (!c)
                                    {
                                    stu.Add(new Student(m, n));
                                    t = false;
                                    }
                                }
                            }
                            break;
                        case 'e':
                            flag = false; Console.WriteLine("输入结束!"); break;
                        default:
                            Console.WriteLine("您输入的格式有误,请重新输入!"); break;
                    }
                }
                return;
        }
        public static void Retrieve()   //查询函数
        {
            bool flag = true;
            while (flag)
            {
                Console.WriteLine("请输入s查找数据,g返回:");
                int num;
                string na;
                char a;
                a = char.Parse(Console.ReadLine());
                switch (a)
                {
                    case 's':
                        {
                            num = int.Parse(Console.ReadLine());
                            na = Console.ReadLine();
                            bool fl = false;
                            if (num == 0 && na == "")
                            {
                                Console.WriteLine("您输入的格式不正确,请重新输入!");
                                break;
                            }
                            else
                            {
                                    foreach (Student s in stu)
                                    {
                                        if (s.number==num && s.name==na)
                                        {
                                            Console.WriteLine("您查找的数据已存在!");
                                            fl = true;
                                            break;
                                        }
                                    }
                                    if (!fl)
                                    {
                                        Console.WriteLine("您查找的数据不存在!");
                                    }
                            }
                        } break;
                    case 'g':
                        flag = false; return;
                    default:
                        Console.WriteLine("输入错误!"); break;
                }
                }
        }
        public static void Delete()      //删除函数
        {
            bool flag = true;
            while (flag)
            {
                Console.WriteLine("请输入您要删除的数据:");
                int num;
                num = int.Parse(Console.ReadLine());
                string na;
                na = Console.ReadLine();
                bool t = false;
                if (num == 0 && na == "")
                {
                    Console.WriteLine("输入的数据有误!");
                }
                else
                {
                    foreach (Student s in stu)
                    {
                        if (s.number == num && s.name == na)
                        {
                            stu.Remove(s);
                            Console.WriteLine("数据已删除!");
                            t = true;
                            return;
                        }
                    }
                    if (!t)
                    {
                        Console.WriteLine("输入的数据不存在!");
                    }
                }
            }
        }
        public static void Update()         //修改函数
        {
            char a;
            bool flag = true;
            while (flag)
            {
                Console.WriteLine("输入n修改姓名,输入m修改学号,其他键退出");
                a = char.Parse(Console.ReadLine());
                switch (a)
                {
                    case 'n':
                        {
                            Console.WriteLine("请输入要修改数据的学号:");
                            int num;
                            num = int.Parse(Console.ReadLine());
                            if (num == 0)
                            {
                                Console.WriteLine("您输入的格式有误!");
                            }
                            else
                            {
                                bool fl = false;
                                foreach (Student s in stu)
                                {
                                    if (s.number == num)
                                    {
                                        Console.WriteLine("请输入修改后的姓名:");
                                        fl = true;
                                        s.name = Console.ReadLine();
                                        break;
                                    }
                                }
                                    if (!fl)
                                    {
                                        Console.WriteLine("该学号不存在!");
                                    }
                            }
                        } break;
                    case 'm':
                        {
                            bool t = false;
                            Console.WriteLine("请输入要修改数据的姓名:");
                            string na;
                            int num;
                            na = Console.ReadLine();
                            if (na == "")
                            {
                                Console.WriteLine("您输入的格式有误!");
                            }
                            else
                            {
                                foreach (Student s in stu)
                                {
                                    if (s.name == na)
                                    {
                                        Console.WriteLine("请输入修改后的学号:");
                                        num = int.Parse(Console.ReadLine());
                                        bool e = false;
                                        foreach (Student w in stu)
                                        {
                                            if (w.number == num)
                                            {
                                                Console.WriteLine("学号已重复,请重新输入!");
                                                e = true;
                                                break;
                                            }
                                        }
                                        if (!e)
                                        {
                                            s.number = num;
                                        }
                                        t = true;
                                        break;
                                    }
                                }
                                if (!t)
                                {
                                    Console.WriteLine("该姓名不存在!");
                                }
                            }
                        } break;
                    default:
                        flag = false; break;
                }
            }
            return;
        }

        static void Main(string[] args)
        {
            Console.WriteLine("已存在的数据如下:");
            stu.Add(new Student(160801, "honey"));
            stu.Add(new Student(160802, "love"));
            foreach (Student s in stu)
            {
                Console.WriteLine("{0},{1}", s.number, s.name);
            }
            bool flag=true;
            char a;
            while (flag)
            {
                Console.WriteLine("学生信息管理:输入c添加数据,输入r查找数据,输入d删除数据,输入u更改数据,按其他键退出");
                a=char.Parse(Console.ReadLine());
                switch (a)
                {
                    case 'c':
                        Create(); break;
                    case 'r':
                        Retrieve(); break;
                    case 'd':
                        Delete(); break;
                    case 'u':
                        Update(); break;
                    default:
                        Console.WriteLine("感谢您的使用!"); flag = false; break;
                }
            }
        }
    }
}
搜索更多相关主题的帖子: 改改 
2009-09-24 12:34
heqinwu8
Rank: 2
来 自:黄土高坡
等 级:论坛游民
帖 子:65
专家分:58
注 册:2009-7-11
收藏
得分:0 
恩,就是想从简单的控制台来了解这个OOP思想

戒烟真难啊,去楼顶抽个,没人发现
2009-09-24 21:02
快速回复:大家能帮我改改着程序吗?
数据加载中...
 
   



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

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