diff --git "a/32\345\221\250\350\211\263/1/\344\275\234\344\270\2321.png" "b/32\345\221\250\350\211\263/1/\344\275\234\344\270\2321.png" new file mode 100644 index 0000000000000000000000000000000000000000..906377dd086c5bb4dc6f79c582ce86607b44a5f1 Binary files /dev/null and "b/32\345\221\250\350\211\263/1/\344\275\234\344\270\2321.png" differ diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\351\235\231\346\200\201.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\351\235\231\346\200\201.cs" new file mode 100644 index 0000000000000000000000000000000000000000..bc9f9c6e9f0d205a9dc9dae645378b62c50d21ba --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\351\235\231\346\200\201.cs" @@ -0,0 +1,51 @@ +using 静态; + +namespace 静态 +{ + /*1、写一个工具类StringUtil,在里面定义一个静态方法,用来判断字符串是否为空。 +如果字符串是null,或者字符串是空"",或者字符串是N个空格" ",那这个方法返回true,否则返回false +然后在主类中(有Main方法的类)调用测试。*/ + internal class StringUtil + { + public static Boolean Pandaun(string str) + { + if (str == null || str == " ") + { + return true; + } + char[] arrchar = str.ToCharArray(); + for (int i = 0; i < arrchar.Length; i++) + { + if (arrchar[i] != ' ') + { + return false; + } + } + return true; + } + } + /*2、写一个工具类ArrayUtil,在里面定义一个静态方法,用来判断数组是否为空。 +如果数组是null,或者数组长度为0,那此方法返回true,否则返回false +然后在主类中(有Main方法的类)调用测试。*/ + internal class ArrUtils + { + public static Boolean Isnull(int[] sc) + { + if (sc == null || sc.Length == 0) + { + return true; + } + else + { + return false; + } + } + } +} + + + + + + + diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/15 \351\242\230\345\212\240\345\210\206.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/15 \351\242\230\345\212\240\345\210\206.cs" new file mode 100644 index 0000000000000000000000000000000000000000..5f2caed8e7654792b62c03dd8c5fa4289cd72b6a --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/15 \351\242\230\345\212\240\345\210\206.cs" @@ -0,0 +1,260 @@ +using System; + +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + /*1. 求圆的面积 + 要求用户输入半径的值,打印出以此值为半径的圆的面积 + 求圆的面积的公式:πr²。 + 圆周率π定义成常量取3.14。 + r由用户输入并存入一个变量中此变量用double比较合适,因为用户可能会输入小数。*/ + Console.WriteLine("第一题"); + Console.WriteLine("请输入半径的值:"); + double r = Convert.ToDouble(Console.ReadLine()); + double S = 3.14 * r * r; + Console.WriteLine($"圆的面积为{S}"); + + /*2.编写一个程序,请用户输入一个四位整数, + 将用户输入的四位数的千位、百位、十位和个位分别显示出来, + 如5632,则显示“用户输入的千位为5,百位为6,十位为3,个位为2”*/ + Console.WriteLine("第二题-----------------"); + Console.WriteLine("请输入一个四位整数:"); + int num = Convert.ToInt32(Console.ReadLine()); + int qian = num / 1000; + int bai = num % 1000 / 100; + int shi = num / 10 % 100 % 10; + int ge = num % 1000 % 100 % 10; + Console.WriteLine($"用户输入的千位为:{qian},百位为:{bai},十位为:{shi},个位为:{ge}"); + + /* 3.用户输入三个数,找出最大的数,打印输出。*/ + Console.WriteLine("第三题--------------"); + Console.WriteLine("请输入三个数:"); + int num = Convert.ToInt32(Console.ReadLine()); + int bai = num % 1000 / 100; + int shi = num / 10 % 100 % 10; + int ge = num % 1000 % 100 % 10; + + /*4.接受用户输入一个数n,求这个数的阶乘;5! = 5 * 4 * 3 * 2 * 1; + 累乘Prouduct变量存放累乘的结果*/ + Console.WriteLine("第四题------------"); + Console.WriteLine("请输入一个数:"); + int num = Convert.ToInt32(Console.ReadLine()); + int sum = 1; + for (int i = 1; i <= num; i++) + { + sum = sum * i; + } + Console.WriteLine($"{num}的阶乘为{sum}"); + + /* 5.接受用户输入的一个数n,求n到1所有数的阶乘和;n! + (n - 1!) + (n - 2)! +……+1!*/ + Console.WriteLine("第五题-------------"); + Console.WriteLine("请输入一个数:"); + int num = Convert.ToInt32(Console.ReadLine()); + int count = 0; + for (int j = 1; j <= num; j++) + { + int sum = 1; + for (int i = 1; i <= j; i++) + { + sum *= i; + } + count += sum; + } + Console.WriteLine(count); + + for (int j = num - 1; j >= 0; j--) + { + Console.Write(" "); + } + for (int i = num * 2 - 1; i >= 0; i--) + { + Console.Write("*"); + } + + /*6.根据用户输入的菱形边长,打印菱形;如边长为3,行数为5;*/ + Console.WriteLine("第六题-----------------"); + Console.WriteLine("请输入菱形的边长:"); + int num = Convert.ToInt32(Console.ReadLine()); + for (int i = 1; i <= num; i++) + { + for (int k = 1; k <= num - i; k++) + { + Console.Write(" "); + } + for (int j = 1; j <= 2 * i - 1; j++) + { + Console.Write("*"); + } + Console.WriteLine(" "); + } + for (int q = num - 1; q > 0; q --) + { + for (int r = 1; r <= num - q; r++) + { + Console.Write(" "); + } + for (int o = 1; o <= q * 2 - 1; o++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + + + + /*7.用循环打印九九乘法表(用二维数组保存字符串后再打印)*/ + Console.WriteLine("第七题--------------"); + for (int i = 1; i < 10; i++) + { + for (int j = 1; j <= i; j++) + { + int k = j * i; + Console.Write("{0}x{1}={2} ", j, i, k); + } + Console.WriteLine(" "); + } + + /* 8.输入一行字符串,分别统计出其中英文字母、数字、空格的个数。*/ + Console.WriteLine("第八题------------"); + Console.WriteLine("请输入一行字符串"); + string get = Console.ReadLine(); + char[] getnum = get.ToCharArray(); + int zimu = 0; + int num = 0; + int blank = 0; + foreach (char c in getnum) + { + if (c == ' ') + { + blank++; + } + else if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') + { + zimu++; + } + else if (c >= 0 && c <= 9) + { + num++; + } + } + Console.WriteLine($"您所输入的字符串中有{zimu}个字母{num}个数字{blank}个空格"); + + + /* 9.在 Main 方法中创建一个 double 类型的数组,并在该数 + 组中存入 5 名学生的考试成绩, + 计算总成绩和平均成绩。(要求使用foreach语句实现该功能)*/ + Console.WriteLine("第九题---------------"); + double[] doubles = { 40, 50, 60, 70, 80 }; + double sum = 0; + double avg = 0; + foreach (double score in doubles) + { + sum += score; + } + avg = sum / doubles.Length; + Console.WriteLine($"学生的总成绩为:{sum}\n学生的平均分为:{avg}"); + + /*10.定义一个方法,实现一维数组的排序功能,从大到小排序。(不要用Array类的方法)*/ + Console.WriteLine("第十题----------"); + Program name = new Program(); + name.Way(); + + /*11.实现查找数组元素索引的功能。定义一个数组,然后控制台输入要查找的元素, + 返回输入值在数组中最后一次出现的位置。若是找不到,请打印找不到。(不要用Array类的方法)*/ + Console.WriteLine("第十一题-------------"); + int[] being = { 36, 10, 20, 80, 30 }; + Console.WriteLine("请输入一个数值:"); + int num = Convert.ToInt32(Console.ReadLine()); + for (int i = 0; i < being.Length; i++) + { + if (being[i] == num) + { + Console.Write(i); + } + else + { + Console.WriteLine("找不到"); + } + } + + /*12.在 Main 方法中创建一个字符串类型的数组,并存入 5 个值,然后将数组中下标是偶数的元素输出*/ + Console.WriteLine("第十二题---------------"); + int[] being = { 15, 8, 12, 64, 24 }; + for (int i = 0; i < being.Length; i++) + { + if (i % 2 == 0 || i != 0) + { + Console.WriteLine(being[i]); + } + } + + + /* 13.用户输入正方形边长,用* 打印出空心正方形。 + 如:用户输入5,则输出如下图形。*/ + Console.WriteLine("第十三题-------------"); + Console.WriteLine("请输入正方形的边长:"); + int get = Convert.ToInt32(Console.ReadLine()); + for (int i = 1; i <= get; i++) + { + if (i == 1 || i == get) + { + for (int j = 1; j <= get; j++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + else + { + Console.Write("*"); + for (int k = 1; k <= get - 2; k++) + { + Console.Write(" "); + } + Console.Write("*"); + Console.WriteLine(); + } + } + + /*14.用户输入正方形边长,用* 打印出实心正方形。 + 如:用户输入5,则输出如下图形。*/ + Console.WriteLine("第十四题-----------"); + Console.WriteLine("请输入正方形的边长:"); + int get = Convert.ToInt32(Console.ReadLine()); + for (int i = 1; i <= get; i++) + { + for (int j = 1; j <= get; j++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + + /*15.用二维数组存放数据,实现杨辉三角形的打印;*/ + Console.WriteLine("第十五题-------------"); + int[,] num = new int[9, 9]; + for (int i = 0; i < 9; i++) + { + for (int j = 0; j <= i; j++) + { + if (j == 0 || i == j) + { + num[i, j] = 1; + } + else + { + num[i, j] = num[i - 1, j - 1] + num[i - 1, j]; //值=左上+上 + } + Console.Write(num[i, j].ToString() + " "); + } + Console.WriteLine(); + } + + } + + } + } +} diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-1.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-1.cs" new file mode 100644 index 0000000000000000000000000000000000000000..386b3fd06814e37f117b97fd2dd8ac63f8d5c537 --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-1.cs" @@ -0,0 +1,94 @@ + +namespace 继承2_1 +{ + internal class Program + { + static void Main(string[] args) + { + Programmer pro = new Programmer("周艳", "云南"); + pro.Wage(10000, 0.05m); + Management mn = new Management("林玉敏", "福建"); + mn.Wage(20000, 0.5m); + Secretary se = new Secretary("林秀清", "广西"); + Dustman du = new Dustman("小积木", "英国"); + + } + } + /*一、 雇员系统,定义雇员基类,共同的属性,姓名、地址和出生日期(可有可无), + * 子类:程序员,秘书,高层管理,清洁工,他们有不同的工资算法, + * 其中高级主管和程序员采用底薪加提成的方式, + * 高级主管和程序员的底薪分别是5000元和2000元 , + * 秘书和清洁工采用工资的方式,工资分别是3000和1000, */ + class Person + { + public string Name { get; set; } + public string Address { get; set; } + public Person() { } + public Person(string name, string address) + { + Name = name; + Address = address; + } + } + internal class Programmer : Person + { + public Programmer() + { + + } + + public Programmer(string name, string address) : base(name, address) + { + + } + public void Wage(decimal sale, decimal ratio) + { + decimal wage = 2000 + sale * ratio; + Console.WriteLine($"{Name}程序员的工资为:{wage}"); + } + } + class Management : Person + { + public Management() + { + + } + + public Management(string name, string address) : base(name, address) + { + + } + public void Wage(decimal sale, decimal ratio) + { + decimal wage = 5000 + sale * ratio; + Console.WriteLine($"{Name}高层管理的工资为:{wage}"); + } + } + class Secretary : Person + { + public Secretary() + { + + } + + public Secretary(string name, string address) : base(name, address) + { + Console.WriteLine($"{Name}秘书的工资为:3000"); + } + + } + class Dustman : Person + { + public Dustman() + { + + } + + public Dustman(string name, string address) : base(name, address) + { + Console.WriteLine($"{Name}清洁工的工资为:1000"); + } + + } + +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-2.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-2.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3136753d0ba731f89b30f0bdc2f2ac2d9519915c --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-2.cs" @@ -0,0 +1,64 @@ +namespace 继承2_2 +{ + internal class Program + { + static void Main(string[] args) + { + Specialty sp = new Specialty("王雷", 17, "专科", "java"); + Console.WriteLine(sp); + Undergraduate under = new Undergraduate("刘文", 22, "本科", "网络技术"); + Console.WriteLine(under); + } + } + /*二、 设计一个学生类Student, +包括的属性有姓名name,年龄age,学位degree。 +由学生类Student + +每个类都有相关数据的输出方法。最后在一个测试类中对设计的类进行测试。 +要求测试结果如下: +姓名:王雷 年龄:17 学位:专科 专业:java +姓名:刘文 年龄:22 学位:本科 研究方向:网络技术 +*/ + class Student + { + public string Name { get; set; } + public int Age { get; set; } + public string Degree { get; set; } + public Student() { } + public Student(string name, int age, string degree) + { + Name = name; + Age = age; + Degree = degree; + } + } + /*派生出专科生类Specialty和本科生类Undergraduate +专科生类包含的属性有专业spec, +本科生类包括的属性有研究方向drec。*/ + class Specialty : Student + { + public string Spec { get; set; } + public Specialty() { } + public Specialty(string name, int age, string degree, string spec) : base(name, age, degree) + { + Spec = spec; + } + public override string ToString() + { + return $"姓名:{Name}\n年龄:{Age}\n学位:{Degree}\n专业:{Spec}"; + } + } + class Undergraduate : Student + { + public string Drec { get; set; } + public Undergraduate() { } + public Undergraduate(string name, int age, string degree, string drec) : base(name, age, degree) + { + Drec = drec; + } + public override string ToString() + { + return $"姓名:{Name}\n年龄:{Age}\n学位:{Degree}\n研究方向:{Drec}"; + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-3.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-3.cs" new file mode 100644 index 0000000000000000000000000000000000000000..8c05b8db92f37fbf3dbc9df0610b58c180289a84 --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-3.cs" @@ -0,0 +1,54 @@ +namespace 继承2_3 +{ + internal class Program + { + static void Main(string[] args) + { + Triangle tr = new Triangle(3, 4, 5, 4); + Round r = new Round(4); + Quadrangle qu = new Quadrangle(5, 6, 9, 10); + } + } + /*三、 图形类: + 求周长,面积(三角形, 四边形, 圆形) +*/ + class Triangle + { + public int W { get; set; } + public int B { get; set; } + public int C { get; set; } + public int H { get; set; } + public Triangle(int w, int h, int b, int c) + { + W = w; + B = b; + C = c; + H = h; + Console.WriteLine($"三角形的面积为:{(double)(w * h / 2)} 三角形的周长为{W + B + C}"); + } + } + class Quadrangle + { + public int A { get; set; } + public int B { get; set; } + public int C { get; set; } + public int H { get; set; } + public Quadrangle(int a, int b, int c, int h) + { + A = a; + B = b; + C = c; + H = h; + Console.WriteLine($"四角形的面积为:不会求 四角形的周长为{A + H + B + C}"); + } + } + class Round + { + public int A { get; set; } + public Round(int a) + { + A = a; + Console.WriteLine($"圆形的面积为:{(double)(a * 3.14 * a)} 圆形的周长为{(double)(2 * a * 3.14)}"); + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-4.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-4.cs" new file mode 100644 index 0000000000000000000000000000000000000000..5d3c50d99894be42f6abaeb6bdbc345ff4265957 --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-4.cs" @@ -0,0 +1,66 @@ +namespace 继承2_4 +{ + /* + 四、员工类Employee + 字段:姓名,工作年限,月薪、 + + 组长(GroupLeader): 月薪+1000*年限 + 客户经理(AccountManager):月薪+1000*年限*分红(基础分红*3) + 求组长,经理的年薪。 + */ + internal class Program + { + static void Main(string[] args) + { + GroupLeader gr = new GroupLeader("狗青", 5, 3000); + Console.WriteLine(gr); + AccountManager ac = new AccountManager("傻狗", 10, 6000); + Console.WriteLine(ac); + } + } + class Employee + { + public string Name { get; set; } + public int Year { get; set; } + public double Money { get; set; } + public Employee(string name, int year, double money) + { + Name = name; + Year = year; + Money = money; + } + } + class GroupLeader : Employee + { + public GroupLeader(string name, int year, double money) : base(name, year, money) + { + Name = name; + Year = year; + Money = money; + } + public override string ToString() + { + return $"组长{Name}工作了年{Year}月薪{Money + 1000 * Year}"; + } + } + class AccountManager : Employee + { + public int Base + { + get + { + return 1000; + } + } + public AccountManager(string name, int year, double money) : base(name, year, money) + { + Name = name; + Year = year; + Money = money; + } + public override string ToString() + { + return $"员工{Name}工作了年{Year}月薪{Money + 1000 * Year * Base}"; + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-5.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-5.cs" new file mode 100644 index 0000000000000000000000000000000000000000..71ec74eae0262a541c63bbd33ec44432be2d6b0e --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2772-5.cs" @@ -0,0 +1,54 @@ +namespace 继承2_5 +{ + /*五、设计一个汽车类Vehicle,包含的属性有汽车品牌brand、车轮个数wheels和车重weight。 + 每个类都有构造方法和输出相关数据的方法。*/ + internal class Program + { + static void Main(string[] args) + { + + Car car = new Car("小车", 4, 1000, 4); + Console.WriteLine(car); + Truck truck = new Truck("卡车", 10, 1000, 3000); + Console.WriteLine(truck); + } + } + class Vehicle + { + public string Brand { get; set; } + public int Wheels { get; set; } + public int Weight { get; set; } + public Vehicle(string brand, int wheels, int weight) + { + Brand = brand; + Wheels = wheels; + Weight = weight; + } + } + //小车类Car是Vehicle的子类,其中包含的属性有载人数loader。 + class Car : Vehicle + { + public int Loader { get; set; } + public Car(string brand, int wheels, int weight, int loader) : base(brand, wheels, weight) + { + Loader = loader; + } + public override string ToString() + { + return $"汽车品牌:{Brand}车轮个数:{Wheels}和车重:{Weight}载人数:{Loader}"; + } + } + //卡车类Truck是Car类的子类,其中包含的属性有载重量payload。 + class Truck : Vehicle + { + public int Payload { get; set; } + public Truck(string brand, int wheels, int weight, int payload) : base(brand, wheels, weight) + { + Payload = payload; + } + public override string ToString() + { + return $"汽车品牌:{Brand}车轮个数:{Wheels}和车重:{Weight}载重量:{Payload}"; + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\267\251\345\233\2721.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\267\251\345\233\2721.cs" new file mode 100644 index 0000000000000000000000000000000000000000..631409fa05c94d48ab9fa5ce0e6219f8ded39f52 --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\267\251\345\233\2721.cs" @@ -0,0 +1,104 @@ +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("善学如春起之苗"); + Console.WriteLine("不见其增,日有所长"); + Console.WriteLine("假学如磨刀之石"); + Console.WriteLine("不见其损,年有所亏"); + Console.WriteLine("加油吧!少年"); + Console.WriteLine("J"); + Console.WriteLine("A"); + Console.WriteLine("V"); + Console.WriteLine("A"); + Console.WriteLine("!"); + } + } + internal class Program1 + { + static void Main(string[] args) + { + Console.WriteLine("true"); + Console.WriteLine("false"); + } + } + + internal class Program2 + { + static void Main(string[] args) + { + sbyte a = -128; + Console.WriteLine(a); + byte b = 127; + Console.WriteLine(b); + short c = -32768; + Console.WriteLine(c); + short d = 32767; + Console.WriteLine(d); + int e = -2147483648; + Console.WriteLine(e); + int f = 2147483647; + Console.WriteLine(f); + long g = -2147483649; + Console.WriteLine(g); + long h = 2147483648; + Console.WriteLine(h); + } + } + + internal class Program3 + { + static void Main(string[] args) + { + float i = -3.14F; + Console.WriteLine(i); + float j = 3.14F; + Console.WriteLine(j); + double k = -3.4; + Console.WriteLine(k); + double l = 3.4; + Console.WriteLine(l); + } + } + + internal class Program4 + { + static void Main(string[] args) + { + int a = 10; + int b = 20; + int temp = 10; + a = b; + b = temp; + Console.WriteLine("a的值是" + a); + Console.WriteLine("b的值是" + b); + } + } + internal class Program5 + { + static void Main(string[] args) + { + int x = 100; + int y = 200; + Console.WriteLine("x和y的和为" + (x + y)); + Console.WriteLine("x和y的差为" + (x - y)); + Console.WriteLine("x和y的积为" + (x * y)); + Console.WriteLine("x和y的商为" + (x / y)); + } + } + internal class Program6 + { + static void Main(string[] args) + { + double x = 100.8; + double y = 20.6; + Console.WriteLine("x和y的和为" + (x + y)); + Console.WriteLine("x和y的差为" + (x - y)); + Console.WriteLine("x和y的积为" + (x * y)); + Console.WriteLine("x和y的商为" + (x / y)); + } + } +} + \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\351\207\215\350\275\275.cs" "b/32\345\221\250\350\211\263/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\351\207\215\350\275\275.cs" new file mode 100644 index 0000000000000000000000000000000000000000..dcc58bac6fda6a4077176ac8507837ac487d5a9c --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\351\207\215\350\275\275.cs" @@ -0,0 +1,68 @@ +using System; +using System.Dynamic; + +namespace 重载 +{ + internal class Program + { + static void Main(string[] args) + { + GetArea gteArea = new GetArea (); + double CircleArea = gteArea.Aa3); + double HeightArea = gteArea.Aa3, 2); + Console.WriteLine($"圆的面积为:{CircleArea};长方形的面积为:{HeightArea}"); + /*new一个新的对象*/ + SumUtils sum=new SumUtils (); + sum.Aa(3, 4); + sum.Aa2.2, 7.7); + sum.Aa("a", "b"); + sum.Aa(10); + } + } + /*1. 定义一个计算图形面积的类,类中定义2个计算面积的方法(重载,方法名相同),分别计算圆面积和长方形面积两个方法。 +提示:计算圆的面积传半径,计算长方形面积传长和宽。*/ + public class Area + { + public double Aa(int r) + { + return r * r * 3.14; + } + public double Aa(int l , int w) + { + return l * w; + } + } + /*2.创建一个名为计算工具类 SumUtils,在类中定义4个方法: +计算两个整数相加、 +两个小数相加、 +两个字符串相加、 +以及从 1 到指定整数的和的方法。 +在 Main 方法中分别调用定义好的方法。 + +提示:根据题目要求,分别定义 3 个带两个参数的方法,以及一个带一个整型参数的方法, +四个方法名相同。*/ +public class SumUtils + { + public void Aa(int a ,int b) + { + Console.WriteLine($"两个整数相加为{a + b}"); + } + public void Aa(double a , double b) + { + Console.WriteLine($"两个小数相加为{a + b}"); + } + public void Aa(string a, string b) + { + Console.WriteLine($"两个字符串相加为{a + b}"); + } + public void Aa(int a) + { + int sum = 0; + for(int i = 1; i <= a; i++) + { + sum = sum + i; + } + Console.WriteLine($"从 1 到指定整数的和为{sum}"); + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2771-1.cs" "b/32\345\221\250\350\211\263/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2771-1.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7ec0d2a0aa16bf1a7d2cd3eeaa7ef0a576e43087 --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2771-1.cs" @@ -0,0 +1,61 @@ +namespace 继承1_1 +{ + /*一、假设要完成一个学校的校园管理信息系统,在员工管理系统中有不同的人员信息,包括学生信息、教师信息等。*/ + internal class Program + { + static void Main(string[] args) + { + Student stu1 = new Student("林秀清", 1, "女", "25698356252", "17587072305", "软件技术", "大一"); + Console.WriteLine(stu1); + Teacher tec = new Teacher("林玉敏", 1, "女", "25634987562", "151985698547", "专业课老师", "1100605614"); + Console.WriteLine(tec); + } + } + /*编号(Id)、姓名(Name)、性别(Sex)、身份证号(Cardid)、联系方式(Tel)*/ + class Person + { + public string Name { get; set; } + public int Id { get; set; } + public string Sex { get; set; } + public string Cardid { get; set; } + public string Tel { get; set; } + public Person(string name, int id, string sex, string cardid, string tel) + { + this.Cardid = cardid; + this.Name = name; + this.Tel = tel; + this.Name = name; + this.Id = id; + } + public Person() { } + } + class Student : Person + { + public string Major { get; set; } + public string Grade { get; set; } + public Student(string name, int id, string sex, string cardid, string tel, string major, string grade) : base(name, id, sex, cardid, tel) + { + Major = major; + Grade = grade; + } + + public override string ToString() + { + return $"学生编号:{Id} \n姓名:{Name} \n性别:{Sex}\n身份证号码:{Cardid} \n联系方式:{Tel}\n专业:{Major}\n年级:{Grade} "; + } + } + class Teacher : Person + { + public string Title { get; set; } + public string Wageno { get; set; } + public Teacher(string name, int id, string sex, string cardid, string tel, string title, string wageno) : base(name, id, sex, cardid, tel) + { + Title = title; + Wageno = wageno; + } + public override string ToString() + { + return $"老师编号:{Id} \n姓名:{Name} \n性别:{Sex}\n身份证号码:{Cardid} \n联系方式:{Tel}\n老师职称:{Title}\n工资号:{Wageno}"; + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2771-2.cs" "b/32\345\221\250\350\211\263/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2771-2.cs" new file mode 100644 index 0000000000000000000000000000000000000000..c32afc4c69282228b8e7734994f02268a31e39dc --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\347\273\247\346\211\2771-2.cs" @@ -0,0 +1,61 @@ +namespace 继承1_2 +{ + /*二、使用类来描述游戏中的角色。 +在很多RPG游戏中,第一次打开游戏,都会先让你创建自己的“英雄”,或者自己要扮演的角色。这些英雄或者角色都是我们游戏中的“对象”,所以在开发的时候,我们需要针对每个角色都要写相应的类来描述。*/ + internal class Program + { + static void Main(string[] args) + { + Son alk = new Son("埃落克", "埃洛克是一名来自末日边境的勇士。他是圣约英雄中名副其实的拳术好手。他用毁灭性的符文魔法和无情的拳术攻击消灭敌人。", "狗清", 12000, 500, 100); + Son tl = new Son("泰拉", "泰拉是为复仇而来的勇者。她挥舞法杖将愤怒转化为强大的元素魔法和攻击力因此战无不胜。", "傻狗", 1600, 600, 800); + Son lks = new Son("卢卡斯", "卢卡斯是一名彬彬有礼的剑客,能控制源质能量。他一手持剑战斗,另一手辅助攻击。", "无敌大聪明", 1800, 900, 600); + Son lf = new Son("洛菲", "洛菲是一名攻击迅猛且擅长传送魔法的时空旅行者,喜欢利用她的幻象伙伴迷惑、吸引并摧毁敌人。", "玉米", 7800, 500, 600); + Console.WriteLine("请选择您要使用的英雄:1.埃落克2.泰拉3.卢卡斯4.洛菲"); + int num = Convert.ToInt32(Console.ReadLine()); + switch (num) + { + case 1: alk.Choose("碎石打击", "烈焰锚钩", "战斗咆哮"); break; + case 2: tl.Choose("巨浪冲击", "元素突击", "复仇杀戮"); break; + case 3: lks.Choose("减速陷阱", "能量浪潮", "旋风剑舞"); break; + case 4: lf.Choose("能量精灵", "暗影传送", "时空进裂"); break; + } + } + } + public class Hero + { + //字段:角色名字,角色介绍,角色昵称,攻击力,防御力,速度。 + public string Name { get; set; } + public string Desc { get; set; } + public string User { get; set; } + public int Attack { get; set; } + public int Def { get; set; } + public int Speed { get; set; } + public Hero(string name, string desc, string user, int attack, int def, int speed) + { + Name = name; + Desc = desc; + User = user; + Attack = attack; + Def = def; + Speed = speed; + } + public Hero() { } + } + class Son : Hero + { + public Son(string name, string desc, string user, int attack, int def, int speed) : base(name, desc, user, attack, def, speed) + { + Console.WriteLine($"您选择的是:{name}\n英雄描述:{desc} \n 昵称:{user} \n攻击力:{attack}\n 防御力:{def}\n 速度:{speed}"); + } + public void Choose(string one, string two, string three) + { + int num = Convert.ToInt32(Console.ReadLine()); + switch (num) + { + case 1: Console.WriteLine($"您使用了{one}"); break; + case 2: Console.WriteLine($"您使用了{two}"); break; + case 3: Console.WriteLine($"您使用了{three}"); break; + } + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/ref\345\222\214out.cs" "b/32\345\221\250\350\211\263/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/ref\345\222\214out.cs" new file mode 100644 index 0000000000000000000000000000000000000000..6c7533f6db671c3ef2e344fd9aed0db8a3a6249b --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/ref\345\222\214out.cs" @@ -0,0 +1,56 @@ +using System.ComponentModel; + +namespace ref和out +{ + + internal class Program + { + static void Main(string[] args) + { + int[] num = { 1, 2, 0, 5, 6, }; + int max; + int min; + int sum; + int avg; + OutTest(num,out max, out min, out sum, out avg); + Console.WriteLine($"整数组中最大值为:{max},最小值为:{min},和为:{sum},平均数为{avg}"); + } + /*1、定义一个方法,求一个整数数组中的最大值, + * 最小值,和,平均数。如果是一个方法只能有一个返回值, + * 那只能每一个都得定义一个方法来实现,不过有了ref和out这实现起来就方便多了。 + +参考步骤: +定义一个一维数组,数组中存放一些数据(控制台输入)。 +定义几个变量:max、min、sum、avg + +定义一个方法,方法返回数组元素之和,方法形参有max min avg。 + +请用ref和out各做一遍,并在注释中,描述他们的区别。*/ + public static void OutTest(int[] num,out int max,out int min,out int sum,out int avg) + { + for (int i = 0; i < num.Length ; i++) + { + for(int j = 0;j < i;j++) + { + if (num [i] > num[j]) + { + int temp; + temp = num[j]; + num[j] = num[i]; + num[i] = temp; + } + } + } + max = num[0]; + min = num[num.Length - 1]; + int count = 0; + foreach (int i in num) + { + count = count + i; + } + sum = count; + avg = sum/num.Length ; + + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\261\273\345\222\214\345\257\271\350\261\241.cs" "b/32\345\221\250\350\211\263/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\261\273\345\222\214\345\257\271\350\261\241.cs" new file mode 100644 index 0000000000000000000000000000000000000000..6fd08ea8d1bf9403edc15f146aaab74520a62480 --- /dev/null +++ "b/32\345\221\250\350\211\263/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\347\261\273\345\222\214\345\257\271\350\261\241.cs" @@ -0,0 +1,295 @@ +using System; +using System.Net.Cache; + +namespace 类和对象 +{/*一. 定义一个用户类 +1.定义字段存放用户的账号、用户名和密码; +2.在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息; +3.在用户类中定义一个 登录身份辨认的方法:规则为用户名为“admin”和密码为“123456”时返回“管理员”,否则返回“普通用户”; +4.在主方法中实例化用户类的对象,然后对其账号、用户名和密码赋值 +5.在主方法中用实例化的对象调用方法,输出用户对象的信息和身份(管理员或者普通用户)*/ + internal class User + {//定义字段 + int id; + string name; + string passward; + public int Id + { + get => id;set => id = value; + } + public string Name + { + get => name;set => name = value; + } + public string Passward + { + get => passward; + set + { + if(value .Length >= 6 && value .Length <= 10) + { + passward = value; + } + else + { + passward = "123456"; + } + } + } + public void Print() + { + Console.WriteLine($"账号:{id}"); + Console.WriteLine($"用户名:{name}"); + Console.WriteLine($"密码:{passward}"); + } + public string Identity() + { + if (name == "asmin" && passward == "123456") + { + return "管理员"; + } + else + { + return "普通用户"; + } + } + /*二. 定义一个学生类 +1.定义字段存放学生的学号、姓名、性别、年龄、专业信息; +2.对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; +3.在学生类中定义一个方法输出学生信息。 +4. 在主方法实例化学生对象,赋值并输出*/ + internal class Student + { + private int id; + private string name; + private char sex; + private int eag; + private string professional; + public Student (int id, string name,char sex, int age, string professional) + { + this.id = id; + this.name = name; + this.sex =sex; + this.age = age; + this.Professional = Professional; + } + public int Id + { + get { return id; } + set { id = value; } + } + public string Name + { + get { return name; } + set { name = value; } + } + public char Sex + { + get { return sex; } + set { sex = value; } + } + public int Eag + { + get { return eag; } + set + { + if(value > 0 && value < 128) + { + age = value; + } + else + { + age = 0; + } + } + } + public string Professional + { + get { return professional} + set { professional = value; } + } + public viod Print() + { + Console.WriteLine($"学号:{this.id}"); + Console.WriteLine($"姓名:{this.name}"); + Console.WriteLine($"性别:{this.sex}"); + Console.WriteLine($"年龄:{this.age}"); + Console.WriteLine($"专业:{this.professional}"); + } + static void Main(string[] args) + { + Student i = new Student(22, "狗清", 18, "软件技术"); + } + } + } + /* +三.定义一个图书类 +1.定义字段存放图书的编号、书名、价格、出版社、作者信息; +2.对价格进行赋值限制,小于0价格,赋值为0 +3.在图书类中定义一个方法输出图书信息; +4.在主方法实例化对象,赋值并输出*/ + public class Book + { + private int id; + public string name; + private double price; + public void SetBook(int id, string name, double price) + { + this.Id = id; + this.name = name; + this.Price = price; + } + public int Id + { + get { return id; } + set { id = value; } + } + public string Name + { + get { return name; } + set { name = value; } + } + public double Price + { + get { return price; } + set + { + if (value >= 0) + { + price = value; + } + else + { + price = 0; + } + } + } + public void Print() + { + Console.WriteLine($"图书编号:{Id}"); + Console.WriteLine($"图书名称:{Name}"); + Console.WriteLine($"图书价格:{Price}"); + } + public static void Main(string[] args) + { + Book book = new Book(); + book.SetBook(2, "童话故事", 50); + book.Print(); + } + + } + /* +四.定义一个敌人类 +1. 定义可以存放敌人的血量、攻击力和魔法值字段; +2.要求敌人的血量、攻击力和魔法值都只能设置为大于等于0的值;如果小于0则将字段值设置为0 +3.在类中定义方法代表敌人具有攻击和逃跑的行为 +4.在主方法中实例化2个敌人对象,为属性赋值,并输出对象的属性值; +5.使用一个对象调用攻击方法,使用一个对象调用逃跑方法*/ + internal class Enemy + { + private int hp; + private int mana; + private int mp; + } + public int Hp + { + get { return hp; } + set + { + if (hp < 0) + { + value = 0; + } + else + { + hp = value; + } + } + } + public int Mana + { + get { return mana; } + set + { + if (mana < 0) + { + value = 0; + } + else + { + mana = value; + } + } + + } + public int Mp + { + get { return mp; } + set + { + if (mp < 0) + { + value = 0; + + } + else + { + mp = value; + } + } + } + public void Attack() + { + Console.WriteLine("敌人的行为是:攻击"); + } + public void RunAway() + { + Console.WriteLine("敌人的行为是:逃跑"); + } + public void Print() + { + Console.WriteLine($"血量为:{hp}"); + Console.WriteLine($"攻击值为:{mana}"); + Console.WriteLine($"魔法值为:{mp}"); + } + /* +五.定义英雄类(Hero) +1.英雄类中的属性包括:姓名、攻击力、防御力、生命值和魔法值; +2.方法包括:攻击、介绍。 +3.在主方法中实例化英雄对象,赋值并调用方法*/ + internal class Hero + { + //1.英雄类中的属性包括:姓名、攻击力、防御力、生命值和魔法值; + public string name { get; set; } + public int attactvalue { get; set; } + public int defense { get; set; } + public int hp { get; set; } + public int mana { get; set; } + //2.方法包括:攻击、介绍 + public void Attract() + { + Console.WriteLine($"{name}发起攻击"); + } + public void Introduce() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"攻击力:{attactvalue}"); + Console.WriteLine($"防御力:{defense}"); + Console.WriteLine($"生命值:{hp}"); + Console.WriteLine($"魔法值:{mana}"); + } + static void Main(string[] args) + { + Hero hero = new Hero(); + hero.name = "D.VA"; + hero.attactvalue = 95; + hero.defense = 100; + hero.hp = 99; + hero.mana = 0; + hero.Introduce(); + hero.Attract(); + } + + } +} + diff --git "a/32\345\221\250\350\211\263/\351\241\271\347\233\256/Program.cs" "b/32\345\221\250\350\211\263/\351\241\271\347\233\256/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..4cb116b29e0a804c21c349f45a122003f34c91f4 --- /dev/null +++ "b/32\345\221\250\350\211\263/\351\241\271\347\233\256/Program.cs" @@ -0,0 +1,209 @@ + + +namespace ADO.NET_项目 +{ + internal class Program + { + private static object constr; + + static void Main(string[] args) + { + //链接数据库 + string constr = "server = ZY1111;uid=sa;wd=1593572580love;database=Stu;"; + try + { + object value = constr.Clone(); + while (true) + { + Console.WriteLine("欢迎来到学生管理系统,请选择:\t1.班级;2.学生;3.退出"); + int num = Convert.ToInt32(Console.ReadLine()); + if (num == 3) + { + Console.WriteLine("谢谢使用"); + break; + } + switch (num) + { + case 1: Find1(); break; + case 2: Find2(); break; + default: Console.WriteLine("没有该操作"); break; + } + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally { constr.Clone(); } + } + public static void Find1() + { + while (true) + { + Console.WriteLine("请选择您的操作:\t1.增加功能2.删除功能3.修改功能4.查询功能5.退出"); + int num = Convert.ToInt32(Console.ReadLine()); + if (num == 5) + { + Console.WriteLine("感谢使用"); + break; + } + switch (num) + { + case 1: Add(); break; + case 2: Delete(); break; + case 3: Updata(); break; + case 4: View(); break; + default: Console.WriteLine("没有该操作"); break; + } + } + } + public static void Find2() + { + + } + // 增加功能: + + + //​ 4)不存在,就将班级信息保存到数据库的班级信息表中; + static public void Add() + { + //​ 1) 要求接收用户输入班级名称 + Console.WriteLine("请输入您想添加的班级名称:"); + string ClassName = Console.ReadLine(); + int num = Check(ClassName); + //​ 2)然后去查询数据库中的班级表是否存在该班级名称 + //存在该班级 + if (num > 0) + { + Console.WriteLine("班级名称重复,添加班级信息失败"); + } + else + { + string a = "insert into Class(ClassNme)values('{0}')"; + a = string.Format(a, ClassName); + SqlCommand add = new SqlCommand(a, constr); + int result = add.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine("添加成功"); + } + } + } + public static int Check(string ClassName) + { + string sql = "select*from Class where ClassName='{0}'"; + sql = string.Format(sql, ClassName); + SqlCommand com = new SqlCommand(sql, constr); + var read = com.ExecuteReader(); + int num = 0; + while (read.Read()) + { + num = 1; + } + read.Close(); + return num; + } + public static int Check(int ClassId) + { + string sql = "select*from Class where ClassId='{0}'"; + sql = string.Format(sql, ClassId); + SqlCommand com = new SqlCommand(sql, constr); + SqlDataReader read = com.ExecuteReader(); + int num = 0; + while (read.Read()) + { + num = 1; + } + read.Close(); + return num; + } + // 删除功能: + + //​ 2)根据班级编号删除数据库中的班级信息 + + //​ 3)如果删除成功提示成功,如果没有要删除的班级编号数据提示删除失败 + public static void Delete() + { + //​ 1)要求用户输入要删除的班级编号; + Console.WriteLine("请输入您要删除的班级编号:"); + int ClassId = Convert.ToInt32(Console.ReadLine()); + int num = Check(ClassId); + if (num > 0) + { + string a = "delete from Class where ClassName='{0}'"; + a = string.Format(a, ClassId); + SqlCommand add = new SqlCommand(a, constr); + int result = add.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine("删除成功"); + } + } + else + { + Console.WriteLine("删除失败"); + } + } + // 修改功能: + + //​ 1)要求用户输入修改信息,需要修改的班级编号,以及修改后的班级名称信息; + + //​ 2)根据用户输入的信息修改班级信息表的数据; + + //​ 3)如果有对应的班级编号信息,提示修改成功,没有提示修改失败 + public static void Updata() + { + Console.WriteLine("请输入要修改的班级编号:"); + int ClassId = Convert.ToInt32(Console.ReadLine()); + int num = Check(ClassId); + if (num > 0) + { + Console.WriteLine("修改后的班级名称:"); + string cname = Console.ReadLine(); + string a = "update Class set cname='{0}' where ClassId={1};"; + a = string.Format(a, cname, ClassId); + SqlCommand add = new SqlCommand(a, constr); + int result = add.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine("修改成功"); + } + } + else + { + Console.WriteLine("修改失败"); + } + + } + public static void View() + { + string sql = "select*from Class"; + SqlCommand com = new SqlCommand(sql, constr); + SqlDataReader read = com.ExecuteReader(); + int num = com.ExecuteNonQuery(); + read.Close(); + } + } + + internal class SqlCommand + { + private string a; + private object constr; + + public SqlCommand(string a, object constr) + { + this.a = a; + this.constr = constr; + } + + internal int ExecuteNonQuery() + { + throw new NotImplementedException(); + } + + internal SqlDataReader ExecuteReader() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git "a/32\345\221\250\350\211\263/\351\241\271\347\233\256/SqlDataReader.cs" "b/32\345\221\250\350\211\263/\351\241\271\347\233\256/SqlDataReader.cs" new file mode 100644 index 0000000000000000000000000000000000000000..fe64c92032fd84a9a3c1c095b9283bbb3af2b2a9 --- /dev/null +++ "b/32\345\221\250\350\211\263/\351\241\271\347\233\256/SqlDataReader.cs" @@ -0,0 +1,15 @@ +namespace ADO.NET_项目 +{ + internal class SqlDataReader + { + internal void Close() + { + throw new NotImplementedException(); + } + + internal bool Read() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file