diff --git "a/17\351\222\261\346\263\260\351\223\255/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/17\351\222\261\346\263\260\351\223\255/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" deleted file mode 100644 index ac704fa1e4c610748568e0e46c894fade79d53ac..0000000000000000000000000000000000000000 --- "a/17\351\222\261\346\263\260\351\223\255/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.txt" +++ /dev/null @@ -1,155 +0,0 @@ -using System.ComponentModel.Design.Serialization; - -namespace one -{ - internal class Program - { - static void Main(string[] args) - { - /** - //1.求圆的面积 - //要求用户输入半径的值,打印出以此值为半径的圆的面积 - Console.WriteLine("请输入圆的半径"); - double r = double.Parse(Console.ReadLine()); - //圆周率π定义成常量取3.14。 - const double π = 3.14; - //求圆的面积的公式:πr²。 - Console.WriteLine(π * r * r); - //r由用户输入并存入一个变量中此变量用double比较合适,因为用户可能会输入小数。 - - //2.编写一个程序,请用户输入一个四位整数 - Console.WriteLine("请输入一个四位整数"); - int a = int.Parse(Console.ReadLine()); - //将用户输入的四位数的千位、百位、十位和个位分别显示出来,如5632,则显示“用户输入的千位为5,百位为6,十位为3,个位为2” - int 千 = a / 1000; - int 百 = a % 1000 / 100; - int 十 = a % 100 / 10; - int 个 = a % 10; - Console.WriteLine("你输入的是" + a + "\n输入的千位为" + 千 + "\n百位为" + 百 + "\n十位为" + 十 + "\n个位为" + 个); - //3.用户输入三个数,找出最大的数,打印输出。 - Console.WriteLine("请输入三个数"); - int b = int.Parse(Console.ReadLine()); - int 百2 = b / 100; - int 十2 = b % 100 / 10; - int 个2 = b % 10; - int max = 百2; - if (十2 > max) - { - max = 十2; - } - if (个2 > max) - { - max = 个2; - }; - Console.WriteLine("你输入的是" + b + "最大值是" + max); - - //a) 接受用户输入一个数n,求这个数的阶乘;5! = 5 * 4 * 3 * 2 * 1; - Console.WriteLine("请输入一个整数"); - int c = int.Parse(Console.ReadLine()); - Console.WriteLine("你输入的数是"+c); - for(int c1=c;c1>0;c1--) - { - c *= c1; - } - Console.WriteLine("这个数的阶乘是"+c); - //.接受用户输入的一个数n,求n到1所有数的阶乘和;n! + (n - 1!) + (n - 2)! +……+1! - Console.WriteLine("请输入一个整数"); - int d = int.Parse(Console.ReadLine()); - for (int d1 = d;d1>0;d1--) - { - for (int d2 = d1;d2>0;d2--) - d *= d1; - } - - Console.WriteLine(); - //5.根据用户输入的菱形边长,打印菱形;如边长为3,行数为5; - for (int f = 1; f <= 3; f++) - { - for (int f1 = 1; f1 <= 3 - f; f1++) - { - Console.Write(" "); - } - for (int f2 = 1; f2 <= 2 * f - 1; f2++) - { - Console.Write("*"); - } - Console.WriteLine(); - } - for (int f = 2; f >= 1; f--) - { - for (int f1 = 1; f1 <= 3 - f; f1++) - { - Console.Write(" "); - } - for (int f2 = 1; f2 <= 2 * f - 1; f2++) - { - Console.Write("*"); - } - Console.WriteLine(); - } - - - //6.用循环打印九九乘法表(用二维数组保存字符串后再打印) - for (int d = 1; d < 10; d++) - { - for (int e = 1; e <= d; e++) - { - Console.Write(d + "x" + e + "=" + d * e + "\t"); - } - Console.WriteLine(); - } - - //7.输入一行字符串,分别统计出其中英文字母、数字、空格的个数。 - int zm = 0; - int sz = 0; - int kg = 0; - int fh = 0; - Console.WriteLine("输入一行字符串"); - string sr = Console.ReadLine(); - char[] sr1 = sr.ToString().ToCharArray(); - foreach(char s in sr1) - { - if (s >= 'a' && s <= 'z' || s >= 'A' && s <= 'Z') - zm++; - else if (s>='1'&&s<='9') - sz++; - else if (s==' ') - kg++; - else - fh++; - } - Console.WriteLine($"字母{zm},数字{sz}空格{kg}符号{fh}"); - //8.在 Main 方法中创建一个 double 类型的数组,并在该数组中存入 5 名学生的考试成绩,计算总成绩和平均成绩。(要求使用foreach语句实现该功能 - double[] scores = { 50,40,60,10,70 }; - - double sum = 0; - double avg = 0; - foreach (double score in scores) - { - sum = sum + score; - } - avg = sum / 5; - Console.WriteLine("总成绩为:" + sum); - Console.WriteLine("平均成绩为:" + avg); - - //9.定义一个方法,实现一维数组的排序功能,从大到小排序。(不要用Array类的方法) - - int[] qq = { 50, 40, 60, 10, 70 }; - for (int i = 0; i < qq.Length; i++) - { - for (int j = 0; j < qq.Length - i - 1; j++) - { - if (qq[j] < qq[j + 1]) - { - int temp = qq[j]; - qq[j] = qq[j + 1]; - qq[j + 1] = temp; - } - } - } - Console.WriteLine("从大到小排序:"); - foreach (int b in qq) - { - Console.Write(b + "\t"); - } - Console.WriteLine(); \ No newline at end of file diff --git "a/22\346\236\227\347\247\200\346\270\205/15\351\242\230/15\351\242\230.cs" "b/22\346\236\227\347\247\200\346\270\205/15\351\242\230/15\351\242\230.cs" new file mode 100644 index 0000000000000000000000000000000000000000..0b7dce30e4c524caf65494ab914ac492e69cb83a --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/15\351\242\230/15\351\242\230.cs" @@ -0,0 +1,297 @@ +namespace 作业 +{ + internal class Program + { + static void Main(string[] args) + { + // 1.求圆的面积 + //要求用户输入半径的值,打印出以此值为半径的圆的面积 + //求圆的面积的公式:πr²。 + //圆周率π定义成常量取3.14。 + //r由用户输入并存入一个变量中此变量用double比较合适,因为用户可能会输入小数。 + Console.WriteLine("第一题-----------------------"); + double π = 3.14; + Console.WriteLine("请输入圆的半径"); + double r = Convert.ToDouble(Console.ReadLine()); + double s = π * r * r; + Console.WriteLine("圆的面积为:" + s); + + + //2.编写一个程序,请用户输入一个四位整数,将用户输入的四位数的千位、百位、十位和个位分别显示出来, + //如5632,则显示“用户输入的千位为5,百位为6,十位为3,个位为2” + Console.WriteLine("第二题-----------------------"); + Console.WriteLine("请输入一个四位数"); + string shuzu = Console.ReadLine(); + int num = int.Parse(shuzu); + int a = num % 10; + int b = num / 10 % 10; + int c = num / 100 % 10; + int d = num / 1000; + Console.WriteLine("个位是" + a + "十位是" + b + "百位是" + c + "千位是" + d); + + + + //3.用户输入三个数,找出最大的数,打印输出。 + Console.WriteLine("第三题-----------------------"); + Console.WriteLine("请输入第一个数"); + int num1 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入第二个数"); + int num2 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入第三个数"); + int num3 = Convert.ToInt32(Console.ReadLine()); + int max = num1; + if (num2 > max) + { + max = num2; + } + if (num3 > max) + { + max = num3; + } + Console.WriteLine("最大的值是" + max); + + //4.接受用户输入一个数n,求这个数的阶乘;5! = 5*4*3*2*1; + Console.WriteLine("第四题-----------------------"); + Console.WriteLine("请输入一个数"); + int num4 = int.Parse(Console.ReadLine()); + int sum = 1; + for (int i = 1; i <= num4; i++) + { + sum *= i; + } + Console.WriteLine("阶乘为" + sum); + + // 5.接受用户输入的一个数n,求n到1所有数的阶乘和;n! + (n - 1!) + (n - 2)! +……+1! + Console.WriteLine("第五题-----------------------"); + Console.WriteLine("请输入一个数"); + int num5 = int.Parse(Console.ReadLine()); + int sum2 = 1; + for (int ab = 1; ab <= num5; ab++) + { + sum2 *= ab; + for (int cc = ab; cc <= ab; cc++) + { + sum2 += cc; + } + } + Console.WriteLine(sum2); + + + //6.根据用户输入的菱形边长,打印菱形;如边长为3,行数为5; + Console.WriteLine("第六题-----------------------"); + Console.WriteLine("输入一个大于2的正整数");//至少3行才能出一个菱形,输入一个偶数菱形就是这个偶数减1行 + int n = Convert.ToInt32(Console.ReadLine()); + for (int i = 1; i <= (n + 1) / 2; i++) //打印菱形的上面部分 + { + for (int j = (n - 1) / 2; j >= i; j--) + { //打印空格 + Console.Write(" "); + } + for (int k = 1; k <= i * 2 - 1; k++) + { //打印“*”号,第i行有i*2-1个“*”号 + Console.Write("*"); + } + Console.WriteLine(); + } + for (int i = (n - 1) / 2; i >= 1; i--)//打印菱形下面的部分 与上面部分同理 + { + for (int j = i - 1; j < (n - 1) / 2; j++) + { + Console.Write(" "); + } + for (int k = 1; k <= i * 2 - 1; k++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + + //7.用循环打印九九乘法表(用二维数组保存字符串后再打印) + Console.WriteLine("第七题-----------------------"); + for (int dd = 1; dd <= 9; dd++) + { + for (int ee = 1; ee <= dd; ee++) + { + Console.WriteLine(ee + "*" + dd + "=" + ee * dd + "\t"); + } + Console.WriteLine("\n"); + } + + //8.输入一行字符串,分别统计出其中英文字母、数字、空格的个数。 + Console.WriteLine("第八题-----------------------"); + string str = ""; + int le = 0;//统计字母的数量 + int sp = 0;//统计空格的数量 + int num8 = 0; //统计数字的数量 + int symbol = 0;//统计其它字符的数量 + Console.Write("请输入一段字符:"); + str = Console.ReadLine(); + char[] c1 = str.ToCharArray();//把字符串转换成字符数组 + foreach (char i in c1) + { + if (i >= 'a' && i <= 'z' || i >= 'A' && i <= 'Z') + le++; + else if (i >= '0' && i <= '9') + num++; + else if (i == ' ') + sp++; + else + symbol++; + } + Console.WriteLine("字母有" + le + "个,空格有" + sp + "个,数字有" + num + "个,其它字符有" + symbol + "个."); + Console.ReadLine(); + + + + //9.在 Main 方法中创建一个 double 类型的数组,并在该数组中存入 5 名学生的考试成绩, + //计算总成绩和平均成绩。(要求使用foreach语句实现该功能) + Console.WriteLine("第九题-----------------------"); + double[] cj = new double[] { 99, 88, 77, 66, 55 }; + double sum3 = 0; + foreach (double o in cj) + { + sum3 += o; + } + Console.WriteLine(sum3); + Console.WriteLine(sum3 / cj.Length); + //10. 定义一个方法,实现一维数组的排序功能,从大到小排序。(不要用Array类的方法) + Console.WriteLine("第十题-----------------------"); + int[] numbers = new int[8];//定义数组 + Random r1 = new Random();//定义随机数 + for (int i = 0; i < numbers.Length; i++) + { + numbers[i] = r1.Next(0, 100);//随机来几个数 + } + foreach (int i in numbers) + { + Console.WriteLine(i);//遍历数组 + } + for (int i = 0; i < numbers.Length - 1; i++) + {//顺序排序,最后一个元素时,不需要与自身比较 + for (int j = i + 1; j < numbers.Length; j++) + { + if (numbers[i] > numbers[j])//判断两数据大小 小到大 + { + int temp = numbers[i];// + numbers[i] = numbers[j];// + numbers[j] = temp;// + } + } + } + //顺序之后的结果 + Console.WriteLine("顺序之后的结果"); + foreach (int item in numbers) + { + Console.WriteLine(item); + } + + //11.实现查找数组元素索引的功能。 + //定义一个数组,然后控制台输入要查找的元素,返回输入值在数组中最后一次出现的位置。 + //若是找不到,请打印找不到。(不要用Array类的方法) + Console.WriteLine("第十一题-----------------------"); + int[] nn = new int[] { 1, 3, 5, 7, 9, 2, 4 }; + Console.WriteLine("请输入要查找的元素"); + int ys = Convert.ToInt32(Console.ReadLine()); + int index = -1; + for (int i = 0; i < nn.Length; i++) + { + if (nn[i] == ys) + { + index = i; + } + } + if (index == -1) + { + Console.WriteLine("找不到"); + } + else + { + Console.WriteLine("该元素最后一次出现的位置是:" + index); + } + + + + + //12.在 Main 方法中创建一个字符串类型的数组,并存入 5 个值,然后将数组中下标是偶数的元素输出。 + Console.WriteLine("第十二题-----------------------"); + int[] arr = new int[5] { 6, 16, 26, 36, 46 }; + for (int i = 0; i < arr.Length; i++) + { + if (arr[i] % 2 == 0) + { + Console.WriteLine("偶数为" + arr[i]); + } + else + { + Console.WriteLine("奇数为" + arr[i]); + } + } + + + + //13.用户输入正方形边长,用*打印出空心正方形。 + Console.WriteLine("第十三题-----------------------"); + Console.WriteLine("请输入正方形边长"); + int bc = int.Parse(Console.ReadLine()); + for (int ff = 0; ff < bc; ff++) + { + for (int jj = 0; jj < bc; jj++) + { + if (ff == 0 || ff == bc - 1) + { + Console.Write("*"); + } + else + { + Console.Write(""); + } + } + Console.Write("\n"); + } + + + //14.用户输入正方形边长,用*打印出实心正方形。 + Console.WriteLine("第十四题-----------------------"); + Console.WriteLine("请输入正方形边长"); + int sx = int.Parse(Console.ReadLine()); + if (sx > 1) + { + for (int gg = 1; gg <= sx; gg++) + { + for (int hh = 1; hh <= sx; hh++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + } + else + { + Console.WriteLine("边长不小于1"); + } + + //15.用二维数组存放数据,实现杨辉三角形的打印; + Console.WriteLine("第十五题-----------------------"); + int[,] arr4 = new int[10, 10]; + for (int ll = 0; ll < 10; ll++) + { + for (int j = ll; j >= 0; j--) + { + if (j == 0 || j == ll) + { + arr4[ll, j] = 1; + } + else + { + arr4[ll, j] = arr4[ll - 1, j - 1] + arr4[ll - 1, j]; + } + Console.Write(arr4[ll, j] + "\t"); + } + Console.WriteLine(); + } + + + + } + } +} \ No newline at end of file diff --git "a/22\346\236\227\347\247\200\346\270\205/\345\237\272\347\241\200\350\257\255\346\263\22502/\345\237\272\347\241\200\350\257\255\346\263\22502.md" "b/22\346\236\227\347\247\200\346\270\205/\345\237\272\347\241\200\350\257\255\346\263\22502/\345\237\272\347\241\200\350\257\255\346\263\22502.md" new file mode 100644 index 0000000000000000000000000000000000000000..9e39161891d7c1bccb8b9550d2fca9562da6c9e8 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\345\237\272\347\241\200\350\257\255\346\263\22502/\345\237\272\347\241\200\350\257\255\346\263\22502.md" @@ -0,0 +1,236 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 用户类 +{ + //1. 定义一个用户类,存放用户的账号、用户名和密码属性; + // 在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息;然后在主方法调用输出; + internal class user + { + public string id; + public string name; + public string password; + public void print() + { + Console.WriteLine("用户账号:" + id); + Console.WriteLine("用户姓名:" + name); + Console.WriteLine("用户密码:" + password); + } + } +} +namespace 用户类 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("用户信息为:"); + user user = new user(); + user.id = "1"; + user.name = "茶兀"; + user.password = "cw"; + user.print(); + Console.WriteLine(" "); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 定义学生类 +{ + internal class student + { + //二.定义一个学生类 + //1.定义字段存放学生的学号、姓名、性别、年龄、专业信息; + //2.对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + //3.在学生类中定义一个方法输出学生信息。 + //4. 在主方法实例化学生对象,赋值并输出 + + private int id; + private string name; + private int sex; + private int age; + private string major; + public int Id + { + get + { + return id; + } + set + { + id = value; + } + } + public string Name + { + get + { + return name; + } + set + { + name = value; + } + } + public int Sex + { + get + { + return sex; + } + set + { + sex = value; + } + } + public int Age + { + get + { + return age; + } + set + { + if (age < 0 || age > 128) + { + age = 0; + } + else + { + age = value; + } + } + } + public string Major + { + get + { + return major; + } + set + { + major = value; + } + } + public void Print() + { + Console.WriteLine("该学生的学号为:" + id); + Console.WriteLine("该学生的姓名为:" + name); + Console.WriteLine("该学生的性别为:" + sex); + Console.WriteLine("该学生的年龄为:" + age); + Console.WriteLine("该学生的专业信息为:" + major); + } + } +} +namespace 定义学生类 +{ + internal class Program + { + static void Main(string[] args) + { + student student = new student(); + student.Id = 1; + student.Name = "zy"; + student.Sex = 1; + student.Age = 18; + student.Major = "软件技术"; + student.Print(); + Console.WriteLine(" "); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 图书馆 +{ + + // 3.定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + //对价格进行赋值限制,小于0价格,赋值为0 + //在图书类中定义一个方法输出图书信息; + //在主方法实例化对象,赋值并输出 + internal class library//1.定义字段存放图书的编号、书名、价格、出版社、作者信息; + { + private int id; + private string name; + private double price; + private string press; + private string autor; + + public int Id { get => id; set => id = value; } + public string Name { get => name; set => name = value; } + public double Price + { + get => price; + + + set//2.对价格进行赋值限制,小于0价格,赋值为0 + { + if (value < 0) + { + price = 0; + } + else + { + price = value; + } + } + } + public string Press { get => press; set => press = value; } + public string Autor { get => autor;set => autor = value; } + + //3.在图书类中定义一个方法输出图书信息; + public void Print() + { + Console.WriteLine($"编号:{Id}"); + Console.WriteLine($"书名:{name}"); + Console.WriteLine($"价格:{price}"); + Console.WriteLine($"出版社:{press}"); + Console.WriteLine($"作者:{autor}"); + } + } +} +namespace 图书馆 +{ + internal class Program + { + static void Main(string[] args) + { + library shu = new library(); + shu.Id = 1; + shu.Name = "童话"; + shu.Price = 59.5; + shu.Press = "人民出版社"; + shu.Autor = "安徒生"; + shu.Print(); + + library shu2= new library(); + shu2.Id = 2; + shu2.Name = "朱志清散文"; + shu2.Price = -21; + shu2.Press = "人民出版社"; + shu2.Autor = "朱自清"; + shu2.Print(); + } + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\345\244\232\346\200\201/\345\244\232\346\200\201.md" "b/22\346\236\227\347\247\200\346\270\205/\345\244\232\346\200\201/\345\244\232\346\200\201.md" new file mode 100644 index 0000000000000000000000000000000000000000..cc434e9e1151fce59548acc6ce24ba087b582eed --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\345\244\232\346\200\201/\345\244\232\346\200\201.md" @@ -0,0 +1,262 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业1_控制台应用程序_ +{ +// 1、创建Calculate基类,其中包含两个整型的protected成员,用以接收用户输入的两个整数。 +//定义一个DisplayResult()虚方法,计算并输出结果。 + internal class Calculate + { + protected int sz1; + protected int sz2; + + public Calculate(int sz1, int sz2) + { + this.sz1 = sz1; + this.sz2 = sz2; + } + + public virtual void DisplayResult() + { + + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业1_控制台应用程序_ +{ + internal class Cheng : Calculate + { + public Cheng(int sz1, int sz2) : base(sz1, sz2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{sz1}*{sz2}={sz1 * sz2}"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业1_控制台应用程序_ +{ + internal class Chu:Calculate + { + public Chu(int sz1, int sz2) : base(sz1, sz2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{sz1}/{sz2}={sz1 / sz2}"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业1_控制台应用程序_ +{ + internal class Jia:Calculate + { + public Jia(int sz1, int sz2) : base(sz1, sz2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{sz1}+{sz2}={sz1 + sz2}"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业1_控制台应用程序_ +{ + internal class Jian:Calculate + { + public Jian(int sz1, int sz2) : base(sz1, sz2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{sz1}-{sz2}={sz1 -sz2}"); + } + } +} +namespace 多态作业1_控制台应用程序_ +{ + internal class Program + { + //一、编写一个控制台应用程序,接受用户输入的两个整数和一个操作符, + //以实现对两个整数的加、减、乘、除运算,并显示出计算结果。 +//1、创建Calculate基类,其中包含两个整型的protected成员, +//用以接收用户输入的两个整数。定义一个DisplayResult()虚方法,计算并输出结果。 +//2、定义四个类继承自Calculate类,分别重写DisplayResult()方法, +//实现两个整数的加、减、乘、除运算,并输出结果。 +//3、根据用户输入的操作符,实例化相应的类,完成运算并输出结果。 +//4、在主类中添加一个方法,形参为父类对象,根据传递实参的类型, +//调用方法,实现计算和显示结果。 + + static void Main(string[] args) + { + Console.WriteLine("请输入第一个整数"); + int sz1=Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入第二个整数"); + int sz2=Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入操作符"); + string czf=Console.ReadLine(); + Calculate c = null; + if (czf == "+") + { + c = new Jia(sz1, sz2); + } + else if(czf == "-") + { + c = new Jian(sz1, sz2); + }else if(czf == "*") + { + c=new Cheng(sz1, sz2); + }else if(czf == "/") + { + c=new Chu(sz1, sz2); + } + + Calculate (c); + } + public static void Calculate(Calculate c) + { + c.DisplayResult(); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业2_Shape_ +{ +// 二、创建一个Shape(形状)类,此类包含一个名为color的数据成员, +// 用于存储颜色, +//这个类还包含一个名为GetArea()的虚方法(这个方法是用来获取形状面积的)。 + internal class Shape + { + public string color; + public Shape(string color) + { + this.color = color; + } + // 名为GetArea()的虚方法(这个方法是用来获取形状面积的)。 + public virtual void GetArea() + { + + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业2_Shape_ +{ +// 基于这个Shape,创建两个子类:Circle(圆形类)和Square(正方形类) +// ,Circle类中包含radius(半径)的数据成员,Square类中包含sideLen(边长)的数据成员, +//这两个子类都去重写父类的GetArea()方法,各自去实现计算自己的面积。 + internal class Circle:Shape + { + + public double radius; + public Circle(string color,double radius):base(color) + { + + this.radius = radius; + } + public override void GetArea() + { + Console.WriteLine($"{color}的圆的面积为{radius}*{radius}*3.14={radius*radius*3.14}"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业2_Shape_ +{ +// 创建两个子类:Circle(圆形类)和Square(正方形类),Circle类中包含radius(半径)的数据成员 +// ,Square类中包含sideLen(边长)的数据成员, +//这两个子类都去重写父类的GetArea()方法,各自去实现计算自己的面积。 + internal class Square:Shape + { + //Square类中包含sideLen(边长)的数据成员 + public int sidelen; + public Square(string color,int sidelen):base(color) + { + this.sidelen = sidelen; + + } + public override void GetArea() + { + Console.WriteLine($"{color}的正方形面积为{sidelen}*{sidelen}={sidelen*sidelen}"); + } + + + } +} +namespace 多态作业2_Shape_ +{ + internal class Program + { +// 二、创建一个Shape(形状)类,此类包含一个名为color的数据成员, +//用于存储颜色,这个类还包含一个名为GetArea()的虚方法(这个方法是用来获取形状面积的)。 +//基于这个Shape,创建两个子类:Circle(圆形类)和Square(正方形类), +//Circle类中包含radius(半径)的数据成员,Square类中包含sideLen(边长)的数据成员, +//这两个子类都去重写父类的GetArea()方法,各自去实现计算自己的面积。 +//在主类中添加一个方法,参数类型就是Shape, +//方法体中,用形参去调用GetArea()方法。 +//main方法中去测试这个方法。 + + static void Main(string[] args) + { + Console.WriteLine("请输入形状颜色"); + string color = Convert.ToString(Console.ReadLine()); + Console.WriteLine("请输入圆的半径"); + double radiuo = Convert.ToDouble(Console.ReadLine()); + Console.WriteLine("请输入正方形的边长"); + int sidelen = Convert.ToInt32(Console.ReadLine()); + Circle cr = new Circle(color, radiuo); + cr.GetArea(); + Square sq = new Square(color,sidelen); + sq.GetArea(); + } + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\345\267\251\345\233\272\345\237\272\347\241\20001/\345\267\251\345\233\272\345\237\272\347\241\20001.cs" "b/22\346\236\227\347\247\200\346\270\205/\345\267\251\345\233\272\345\237\272\347\241\20001/\345\267\251\345\233\272\345\237\272\347\241\20001.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b33f623cbae83da5adcb1bb20e80dfcdd7a0742c --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\345\267\251\345\233\272\345\237\272\347\241\20001/\345\267\251\345\233\272\345\237\272\347\241\20001.cs" @@ -0,0 +1,77 @@ +namespace 01 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("һ"); + Console.WriteLine("ѧ紺֮"); + Console.WriteLine(""); + Console.WriteLine("ѧĥ֮ʯ"); + Console.WriteLine(""); + Console.WriteLine("Ͱɣ"); + Console.WriteLine("J"); + Console.WriteLine("A"); + Console.WriteLine("V"); + Console.WriteLine("A"); + Console.WriteLine("!"); + + Console.WriteLine("ڶ"); + Console.WriteLine("true"); + Console.WriteLine("false"); + + Console.WriteLine(""); + sbyte a = -128; + Console.WriteLine(a); + int 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 l = -2147483649; + Console.WriteLine(l); + long h = 2147483648; + Console.WriteLine(h); + + Console.WriteLine(""); + float i = -3.14F; + Console.WriteLine(i); + float j = 3.14F; + Console.WriteLine(j); + double k = -3.4; + Console.WriteLine(k); + double ll = 3.4; + Console.WriteLine(ll); + + Console.WriteLine(""); + int a1 = 10; + int b1 = 20; + int temp = 10; + a1 = b1; + b1 = temp; + Console.WriteLine("aֵ" + a1); + Console.WriteLine("bֵ" + b1); + + Console.WriteLine(""); + int x = 100; + int y = 200; + Console.WriteLine("xyĺΪ" + (x + y)); + Console.WriteLine("xyIJΪ" + (x - y)); + Console.WriteLine("xyĻΪ" + (x * y)); + Console.WriteLine("xyΪ" + (x / y)); + + Console.WriteLine(""); + double x1 = 100.8; + double y1 = 20.6; + Console.WriteLine("x1y1ĺΪ" + (x1 + y1)); + Console.WriteLine("x1y1IJΪ" + (x1 - y1)); + Console.WriteLine("x1y1ĻΪ" + (x1 * y1)); + Console.WriteLine("x1y1Ϊ" + (x1 / y1)); + } + } +} \ No newline at end of file diff --git "a/22\346\236\227\347\247\200\346\270\205/\346\210\252\345\233\276/\345\276\256\344\277\241\345\233\276\347\211\207_20230418182126.png" "b/22\346\236\227\347\247\200\346\270\205/\346\210\252\345\233\276/\345\276\256\344\277\241\345\233\276\347\211\207_20230418182126.png" new file mode 100644 index 0000000000000000000000000000000000000000..a73c8fad474aa5ab09efc316449455d22228d732 Binary files /dev/null and "b/22\346\236\227\347\247\200\346\270\205/\346\210\252\345\233\276/\345\276\256\344\277\241\345\233\276\347\211\207_20230418182126.png" differ diff --git "a/22\346\236\227\347\247\200\346\270\205/\346\216\245\345\217\243/\346\216\245\345\217\243.md" "b/22\346\236\227\347\247\200\346\270\205/\346\216\245\345\217\243/\346\216\245\345\217\243.md" new file mode 100644 index 0000000000000000000000000000000000000000..8cc5ad839553e7461180d379418c833bb018c7c9 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\346\216\245\345\217\243/\346\216\245\345\217\243.md" @@ -0,0 +1,427 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业1_猫_狗_鸭_猴_ +{ + // 1、猫、狗、鸭、猴,(吃、睡觉、游泳、爬树) + //所有动物都有吃的方法 + //狗和鸭会游泳,不会爬树 + //猫和猴不会游泳会爬树 + //将吃的方法定义在父类方法中,将游泳和爬树的技能定义为接口 + //所有子类继承父类后,再去继承相应的接口实现技能 + internal abstract class Dongwu + { + string name; + + public string Name { get => name; set => name = value; } + public Dongwu() { } + public Dongwu(string name) + { + this.name = name; + } + + public abstract void Eat(); + + public virtual void Sleep() + { + Console.WriteLine($"{name}正在睡觉"); + } + internal interface Pa + { + void Paa(); + } + internal interface You + { + void youu(); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业1_猫_狗_鸭_猴_ +{ + internal class Dog:Dongwu + { + public override void Eat() + { + Console.WriteLine("小狗在啃骨头"); + } + + public void Pa() + { + Console.WriteLine("小狗不会游泳,小狗在爬树"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业1_猫_狗_鸭_猴_ +{ + internal class Hou:Dongwu + { + public override void Eat() + { + Console.WriteLine("猴子在吃香蕉"); + } + public void Pa() + { + Console.WriteLine("猴子在爬树"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业1_猫_狗_鸭_猴_ +{ + internal class Mao:Dongwu + { + + + public override void Eat() + { + Console.WriteLine("小猫在吃小鱼干"); + } + + public void Pa() + { + Console.WriteLine("小猫在爬树"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业1_猫_狗_鸭_猴_ +{ + internal class Ya:Dongwu + { + public override void Eat() + { + Console.WriteLine("鸭子在吃田螺"); + } + + public void You() + { + Console.WriteLine("鸭子会游泳"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业1_猫_狗_鸭_猴_ +{ + internal class Ya:Dongwu + { + public override void Eat() + { + Console.WriteLine("鸭子在吃田螺"); + } + + public void You() + { + Console.WriteLine("鸭子会游泳"); + } + } +} + +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业2 +{ + + + + public class Bianfu : Car, IFly + { + public Bianfu(string brand) : base(brand) + { + } + + public void Fly() + { + Console.WriteLine("蝙蝠战车会飞。"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业2 +{ + internal class Car + { + //定义一个父类表示车的共同属性特征行为:品牌名Brand,会跑Run方法 + + private string brand; + + public Car() + { + } + + public Car(string brand) + { + Brand = brand; + } + + public string Brand { get => brand; set => brand = value; } + public virtual void Run() + { + Console.WriteLine("车会跑。"); + } + + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业2 +{ + internal interface IFly + { + //定义一个飞的功能接口类IFly:定义飞的方法Fly + + void Fly(); + } +} +namespace 接口作业2 +{ + internal class Program + { + // 2、蝙蝠战车的例子 + //定义一个父类表示车的共同属性特征行为:品牌名Brand,会跑Run方法 + //定义一个飞的功能接口类IFly:定义飞的方法Fly + //然后定义蝙蝠战车类继承Cat类和飞的接口 + //在主方法实例化蝙蝠战车的对象,并为品牌名赋值,调用跑和飞的方法 + + + static void Main(string[] args) + { + + + Bianfu bianfu = new Bianfu("ZY"); + bianfu.Run(); + bianfu.Fly(); + } + } +} + +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业3_超人_小鸟_飞机_ +{ + internal class Chaoren:Dongwu,IFlyable + { + //超人都是动物类,都有吃的方法; + + public override void Eat() + { + //base.Eat(); + Console.WriteLine("超人在吃棒棒糖"); + } + public void TakeOff() + { + Console.WriteLine("超人在天空飞"); + } + public void Fly() + { + Console.WriteLine("超人正在飞"); + } + public void Land() + { + Console.WriteLine("超人安全着路"); + + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业3_超人_小鸟_飞机_ +{ + // //定义一个动物类 + public abstract class Dongwu + { + public virtual void Eat() + { + Console.WriteLine("会吃"); + } + } + //定义飞的接口 + public interface IFlyable + { + void TakeOff();//起飞 + void Fly();//飞行中 + void Land();//着陆 + } + //飞机是交通工具类,有运输载人的功能; + public class Plant : Vehicle, IFlyable + { + + + public override void Gn() + { + + Console.WriteLine("飞机会飞"); + } + public void TakeOff() + { + Console.WriteLine("飞机起飞"); + } + public void Fly() + { + Console.WriteLine("飞机飞行中"); + } + public void Land() + { + Console.WriteLine("飞机着陆"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业3_超人_小鸟_飞机_ +{ + + + //2. 小鸟是动物类,都有吃的方法; + public class Niao : Dongwu, IFlyable + { + + + public override void Eat() + { + + Console.WriteLine("鸟会吃"); + } + + public void Fly() + { + throw new NotImplementedException(); + } + + public void Land() + { + throw new NotImplementedException(); + } + + public void TakeOff() + { + throw new NotImplementedException(); + } + //3. 小鸟有自己的特有方法,下蛋; + public void LayEggs() + { + Console.WriteLine("鸟会下蛋"); + } + public void Zhengzfei() + { + Console.WriteLine("鸟起飞"); + } + public void Fei() + { + Console.WriteLine("鸟飞行中"); + } + public void Lu() + { + Console.WriteLine("鸟着陆"); + } + + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业3_超人_小鸟_飞机_ +{ + // 1.飞机是交通工具类,有运输载人的功能; + internal abstract class Vehicle + { + + public virtual void Gn() + { + Console.WriteLine("飞机有运输载人功能"); + } + } +} +namespace 接口作业3_超人_小鸟_飞机_ +{ + internal class Program + { + // 1.飞机是交通工具类,有运输载人的功能; + //2.小鸟和超人都是动物类,都有吃的方法; + //3.小鸟有自己的特有方法,下蛋; + //4.超人、小鸟、飞机都有飞的功能,可以定义飞的接口:飞的接口有起飞、飞行中、着陆的方法; + //超人、小鸟、飞机除了继承各自的父类后,还要继承飞的接口,实现飞的接口的方法; + static void Main(string[] args) + { + Niao niao = new Niao(); + niao.Fei(); + niao.Zhengzfei(); + niao.Lu(); + + Vehicle v = new Vehicle(); + v.Gn(); + + Chaoren chaoren = new Chaoren(); + chaoren.Fly(); + chaoren.TakeOff(); + chaoren.Eat(); + chaoren.Land(); + } + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/ref,out.md" "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/ref,out.md" new file mode 100644 index 0000000000000000000000000000000000000000..c9441ed64f896af889939debc0b29715cff60d22 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/ref,out.md" @@ -0,0 +1,131 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ref_与out +{ + internal class ref_oyt + { + /*1、定义一个方法,求一个整数数组中的最大值, + * 最小值,和,平均数。如果是一个方法只能有一个返回值, + * 那只能每一个都得定义一个方法来实现,不过有了ref和out这实现起来就方便多了。 + + 参考步骤: + 定义一个一维数组,数组中存放一些数据(控制台输入)。 + 定义几个变量:max、min、sum、avg + + 定义一个方法,方法返回数组元素之和,方法形参有max min avg。 + + 请用ref和out各做一遍,并在注释中,描述他们的区别。*/ + public static void Out(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; + + } + } +} +using System.Runtime.Intrinsics.X86; +using System; + +namespace ref_与out +{ + internal class Program + { + static void Main(string[] args) + { + int[] num = { 1, 2, 3, 2, 1, }; + int max; + int min; + int sum; + int avg; + OutTest(num, out max, out min, out sum, out avg); + Console.WriteLine($"整数组中最大值为:{max},最小值为:{min},和为:{sum},平均数为{avg}"); + } + + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tostring +{ + internal class person + { + public int ID { get; set; } + public string Name { get; set; } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tostring +{ + internal class Student:person + { + public string major { get; set; } + public override string ToString() + { + return $"编码{ID},姓名{Name},专业{major}"; + } + } +} + +using Tostring; + +namespace Tostring类 +{ + internal class Program + { + static void Main(string[] args) + { + Student student1 = new Student(); + student1.ID = 1; + student1.Name = "蛙"; + student1.major = "潜水"; + + Student student2 = new Student(); + student2.ID = 2; + student2.Name = "鱼"; + student2.major = "潜水"; + + Console.WriteLine("student1:"+student1.ToString); + Console.WriteLine("student2:"+student2.ToString); + + } + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\346\236\204\351\200\240\346\226\271\346\263\225.md" "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\346\236\204\351\200\240\346\226\271\346\263\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..70e299f3eec9350c660ef86b07af8e90e2c9bbe5 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\346\236\204\351\200\240\346\226\271\346\263\225.md" @@ -0,0 +1,70 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 构建方法作业1_员工类__ +{ + internal class yuangong + { + //一、定义一个员工类 + //1.定义字段,存放用户的工号、姓名、性别、学历和部门信息; + //2.定义属性封装字段 + //3.定义2个构造函数: + // 一个是无参构造函数,学历默认为专科; + // 一个有参构造函数,根据参数对类的属性进行初始化。 + private int id; + private string name; + private char sex; + private string xli; + private string bmxx; + + public int Id { get => id; set => id = value; } + public string Name { get => name; set => name = value; } + public char Sex { get => sex; set => sex = value; } + public string Xli { get => xli; set => xli = value; } + public string Bmxx { get => bmxx; set => bmxx = value; } + public yuangong() { xli = "专科"; } + public yuangong(int id, string name, char sex, string xli, string bmxx) + { + this.Id = id; + this.Name = name; + this.Sex = sex; + this.Xli = xli; + this.Bmxx = bmxx; + } + public void Print() + { + Console.WriteLine($"工号:{Id}"); + Console.WriteLine($"姓名:{Name}"); + Console.WriteLine($"性别:{Sex}"); + Console.WriteLine($"学历:{xli}"); + Console.WriteLine($"部门信息:{bmxx}"); + } + } + +} +namespace 构建方法作业1_员工类__ +{ + internal class Program + { + static void Main(string[] args) + { + yuangong yuangoong= new yuangong(); + yuangoong.Id = 1; + yuangoong.Name= "婷"; + yuangoong.Sex= '女'; + yuangoong.Xli = "专科"; + yuangoong.Bmxx = "工头"; + yuangoong.Print(); + + yuangong yuangoong2 = new yuangong(2, "倩", '女', "专科", "助理"); + yuangoong.Print(); + } + + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\347\261\273\345\222\214\345\257\271\350\261\241.md" "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\347\261\273\345\222\214\345\257\271\350\261\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..3f6dcb53f9656dafe259ff9e7135f422fada3308 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\347\261\273\345\222\214\345\257\271\350\261\241.md" @@ -0,0 +1,413 @@ +```c# + +using System.Xml.Linq; +//一. 定义一个用户类 +//1.定义字段存放用户的账号、用户名和密码; +//2.在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息; +//3.在用户类中定义一个 登录身份辨认的方法:规则为用户名为“admin”和密码为“123456”时返回“管理员”,否则返回“普通用户”; +//4.在主方法中实例化用户类的对象,然后对其账号、用户名和密码赋值 +//5.在主方法中用实例化的对象调用方法,输出用户对象的信息和身份(管理员或者普通用户) +namespace user +{ + internal class User + { + public int Zhao + { + get; set; + } + + public string UserName + { + get; set; + } + + public int PassWord + { + get; set; + } + + public void PrintUser() + { + Console.WriteLine("账号: " + Zhao); + Console.WriteLine("用户名: " + UserName); + Console.WriteLine("密码: " + PassWord); + } + + public string Identity() + { + if (UserName == "admin" && PassWord == 123456) + { + return "管理员"; + } + else + { + return "普通用户"; + } + } + } + +} +namespace 英雄类 +{ + internal class Program + { + static void Main(string[] args) + { + static void Main(string[] args) + { + hero hero = new hero(); + hero.name = "冰糖雪梨"; + hero.attactvalue = 100; + hero.defense = 98; + hero.hp = 86; + hero.mana = 0; + hero.Introduce(); + hero.Attract(); + + } + } + } +} + +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 定义学生类 +{ + internal class student + { + //二.定义一个学生类 + //1.定义字段存放学生的学号、姓名、性别、年龄、专业信息; + //2.对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + //3.在学生类中定义一个方法输出学生信息。 + //4. 在主方法实例化学生对象,赋值并输出 + + private int id; + private string name; + private int sex; + private int age; + private string major; + public int Id + { + get + { + return id; + } + set + { + id = value; + } + } + public string Name + { + get + { + return name; + } + set + { + name = value; + } + } + public int Sex + { + get + { + return sex; + } + set + { + sex = value; + } + } + public int Age + { + get + { + return age; + } + set + { + if (age < 0 || age > 128) + { + age = 0; + } + else + { + age = value; + } + } + } + public string Major + { + get + { + return major; + } + set + { + major = value; + } + } + public void Print() + { + Console.WriteLine("该学生的学号为:" + id); + Console.WriteLine("该学生的姓名为:" + name); + Console.WriteLine("该学生的性别为:" + sex); + Console.WriteLine("该学生的年龄为:" + age); + Console.WriteLine("该学生的专业信息为:" + major); + } + } +} +namespace 定义学生类 +{ + internal class Program + { + static void Main(string[] args) + { + student student = new student(); + student.Id = 1; + student.Name = "zy"; + student.Sex = 1; + student.Age = 18; + student.Major = "软件技术"; + student.Print(); + Console.WriteLine(" "); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 图书馆 +{ + + // 3.定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + //对价格进行赋值限制,小于0价格,赋值为0 + //在图书类中定义一个方法输出图书信息; + //在主方法实例化对象,赋值并输出 + internal class library//1.定义字段存放图书的编号、书名、价格、出版社、作者信息; + { + private int id; + private string name; + private double price; + private string press; + private string autor; + + public int Id { get => id; set => id = value; } + public string Name { get => name; set => name = value; } + public double Price + { + get => price; + + + set//2.对价格进行赋值限制,小于0价格,赋值为0 + { + if (value < 0) + { + price = 0; + } + else + { + price = value; + } + } + } + public string Press { get => press; set => press = value; } + public string Autor { get => autor;set => autor = value; } + + //3.在图书类中定义一个方法输出图书信息; + public void Print() + { + Console.WriteLine($"编号:{Id}"); + Console.WriteLine($"书名:{name}"); + Console.WriteLine($"价格:{price}"); + Console.WriteLine($"出版社:{press}"); + Console.WriteLine($"作者:{autor}"); + } + } +} +namespace 图书馆 +{ + internal class Program + { + static void Main(string[] args) + { + library shu = new library(); + shu.Id = 1; + shu.Name = "童话"; + shu.Price = 59.5; + shu.Press = "人民出版社"; + shu.Autor = "安徒生"; + shu.Print(); + + library shu2= new library(); + shu2.Id = 2; + shu2.Name = "朱志清散文"; + shu2.Price = -21; + shu2.Press = "人民出版社"; + shu2.Autor = "朱自清"; + shu2.Print(); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace hero +{ + internal class enemy + { + //四.定义一个敌人类 + + //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 => 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}"); + } + } +} +namespace hero +{ + internal class Program + { + static void Main(string[] args) + { + enemy enemy = new enemy(); + enemy.Hp = -10; + enemy.Mp = 20; + enemy.Mana = 30; + enemy.Print(); + Console.WriteLine("enemy的血量为:" + enemy.Hp + "\t" + "攻击力为:" + enemy.Mana+ "\t" + "魔法值为:" + enemy.Mp); + } + } +} +``` + +```c# +namespace hero +{ + internal class Program + { + static void Main(string[] args) + { + enemy enemy = new enemy(); + enemy.Hp = -10; + enemy.Mp = 20; + enemy.Mana = 30; + enemy.Print(); + Console.WriteLine("enemy的血量为:" + enemy.Hp + "\t" + "攻击力为:" + enemy.Mana+ "\t" + "魔法值为:" + enemy.Mp); + } + } +} +namespace 英雄类 +{ + internal class Program + { + static void Main(string[] args) + { + static void Main(string[] args) + { + hero hero = new hero(); + hero.name = "冰糖雪梨"; + hero.attactvalue = 100; + hero.defense = 98; + hero.hp = 86; + hero.mana = 0; + hero.Introduce(); + hero.Attract(); + + } + } + } +} + +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\351\207\215\350\275\275.md" "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\351\207\215\350\275\275.md" new file mode 100644 index 0000000000000000000000000000000000000000..f60f69341550489ad4b076f60a68ce145fc3deeb --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\351\207\215\350\275\275.md" @@ -0,0 +1,98 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 重载_圆的面积长方形的面积_ +{ + // 定义一个计算图形面积的类,类中定义2个计算面积的方法(重载,方法名相同),分别计算圆面积和长方形面积两个方法。 + //提示:计算圆的面积传半径,计算长方形面积传长和宽。 + internal class mianji + { + public double A(int r) + { + return r * r * 3.14; + } + public double A(int k, int c) + { + return k * c; + } + } +} +namespace 重载_圆的面积长方形的面积_ +{ + internal class Program + { + static void Main(string[] args) + { + mianji mianji = new mianji(); + double yuan = mianji.A); + double cfx = mianji.A, 2); + Console.WriteLine($"圆的面积为:{yuan};长方形的面积为:{cfx}"); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 计算工具类SumUtils +{ + internal class SumUtils + { + /*2.创建一个名为计算工具类 SumUtils,在类中定义4个方法: + 计算两个整数相加、 + 两个小数相加、两个字符串相加、 + 以及从 1 到指定整数的和的方法。 + 在 Main 方法中分别调用定义好的方法。 + + 提示:根据题目要求,分别定义 3 个带两个参数的方法 + 以及一个带一个整型参数的方法, + 四个方法名相同。*/ + + public void l(int a, int b) + { + Console.WriteLine($"两个整数相加为{a + b}"); + } + public void l(double a, double b) + { + Console.WriteLine($"两个小数相加为{a + b}"); + } + public void l(string a, string b) + { + Console.WriteLine($"两个字符串相加为{a + b}"); + } + public void l(int a) + { + int sum = 0; + for (int i = 1; i <= a; i++) + { + sum = sum + i; + } + Console.WriteLine($"从 1 到指定整数的和为{sum}"); + } + } +} +namespace 计算工具类SumUtils +{ + internal class Program + { + static void Main(string[] args) + { + SumUtils sum = new SumUtils(); + sum.l(3, 4); + sum.l(2.5, 3.14); + sum.l("a", "b"); + sum.l(10); + } + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\351\235\231\346\200\201.md" "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\351\235\231\346\200\201.md" new file mode 100644 index 0000000000000000000000000000000000000000..9029934046266d56fff53e9e08bf6949b27b14bf --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\347\261\273\345\222\214\345\257\271\350\261\241/\351\235\231\346\200\201.md" @@ -0,0 +1,92 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 静态方法作业1_工具类StringUtil_ +{ + internal class StringUtil + { + // 1、写一个工具类StringUtil,在里面定义一个静态方法,用来判断字符串是否为空。 + //如果字符串是null,或者字符串是空"",或者字符串是N个空格" ", + //那这个方法返回true,否则返回false + //然后在主类中(有Main方法的类)调用测试。 + + + public static bool IsEmpty(string str) + { + if (str == null || str == "") + { + return true; + } + char[] chars = str.ToCharArray(); + for (int i = 0; i < chars.Length; i++) + { + if (chars[i] != ' ') + { + return false; + } + } + return true; + } + } +} +amespace 静态方法作业1_工具类StringUtil_ +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine(StringUtil.IsEmpty("")); + Console.WriteLine(StringUtil.IsEmpty(" ")); + Console.WriteLine(StringUtil.IsEmpty(" L")); + Console.WriteLine(StringUtil.IsEmpty(null)); + + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 静态方法作业2__工具类ArrayUtil_ +{ + internal class ArrayUtil + { + // 2、写一个工具类ArrayUtil,在里面定义一个静态方法,用来判断数组是否为空。 +//如果数组是null,或者数组长度为0,那此方法返回true,否则返回false +//然后在主类中(有Main方法的类)调用测试。 + + public static Boolean Isnull(int[] sc) + { + if (sc == null || sc.Length == 0) + { + return true; + } + else + { + return false; + } + } + } +} +namespace 静态方法作业2__工具类ArrayUtil_ +{ + internal class Program + { + static void Main(string[] args) + { + int[] sc = { 34, 53, 64, 74 }; + Console.WriteLine(ArrayUtil.Isnull(sc)); + } + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\347\273\247\346\211\277/\347\273\247\346\211\277.md" "b/22\346\236\227\347\247\200\346\270\205/\347\273\247\346\211\277/\347\273\247\346\211\277.md" new file mode 100644 index 0000000000000000000000000000000000000000..f4679854b93a3716ceaf788c101ce8e7ca9fd7c1 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\347\273\247\346\211\277/\347\273\247\346\211\277.md" @@ -0,0 +1,657 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace 继承1._1_校园管理信息_ +{ +// 一、假设要完成一个学校的校园管理信息系统,在员工管理系统中有不同的人员信息,包括学生信息、教师信息等。 +//学生的字段:编号(Id)、姓名(Name)、性别(Sex)、身份证号(Cardid)、联系方式(Tel)、专业(Major)、年级(Grade) +//教师的字段:编号(Id)、姓名(Name),性别 (Sex)、身份证号(Cardid)、联系方式(Tel)、职称(Title)、工资号(Wageno) +//方法一: +//为学生信息、教师信息创建两个类,并在两个类中分别定义属性和方法: +//学生类中定义编号(Id)、姓名(Name)、性别(Sex)、身份证号(Cardid)、联系方式(Tel)、专业(Major)、年级(Grade)7 个属性,并定义一个方法在控制台输出这些属性的值。 + +//教师类(Teacher)中定义编号(Id)、姓名(Name),性别 (Sex)、身份证号(Cardid)、联系方式(Tel)、职称(Title)、工资号(Wageno),并将上述属性输岀到控制台。 +//方法二: +//将 Student 类和 Teacher 类中共有的 属性抽取出来定义为一个类Person,并让Student和Teacher继承Person +//每个类都要有一个输出属性的方法。 +//每个类都要有初始化数据的有参构造方法。 + internal class glxt + { + 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 glxt(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; + this.Sex = sex; + } + public glxt() { } + } + //学生的字段:编号(Id)、姓名(Name)、性别(Sex)、 + // 身份证号(Cardid)、联系方式(Tel)、专业(Major)、年级(Grade) + class Student : glxt + { + 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} "; + } + } + //教师的字段:编号(Id)、姓名(Name),性别 (Sex)、身份证号(Cardid) + // 、联系方式(Tel)、职称(Title)、工资号(Wageno) + class Teacher : glxt + { + 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}"; + } + } +} +namespace 继承1._1_校园管理信息_ +{ + internal class Program + { + static void Main(string[] args) + { + Student stu1 = new Student("qq", 1, "女", "1111111", "2222222", "软件技术", "大一"); + Console.WriteLine(stu1); + Teacher techer = new Teacher("x", 1, "女", "0000000", "6666666", "专业课老师", "11000"); + Console.WriteLine(techer); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承1._2_英雄类_ +{ + internal class hero + { + // 二、使用类来描述游戏中的角色。 + //在很多RPG游戏中,第一次打开游戏,都会先让你创建自己的“英雄”, + // 或者自己要扮演的角色。这些英雄或者角色都是我们游戏中的“对象”, + // 所以在开发的时候,我们需要针对每个角色都要写相应的类来描述。 + //见英雄文件夹的图片。 + //分析1:角色具有以下信息(简单数据) + //字段:角色名字,角色介绍,角色昵称,攻击力,防御力,速度。 + //方法:每个角色都有三个不同的攻击技能。 + //分析2:四个英雄的公共数据?公共数据向上抽取 + // ,抽象成一个Hero类,然后四个英雄继承这个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) + { + Console.WriteLine($"请选择您要使用的英雄"); + } + } +} +namespace 继承1._2_英雄类_ +{ + internal class Program + { + static void Main(string[] args) + { + Son alk = new Son("埃落克", "埃洛克是一名来自末日边境的勇士。他是圣约英雄中名副其实的拳术好手。他用毁灭性的符文魔法和无情的拳术攻击消灭敌人。", "zy", 1000, 800, 700); + Son tl = new Son("泰拉", "泰拉是为复仇而来的勇者。她挥舞法杖将愤怒转化为强大的元素魔法和攻击力因此战无不胜。", "lxy", 1100, 700, 600); + Son lks = new Son("卢卡斯", "卢卡斯是一名彬彬有礼的剑客,能控制源质能量。他一手持剑战斗,另一手辅助攻击。", "lst", 1200, 600, 500); + Son lf = new Son("洛菲", "洛菲是一名攻击迅猛且擅长传送魔法的时空旅行者,喜欢利用她的幻象伙伴迷惑、吸引并摧毁敌人。", "lq", 1100, 900, 1000); + 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; + } + } + } +} + +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace 继承作业2._1_雇员系统_ +{ + internal class guyuan + { + // 一、雇员系统,定义雇员基类,共同的属性,姓名、地址和出生日期(可有可无),子类:程序员,秘书,高层管理,清洁工,他们有不同的工资算法, + // 其中高级主管和程序员采用底薪加提成的方式,高级主管和程序员的底薪分别是5000元和2000元 ,秘书和清洁工采用工资的方式,工资分别是3000和1000, + public string name; + public string address; + public string birthday; + } + internal class programmer : guyuan + { + int bpay = 2000; + private int add; + + public int Add { get; set; } + public programmer() + { + } + public programmer(string name, string address, string birhtday, int add) + { + base.name = name; + base.address = address; + base.birthday = birhtday; + this.add = add; + } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"底薪:{bpay}"); + Console.WriteLine($"加成:{add}"); + Console.WriteLine($"总工资:{bpay + add}"); + } + } + internal class mannger : guyuan + { + int bpay = 5000; + private int add; + + public int Add { get => add; set => add = value; } + public mannger() + { + } + public mannger(string name, string address, string birhtday, int add) + { + base.name = name; + base.address = address; + base.birthday = birhtday; + this.add = add; + } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"底薪:{bpay}"); + Console.WriteLine($"加成:{add}"); + Console.WriteLine($"总工资:{bpay + add}"); + } + } + internal class mishu : guyuan + { + public int wage { get; set; } + public mishu() + { + } + public mishu(string name, string address, string birhtday, int wage) + { + base.name = name; + base.address = address; + base.birthday = birhtday; + this.wage = wage; + } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"总工资:{wage}"); + } + } + internal class cleaner : guyuan + { + public int wage { get; set; } + public cleaner() { } + public cleaner(string name, string address, string birthday, int wage) + { + base.name = name; + base.address = address; + base.birthday = birthday; + this.wage = wage; + } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"总工资:{wage}"); + } + } +} +namespace 继承作业2._1_雇员系统_ +{ + internal class Program + { + static void Main(string[] args) + { + programmer p = new programmer("zy", "云南昭通", "2002年7月", 4000); + p.print(); + Console.WriteLine(" "); + mannger m = new mannger("lq", "广西南宁", "2004年8月", 3000); + m.print(); + Console.WriteLine(" "); + mishu mi = new mishu("lst", "广西南宁", "2003年9月", 3000); + mi.print(); + Console.WriteLine(" "); + cleaner q= new cleaner("ym", "福建泉州", "2004年8月", 1000); + q.print(); + Console.WriteLine(" "); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace 继承作业2._2_学生类_ +{ + // 二、 设计一个学生类Student, +//包括的属性有姓名name,年龄age,学位degree。 +//由学生类Student + +//每个类都有相关数据的输出方法。最后在一个测试类中对设计的类进行测试。 +//要求测试结果如下: +//姓名:王雷 年龄:17 学位:专科 专业:java +//姓名:刘文 年龄:22 学位:本科 研究方向:网络技术 + internal 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; + } + } + + 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}"; + } + } +} +using System.Text; + +namespace 继承作业2._2_学生类_ +{ + internal class Program + { + static void Main(string[] args) + { + Specialty s = new Specialty("王雷", 17, "专科", "java"); + Console.WriteLine(s); + Undergraduate u = new Undergraduate("刘文", 22, "本科", "网络技术"); + Console.WriteLine(u); + } + } +} + +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业2._3_图形类_ +{ + internal class zcmj + { + //三、图形类: + // 求周长,面积(三角形, 四边形, 圆形) + public double zc { get; set; } + public double mj { get; set; } + public void print() + { + Console.WriteLine($"面积:{mj}"); + Console.WriteLine($"周长:{zc}"); + } + } + internal class san : zcmj + { + public san() { } + public san(double b1, double b2, double b3) + { + this.b1 = b1; + this.b2 = b2; + } + + public double b1 { get; set; } + public double b2 { get; set; } + public double b3 { get; set; } + public void print() + { + base.print(); + } + } + internal class si : zcmj + { + public si(double c, double k) + { + this.c = c; + this.k = k; + } + + public double c { get; set; } + public double k { get; set; } + public void print() + { + base.print(); + } + } + internal class yuan : zcmj + { + public yuan(double r) + { + this.r = r; + } + + public double r { get; set; } + public void print() + { + base.print(); + } + } +} + + +namespace 继承作业2._3_图形类_ +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine(" 三角形面积,周长"); + san s1 = new san(3, 4, 5); + s1.mj = (3 + 4 + 5) / 2; + s1.zc = 3 + 4+ 5; + s1.print(); + Console.WriteLine(" "); + + Console.WriteLine("四边形面积,周长 "); + si bian = new si(5, 6); + bian.mj = bian.c * bian.k; + bian.zc = (bian.c + bian.k) * 2; + bian.print(); + Console.WriteLine(" "); + + Console.WriteLine("圆的面积,周长"); + yuan y = new yuan(5); + y.mj = y.r * y.r * 3.14; + y.zc = 2 * 3.14 * y.r; + y.print(); + Console.WriteLine(" "); + } + } +} +``` + +```c# +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业2._4_员工类employee_ +{ + internal class employee + { + + //四、员工类Employee + // 字段:姓名,工作年限,月薪、 + + //组长(GroupLeader): 月薪 + 1000 * 年限 + //经理(Manager) :月薪 + 1000 * 年限 * 基础分红;需要增加一个 字段:基础分红1000 + //客户经理(AccountManager):月薪 + 1000 * 年限 * 分红(基础分红 * 3) + + //求组长,经理的年薪。 + public string name { get; set; } + public int age { get; set; } + public int mwage { get; set; } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"年限:{age}"); + Console.WriteLine($"月薪:{mwage}"); + } + } + internal class groupleader : employee + { + public groupleader(string name, int age, int mwage) + { + this.name = name; + this.age = age; + this.mwage = mwage; + } + + public int wage { get; set; } + public void print() + { + base.print(); + } + } + internal class manager : employee + { + public manager(string name, int age, int mwage, int bpay) + { + this.name = name; + this.age = age; + this.mwage = mwage; + } + public int wage { get; set; } + public int bpay { get; set; } + public void print() + { + base.print(); + } + } + internal class AccountManager : employee + { + public AccountManager(string name, int age, int mwage, int bpay) + { + this.name = name; + this.age = age; + this.mwage = mwage; + this.bpay = bpay; + } + + public int bpay { get; set; } + public int wage { get; set; } + public void print() + { + base.print(); + } + } +} +using System.Diagnostics; + +namespace 继承作业2._4_员工类employee_ +{ + internal class Program + { + static void Main(string[] args) + { + groupleader g1 = new groupleader("zy", 3, 4000); + g1.wage = g1.mwage + 1000 * g1.age; + g1.print(); + Console.WriteLine(" "); + manager n1 = new manager("qq", 6, 5000, 2); + n1.wage = n1.mwage + 1000 * n1.age * n1.bpay; + n1.print(); + Console.WriteLine(" "); + AccountManager d1 = new AccountManager("ll", 7000, 6, 50); + d1.wage = d1.wage + 1000 * d1.age * d1.bpay; + d1.print(); + + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业2._5_汽车类Vehicle_ +{ + internal class Vehicle + { + //五、设计一个汽车类Vehicle,包含的属性有汽车品牌brand、车轮个数wheels和车重weight。 + //小车类Car是Vehicle的子类,其中包含的属性有载人数loader。 + //卡车类Truck是Car类的子类,其中包含的属性有载重量payload。 + //每个类都有构造方法和输出相关数据的方法。 + public string brand { get; set; } + public int wheels { get; set; } + public int weight { get; set; } + public void print() + { + Console.WriteLine($"品牌:{brand}"); + Console.WriteLine($"车轮数量:{wheels}"); + Console.WriteLine($"车重:{weight}"); + } + } + internal class car : Vehicle + { + public car(string brand, int wheels, int weight, int loader) + { + base.brand = brand; + base.wheels = wheels; + base.weight = weight; + this.loader = loader; + } + + public int loader { get; set; } + public void print() + { + base.print(); + Console.WriteLine($"载人数:{loader}"); + } + } + internal class Truck : Vehicle + { + public int payload { get; set; } + public Truck(string brand, int wheels, int weight, int payload) + { + base.brand = brand; + base.wheels = wheels; + base.weight = weight; + this.payload = payload; + } + public void print() + { + base.print(); + Console.WriteLine($"可载重量:{payload}"); + } + } +} +namespace 继承作业2._5_汽车类Vehicle_ +{ + 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); + } + } +} +``` + + + diff --git "a/22\346\236\227\347\247\200\346\270\205/\350\231\232\346\226\271\346\263\225/\350\231\232\346\226\271\346\263\225.md" "b/22\346\236\227\347\247\200\346\270\205/\350\231\232\346\226\271\346\263\225/\350\231\232\346\226\271\346\263\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..847f13e0bcc6ce3025cdb7a750bc22c1db8a2dd1 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\350\231\232\346\226\271\346\263\225/\350\231\232\346\226\271\346\263\225.md" @@ -0,0 +1,387 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_1_员工系统_ +{ + internal class Yuangong + { + //1.定义一个员工类,作为基类,包含姓名,性别,年龄等属性; + //包含一个方法代表工作的行为 + private string name; + private char sex; + private int age; + + public string Name { get; set; } + public char Sex { get ; set ; } + public int Age { get ; set; } + public Yuangong(string name, char sex, int age) + { + Name = name; + Sex = sex; + Age = age; + } + public Yuangong() { } + public virtual void Gz() + { + Console.WriteLine($"{Name}在工作"); + } + public virtual void Sj() + { + Console.WriteLine($"{Name}在睡觉"); + } + public virtual void Yd() + { + Console.WriteLine($"{Name}在运动"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_1_员工系统_ +{ + //2.定义一个医生类,继承员工类, + //重写工作的方法,描述医生的具体工作 + internal class Yisheng : Yuangong + { + public Yisheng(string name, char sex, int age): base(name, sex, age) + { + } + public void Jr() + { + Console.WriteLine($"{Name}在救人"); + } + public override void Gz() + { + base.Gz(); + Console.WriteLine($"{Name};在看教科书,看病人,在写报告"); + } + } + + +} +namespace 虚方法作业_1_员工系统_ +{ + //3.定义一个程序员类,继承员工类, + //重写工作方法,描述程序员具体工作 + internal class Cxy : Yuangong + { + public Cxy(string name, char sex, int age) : base(name, sex, age) + { + } + public void Qdm() + { + Console.WriteLine($"在敲代码"); + } + public override void Gz() + { + base.Gz(); + Console.WriteLine($"{Name}:爱喝咖啡"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_1_员工系统_ +{ + //4.定义一个清洁工类,继承员工类, + //重写工作方法,描述清洁工的具体工作 + + internal class Qjg:Yuangong + { + public Qjg(string name ,char sex,int age) :base(name,sex,age) + { + } + public void Ds() + { + Console.WriteLine("在打扫卫生"); + } + public override void Gz() + { + base.Gz(); + Console.WriteLine($"{Name}:在公园打扫卫生"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace 虚方法作业_1_员工系统_ +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine( "员工"); + Yuangong yuangong=new Yuangong("zy",'女',3); + yuangong.Gz(); + + Console.WriteLine( "医生"); + Yisheng yisheng = new Yisheng("wyj", '女', 22); + yisheng.Gz(); + + + Console.WriteLine( "程序员"); + Cxy cxy = new Cxy("ll",'女',19); + cxy.Gz(); + + + Console.WriteLine( "清洁工"); + Qjg qjg=new Qjg("l2",'女',48); + qjg.Gz(); + } + } +} +``` + +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_2_动物_ +{ + //1.动物类:具有动物的共同属性:腿,重量等; + //共同行为:吃,叫,睡 + internal class Dongwu + { + //动物的共同属性:腿,重量等; + public string Name { get; set; } + public int Leg { get; set; } + public double Zhongliang { get; set; } + // 共同行为:吃,叫,睡 + public virtual void Eat() + { + Console.WriteLine($"{Name}在吃东西"); + } + public void Cry() + { + Console.WriteLine($"{Name}在呼叫"); + } + public void Sleep() + { + Console.WriteLine($"{Name}在睡觉"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_2_动物_ +{ + //2.猫科类:具有猫科动物的共同属性:胡须等, + //共同能力:夜视能力 + internal class Maoke:Dongwu + { + //猫科动物的共同属性:胡须等, + public int Huxu { get; set; } + public Maoke(){ } + public Maoke(string name, int leg, double zhongliang, int huxu) { + Name = name; + Leg = leg; + Zhongliang= zhongliang; + Huxu = huxu; + } + //共同能力:夜视能力 + public void Yeshi() + { + Console.WriteLine($"具有夜视能力"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_2_动物_ +{ + // 3.鸟类:具有鸟类的共同行为:飞行 + internal class Niaolei:Dongwu + { + + public Niaolei() { } + public Niaolei(string name, int leg, double zhongliang) + { + Name= name; + Leg=leg; + Zhongliang=zhongliang; + + } + public void Feixing() + { + Console.WriteLine($"{Name}在天空飞"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_2_动物_ +{ + internal class Mao:Maoke + { + //猫 吃和叫的方法; + public Mao() { } + public Mao(string name, int leg, double zhongliang, int huxu) + { + Name= name; + Leg=leg; + Zhongliang= zhongliang; + Huxu= huxu; + + } + public void Eat() + { + Console.WriteLine($"{Name}津津有味的吃着小鱼干"); + } + public void Cry() + { + Console.WriteLine($"{Name}在喵"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_2_动物_ +{ + //老虎 吃和叫的方法; + internal class Laofu:Maoke + { + public Laofu() { } + public Laofu(string name, int leg, double zhongliang, int huxu) + { + Name= name; + Leg= leg; + Zhongliang = zhongliang; + Huxu = huxu; + } + public void Eat() + { + Console.WriteLine($"{Name}津津有味的吃着肉"); + } + public void Cry() + { + Console.WriteLine($"{Name} 在怒吼"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_2_动物_ +{ + //燕子 吃和叫的方法; + internal class Yanzi:Niaolei + { + public Yanzi() { } + public Yanzi(string name, int leg, double zhongliang) + { + Name = name; + Leg = leg; + Zhongliang = zhongliang; + } + public void Eat() + { + Console.WriteLine($"{Name}在吃虫子"); + } + public void Cry() + { + Console.WriteLine($"{Name} 在唱歌"); + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 虚方法作业_2_动物_ +{ + //老鹰 吃和叫的方法; + internal class Laoying:Niaolei + { + public Laoying() { } + public Laoying(string name, int leg, double zhongliang) + { + Name = name; + Leg = leg; + Zhongliang = zhongliang; + } + public void Eat() + { + Console.WriteLine($"{Name}在吃小鸡"); + } + public void Cry() + { + Console.WriteLine($"{Name} 在尖叫"); + } + } +} +namespace 虚方法作业_2_动物_ +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("老鹰"); + Laoying laoying = new Laoying("zz",2,36); + laoying.Eat(); + laoying.Cry(); + laoying.Sleep(); + + Console.WriteLine("燕子"); + Yanzi yanzi = new Yanzi("WW",2,5); + yanzi.Eat(); + yanzi.Cry(); + yanzi.Sleep(); + + Console.WriteLine("猫"); + Mao mao = new Mao("MM",4,14,8); + mao.Eat(); + mao.Cry(); + mao.Sleep(); + + Console.WriteLine("老虎"); + Laofu laofu = new Laofu("hh", 4, 80, 8); + laofu.Eat(); + laofu.Cry(); + laofu.Sleep(); + + } + } +} +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\351\241\271\347\233\256/\346\225\260\346\215\256\345\272\223.md" "b/22\346\236\227\347\247\200\346\270\205/\351\241\271\347\233\256/\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000000000000000000000000000000000000..b4be23efbea3ed3b4dd3749a0e2e6208b9c7f5b2 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\351\241\271\347\233\256/\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,21 @@ +```sql +create database TextDB +use TextDB +create table Class( +classid int primary key identity, +name nvarchar(50), +); +go +create table Student( +studentid int, +studentname nvarchar(50), +sex char(5), +age int, +classid int foreign key(classid) references Class(classid) +); +insert into Class(name)values('zy'),('lst'),('lqq'); +insert into Student values(1,'gym','女',18,1),(2,'lxy','女',18,2); +select * from Class; +select * from Student; +``` + diff --git "a/22\346\236\227\347\247\200\346\270\205/\351\241\271\347\233\256/\350\277\236\346\216\245\346\225\260\346\215\256\345\272\223\357\274\210\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\357\274\211.md" "b/22\346\236\227\347\247\200\346\270\205/\351\241\271\347\233\256/\350\277\236\346\216\245\346\225\260\346\215\256\345\272\223\357\274\210\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\357\274\211.md" new file mode 100644 index 0000000000000000000000000000000000000000..9b08c44907b7a2f43757350f965d16675999ac27 --- /dev/null +++ "b/22\346\236\227\347\247\200\346\270\205/\351\241\271\347\233\256/\350\277\236\346\216\245\346\225\260\346\215\256\345\272\223\357\274\210\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\357\274\211.md" @@ -0,0 +1,193 @@ +```c# +using System.Data.SqlClient; + +namespace 项目 +{ + internal class Program + { + public static SqlConnection con = new SqlConnection("server=.;database=TextDB;uid=sa;pwd=123456"); + static void Main(string[] args) + { + + try + { + con.Open(); + while (true) + { + Console.WriteLine("欢迎来到学生管理系统,请选择您所需要进行操作:\n"); + Console.WriteLine("1.班级操作"); + Console.WriteLine("2.学生操作"); + Console.WriteLine("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 { con.Close(); } + } + public static void Find1() + { + while (true) + { + Console.WriteLine("请选择您的操作:\n"); + Console.WriteLine("1.增加功能"); + Console.WriteLine("2.删除功能"); + Console.WriteLine("3.修改功能"); + Console.WriteLine("4.查询功能"); + Console.WriteLine("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() + { + + } + // 1.增加功能: + + static public void Add() + { + //​ 1) 要求接收用户输入班级名称+ + Console.WriteLine("请输入您要添加的班级名称:"); + string name = Console.ReadLine(); + int num = Check(name); + //​ 2)然后去查询数据库中的班级表是否存在该班级名称 + //存在该班级 + if (num > 0) + { + //​ 3)存在就提示“班级名称重复,添加班级信息失败” + Console.WriteLine("班级名称重复,添加班级信息失败"); + } + else + //​ 4)不存在,就将班级信息保存到数据库的班级信息表中; + { + string a = "insert into Class(cname)values('{0}')"; + a = string.Format(a, name); + SqlCommand add = new SqlCommand(a, con); + int result = add.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine("添加成功"); + } + } + } + public static int Check(string name) + { + string sql = "select*from Class where name='{0}'"; + sql = string.Format(sql, name); + SqlCommand com = new SqlCommand(sql, con); + SqlDataReader read = com.ExecuteReader(); + int num = 0; + while (read.Read()) + { + num = 1; + } + read.Close(); + return num; + } + public static int Check(int cid) + { + string sql = "select*from Class where id={0}"; + sql = string.Format(sql, cid); + SqlCommand com = new SqlCommand(sql, con); + SqlDataReader read = com.ExecuteReader(); + int num = 0; + while (read.Read()) + { + num = 1; + } + read.Close(); + return num; + } + // 2. 删除功能: + + public static void Delete() + { + //​ 1)要求用户输入要删除的班级编号; + Console.WriteLine("请输入您要删除的班级编号:"); + int id = Convert.ToInt32(Console.ReadLine()); + int num = Check(id); + //​ 2)根据班级编号删除数据库中的班级信息 + if (num > 0) + { + string a = "delete from Class where name={0}"; + a = string.Format(a, id); + SqlCommand add = new SqlCommand(a, con); + int result = add.ExecuteNonQuery(); + //​ 3)如果删除成功提示成功,如果没有要删除的班级编号数据提示删除失败 + if (result > 0) + { + Console.WriteLine("删除成功"); + } + } + else + { + Console.WriteLine("删除失败"); + } + } + // 3. 修改功能: + + public static void Updata() + { + //​ 1)要求用户输入修改信息,需要修改的班级编号,以及修改后的班级名称信息; + Console.WriteLine("请输入要修改的班级编号:"); + int id = Convert.ToInt32(Console.ReadLine()); + int num = Check(id); + //​ 2)根据用户输入的信息修改班级信息表的数据; + if (num > 0) + { + Console.WriteLine("修改后的班级名称:"); + string name = Console.ReadLine(); + string a = "update Class set name='{0}' where id={1};"; + a = string.Format(a, name, id); + SqlCommand add = new SqlCommand(a, con); + int result = add.ExecuteNonQuery(); + // 3)如果有对应的班级编号信息,提示修改成功,没有提示修改失败 + if (result > 0) + { + Console.WriteLine("修改成功"); + } + } + else + { + Console.WriteLine("修改失败"); + } + + } + public static void View() + { + string sql = "select*from Class"; + SqlCommand com = new SqlCommand(sql, con); + SqlDataReader read = com.ExecuteReader(); + int num = com.ExecuteNonQuery(); + read.Close(); + } + } +} +``` + diff --git "a/48 \346\235\216\345\240\224\344\271\211 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.png" "b/48 \346\235\216\345\240\224\344\271\211 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.png" deleted file mode 100644 index a1ca35ef025871b93711cdcd044b3a9f7d59ba6b..0000000000000000000000000000000000000000 Binary files "a/48 \346\235\216\345\240\224\344\271\211 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.png" and /dev/null differ diff --git "a/c#48\346\235\216\345\240\224\344\271\211.cs" "b/c#48\346\235\216\345\240\224\344\271\211.cs" deleted file mode 100644 index 48ace1fbc3af8287daf7649a9eac3e13974d7c8f..0000000000000000000000000000000000000000 --- "a/c#48\346\235\216\345\240\224\344\271\211.cs" +++ /dev/null @@ -1,112 +0,0 @@ -namespace lishenyi -{ - //internal class HomeWork1 - //{ - // static void Main(string[] args) - // { - // Console.WriteLine("善学如春起之苗"); - // Console.WriteLine("不见其增,日有所长"); - // Console.WriteLine("假学如磨刀之石"); - // Console.WriteLine("不见其损,年有所亏"); - // Console.WriteLine("加油吧!少年"); - // Console.WriteLine("J\nA\nV\nA\n!\n"); - // } - //} - //internal class HomeWork3 - // { - // static void Main(string[] args) - // { - // Console.WriteLine("true"); - // Console.WriteLine("false"); - // } - // } - - //internal class HomeWork4 - //{ - // static void Main(string[] args) - // { - // sbyte num1 = -128; - // byte num2 = 127; - // Console.WriteLine("num1"); - // Console.WriteLine("num2"); - // - // short num3 = -32768; - // ushort num4 = 32768; - // Console.WriteLine("num3"); - // Console.WriteLine("num4"); - // - // int num5 = -2147483648; - // uint num6 = 2147483648; - // Console.WriteLine("num5"); - // Console.WriteLine("num6"); - // - // long num7 = -2147463649; - // ulong unm8 = 2147483649; - // Console.WriteLine("num7"); - // Console.WriteLine("num8"); - // } - //} - //internal class Homework5 - // { - // static void Main(string[] ags) - // { - // float num9 = -3.14f; - // float num10 = 3.14f; - // Console.WriteLine("num9"); - // Console.WriteLine("num10"); - // - // double num11 = -3.4; - // double num12 = 3.4; - // Console.WriteLine("num11"); - // Console.WriteLine("num12"); - // - // } - // } - //internal class HomeWork6 - // { - // static void Main(string[] avgs) - // { - // int a = 10; - // int b = 20; - // int temp = a; - // a = b; - // b = temp; - // Console.WriteLine("a的值是"+a); - // Console.WriteLine("b的值是"+b); - // } - // - // } - //internal class HomeWork7 - // { - // static void Main(string[] args) - // { - // int x = 100; - // int y = 200; - // int add = x + y; - // int sub = x - y; - // int mul = x * y; - // int div = x / y; - // Console.WriteLine("x,y的和为:"+add); - // Console.WriteLine("x,y的差为:"+sub); - // Console.WriteLine("x,y的积为:"+mul); - // Console.WriteLine("x,y的商为:"+div); - // } - // } - //internal class HomeWork8 - // { - // static void Main(string[] args) - // { - // double x = 100.8; - // double y = 20.6; - // double add = x + y; - // double sub = x - y; - // double mul = x * y; - // double div = x / y; - // Console.WriteLine("x,y的和为:"+add); - // Console.WriteLine("x,y的差为:"+sub); - // Console.WriteLine("x,y的积为:"+mul); - // Console.WriteLine("x,y的商为:"+div); - // } - // } - -} \ No newline at end of file