From 658cc481727bf6f5eb591fdf3c1203a9a316c3fe Mon Sep 17 00:00:00 2001 From: "@yang-fenghao" <3440490984@qq.com> Date: Mon, 21 Jun 2021 19:05:46 +0800 Subject: [PATCH] first commit --- .../Program.cs" | 73 +++++++++ .../TuShu.cs" | 45 ++++++ .../Yhu.cs" | 31 ++++ .../YuanGong.cs" | 44 +++++ .../\346\216\245\345\217\243/Cat.cs" | 21 +++ .../\346\216\245\345\217\243/Climb.cs" | 13 ++ .../\346\216\245\345\217\243/Dog.cs" | 23 +++ .../\346\216\245\345\217\243/Duck.cs" | 21 +++ .../\346\216\245\345\217\243/Program.cs" | 25 +++ .../\346\216\245\345\217\243/Swin.cs" | 13 ++ .../Class1.cs" | 17 ++ .../Class2.cs" | 25 +++ .../Class3.cs" | 28 ++++ .../Program.cs" | 52 ++++++ .../Program.cs" | 30 ++++ .../Yuang.cs" | 46 ++++++ .../Program.cs" | 73 +++++++++ .../TuShu.cs" | 45 ++++++ .../Yhu.cs" | 31 ++++ .../YuanGong.cs" | 44 +++++ .../Program.cs" | 150 ++++++++++++++++++ .../Student.cs" | 35 ++++ .../age.cs" | 12 ++ .../name.cs" | 12 ++ .../num.cs" | 12 ++ 25 files changed, 921 insertions(+) create mode 100644 "\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Program.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/TuShu.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Yhu.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/YuanGong.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Cat.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Climb.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Dog.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Duck.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Program.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Swin.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class1.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class2.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class3.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Program.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Yuang.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Program.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/TuShu.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Yhu.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/YuanGong.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Program.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Student.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/age.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/name.cs" create mode 100644 "\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/num.cs" diff --git "a/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Program.cs" "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Program.cs" new file mode 100644 index 0000000..eba0d42 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Program.cs" @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class Program + { + static void Main(string[] args) + { + test1(); + test3(); + test2(); + + } + + private static void test1() + { + // 定义一个用户类,存放用户的账号、用户名和密码属性; + //在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息;然后在主方法调用输出; + Yhu yhu = new Yhu(); + Console.WriteLine("请输入用户名"); + yhu.username = Console.ReadLine(); + Console.WriteLine("密码"); + yhu.Password = int.Parse(Console.ReadLine()); + yhu.js(); + } + + public static void test3() + { + // 定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + //对价格进行赋值限制,小于0价格,赋值为0 + //在图书类中定义一个方法输出图书信息; + //在主方法实例化对象,赋值并输出 + TuShu tuShu = new TuShu(); + Console.WriteLine("输入图书编号"); + tuShu.Inbns =int.Parse( Console.ReadLine()); + Console.WriteLine("输入图书名字"); + tuShu.Name = Console.ReadLine(); + Console.WriteLine("输入图书价格"); + tuShu.Jiage = int.Parse(Console.ReadLine()); + Console.WriteLine("输入图书出版社"); + tuShu.Cbans = Console.ReadLine(); + Console.WriteLine("输入图书作者名字"); + tuShu.Author = Console.ReadLine(); + tuShu.shuchu(); + } + + public static void test2() + { + // 定义一个学生类,存放学生的学号、姓名、性别、年龄、专业信息; + //对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + //在学生类中定义一个方法输出学生信息。 + //在主方法实例化对象,赋值并输出 + YuanGong yuanGong = new YuanGong(); + Console.WriteLine("请输入学生的学号"); + yuanGong.Num = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入学生的姓名"); + yuanGong.Name = Console.ReadLine(); + Console.WriteLine("请输入学生的性别"); + yuanGong.Sex = Console.ReadLine(); + Console.WriteLine("请输入学生的年龄"); + yuanGong.Age =int.Parse( Console.ReadLine()); + Console.WriteLine("请输入学生的专业"); + yuanGong.Zy = Console.ReadLine(); + + yuanGong.shuchu(); + + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/TuShu.cs" "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/TuShu.cs" new file mode 100644 index 0000000..bc6f7f4 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/TuShu.cs" @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class TuShu + { + private int inbns; + private string name; + private int jiage; + private string cbans; + private string author; + + public int Inbns { get => inbns; set => inbns = value; } + public string Name { get => name; set => name = value; } + public string Cbans { get => cbans; set => cbans = value; } + public string Author { get => author; set => author = value; } + + public int Jiage + { + get + { + return this.jiage; + } + set + { + if (value < 0 || value > 128) + { + this.jiage = 0; + } + else + { + this.jiage = value; + } + } + } + public void shuchu() + { + Console.WriteLine("图书编号:{0} 书名:{1} 价格:{2} 出版社:{3} 作者名字:{4}",this.inbns,this.Name,this.jiage,this.Cbans,this.author); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Yhu.cs" "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Yhu.cs" new file mode 100644 index 0000000..bd03326 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/Yhu.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class Yhu + { + private string UserName; + private int password; + + public string username + { + get { return this.UserName; } + set { this.UserName = value; } + } + public int Password + { + get { return this.password; } + set { this.password = value; } + } + public void js() + { + Console.WriteLine("用户名:{0} 密码:{1}",this.UserName,this.password); + } + + + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/YuanGong.cs" "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/YuanGong.cs" new file mode 100644 index 0000000..620e032 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\345\261\236\346\200\247\345\222\214\347\261\273/YuanGong.cs" @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class YuanGong + { + private int num; + private string name; + private int age; + private string sex; + private string zy; + + public string Name { get => name; set => name = value; } + public string Sex { get => sex; set => sex = value; } + public string Zy { get => zy; set => zy = value; } + + public int Age + { + get { return this.age; } + set + { + if (value <= 0 || value > 128) + { + this.age = 0; + } + else + { + this.age =value ; + } + } + } + + public int Num { get => num; set => num = value; } + public void shuchu() + { + Console.WriteLine("学号:{0} 名字:{1} 年龄:{2} 性别:{3} 专业:{4}",this.Num,this.Name,Age,this.Sex,this.Zy); + } + + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Cat.cs" "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Cat.cs" new file mode 100644 index 0000000..3b5d4b7 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Cat.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp21 +{ + class Cat:anmin,Climb + { + public Cat(string name) : base(name) + { + + } + + public void climb() + { + Console.WriteLine("{0}可以爬树",Name); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Climb.cs" "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Climb.cs" new file mode 100644 index 0000000..4eb0297 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Climb.cs" @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp21 +{ + interface Climb + { + void climb(); + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Dog.cs" "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Dog.cs" new file mode 100644 index 0000000..5a4d886 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Dog.cs" @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp21 +{ + class Dog:anmin,Climb,Swin + { + public Dog(string name) : base(name) { } + + public void climb() + { + Console.WriteLine("{0}可以爬山",Name); + } + + public void swin() + { + Console.WriteLine("{0}可以游泳",Name); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Duck.cs" "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Duck.cs" new file mode 100644 index 0000000..01a5080 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Duck.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp21 +{ + class Duck:anmin,Swin + { + public Duck(string name) : base(name) + { + + } + + public void swin() + { + Console.WriteLine("{0}可以游泳",Name); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Program.cs" "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Program.cs" new file mode 100644 index 0000000..b8ed169 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Program.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp21 +{ + class Program + { + static void Main(string[] args) + { + Dog dog = new Dog("狗"); + dog.eat(); + dog.climb(); + dog.swin(); + Cat cat = new Cat("猫"); + cat.eat(); + cat.climb(); + Duck duck = new Duck("鸭子"); + duck.eat(); + duck.swin(); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Swin.cs" "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Swin.cs" new file mode 100644 index 0000000..646c8b5 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\216\245\345\217\243/Swin.cs" @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp21 +{ + interface Swin + { + void swin(); + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class1.cs" "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class1.cs" new file mode 100644 index 0000000..2cebddb --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class1.cs" @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp15 +{ + class Class1 + { + + public virtual void js() + { + + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class2.cs" "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class2.cs" new file mode 100644 index 0000000..61115c4 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class2.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp15 +{ + class Class2:Class1 + { + private double r; + + public Class2(double r) + { + this.r = r; + } + + public double R { get => r; set => r = value; } + + public override void js() + { + Console.WriteLine("圆的面积"+r*r*3.14); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class3.cs" "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class3.cs" new file mode 100644 index 0000000..3b5a2e9 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Class3.cs" @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp15 +{ + class Class3:Class1 + { + private int a; + private int b; + + public Class3(int a, int b) + { + this.A = a; + this.B = b; + } + + public int A { get => a; set => a = value; } + public int B { get => b; set => b = value; } + + public override void js() + { + Console.WriteLine("长方形的面积"+a*b); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" new file mode 100644 index 0000000..7528287 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\226\271\346\263\225\351\207\215\350\275\275/Program.cs" @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp15 +{ + class Program + { + static void Main(string[] args) + { + // 1.定义一个计算图形面积的类,类中定义2个计算面积的方法(重载,方法名相同),分别计算圆面积和长方形面积两个方法。 + //提示:计算圆的面积传半径,计算长方形面积传长和宽。 + + //2.创建一个名为计算工具类 SumUtils,在类中定义4个方法: + // 计算两个整数相加、 + // 两个小数相加、 + // 两个字符串相加、 + // 以及从 1 到指定整数的和的方法。 + //在 Main 方法中分别调用定义好的方法。 + + //提示:根据题目要求,分别定义 3 个带两个参数的方法,以及一个带一个整型参数的方法, + // 四个方法名相同。 + Console.WriteLine("请输入你要的计算:1.圆的面积 2.长方形面积"); + int d = int.Parse(Console.ReadLine()); + + switch (d) + { + case 1: + Console.WriteLine("请输入圆的半径R"); + double R = double.Parse(Console.ReadLine()); + Class2 class2 = new Class2(R); + class2.js(); + break; + case 2: + Console.WriteLine("请输入长方形的长"); + int a = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入长方形高"); + int b = int.Parse(Console.ReadLine()); + Class3 class3 = new Class3(a,b); + class3.js(); + break; + default: + break; + } + + + + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Program.cs" "b/\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Program.cs" new file mode 100644 index 0000000..a56ad5c --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Program.cs" @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp20 +{ + class Program + { + static void Main(string[] args) + { + // 定义一个员工类,存放用户的工号、姓名、性别、学历和部门信息; + //定义两个构造函数: + // 一个是无参构造函数,学历默认为专科; + //一个有参构造函数,根据参数对类的属性进行初始化。 + + Yuang yuang = new Yuang(1,"小东","男","博士","软件工程"); + Yuang yuang1 = new Yuang(); + yuang1.Num = 2; + yuang1.Name = "昌宝"; + yuang1.Sex = "男"; + yuang1.Xueli = "本科"; + yuang1.Bumen = "软件工程"; + yuang.shuchu(); + yuang1.shuchu(); + + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Yuang.cs" "b/\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Yuang.cs" new file mode 100644 index 0000000..d03c71d --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\346\227\240\345\217\202\345\222\214\346\227\240\345\217\202\346\236\204\351\200\240/Yuang.cs" @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp20 +{ + class Yuang + { + private int num; + private string name; + private string sex; + private string xueli="专科"; + private string bumen; + + public Yuang(int num, string name, string sex, string xueli, string bumen) + { + this.num = num; + this.name = name; + this.sex = sex; + this.xueli = xueli; + this.bumen = bumen; + } + + public int Num { get => num; set => num = value; } + public string Name { get => name; set => name = value; } + public string Sex { get => sex; set => sex = value; } + + public string Bumen { get => bumen; set => bumen = value; } + + public string Xueli + { + get { return this.xueli; } + set { this.xueli = value; } + } + + public Yuang() + { + } + public void shuchu() + { + Console.WriteLine("工号:{0} 姓名:{1} 性别:{2} 学历:{3} 部门:{4}", this.num, this.name, this.sex, this.xueli, this.bumen); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Program.cs" "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Program.cs" new file mode 100644 index 0000000..b2a2f97 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Program.cs" @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class Program + { + static void Main(string[] args) + { + //test1(); + test3(); + test2(); + + } + + private static void test1() + { + // 定义一个用户类,存放用户的账号、用户名和密码属性; + //在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息;然后在主方法调用输出; + Yhu yhu = new Yhu(); + Console.WriteLine("请输入用户名"); + yhu.username = Console.ReadLine(); + Console.WriteLine("密码"); + yhu.Password = int.Parse(Console.ReadLine()); + yhu.js(); + } + + public static void test3() + { + // 定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + //对价格进行赋值限制,小于0价格,赋值为0 + //在图书类中定义一个方法输出图书信息; + //在主方法实例化对象,赋值并输出 + TuShu tuShu = new TuShu(); + Console.WriteLine("输入图书编号"); + tuShu.Inbns =int.Parse( Console.ReadLine()); + Console.WriteLine("输入图书名字"); + tuShu.Name = Console.ReadLine(); + Console.WriteLine("输入图书价格"); + tuShu.Jiage = int.Parse(Console.ReadLine()); + Console.WriteLine("输入图书出版社"); + tuShu.Cbans = Console.ReadLine(); + Console.WriteLine("输入图书作者名字"); + tuShu.Author = Console.ReadLine(); + tuShu.shuchu(); + } + + public static void test2() + { + // 定义一个学生类,存放学生的学号、姓名、性别、年龄、专业信息; + //对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + //在学生类中定义一个方法输出学生信息。 + //在主方法实例化对象,赋值并输出 + YuanGong yuanGong = new YuanGong(); + Console.WriteLine("请输入学生的学号"); + yuanGong.Num = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入学生的姓名"); + yuanGong.Name = Console.ReadLine(); + Console.WriteLine("请输入学生的性别"); + yuanGong.Sex = Console.ReadLine(); + Console.WriteLine("请输入学生的年龄"); + yuanGong.Age =int.Parse( Console.ReadLine()); + Console.WriteLine("请输入学生的专业"); + yuanGong.Zy = Console.ReadLine(); + + yuanGong.shuchu(); + + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/TuShu.cs" "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/TuShu.cs" new file mode 100644 index 0000000..bc6f7f4 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/TuShu.cs" @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class TuShu + { + private int inbns; + private string name; + private int jiage; + private string cbans; + private string author; + + public int Inbns { get => inbns; set => inbns = value; } + public string Name { get => name; set => name = value; } + public string Cbans { get => cbans; set => cbans = value; } + public string Author { get => author; set => author = value; } + + public int Jiage + { + get + { + return this.jiage; + } + set + { + if (value < 0 || value > 128) + { + this.jiage = 0; + } + else + { + this.jiage = value; + } + } + } + public void shuchu() + { + Console.WriteLine("图书编号:{0} 书名:{1} 价格:{2} 出版社:{3} 作者名字:{4}",this.inbns,this.Name,this.jiage,this.Cbans,this.author); + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Yhu.cs" "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Yhu.cs" new file mode 100644 index 0000000..bd03326 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/Yhu.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class Yhu + { + private string UserName; + private int password; + + public string username + { + get { return this.UserName; } + set { this.UserName = value; } + } + public int Password + { + get { return this.password; } + set { this.password = value; } + } + public void js() + { + Console.WriteLine("用户名:{0} 密码:{1}",this.UserName,this.password); + } + + + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/YuanGong.cs" "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/YuanGong.cs" new file mode 100644 index 0000000..620e032 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\347\261\273\345\222\214\345\257\271\350\261\241/YuanGong.cs" @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp19 +{ + class YuanGong + { + private int num; + private string name; + private int age; + private string sex; + private string zy; + + public string Name { get => name; set => name = value; } + public string Sex { get => sex; set => sex = value; } + public string Zy { get => zy; set => zy = value; } + + public int Age + { + get { return this.age; } + set + { + if (value <= 0 || value > 128) + { + this.age = 0; + } + else + { + this.age =value ; + } + } + } + + public int Num { get => num; set => num = value; } + public void shuchu() + { + Console.WriteLine("学号:{0} 名字:{1} 年龄:{2} 性别:{3} 专业:{4}",this.Num,this.Name,Age,this.Sex,this.Zy); + } + + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Program.cs" "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Program.cs" new file mode 100644 index 0000000..3cb9274 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Program.cs" @@ -0,0 +1,150 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp18 +{ + class Program + { + static void Main(string[] args) + { + Hashtable hashtable = new Hashtable(); + Student s1 = new Student("东东", 1, 18); + Student s3 = new Student("宝宝", 3, 20); + Student s2 = new Student("鑫鑫", 2, 19); + hashtable.Add(s1.Num,s1); + hashtable.Add(s2.Num, s2); + hashtable.Add(s3.Num, s3); + List list = new List() { s1, s2, s3 }; + test1(hashtable,list); + } + + public static void test1(Hashtable hashtable,List list) + { + Console.WriteLine("请选择:1、添加学生信息。2、查询学生信息,3、删除学生信息 4、退出"); + int str = int.Parse(Console.ReadLine()); + switch (str) + { + case 1: + Add(hashtable,list); + test1(hashtable, list); + break; + case 2: + ChaXun(hashtable, list); + break; + case 3: + Console.WriteLine("请输入学生的学号"); + int num = int.Parse(Console.ReadLine()); + foreach (Student i in hashtable.Values) + { + if (hashtable.ContainsKey(num)) + { + hashtable.Remove(i.Num); + foreach (Student j in list) + { + if (num == j.Num) + { + list.Remove(j); + Console.WriteLine("删除成功!"); + test1(hashtable, list); + } + } + } + else + { + Console.WriteLine("此学生不存在"); + test1(hashtable, list); + } + } + break; + case 4: + Console.WriteLine("退出成功!"); + break; + default: + test1(hashtable, list); + break; + } + } + + public static void ChaXun(Hashtable hashtable, List list) + { + Console.WriteLine(); + Console.WriteLine("1、查询所有(按学号排序)2、查询所有(按姓名排序),3、查询所有(按年龄排序)4、按学号查询(查没有,则打印查无此学生)5、退出"); + int str = int.Parse(Console.ReadLine()); + switch (str) + {case 1: + list.Sort(new num()); + foreach (Student i in list) + { + Console.WriteLine("学号:{0} 姓名:{1} 年龄:{2}",i.Num,i.Name,i.Age); + } + ChaXun(hashtable, list); + break; + case 2: + list.Sort(new name()); + foreach(Student i in list) + { + Console.WriteLine("学号:{0} 姓名:{1} 年龄:{2}", i.Num, i.Name, i.Age); + } + ChaXun(hashtable, list); + break; + case 3: + list.Sort(new age()); + foreach (Student i in list) + { + Console.WriteLine("学号:{0} 姓名:{1} 年龄:{2}", i.Num, i.Name, i.Age); + } + ChaXun(hashtable, list); + break; + case 4: + Console.WriteLine("请输入你的学生号"); + int num = int.Parse(Console.ReadLine()); + if (hashtable.ContainsKey(num)) + { + Console.WriteLine(hashtable[num]); + Console.WriteLine(); + ChaXun(hashtable, list); + } + else + { + Console.WriteLine("没有此学生!"); + Console.WriteLine(); + ChaXun(hashtable, list); + } + break; + case 5: + Console.WriteLine("退出成功!"); + break; + default: + ChaXun(hashtable, list); + break; + } + } + + public static void Add(Hashtable hashtable, List list) + { + Student s4 = new Student(); + Console.WriteLine("请输入你的名字"); + s4.Name = Console.ReadLine(); + Console.WriteLine("请输入你的年龄"); + s4.Age =int.Parse( Console.ReadLine()); + Console.WriteLine("请输入你的学号"); + s4.Num= int.Parse(Console.ReadLine()); + + if (hashtable.ContainsKey(s4.Num)) + { + Console.WriteLine("已存在此学生"); + } + else + { + list.Add(s4); + hashtable.Add(s4.Num,s4); + Console.WriteLine("添加成功!"); + } + } + } + +} diff --git "a/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Student.cs" "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Student.cs" new file mode 100644 index 0000000..7e5a4a1 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/Student.cs" @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp18 +{ + class Student + { + private String name; + private int num; + private int age; + + public Student() + { + } + + public Student(string name, int num, int age) + { + this.Name = name; + this.Num = num; + this.Age = age; + } + + public string Name { get => name; set => name = value; } + public int Num { get => num; set => num = value; } + public int Age { get => age; set => age = value; } + + public override string ToString() + { + return "学号:" + num + " 姓名:" + name + " 年龄:" + age; + } + } +} diff --git "a/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/age.cs" "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/age.cs" new file mode 100644 index 0000000..839dbd8 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/age.cs" @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace ConsoleApp18 +{ + internal class age : IComparer + { + public int Compare(Student x, Student y) + { + return x.Age.CompareTo(y.Age); + } + } +} \ No newline at end of file diff --git "a/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/name.cs" "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/name.cs" new file mode 100644 index 0000000..d863847 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/name.cs" @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace ConsoleApp18 +{ + internal class name : IComparer + { + public int Compare(Student x, Student y) + { + return x.Name.CompareTo(y.Name); + } + } +} \ No newline at end of file diff --git "a/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/num.cs" "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/num.cs" new file mode 100644 index 0000000..95e73a2 --- /dev/null +++ "b/\346\235\250\344\270\260\350\261\252/\351\233\206\345\220\210\346\263\233\345\236\213/num.cs" @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace ConsoleApp18 +{ + internal class num : IComparer + { + public int Compare(Student x, Student y) + { + return x.Num.CompareTo(y.Num); + } + } +} \ No newline at end of file -- Gitee