using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 学生信息表
{
class Student
{
public string name
{
get;
set;
}
public string id
{
get;
set;
}
public string sex
{
get;
set;
}
public Student()
{
}
public Student(string name,string id,string sex)
{
this.name = name;
this.id = id;
this.sex = sex;
}
public override string ToString()
{
return this.name + "\t" + this.id + "\t" + this.sex;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 学生信息表
{
class Program
{
public static Hashtable hs = new Hashtable();
static void Main(string[] args)
{
menu();
while (true)
{
Console.WriteLine("请输入你的功能代号:");
string str = Console.ReadLine();
int a;
if (int.TryParse(str, out a))
{
if (a == 9)
{
Console.WriteLine("退出");
break;
}
else if (a == 0)
{
showmenu1();
}
else if (a == 1)
{
showmenu2();
}
else if (a == 2)
{
showmenu3();
}
else if (a == 3)
{
showmenu4();
}
else if (a == 4)
{
showmenu5();
}
else if (a == 5)
{
showmenu6();
}
else if (a == 6)
{
showmenu7();
}
else if (a == 9)
{
showmenu9();
}
}
else
{
Console.WriteLine("请正确的输入序号");
}
}
Console.ReadLine();
}
public static void showmenu1()
{
Console.WriteLine("0.显示菜单");
}
public static void showmenu2()
{
Console.WriteLine("1.查看列表");
Console.WriteLine("=======学生列表=======");
Console.WriteLine("学号" + "\t" + "姓名" + "\t" + "性别");
foreach (object obj in hs.Values)
{
Console.WriteLine(obj);
}
}
public static void showmenu3()
{
Console.WriteLine("2.录入");
Console.WriteLine("输入学号,姓名,性别以空格分开");
string into = Console.ReadLine();
string[] arr = into.Split(' ');
int a;
if (int.TryParse(arr[0], out a))
{
if (arr[1].Length > 1 && arr[1].Length <= 3)
{
if (arr[2] == "男" || arr[2] == "女")
{
Student p = new Student(arr[0], arr[1], arr[2]);
hs.Add(arr[0], p);
Console.WriteLine("=======学生列表=======");
Console.WriteLine("学号" + "\t" + "姓名" + "\t" + "性别");
Console.WriteLine(hs[arr[0]]);
}
else
{
Console.WriteLine("性别必须是男或者女");
}
}
else
{
Console.WriteLine("姓名长度必须大于一位小于四位");
}
}
else
{
Console.WriteLine("请重新输入正确的学号");
}
}
public static void showmenu4()
{
Console.WriteLine("3.删除");
Console.WriteLine("=======学生列表=======");
Console.WriteLine("学号" + "\t" + "姓名" + "\t" + "性别");
string num = Console.ReadLine();
Console.WriteLine("1:确认删除");
Console.WriteLine("2:取消删除");
int number = int.Parse(Console.ReadLine());
if (number == 1)
{
Console.WriteLine("正在删除");
if (hs.ContainsKey(num))
{
hs.Remove(num);
}
else
{
Console.WriteLine("没有你输入存在的数据,请重新输入!");
}
}
else
{
Console.WriteLine("取消返回");
}
}
public static void showmenu5()
{
Console.WriteLine("4.修改");
Console.WriteLine("=======学生列表=======");
Console.WriteLine("学号" + "\t" + "姓名" + "\t" + "性别");
string delete = Console.ReadLine();
hs.Remove(delete);
string into = Console.ReadLine();
string[] arr = into.Split(' ');
Student p = new Student(arr[0], arr[1], arr[2]);
hs.Add(arr[0], p);
}
public static void showmenu6()
{
Console.WriteLine("5.查询");
Console.WriteLine("=======学生列表=======");
Console.WriteLine("学号" + "\t" + "姓名" + "\t" + "性别");
string see = Console.ReadLine();
Console.WriteLine(hs[see]);
}
public static void showmenu7()
{
Console.WriteLine("6.清屏");
Console.WriteLine("=======学生列表=======");
Console.WriteLine("学号" + "\t" + "姓名" + "\t" + "性别");
Console.Clear();
menu();
}
public static void showmenu9()
{
Console.WriteLine("9.退出");
}
public static void menu()
{
Console.WriteLine("欢迎使用学生管理系统");
Console.WriteLine("0.显示菜单");
Console.WriteLine("1.查看列表");
Console.WriteLine("2.录入");
Console.WriteLine("3.删除");
Console.WriteLine("4.修改");
Console.WriteLine("5.查询");
Console.WriteLine("6.清屏");
Console.WriteLine("9.退出");
}
}
}
一个简单的学生情况信息表,我是才学的。感觉问题太多,希望你们给我我指导!
浙公网安备 33010602011771号