class Program
{
static void Main(string[] args)
{
//// 1、使用你所学的C#的容器类实现员工考勤信息管理,
//实现以下功能:要求:使用泛型集合list的添加,查询和删除操作)
// A:实现新增员工(工号,年龄,姓名,性别)
List<StaffClass> list = new List<StaffClass>();
list.Add(new StaffClass(11, 18, "zhang3", "男"));
list.Add(new StaffClass(22, 28, "li4", "女"));
list.Add(new StaffClass(33, 38, "wang5", "男"));
list.Add(new StaffClass(44, 48, "zhao6", "女"));
list.Add(new StaffClass(55, 58, "qian7", "男"));
list.Add(new StaffClass(66, 68, "sun8", "女"));
for (int i = 0; i < list.Count; i++)
{
list[i].ShowMsg();
}
//C:根据工号删除员工信息
// Console.WriteLine("请输入删除员工信息!工号:");
int numDel=Convert.ToInt32(Console.ReadLine()) ;
for (int i = 0; i < list.Count; i++)
{
if (list[i].ID==numDel)
{
// list.RemoveAt(i);
}
}
for (int i = 0; i < list.Count; i++)
{
// list[i].ShowMsg();
}
//D根据员工工号查询员工信息
Console.WriteLine("请输入查询员工信息!工号:");
int numShu = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < list.Count; i++)
{
if (list[i].ID == numShu)
{
// list[i].ShowMsg();
}
}
//2、使用你所学的C#的容器类实现员工打卡(签到,签退,在第一题的操作再加上签到,签退标签)
//实现以下功能:A:每天只能签到一次
//B:签退前必须已经签到
//C:显示打卡记录 (要求:泛型集合Dictionary的基本操作)
Dictionary<string, int> chuqin = new Dictionary<string, int>();
Console.WriteLine("0表示没签 1表示签到 2表示签退");
int qiantui = 0;
for (int i = 0; i < 3; i++)
{
if (i == 0)
{
Console.Write("请zhan3员工签到:");
chuqin.Add("zhang3", Convert.ToInt32(Console.ReadLine()));
Console.Write("请li4员工签到:");
chuqin.Add("li4", Convert.ToInt32(Console.ReadLine()));
Console.Write("请wang5员工签到:");
chuqin.Add("wang5", Convert.ToInt32(Console.ReadLine()));
}
else {
Console.Write("\n请zhan3员工签到:");
chuqin["zhang3"] = Convert.ToInt32(Console.ReadLine());
Console.Write("请li4员工签到:");
chuqin["li4"] = Convert.ToInt32(Console.ReadLine());
Console.Write("请wang5员工签到:");
chuqin["wang5"] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\n第{0}天出勤情况", i + 1);
foreach (var item in chuqin.Keys)
{
if (chuqin[item] == 1)
{
qiantui = 2;
}
Console.WriteLine("出勤情况:姓名:{0}, 签到:{1}, 签退:{2} ", item, chuqin[item], qiantui);
qiantui = 0;
}
}
//3,选择合适的容器类,完成下面题 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。
//如果该年没有举办世界杯,则输出:没有举办世界杯。
Dictionary<int, string> worldCup = new Dictionary<int, string>();
worldCup.Add(2006, "意大利");
worldCup.Add(2002, "巴西");
worldCup.Add(1998, "法国");
worldCup.Add(1994, "巴西");
worldCup.Add(1990, "德国");
worldCup.Add(1986, "阿根廷");
worldCup.Add(1982, "意大利");
worldCup.Add(1978, "阿根廷");
worldCup.Add(1974, "德国");
worldCup.Add(1970, "巴西");
worldCup.Add(1966, "英格兰");
worldCup.Add(1962, "巴西");
worldCup.Add(1958, "巴西");
worldCup.Add(1954, "德国");
worldCup.Add(1950, "乌拉圭");
worldCup.Add(1938, "意大利");
worldCup.Add(1934, "意大利");
worldCup.Add(1930, "乌拉圭");
int newYear = 0;
try
{
Console.WriteLine("\n请输入要查询的年份:");
int years = Convert.ToInt32(Console.ReadLine());
foreach (var item in worldCup.Keys)
{
if (worldCup.ContainsKey(years))
{
newYear = years;
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (newYear > 0)
{
Console.WriteLine("{0}获得{1}年世界杯冠军!", worldCup[newYear], newYear);
}
else
{
Console.WriteLine("当年没有世界杯冠军!");
}
}
Console.ReadKey();
}
}
class StaffClass
{
private int id;
public int ID
{
get { return id; }
set { id = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string sex;
public string Sex
{
get { return sex; }
set { sex = value; }
}
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
// A:实现新增员工(工号,年龄,姓名,性别)
public StaffClass(int _id, int _age, string _name, string _sex)
{
this.Name = _name;
this.Age = _age;
this.Sex = _sex;
this.ID = _id;
}
//B:展示员工信息,
public void ShowMsg() {
Console.WriteLine("工号:{0} 年龄:{1} 姓名:{2} 性别:{3}",this.ID, this.Age, this.Name, this.Sex);
}
}