diff --git "a/37\351\231\206\346\200\235\345\251\267/word\345\237\272\347\241\200\350\257\255\346\263\225\344\275\234\344\270\232.cs" "b/37\351\231\206\346\200\235\345\251\267/word\345\237\272\347\241\200\350\257\255\346\263\225\344\275\234\344\270\232.cs" new file mode 100644 index 0000000000000000000000000000000000000000..c01a7ec2c6a4eb6792965a602474c672f1c386f2 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/word\345\237\272\347\241\200\350\257\255\346\263\225\344\275\234\344\270\232.cs" @@ -0,0 +1,323 @@ +namespace 作业03 +{ + internal class word基础语法作业 + { + static void Main(string[] args) + { + //1.求圆的面积 + //要求用户输入半径的值,打印出以此值为半径的圆的面积 + #region + double r, s, l; + Console.Write("请输入半径值:"); + r = double.Parse(Console.ReadLine());//数据类型转换 + s = Math.PI * r * r; + l = 2 * r * Math.PI; + Console.WriteLine("圆的半径={0},面积={1},周长={2}",r,s,l); + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //2.编写一个程序,请用户输入一个四位整数 + // 将用户输入的四位数的千位、百位、十位和个位分别显示出来 + #region + Console.WriteLine("请输入一个四位整数:"); + string a = Console.ReadLine();//数据类型转换 + int number = int.Parse(a); + int a1 = number % 10;//获取个位数 + int a2 = (number % 100) / 10;//获取十位数 + int a3 = (number / 100) % 10;//获取百位数 + int a4 = (number / 1000);//获取千位数 + Console.WriteLine("个位:"+a1); + Console.WriteLine("十位:" + a2); + Console.WriteLine("百位:" + a3); + Console.WriteLine("千位:" + a4); + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //3.用户输入三个数,找出最大的数,打印输出 + #region + Console.WriteLine("请输入第一个数:"); + double c1 = double.Parse(Console.ReadLine()); + Console.WriteLine("请输入第二个数:"); + double c2 = double.Parse(Console.ReadLine()); + Console.WriteLine("请输入第三个数:"); + double c3 = double.Parse(Console.ReadLine()); + double max = c1 > c2 ? c1 : c2; + max = max > c3 ? max : c3; + Console.WriteLine($"输出这三个数中最大的数:{max}"); + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //4.接受用户输入一个数n,求这个数的阶乘;5! = 5*4*3*2*1; + #region + Console.WriteLine("请输入一个正整数"); + int num = int.Parse(Console.ReadLine()); + if (num <= 0) + { + Console.WriteLine("输入的整数不正确,请重新输入!"); + Console.ReadLine(); + return; + } + int sum = 1; + for (int i = 1; i <= num; i++) + { + sum = sum * i; + } + Console.WriteLine(num + "的阶乘是:" + sum.ToString()); + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //5.接受用户输入的一个数n,求n到1所有数的阶乘和;n!+(n-1!)+(n-2)!+……+1! + #region + Console.WriteLine("请输入一个正整数"); + int num = int.Parse(Console.ReadLine()); + if (num <= 0) + { + Console.WriteLine("请输入正确的整数"); + return; + } + int sum = 0; + int result = 1; + for (int i = 1; i <= num; i++) + { + result = result * i; + sum += result; + } + Console.WriteLine(num + "的阶乘之和为:" + sum.ToString()); + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //6.根据用户输入的菱形边长,打印菱形; + #region + Console.WriteLine("边长为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(); + } + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //7.用循环打印九九乘法表(用二维数组保存字符串后再打印) + #region + Console.WriteLine("九九乘法表:"); + for (int d = 1; d < 10; d++) + { + for (int e = 1; e <= d; e++) + { + Console.Write(d + "x" + e + "=" + d * e + "\t"); + } + Console.WriteLine(); + } + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //8.输入一行字符串,分别统计出其中英文字母、数字、空格的个数 + #region + 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 t in sr1) + { + if (t >= 'a' && t <= 'z' || t >= 'A' && t <= 'Z') + zm++; + else if (t >= '1' && t <= '9') + sz++; + else if (t == ' ') + kg++; + else + fh++; + } + Console.WriteLine($"字母{zm},数字{sz}空格{kg}符号{fh}"); + Console.WriteLine(""); + Console.WriteLine(""); + #endregion + + //9.在 Main 方法中创建一个 double 类型的数组 + // 并在该数组中存入 5 名学生的考试成绩,计算总成绩和平均成绩。 + // (要求使用foreach语句实现该功能) + double[] scores = { 60, 80, 60, 66, 70 }; + + double sum = 0; + double avg = 0; + foreach (double score in scores) + { + sum = sum + score; + } + avg = sum / 5; + Console.WriteLine("总成绩为:" + sum); + Console.WriteLine("平均成绩为:" + avg); + Console.WriteLine(""); + Console.WriteLine(""); + + //10.定义一个方法,实现一维数组的排序功能, + // 从大到小排序。(不要用Array类的方法) + int[] qq = { 50, 80, 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(); + Console.WriteLine(""); + Console.WriteLine(""); + + //11.实现查找数组元素索引的功能。定义一个数组,然后控制台输入要查找的元素, + // 返回输入值在数组中最后一次出现的位置。若是找不到,请打印找不到。 + // (不要用Array类的方法) + int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Console.WriteLine("数组元素有:"); + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + Console.WriteLine(" "); + Console.WriteLine("请输入要查找的元素"); + int find = int.Parse(Console.ReadLine()); + for (int i = 0; i < arr.Length; i++) + { + if (arr[i] == find) + { + Console.WriteLine("查找的元素的索引位置为:" + i); + } + else if (arr[i] != find) + { + Console.Write("找不到"); + } + } + Console.WriteLine(""); + Console.WriteLine(""); + + + //12.在 Main 方法中创建一个字符串类型的数组,并存入 5 个值, + // 然后将数组中下标是偶数的元素输出。 + string[] input = { "z", "h", "o", "u", "e" }; + Console.WriteLine("数组中下标是偶数的元素有:"); + for (int i = 0; i < input.Length; i = i + 2) + { + Console.Write(input[i] + " "); + } + Console.WriteLine(""); + Console.WriteLine(""); + + + //13.用户输入正方形边长,用*打印出空心正方形 + Console.WriteLine("请输入边长"); + int h = Convert.ToInt32(Console.ReadLine()); + for (int i = 0; i < h; i++)//行数 + { + for (int j = 0; j < h; j++)//列数 + {//满足条件输出 * ,即在边界上就是 * + if (i == 0 || j == 0 || i == h - 1 || j == h - 1) + { + Console.Write("*"); + } + else + Console.Write(" "); + } + Console.Write("\n"); + } + Console.WriteLine(""); + Console.WriteLine(""); + + //14.用户输入正方形边长,用*打印出实心正方形 + Console.WriteLine("请输入边长"); + int h1 = Convert.ToInt32(Console.ReadLine()); + for (int i = 0; i < h1; i++)//行数 + { + for (int j = 0; j < h1; j++)//列数 + {//满足条件输出 * ,即在边界上就是 * + Console.Write("*"); + } + Console.Write("\n"); + } + Console.WriteLine(""); + Console.WriteLine(""); + + //15.用二维数组存放数据,实现杨辉三角形的打印 + #region 杨辉三角 + double[][] scores2 = new double[10][]; + for (int j = 0; j < scores2.GetLength(0); j++) + { + scores2[j] = new double[j + 1]; + for (int i = 0; i < scores2[j].Length; i++) + { + if (i == 0 || i == j) + { + scores2[j][i] = 1; + } + else + { + scores2[j][i] = scores2[j - 1][i - 1] + scores2[j - 1][i]; + } + } + } + //外层循环控制变量j,代表行号0-二维数组第一维长度-1 + for (int j = 0; j < scores2.Length; j++) + { + //内层循环控制变量i,代表列号0~每一行数组长度-1 + for (int i = 0; i < scores2[j].Length; i++) + { + Console.Write(scores2[j][i] + "\t"); + } + } + #endregion + } + public static int fun(int n)//第四题的阶乘 + { + if (n < 1) + return 0; + if (n == 1) + return 1; + return n * fun(n - 1); + } + public static int jiecheng(int n)//第五题的阶乘和 + { + if (n == 1) + return 1; + else + return n * jiecheng(n - 1); + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\344\275\234\344\270\23201/\344\275\234\344\270\23201.cs" "b/37\351\231\206\346\200\235\345\251\267/\344\275\234\344\270\23201/\344\275\234\344\270\23201.cs" new file mode 100644 index 0000000000000000000000000000000000000000..896b241504c7b759c9d2d7a4a6bc5c83fc98e436 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\344\275\234\344\270\23201/\344\275\234\344\270\23201.cs" @@ -0,0 +1,11 @@ +namespace 作业01 +{ + internal class 作业01 + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + Console.ReadKey(); + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\344\275\234\344\270\23201/\344\275\234\344\270\23201.png" "b/37\351\231\206\346\200\235\345\251\267/\344\275\234\344\270\23201/\344\275\234\344\270\23201.png" new file mode 100644 index 0000000000000000000000000000000000000000..fc55e3b88c4315a27e196e962950291442169556 Binary files /dev/null and "b/37\351\231\206\346\200\235\345\251\267/\344\275\234\344\270\23201/\344\275\234\344\270\23201.png" differ diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\237\272\347\241\200\350\257\255\346\263\225\345\267\251\345\233\2721.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\237\272\347\241\200\350\257\255\346\263\225\345\267\251\345\233\2721.cs" new file mode 100644 index 0000000000000000000000000000000000000000..1c3ac98955ae5e9e5d29d936f8985593db784f15 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\237\272\347\241\200\350\257\255\346\263\225\345\267\251\345\233\2721.cs" @@ -0,0 +1,135 @@ +namespace 作业02 +{ + internal class 作业二 + { + static void Main(string[] args) + { + Console.WriteLine("第一题"); + //控制台输出5行字符串类型常量值 + Console.WriteLine("Hello, World!"); + Console.WriteLine("Hello, World!"); + Console.WriteLine("Hello, World!"); + Console.WriteLine("Hello, World!"); + Console.WriteLine("Hello, World!"); + Console.WriteLine("********************"); + + Console.WriteLine("第二题");//布尔型 + //控制台输出所有布尔类型常量值 + bool a = true; + Console.WriteLine(a); + bool b = false; + Console.WriteLine(b); + Console.WriteLine("********************"); + + Console.WriteLine("第三题");//整型 + //byte类型(不能存放负数) + //定义2个 byte类型变量,分别赋byte类型范围内最大值和最小值,并输出在控制台 + byte c = 255; + Console.WriteLine(c); + byte d = 0; + Console.WriteLine(d); + + //short类型 + //定义2个 short类型变量,分别赋short类型范围内的值,并输出在控制台 + short e = -100; + short f = 100; + Console.WriteLine(e); + Console.WriteLine(f); + + //int类型 + //定义2个 int类型变量,分别赋int类型范围内的值,并输出在控制台 + int g = -200; + int h = 200; + Console.WriteLine(g); + Console.WriteLine(h); + + //long类型 + //定义2个 long类型变量,分别赋超过int类型范围的值,并输出在控制台 + long i = -10; + long j = 10; + Console.WriteLine(i); + Console.WriteLine(j); + Console.WriteLine("********************"); + + Console.WriteLine("第四题"); + //单精度(值必须加f作为后缀) + //定义2个 float类型变量,分别赋值,并输出在控制台 + float k = -6.18f; + float l = 6.18f; + Console.WriteLine(k); + Console.WriteLine(l); + //双精度 + //定义2个 double类型变量,分别赋值,并输出在控制台 + double m = -5.5; + double n = 5.5; + Console.WriteLine(m); + Console.WriteLine(n); + Console.WriteLine("********************"); + + Console.WriteLine("第五题"); + //定义两个整数变量a,b并赋值 + int a1 = 10; + int b1 = 20; + + //控制台输出变量a,b互换前的值 + Console.WriteLine(a1); + Console.WriteLine(b1); + + //定义一个第三方变量temp + int temp = a1; + + //利用第三方变量temp使a,b的值互换 + a1 = b1; + b1 = temp; + + //控制台输出变量a,b互换后的值 + Console.WriteLine("交换后的值为:" + a1); + Console.WriteLine("交换后的值为:" + b1); + Console.WriteLine("********************"); + + + Console.WriteLine("第六题"); + //定义2个int类型变量x、y,x赋值为100,y赋值为200 + int x = 100, y = 200; + + //定义新变量add,保存变量x,y的和并打印到控制台 + int add = x + y; + Console.WriteLine("x,y的和为" + add); + + //定义新变量sub,保存变量x,y的差并打印到控制台 + int sub = x - y; + Console.WriteLine("x,y的差为" + sub); + + //定义新变量mul,保存变量x,y的积并打印到控制台 + int mul = x * y; + Console.WriteLine("x,y的积为" + mul); + + //定义新变量div,保存变量x,y的商并打印到控制台 + int div = x / y; + Console.WriteLine("x,y的商为" + div); + Console.WriteLine("********************"); + + + Console.WriteLine("第七题"); + //定义2个double类型变量x、y,x赋值为100.8,y赋值为20.6 + double x1 = 100.8, y1 = 20.6; + + //定义新变量add,保存变量x,y的和并打印到控制台 + double add1 = x1 + y1; + Console.WriteLine("x,y的和为" + add1); + + //定义新变量sub,保存变量x,y的差并打印到控制台 + double sub1 = x1 - y1; + Console.WriteLine("x,y的差为" + sub1); + + //定义新变量mul,保存变量x,y的积并打印到控制台 + double mul1 = x1 * y1; + Console.WriteLine("x,y的积为" + mul1); + + + //定义新变量div,保存变量x,y的商并打印到控制台 + double div1 = x1 / y1; + Console.WriteLine("x,y的商为" + div1); + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Add.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Add.cs" new file mode 100644 index 0000000000000000000000000000000000000000..4f82242d1ce7cfe7a96bdf259f005f9cbe3d2c9b --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Add.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal class Add:Calculate + { + //加法 + public Add(int integer1, int integer2) + : base(integer1, integer2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{integer1}+{integer2}={integer1 + integer2}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Calculate.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Calculate.cs" new file mode 100644 index 0000000000000000000000000000000000000000..61633bd973f2fba333b22367a55129170a1f7483 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Calculate.cs" @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal abstract class Calculate + { + //创建Calculate基类,其中包含两个整型的protected成员, + // 用以接收用户输入的两个整数。定义一个DisplayResult()虚方法,计算并输出结果。 + + //字段 + protected int integer1; + protected int integer2; + + //构造方法 + //有参 + public Calculate(int integer1, int integer2) + { + this.integer1 = integer1; + this.integer2 = integer2; + } + //无参 + public Calculate() { } + + //属性 + protected int Integer1 { get => integer1; set => integer1 = value; } + protected int Integer2 { get => integer2; set => integer2 = value; } + + //定义虚方法 + public abstract void DisplayResult(); + + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Circle.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Circle.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ccdd8af91d41f9f7955a083b1c2fe1c8535d1b9b --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Circle.cs" @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal class Circle:Shape + { + //Circle类中包含radius(半径)的数据成员, + double radius; + //属性封装半径,要求半径大于等于0 + public double Radius + { + get => radius; + set + { + if (value >= 0) + { + radius = value; + } + + } + } + //重写父类的GetArea()方法,各自去实现计算自己的面积 + public Circle() + { + + } + public override double GetArea() + { + return 3.14 * radius * radius; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Divide.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Divide.cs" new file mode 100644 index 0000000000000000000000000000000000000000..f54748858a6e7a3e2ca3055f8b917d515b57e060 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Divide.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal class Divide : Calculate + { + //除法 + public Divide(int integer1, int integer2) + : base(integer1, integer2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{integer1}/{integer2}={integer1 / (double)integer2}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Minus.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Minus.cs" new file mode 100644 index 0000000000000000000000000000000000000000..a1eb3c52ce3bb278d05f493f19aee90ffc5bff72 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Minus.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal class Minus:Calculate + { + //减法 + public Minus(int integer1, int integer2) + : base(integer1,integer2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{integer1}-{integer2}={integer1 - integer2}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Multiply.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Multiply.cs" new file mode 100644 index 0000000000000000000000000000000000000000..dee0c244f1c1fc1790c5dc14b4b18535a0c5d4bc --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Multiply.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal class Multiply : Calculate + { + //乘法 + public Multiply(int integer1, int integer2) + : base(integer1, integer2) + { + } + public override void DisplayResult() + { + Console.WriteLine($"{integer1}*{integer2}={integer1 * integer2}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Program.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..4f2e7074e04409a6d5a7012eb0ea664fbefb5752 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Program.cs" @@ -0,0 +1,85 @@ +namespace 多态作业 +{ + internal class Program + { + //一、编写一个控制台应用程序,接受用户输入的两个整数和一个操作符, + // 以实现对两个整数的加、减、乘、除运算,并显示出计算结果。 + //1、创建Calculate基类,其中包含两个整型的protected成员, + // 用以接收用户输入的两个整数。定义一个DisplayResult()虚方法,计算并输出结果。 + //2、定义四个类继承自Calculate类,分别重写DisplayResult()方法, + // 实现两个整数的加、减、乘、除运算,并输出结果。 + //3、根据用户输入的操作符,实例化相应的类,完成运算并输出结果。 + //4、在主类中添加一个方法,形参为父类对象, + // 根据传递实参的类型,调用方法,实现计算和显示结果。 + + + //二、创建一个Shape(形状)类,此类包含一个名为color的数据成员, + // 用于存储颜色,这个类还包含一个名为GetArea()的虚方法(这个方法是用来获取形状面积的)。 + //基于这个Shape,创建两个子类:Circle(圆形类)和Square(正方形类), + //Circle类中包含radius(半径)的数据成员,Square类中包含sideLen(边长)的数据成员, + //这两个子类都去重写父类的GetArea()方法,各自去实现计算自己的面积。 + //在主类中添加一个方法,参数类型就是Shape,方法体中,用形参去调用GetArea()方法。 + //main方法中去测试这个方法。 + + static void Main(string[] args) + { + //接受用户输入的两个整数和一个操作符 + Console.WriteLine("请输入参与运算的第一个整数"); + int a = Convert.ToInt32(Console.ReadLine()); + + Console.WriteLine("请输入参与运算的第二个整数"); + int b = Convert.ToInt32(Console.ReadLine()); + + Console.WriteLine("请输入操作符:"); + string op = Console.ReadLine(); + Calculate calculate = null; + //判断op的值,实例化出相应的对象 + if (op == "+") + { + calculate = new Add(a, b); + } + else if (op == "-") + { + calculate = new Minus(a, b); + } + else if (op == "*") + { + calculate = new Multiply(a, b); + } + else if (op == "/") + { + calculate = new Divide(a, b); + } + Calculate(calculate); + + + Console.WriteLine(""); + Console.WriteLine(""); + + + Shape shape = new Circle(); + //圆形类的面积 + Circle circle = new Circle(); + circle.Radius = 10; + circle.Color = "red"; + TestShape(circle); + //正方形类的面积 + Square square = new Square(); + square.SideLen = 2; + square.Color = "blue"; + TestShape(square); + } + //第一问 + public static void Calculate(Calculate calculate) + { + calculate.DisplayResult(); + } + //第二问 + public static void TestShape(Shape shape) + { + double area = shape.GetArea(); + Console.WriteLine("图形面积为:" + area); + } + + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Shape.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Shape.cs" new file mode 100644 index 0000000000000000000000000000000000000000..687711230b6f600d12270610c80fb5f792c2ae40 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Shape.cs" @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal abstract class Shape + { + //创建一个Shape(形状)类,此类包含一个名为color的数据成员, + // 用于存储颜色,这个类还包含一个名为GetArea()的虚方法(这个方法是用来获取形状面积的)。 + + string color; + + public string Color { get => color; set => color = value; } + //无参的构造方法 + public Shape() { } + //有参的构造方法 + public Shape(string color) + { + this.color = color; + } + public abstract double GetArea(); + + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Square.cs" "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Square.cs" new file mode 100644 index 0000000000000000000000000000000000000000..2dcaf7f673085de073f0b5c761ad77c670a5dfea --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\345\244\232\346\200\201\344\275\234\344\270\232/Square.cs" @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 多态作业 +{ + internal class Square:Shape + { + //Square类中包含sideLen(边长)的数据成员 + double sideLen; + + public double SideLen + { + get => sideLen; + set + { + if (value >= 0) + { + sideLen = value; + } + } + } + public override double GetArea() + { + return sideLen * sideLen; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\346\236\204\351\200\240\346\226\271\346\263\225/staff.cs" "b/37\351\231\206\346\200\235\345\251\267/\346\236\204\351\200\240\346\226\271\346\263\225/staff.cs" new file mode 100644 index 0000000000000000000000000000000000000000..08cf33ca037bef48ff1e3ba515b3908292fa7822 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\346\236\204\351\200\240\346\226\271\346\263\225/staff.cs" @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 作业06 +{ + internal class staff + { + //工号 + private int wkno; + //姓名 + private string name; + //性别 + private char sex; + //学历 + private string education; + //部门信息 + private string departments; + + public int Wkno { get => wkno; set => wkno = value; } + public string Name { get => name; set => name = value; } + public char Sex { get => sex; set => sex = value; } + public string Education { get => education; set => education = value; } + public string Departments { get => departments; set => departments = value; } + + //定义2个构造函数 + ///一个是无参构造函数,学历默认为专科 + public staff() + { + education = "专科"; + } + ///一个有参构造函数,根据参数对类的属性进行初始化 + + public staff(int wkno,string name,char sex,string education,string departments) + { + this.wkno = wkno; + this.name = name; + this.sex = sex; + this.education = education; + this.departments = departments; + } + + public void PrintInfo() + { + Console.WriteLine($"工号:{this.wkno}"); + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"性别: {sex}"); + Console.WriteLine($"学历:{education}"); + Console.WriteLine($"部门信息: {departments}"); + } + + + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\346\236\204\351\200\240\346\226\271\346\263\225/\344\270\273\346\226\271\346\263\225.cs" "b/37\351\231\206\346\200\235\345\251\267/\346\236\204\351\200\240\346\226\271\346\263\225/\344\270\273\346\226\271\346\263\225.cs" new file mode 100644 index 0000000000000000000000000000000000000000..0c3b70ae1f5a2422e2cbfe662ec06a3d0c3a1b0c --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\346\236\204\351\200\240\346\226\271\346\263\225/\344\270\273\346\226\271\346\263\225.cs" @@ -0,0 +1,80 @@ +namespace 作业06 +{ + internal class 主方法 + { + static void Main(string[] args) + { + /*一、定义一个员工类 + 1.定义字段,存放用户的工号、姓名、性别、学历和部门信息; + 2.定义属性封装字段 + 3.定义2个构造函数: + 一个是无参构造函数,学历默认为专科; + 一个有参构造函数,根据参数对类的属性进行初始化。*/ + + staff staff01 = new staff(); + staff01.Wkno = 001; + staff01.Name = "清清"; + staff01.Education = "初中" + ; + staff01.Departments = "大哥"; + + staff staff02 = new staff(); + staff02.Wkno = 001; + staff02.Name = "倩倩"; + staff02.Education = "高中"; + staff02.Departments = "大哥"; + + Console.WriteLine("员工信息:"); + Console.WriteLine(""); + staff01.PrintInfo(); + Console.WriteLine("*****************"); + staff02.PrintInfo(); + + + /*二、为之前作业中的学生类、用户类和图书类添加2个构造方法 + 1.一个无参的构造方法 + 2.一个有参的构造方法,根据参数对类的属性进行初始化*/ + + ////一个无参的构造方法 + //public 用户() + //{ + + //} + ////一个有参的构造方法,根据参数对类的属性进行初始化 + //public 用户(int zh, string yhm, string mm) + //{ + // this.zh = zh; + // this.yhm = yhm; + // this.mm = mm; + //} + ////一个无参的构造方法 + //public 学生() + //{ + + //} + ////一个有参的构造方法,根据参数对类的属性进行初始化 + //public 学生(int id, string name, char sex, int age, string zy) + //{ + // this.id = id; + // this.name = name; + // this.sex = sex; + // this.age = age; + // this.zy = zy; + //} + ////一个无参的构造方法 + //public 图书() + //{ + + //} + ////一个有参的构造方法,根据参数对类的属性进行初始化 + //public 图书(int number, string title, double price, string press, string information) + //{ + // this.number = number; + // this.title = title; + // this.price = price; + // this.press = press; + // this.information = information; + //} + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\344\270\273\346\226\271\346\263\225.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\344\270\273\346\226\271\346\263\225.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3189cd73288c41aee6ccdcb1436c9631d284d3e2 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\344\270\273\346\226\271\346\263\225.cs" @@ -0,0 +1,115 @@ +namespace 作业04 +{ + internal class 主方法 + { + static void Main(string[] args) + { + + //1.定义一个用户类,存放用户的账号、用户名和密码属性; + // 在用户类中定义一个方法输出当前用户对象的账号、用户名和密码 的信息; + // 然后在主方法调用输出; + 用户 用户01 = new 用户(); + 用户01.Zh = 01; + 用户01.Yhm = "昔归"; + 用户01.Mm = "l01"; + + 用户 用户02 = new 用户(); + 用户02.Zh = 02; + 用户02.Yhm = "春酲"; + 用户02.Mm = "c02"; + + Console.WriteLine("用户01的信息"); + 用户01.PrintInfo(); + Console.WriteLine("**************************"); + Console.WriteLine("用户02的信息"); + 用户02.PrintInfo(); + Console.WriteLine(""); + Console.WriteLine(""); + + + //2.定义一个学生类,存放学生的学号、姓名、性别、年龄、专业信息; + // 对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + // 在学生类中定义一个方法输出学生信息。 + // 在主方法实例化对象,赋值并输出 + 学生 学生01 = new 学生(); + 学生01.Id = 01; + 学生01.Name = "春"; + 学生01.Sex = '男'; + 学生01.Age = 17; + 学生01.Zy = "web前端开发"; + + 学生 学生02 = new 学生(); + 学生02.Id = 02; + 学生02.Name = "夏"; + 学生02.Sex = '女'; + 学生02.Age = 16; + 学生02.Zy = "运维工程师"; + + 学生 学生03 = new 学生(); + 学生03.Id = 03; + 学生03.Name = "秋"; + 学生03.Sex = '女'; + 学生03.Age = 18; + 学生03.Zy = "实施工程师"; + + 学生 学生04 = new 学生(); + 学生04.Id = 04; + 学生04.Name = "冬"; + 学生04.Sex = '男'; + 学生04.Age = 19; + 学生04.Zy = "开发工程师"; + + Console.WriteLine("01号同学的信息"); + 学生01.PrintInfo(); + Console.WriteLine("**************************"); + Console.WriteLine("02号同学的信息"); + 学生02.PrintInfo(); + Console.WriteLine("**************************"); + Console.WriteLine("03号同学的信息"); + 学生03.PrintInfo(); + Console.WriteLine("**************************"); + Console.WriteLine("04号同学的信息"); + 学生04.PrintInfo(); + Console.WriteLine(""); + Console.WriteLine(""); + + + //3.定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + // 对价格进行赋值限制,小于0价格,赋值为0 + // 在图书类中定义一个方法输出图书信息; + // 在主方法实例化对象,赋值并输出 + 图书 图书a = new 图书(); + 图书a.Number = 3020; + 图书a.Title = "《与往事说再见》(《滕州二中新校》)"; + 图书a.Price = "22元"; + 图书a.Press = "上海社会科学院出版社"; + 图书a.Information = "菲利普·贝松"; + + 图书 图书b = new 图书(); + 图书b.Number = 6603; + 图书b.Title = "《一路两个人》"; + 图书b.Price = "16元"; + 图书b.Press = "人民文学出版社"; + 图书b.Information = "(美)盖尔·考德威尔"; + + 图书 图书c = new 图书(); + 图书c.Number = 6811; + 图书c.Title = "《我只想和你说说话》"; + 图书c.Price = "32.80元"; + 图书c.Press = " 中国华侨出版社"; + 图书c.Information = "张超"; + + Console.WriteLine("第一本图书信息"); + 图书a.PrintInfo(); + Console.WriteLine("********************************************"); + Console.WriteLine("第二本图书信息"); + 图书b.PrintInfo(); + Console.WriteLine("********************************************"); + Console.WriteLine("第三本图书信息"); + 图书c.PrintInfo(); + Console.WriteLine(""); + Console.WriteLine(""); + } + + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\345\233\276\344\271\246.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\345\233\276\344\271\246.cs" new file mode 100644 index 0000000000000000000000000000000000000000..edd6fbc0901752343752a041bcbea89f4787dd09 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\345\233\276\344\271\246.cs" @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 作业04 +{ + internal class 图书 + { + //3.定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + // 对价格进行赋值限制,小于0价格,赋值为0 + // 在图书类中定义一个方法输出图书信息; + // 在主方法实例化对象,赋值并输出 + + //编号 + private int number; + //书名 + private string title; + //价格 + private string price; + //出版社 + private string press; + //作者信息 + private string information; + + public int Number + { + get { return number; } + set { number = value; } + } + public string Title + { + get { return title; } + set { title = value; } + } + public string Price + { + get { return price; } + set { price = value; } + } + public string Press + { + get { return press; } + set { press = value;} + } + public string Information + { + get { return information; } + set { information = value;} + } + + public void PrintInfo() + { + Console.WriteLine($"编号:{this.Number}"); + Console.WriteLine($"书名:{title}"); + Console.WriteLine($"价格:{price}"); + Console.WriteLine($"出版社:{press}"); + Console.WriteLine($"作者信息:{information}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\345\255\246\347\224\237.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\345\255\246\347\224\237.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9e1ef1127ed99c3f5564113e5f044f1e2e99c065 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\345\255\246\347\224\237.cs" @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 作业04 +{ + public class 学生 + { + //2.定义一个学生类,存放学生的学号、姓名、性别、年龄、专业信息; + // 对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + // 在学生类中定义一个方法输出学生信息。 + // 在主方法实例化对象,赋值并输出 + + //学号 + private int id; + //姓名 + private string name; + //性别 + private char sex; + //年龄 + private int age; + //专业信息 + private string zy; + + 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 Age + { + get + { + return age-10; + } + //对年龄字段进行赋值的安全性设置 + //如果是非法值(小于0或者大于128岁),该年龄值为0; + set + { + if (value < 0 || value > 128) + { + age = 0; + } + else + { + age = value; + } + } + } + public string Zy + { + get { return zy; } + set { zy = value;} + } + public void PrintInfo() + { + Console.WriteLine($"学号:{this.id}"); + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"性别:{sex}"); + Console.WriteLine($"年龄:{age}"); + Console.WriteLine($"专业信息:{zy}"); + } + } + +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\347\224\250\346\210\267.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\347\224\250\346\210\267.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b8980fff38e221c333ba2ac6c7f5d62e3209a2a9 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\261\273\345\222\214\345\261\236\346\200\247\344\275\234\344\270\232/\347\224\250\346\210\267.cs" @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace 作业04 +{ + internal class 用户 + { + //1.定义一个用户类,存放用户的账号、用户名和密码属性; + // 在用户类中定义一个方法输出当前用户对象的账号、用户名和密码 的信息; + // 然后在主方法调用输出; + + //账号 + private int zh; + //用户名 + private string yhm; + //密码 + private string mm; + + public int Zh + { + get { return zh; } + set { zh = value; } + } + public string Yhm + { + get { return yhm; } + set { yhm = value; } + } + public string Mm + { + get { return mm; } + set { mm = value; } + } + + public void PrintInfo() + { + Console.WriteLine($"帐户:{this.zh}"); + Console.WriteLine($"用户名:{yhm}"); + Console.WriteLine($"密码: {mm}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\344\270\273\346\226\271\346\263\225.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\344\270\273\346\226\271\346\263\225.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b0b4c14bd6656350cb0dcf24b272b620865c5473 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\344\270\273\346\226\271\346\263\225.cs" @@ -0,0 +1,42 @@ +namespace 继承作业01 +{ + internal class 主方法 + { + static void Main(string[] args) + { + //假设要完成一个学校的校园管理信息系统, + //在员工管理系统中有不同的人员信息,包括学生信息、教师信息等 + + 学生 s1 = new 学生("春酲", 1, "女", "1234567", "1654645", "软件技术", "大一"); + Console.WriteLine(s1); + + Console.WriteLine(""); + + 老师 t1 = new 老师("栖迟", 1, "女", "9876543", "1597646", "专业课老师", "10001"); + Console.WriteLine(t1); + Console.WriteLine(""); + + //使用类来描述游戏中的角色。 + //在很多RPG游戏中,第一次打开游戏,都会先让你创建自己的“英雄”,或者自己要扮演的角色。 + //这些英雄或者角色都是我们游戏中的“对象”,所以在开发的时候,我们需要针对每个角色都要写相应的类来描述。 + + 英雄 alk = new 英雄("埃落克", "埃洛克是一名来自末日边境的勇士。他是圣约英雄中名副其实的拳术好手。他用毁灭性的符文魔法和无情的拳术攻击消灭敌人。","春",2000,1200,600); + Console.WriteLine(""); + 英雄 tl = new 英雄("泰拉", "泰拉是为复仇而来的勇者。她挥舞法杖将愤怒转化为强大的元素魔法和攻击力因此战无不胜。","夏",3000,1800,1300); + Console.WriteLine(""); + 英雄 lks = new 英雄("卢卡斯", "卢卡斯是一名彬彬有礼的剑客,能控制源质能量。他一手持剑战斗,另一手辅助攻击。","秋",2600,1600,800); + Console.WriteLine(""); + 英雄 lf = new 英雄("洛菲", "洛菲是一名攻击迅猛且擅长传送魔法的时空旅行者,喜欢利用她的幻象伙伴迷惑、吸引并摧毁敌人。","冬",2800,800,1800); + Console.WriteLine(""); + 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; + } + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\344\277\241\346\201\257.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\344\277\241\346\201\257.cs" new file mode 100644 index 0000000000000000000000000000000000000000..a8af6e7de7cd443597cf9a510c6d7f79904f71c3 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\344\277\241\346\201\257.cs" @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业01 +{ + internal class 信息 + { + 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 信息(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 信息() { } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\345\255\246\347\224\237.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\345\255\246\347\224\237.cs" new file mode 100644 index 0000000000000000000000000000000000000000..5c5ff4e32a0bd3fb2c5f0825610a877556d0a2c1 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\345\255\246\347\224\237.cs" @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace 继承作业01 +{ + internal class 学生:信息 + { + //学生的字段:编号(Id)、姓名(Name)、性别(Sex)、 + // 身份证号(Cardid)、联系方式(Tel)、专业(Major)、年级(Grade) + public string Major { get; set; } + public string Grade { get; set; } + public 学生(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} "; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\200\201\345\270\210.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\200\201\345\270\210.cs" new file mode 100644 index 0000000000000000000000000000000000000000..6a60cfa7910f2eab5509c9d67d1ae254934db439 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\200\201\345\270\210.cs" @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace 继承作业01 +{ + internal class 老师:信息 + { + //教师的字段:编号(Id)、姓名(Name),性别 (Sex)、 + // 身份证号(Cardid)、联系方式(Tel)、职称(Title)、工资号(Wageno) + public string Title { get; set; } + public string Wageno { get; set; } + public 老师(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}"; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\213\261\351\233\204.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\213\261\351\233\204.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ff59fc3f7e7efefb8a4ccc00d4221208090f0116 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\213\261\351\233\204.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业01 +{ + internal class 英雄: 角色信息 + { + public 英雄(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($"请选择您要使用的英雄"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\247\222\350\211\262\344\277\241\346\201\257.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\247\222\350\211\262\344\277\241\346\201\257.cs" new file mode 100644 index 0000000000000000000000000000000000000000..1e4415ca8588213ea95968173678fccc89604adb --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27701/\350\247\222\350\211\262\344\277\241\346\201\257.cs" @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业01 +{ + internal class 角色信息 + { + //字段:角色名字,角色介绍,角色昵称,攻击力,防御力,速度 + //方法:每个角色都有三个不同的攻击技能 + 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 角色信息(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 角色信息() { } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\211\350\247\222\345\275\242.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\211\350\247\222\345\275\242.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b9d6f931ebe259942db414419ef429616fe8a92e --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\211\350\247\222\345\275\242.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 三角形:图形 + { + private double a, b, c; + + public 三角形(double a, double b, double c) + { + this.a = a; + this.b = b; + this.c = c; + } + + public override double GetArea() + { + double p = (a + b + c) / 2;//a,b,c 是三角形的三条边长,p是半周长,即(a+b+c)/2,海伦公式 + return Math.Sqrt(p * (p - a) * (p - b) * (p - c));//用于计算平方根 + } + + public override double GetPerimeter() + { + return a + b + c; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\223\347\247\221\347\224\237.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\223\347\247\221\347\224\237.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7d5696e67065991b3e0fe150d4eb2bd844c62e40 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\223\347\247\221\347\224\237.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 专科生:学生 + { + public string spec { get; set; } + + public 专科生() { } + + public 专科生(string name, int age, string degree, string spec) : base(name, age, degree) + { + this.spec = spec; + } + + public void Print() + { + base.Print(); + Console.WriteLine("专业:" + spec); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\273\346\226\271\346\263\225.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\273\346\226\271\346\263\225.cs" new file mode 100644 index 0000000000000000000000000000000000000000..8b4cb75885cc85e64e126025fdd3557ee8bad793 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\344\270\273\346\226\271\346\263\225.cs" @@ -0,0 +1,104 @@ +using System.Diagnostics; +using System.Drawing; +using static System.Net.Mime.MediaTypeNames; + +namespace 继承作业02 +{ + internal class 主方法 + { + static void Main(string[] args) + { + //一、雇员系统,定义雇员基类,共同的属性,姓名、地址和出生日期(可有可无), + // 子类:程序员,秘书,高层管理,清洁工,他们有不同的工资算法, + // 其中高级主管和程序员采用底薪加提成的方式, + // 高级主管和程序员的底薪分别是5000元和2000元, + // 秘书和清洁工采用工资的方式,工资分别是3000和1000, + 程序员 p1 = new 程序员("春酲", "福建漳州", 2000); + p1.Raise(0.9); + p1.Print(); + Console.WriteLine(); + + 高级主管 p2 = new 高级主管("栖迟", "福建厦门", 5000); + p2.Raise(0.5); + p2.Print(); + Console.WriteLine(); + + 秘书 p3 = new 秘书("秋分", "福建厦门", 3000); + p3.Print(); + Console.WriteLine(); + + 清洁工 p4 = new 清洁工("冬至", "福建厦门", 1000); + p4.Print(); + Console.WriteLine(); + Console.WriteLine(); + + //二、设计一个学生类Student, + // 包括的属性有姓名name,年龄age,学位degree。 + // 由学生类Student + // 派生出专科生类Specialty和本科生类Undergraduate + // 专科生类包含的属性有专业spec, + // 本科生类包括的属性有研究方向drec。 + // 每个类都有相关数据的输出方法。最后在一个测试类中对设计的类进行测试。 + // 要求测试结果如下: + // 姓名:王雷 年龄:17 学位:专科 专业:java + // 姓名:刘文 年龄:22 学位:本科 研究方向:网络技术 + 专科生 专科生 = new 专科生("李华", 17, "专科", "Java"); + 专科生.Print(); + + 本科生 本科生 = new 本科生("莉莉", 22, "本科", "网络技术"); + 本科生.Print(); + Console.WriteLine(); + Console.WriteLine(); + + //三、 图形类: + // 求周长,面积(三角形, 四边形, 圆形) + 三角形 三角形 = new 三角形(3, 4, 5); + Console.WriteLine($"三角形的面积是{三角形.GetArea()},周长是{三角形.GetPerimeter()}"); + + 矩形 矩形 = new 矩形(2, 3); + Console.WriteLine($"正方形的面积是{矩形.GetArea()},周长是{矩形.GetPerimeter()}"); + + 圆形 圆形 = new 圆形(5); + Console.WriteLine($"圆形的面积是{圆形.GetArea()},周长是{圆形.GetPerimeter()}"); + Console.WriteLine(); + Console.WriteLine(); + + //四、员工类Employee + // 字段:姓名,工作年限,月薪、 + // 组长(GroupLeader): 月薪 + 1000 * 年限 + // 经理(Manager) :月薪 + 1000 * 年限 * 基础分红;需要增加一个 字段:基础分红1000 + // 客户经理(AccountManager):月薪 + 1000 * 年限 * 分红(基础分红 * 3) + // 求组长,经理的年薪。 + 组长 组长 = new 组长(); + 组长.YearOfSerive = 3; + 组长.MonthlySalary = 5000; + Console.WriteLine($"组长的年薪是{组长.GetGroupLeader()}"); + + 经理 经理 = new 经理(); + 经理.YearOfSerive = 3; + 经理.MonthlySalary = 6500; + 经理.Bouns = 1000; + Console.WriteLine($"经理的年薪是{经理.GetManager()}"); + + 客户经理 客户经理 = new 客户经理(); + 客户经理.YearOfSerive = 3; + 客户经理.MonthlySalary = 8500; + 客户经理.Bouns = 1000; + Console.WriteLine($"客户经理的年薪是{客户经理.GetAccountManager()}"); + Console.WriteLine(); + Console.WriteLine(); + + //五、设计一个汽车类Vehicle,包含的属性有汽车品牌brand、车轮个数wheels和车重weight。 + // 小车类Car是Vehicle的子类,其中包含的属性有载人数loader。 + // 卡车类Truck是Car类的子类,其中包含的属性有载重量payload。 + // 每个类都有构造方法和输出相关数据的方法。 + 小车 car = new 小车("奔驰", 4, 120, 4); + car.Print(); + Console.WriteLine(); + + 卡车 truck = new 卡车("大卡车", 16, 1200, 200); + truck.Print(); + + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\215\241\350\275\246.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\215\241\350\275\246.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ca64d63db8f38b35cd16acadd6648cb66a5ee15e --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\215\241\350\275\246.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 卡车:汽车 + { + public int Payload { get; set; } + + public 卡车() { } + public 卡车(string brand, int wheels, int weight, int payload) : base(brand, wheels, weight) + { + this.Payload = payload; + } + + public void Print() + { + base.Print(); + Console.WriteLine($"载重量:{Payload}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\221\230\345\267\245.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\221\230\345\267\245.cs" new file mode 100644 index 0000000000000000000000000000000000000000..26ebcba13e5dba12b7bf399b877f7e61b9d25ff5 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\221\230\345\267\245.cs" @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 员工 + { + public string Name { get; set; } + public int YearOfSerive { get; set; } + public double MonthlySalary { get; set; } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\233\276\345\275\242.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\233\276\345\275\242.cs" new file mode 100644 index 0000000000000000000000000000000000000000..2344026d2e091e2f8f9d53a4d154560b82dbd23e --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\233\276\345\275\242.cs" @@ -0,0 +1,15 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal abstract class 图形 + { + public abstract double GetArea(); + public abstract double GetPerimeter(); + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\234\206\345\275\242.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\234\206\345\275\242.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9c275258705be27f3560988ec1144d316de35d29 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\234\206\345\275\242.cs" @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 圆形:图形 + { + private double radius; + + public 圆形(double radius) + { + this.radius = radius; + } + + public override double GetArea() + { + return Math.PI * radius * radius; + } + + public override double GetPerimeter() + { + return 2 * Math.PI * radius; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\255\246\347\224\237.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\255\246\347\224\237.cs" new file mode 100644 index 0000000000000000000000000000000000000000..19ef49faa5013832f87e4b27539883cb1e79f1dd --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\255\246\347\224\237.cs" @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 学生 + { + public string Name { get; set; } + public int Age { get; set; } + public string Degree { get; set; } + + public 学生() { } + public 学生(string name, int age, string degree) + { + this.Name = name; + this.Age = age; + this.Degree = degree; + } + + public void Print() + { + Console.Write("姓名:{0} 年龄:{1} 学位:{2} ", Name, Age, Degree); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\256\242\346\210\267\347\273\217\347\220\206.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\256\242\346\210\267\347\273\217\347\220\206.cs" new file mode 100644 index 0000000000000000000000000000000000000000..30978d80be5ce38a3157da9bee135b5173d3de5b --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\256\242\346\210\267\347\273\217\347\220\206.cs" @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 客户经理:员工 + { + public double Bouns { get; set; } + public double GetAccountManager() + { + return (MonthlySalary + 1000 * YearOfSerive * Bouns * 3) * 12; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\260\217\350\275\246.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\260\217\350\275\246.cs" new file mode 100644 index 0000000000000000000000000000000000000000..08306079b9c66dba6dceb3b3ca699eaa00a2e665 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\345\260\217\350\275\246.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 小车:汽车 + { + public int Loader { get; set; } + public 小车() { } + + public 小车(string brand, int wheels, int weight, int loader) : base(brand, wheels, weight) + { + this.Loader = loader; + } + + public void Print() + { + base.Print(); + Console.WriteLine($"可载人数:{Loader}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\234\254\347\247\221\347\224\237.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\234\254\347\247\221\347\224\237.cs" new file mode 100644 index 0000000000000000000000000000000000000000..d0e23675b22c0cb5bc5937eb2dfb6c850a3d5a44 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\234\254\347\247\221\347\224\237.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 本科生:学生 + { + public string drec { get; set; } + + public 本科生() { } + + public 本科生(string name, int age, string degree, string drec) : base(name, age, degree) + { + this.drec = drec; + } + + public void Print() + { + base.Print(); + Console.WriteLine("研究方向:" + drec); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\261\275\350\275\246.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\261\275\350\275\246.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9f43f4c4390249f11e1ca9ea1e149c567eab7fe6 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\261\275\350\275\246.cs" @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 汽车 + { + public string Brand { get; set; } + public int Wheels { get; set; } + public int Weight { get; set; } + + public 汽车() { } + public 汽车(string brand, int wheels, int weight) + { + this.Brand = brand; + this.Wheels = wheels; + this.Weight = weight; + } + + public void Print() + { + Console.WriteLine($"汽车品牌:{Brand}"); + Console.WriteLine($"车轮个数:{Wheels}"); + Console.WriteLine($"车重:{Weight}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\270\205\346\264\201\345\267\245.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\270\205\346\264\201\345\267\245.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b74a2c79d75821d8e49170d6d9fe4a1e27408d05 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\346\270\205\346\264\201\345\267\245.cs" @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 清洁工:雇员 + { + public 清洁工(string name, string adderss, int salary) + : base(name, adderss, salary) + { + Console.WriteLine("清洁工"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\237\251\345\275\242.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\237\251\345\275\242.cs" new file mode 100644 index 0000000000000000000000000000000000000000..a7115a9d32a011e9d172acbd433272d6da849579 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\237\251\345\275\242.cs" @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 矩形:图形 + { + private double width; + private double height; + + public 矩形(double width, double height) + { + this.width = width; + this.height = height; + } + + public override double GetArea() + { + return width * height; + } + + public override double GetPerimeter() + { + return 2 * (width + height); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\247\230\344\271\246.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\247\230\344\271\246.cs" new file mode 100644 index 0000000000000000000000000000000000000000..fc62820d7c51342ed12e9a2d9df031c40d9e82e8 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\247\230\344\271\246.cs" @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 秘书:雇员 + { + public 秘书(string name, string adderss, int salary) + : base(name, adderss, salary) + { + Console.WriteLine("秘书"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\250\213\345\272\217\345\221\230.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\250\213\345\272\217\345\221\230.cs" new file mode 100644 index 0000000000000000000000000000000000000000..33cb69a8c51eeab07e17fc826325ed64418d73ef --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\250\213\345\272\217\345\221\230.cs" @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 程序员 : 雇员 + { + public 程序员(string name, string address, double salary) + : base(name, address, salary) + { + Console.WriteLine("程序员"); + } + + public override void Raise(double percent) + { + base.Raise(percent); + base.Salary += base.Increase; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\273\204\351\225\277.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\273\204\351\225\277.cs" new file mode 100644 index 0000000000000000000000000000000000000000..92aede9b5856a5ea3e973ff2e0692bc0feda9d8c --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\273\204\351\225\277.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 组长:员工 + { + public double GetGroupLeader() + { + return (MonthlySalary + 1000 * YearOfSerive) * 12; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\273\217\347\220\206.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\273\217\347\220\206.cs" new file mode 100644 index 0000000000000000000000000000000000000000..eab52794c7529d5307b108659215e9afca235f09 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\347\273\217\347\220\206.cs" @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 经理:员工 + { + public double Bouns { get; set; } + public double GetManager() + { + return (MonthlySalary + 1000 * YearOfSerive * Bouns) * 12; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\351\233\207\345\221\230.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\351\233\207\345\221\230.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ca64d63db8f38b35cd16acadd6648cb66a5ee15e --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\351\233\207\345\221\230.cs" @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 卡车:汽车 + { + public int Payload { get; set; } + + public 卡车() { } + public 卡车(string brand, int wheels, int weight, int payload) : base(brand, wheels, weight) + { + this.Payload = payload; + } + + public void Print() + { + base.Print(); + Console.WriteLine($"载重量:{Payload}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\351\253\230\347\272\247\344\270\273\347\256\241.cs" "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\351\253\230\347\272\247\344\270\273\347\256\241.cs" new file mode 100644 index 0000000000000000000000000000000000000000..5bef445e4e6bec2de96efa8c5cc2bf4070f4795b --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\347\273\247\346\211\27702/\351\253\230\347\272\247\344\270\273\347\256\241.cs" @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 继承作业02 +{ + internal class 高级主管:雇员 + { + public 高级主管(string name, string address, double salary) + : base(name, address, salary) + { + Console.WriteLine("高级主管"); + } + + public override void Raise(double percent) + { + base.Raise(percent); + base.Salary += base.Increase; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\344\270\273\346\226\271\346\263\225.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\344\270\273\346\226\271\346\263\225.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3fc992bd2598b85f0340bccff4e5763affb2d1a6 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\344\270\273\346\226\271\346\263\225.cs" @@ -0,0 +1,38 @@ +namespace _11虚方法二 +{ + internal class 主方法 + { + static void Main(string[] args) + { + Console.WriteLine("鸟类"); + Console.WriteLine(""); + + 老鹰 l = new 老鹰("老鹰", 2, 26); + l.吃(); + l.叫(); + l.睡觉(); + Console.WriteLine(""); + + 燕子 y = new 燕子("燕子", 2, 6); + y.吃(); + y.叫(); + y.睡觉(); + Console.WriteLine(""); + Console.WriteLine(""); + + Console.WriteLine("猫科类"); + Console.WriteLine(""); + + 猫 m = new 猫("猫", 4, 8,6); + m.吃(); + m.叫(); + m.睡觉(); + Console.WriteLine(""); + + 老虎 h = new 老虎("老虎", 4, 180,6); + h.吃(); + h.叫(); + h.睡觉(); + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\345\212\250\347\211\251.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\345\212\250\347\211\251.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7da81d6c8c01f94544ac7e8e4b5a21c1370d1a91 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\345\212\250\347\211\251.cs" @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _11虚方法二 +{ + internal class 动物 + { + //1.动物类: + // 具有动物的共同属性:腿,重量等; + // 共同行为:吃,叫,睡 + private string name; + public int leg; + public double weight; + + public string Name { get => name; set => name = value; } + public int Leg { get => leg; set => leg = value; } + public double Weight { get => weight; set => weight = value; } + + public 动物(string name,int leg, double weight) + { + Name = name; + Leg = leg; + Weight = weight; + } + public 动物() { } + + /** + 父类中用virtual修饰的方法称为虚方法; + 在子类中可以用override对父类中的虚方法进行重写 + */ + public virtual void 吃() + { + Console.WriteLine($"{Name}在吃"); + } + public void 叫() + { + Console.WriteLine($"{Name}在叫"); + } + public void 睡觉() + { + Console.WriteLine($"{Name}在睡觉"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\207\225\345\255\220.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\207\225\345\255\220.cs" new file mode 100644 index 0000000000000000000000000000000000000000..4660431090ea6ed9d7a85dd8f6c04f3295e1e522 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\207\225\345\255\220.cs" @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _11虚方法二 +{ + internal class 燕子:鸟类 + { + public 燕子(string name, int leg, double weight) + { + Name = name; + Leg = leg; + Weight = weight; + } + public 燕子() { } + + public override void 吃() + { + Console.WriteLine($"{Name}在吃虫子"); + } + public void 叫() + { + Console.WriteLine($"{Name}在唱歌"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\214\253.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\214\253.cs" new file mode 100644 index 0000000000000000000000000000000000000000..23b6174fcd7507543840aeba84c198be02aea09a --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\214\253.cs" @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _11虚方法二 +{ + internal class 猫:猫科类 + { + public 猫(string name, int leg, double weight, double beard) + { + Name = name; + Leg = leg; + Weight = weight; + Beard = beard; + } + public 猫() { } + + //猫独有的 + public void 抓老鼠() + { + Console.WriteLine("猫在抓老鼠"); + } + + public void 吃() + { + Console.WriteLine($"{Name}爱吃鱼,老鼠,巧克力,牛奶,千层面,披萨,铜锣烧"); + } + + public void 叫() + { + Console.WriteLine($"{Name}在喵喵叫"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\214\253\347\247\221\347\261\273.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\214\253\347\247\221\347\261\273.cs" new file mode 100644 index 0000000000000000000000000000000000000000..165d5cb81e17e23d0b2b1f7596b60b31641979f5 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\347\214\253\347\247\221\347\261\273.cs" @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _11虚方法二 +{ + internal class 猫科类:动物 + { + //2.猫科类:具有猫科动物的共同属性:胡须等, + // 共同能力:夜视能力 + + public double beard; + public double Beard { get => beard; set => beard = value; } + public 猫科类(string name,int leg, double weight, double beard) + { + Name = name; + Leg = leg; + Weight = weight; + Beard = beard; + } + public 猫科类() { } + + public void 夜视能力() + { + Console.WriteLine($"晚上能看见"); + } + + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\350\200\201\350\231\216.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\350\200\201\350\231\216.cs" new file mode 100644 index 0000000000000000000000000000000000000000..282c63ea77efafef88554b196f0cbea29329a723 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\350\200\201\350\231\216.cs" @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _11虚方法二 +{ + internal class 老虎:猫科类 + { + public 老虎(string name,int leg, double weight, double beard) + { + Name = name; + Leg = leg; + Weight = weight; + Beard = beard; + } + public 老虎() { } + + //老虎独有的 + public void 捕猎() + { + Console.WriteLine("老虎在捕抓猎豹"); + } + + public void 吃() + { + Console.WriteLine($"{Name}爱吃鲜肉,马鹿和野猪"); + } + + public void 叫() + { + Console.WriteLine($"{Name}在嘶吼"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\350\200\201\351\271\260.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\350\200\201\351\271\260.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ef20fd5d2457d3b9326eacb4669c9e4b45239861 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\350\200\201\351\271\260.cs" @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _11虚方法二 +{ + internal class 老鹰:鸟类 + { + public 老鹰(string name, int leg, double weight) + { + Name = name; + Leg = leg; + Weight = weight; + } + public 老鹰() { } + + public void 吃() + { + Console.WriteLine($"{Name}在吃肉"); + } + public void 叫() + { + Console.WriteLine($"{Name}在啼叫"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\351\270\237\347\261\273.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\351\270\237\347\261\273.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b4a46e7e294117e79ab5c744fdfa3a5f3da9f530 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\212\250\347\211\251/\351\270\237\347\261\273.cs" @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _11虚方法二 +{ + internal class 鸟类:动物 + { + //3.鸟类:具有鸟类的共同行为:飞行 + public 鸟类(string name,int leg, double weight) + { + Name = name; + Leg = leg; + Weight = weight; + } + public 鸟类() { } + + public virtual void 飞行() + { + Console.WriteLine($"{Leg}在低飞"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\344\270\273\346\226\271\346\263\225.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\344\270\273\346\226\271\346\263\225.cs" new file mode 100644 index 0000000000000000000000000000000000000000..075da879f69af9e60997a2a9e775d4a7fd711586 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\344\270\273\346\226\271\346\263\225.cs" @@ -0,0 +1,21 @@ +namespace _11虚方法一 +{ + internal class 主方法 + { + static void Main(string[] args) + { + //5.在主方法中为每个类实例化一个对象,用每个对象调用工作方法 + 清洁工 q = new 清洁工("小安", '女', 46); + q.工作(); + Console.WriteLine(""); + + 程序员 c = new 程序员("栖", '女', 23); + c.工作(); + Console.WriteLine(""); + + 医生 y = new 医生("春酲", '女', 26); + y.工作(); + Console.WriteLine(""); + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\345\214\273\347\224\237.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\345\214\273\347\224\237.cs" new file mode 100644 index 0000000000000000000000000000000000000000..01de4f82a3eef74303ab973701c8d979d2960012 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\345\214\273\347\224\237.cs" @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _11虚方法一 +{ + internal class 医生:员工 + { + //2.定义一个医生类,继承员工类,重写工作的方法, + // 描述医生的具体工作 + public 医生(string name, char sex, int age) + : base(name, sex, age) + { + + } + public override void 工作() + { + Console.WriteLine($"{Name}在给病人做诊断"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\345\221\230\345\267\245.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\345\221\230\345\267\245.cs" new file mode 100644 index 0000000000000000000000000000000000000000..93eabfca18e80012fd39bfdffa05076c441ee02f --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\345\221\230\345\267\245.cs" @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _11虚方法一 +{ + internal class 员工 + { + //1.定义一个员工类,作为基类,包含姓名,性别,年龄等属性; + // 包含一个方法代表工作的行为 + + private string name;//姓名 + private char sex;//性别 + private int age;//年龄 + + public string Name { get => name; set => name = value; } + public char Sex { get => sex; set => sex = value; } + public int Age { get => age; set => age = value; } + + public 员工(string name, char sex, int age) + { + Name = name; + Sex = sex; + Age = age; + } + public 员工() { } + + /** + 父类中用virtual修饰的方法称为虚方法; + 在子类中可以用override对父类中的虚方法进行重写 + */ + public virtual void 工作() + { + Console.WriteLine($"{Name}在认真工作"); + } + public void 检查() + { + Console.WriteLine($"{Name}在认真检查"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\346\270\205\346\264\201\345\267\245.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\346\270\205\346\264\201\345\267\245.cs" new file mode 100644 index 0000000000000000000000000000000000000000..053205bb5192c9225dedc5ff05d3d7ff0a4b006b --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\346\270\205\346\264\201\345\267\245.cs" @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _11虚方法一 +{ + internal class 清洁工:员工 + { + //4.定义一个清洁工类,继承员工类,重写工作方法, + // 描述清洁工的具体工作 + public 清洁工(string name, char sex, int age) : base(name, sex, age) + { + + } + public void 城市环境保护员() + { + Console.WriteLine($"{Name}在进行废物清理"); + } + //子类重写父类的方法 + public override void 工作() + { + Console.WriteLine($"{Name}在做河岸设施养护"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\347\250\213\345\272\217\345\221\230.cs" "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\347\250\213\345\272\217\345\221\230.cs" new file mode 100644 index 0000000000000000000000000000000000000000..bb59940778235d2d3386f5f7b2c1146248efee10 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\350\231\232\346\226\271\346\263\225\347\232\204\344\275\234\344\270\232/\345\221\230\345\267\245\347\263\273\347\273\237/\347\250\213\345\272\217\345\221\230.cs" @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace _11虚方法一 +{ + internal class 程序员:员工 + { + //3.定义一个程序员类,继承员工类,重写工作方法, + // 描述程序员具体工作 + public 程序员(string name, char sex, int age) : base(name, sex, age) + { + + } + public override void 工作() + { + Console.WriteLine($"{Name}在敲代码"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/SumUtils.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/SumUtils.cs" new file mode 100644 index 0000000000000000000000000000000000000000..a1d32213f33eaebbeb68a5117bd8450923a41cce --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/SumUtils.cs" @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 作业05 +{ + internal class SumUtils + { + //计算两个整数相加 + public static void Sum(int num1, int num2) + { + int sum = num1 + num2; + Console.WriteLine($"{num1}+{num2}={sum}"); + } + //两个小数相加 + public static void Sum(double num1, double num2) + { + double sum = num1 + num2; + Console.WriteLine($"{num1}+{num2}={sum}"); + } + //两个字符串相加 + public static void Sum(string num1, string num2) + { + string sum = num1 + num2; + Console.WriteLine($"{num1}+{num2}={sum}"); + } + + //从 1 到指定整数的和 + public static void Sum(int n) + { + + int sum = 0; + + //求1到n的累加和 + for (int i = 1; i <= n; i++) + { + sum = sum + i;//sum+=i; + } + Console.WriteLine($"1到{n}和{sum}"); + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/area.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/area.cs" new file mode 100644 index 0000000000000000000000000000000000000000..cd3536643ce29a3dd98833541931610f065cc981 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/area.cs" @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 作业05 +{ + internal class Area + { + public double acreage(double r) + { + return Math.PI * r * r; + } + + public double acreage(double length, double width) + { + return length * width; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/\344\270\273\346\226\271\346\263\225.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/\344\270\273\346\226\271\346\263\225.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ff325e877b5743078dfd89030be680e8df11e48b --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\207\215\350\275\275/\344\270\273\346\226\271\346\263\225.cs" @@ -0,0 +1,42 @@ +namespace 作业05 +{ + internal class 主方法 + { + static void Main(string[] args) + { + //1.定义一个计算图形面积的类,类中定义2个计算面积的方法(重载,方法名相同) + //分别计算圆面积和长方形面积两个方法。 + //提示:计算圆的面积传半径,计算长方形面积传长和宽。 + Area area = new Area(); + Console.WriteLine("圆的面积是" + area.acreage(2)); + Console.WriteLine(""); + Console.WriteLine("长方形面积是" + area.acreage(3, 6)); + Console.WriteLine(""); + + + + //2.创建一个名为计算工具类 SumUtils,在类中定义4个方法: + //计算两个整数相加、两个小数相加、 + //两个字符串相加、以及从 1 到指定整数的和的方法。在 Main 方法中分别调用定义好的方法。 + //提示:根据题目要求,分别定义 3 个带两个参数的方法 + //以及一个带一个整型参数的方法,四个方法名相同。 + SumUtils sumUtils = new SumUtils(); + + Console.WriteLine("两个整数相加:"); + SumUtils.Sum(1478, 2789); + Console.WriteLine(""); + + Console.WriteLine("两个小数相加:"); + SumUtils.Sum(1478.34, 2789); + Console.WriteLine(""); + + Console.WriteLine("两个字符串相加:"); + SumUtils.Sum("Hello", "World"); + Console.WriteLine(""); + + Console.WriteLine("从 1 到指定整数的和:"); + SumUtils.Sum(5); + + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\345\255\227\346\256\265\344\275\234\344\270\232/Program.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\345\255\227\346\256\265\344\275\234\344\270\232/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..69930056d021dd441077e5ac39309ef15a84ce99 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\345\255\227\346\256\265\344\275\234\344\270\232/Program.cs" @@ -0,0 +1,35 @@ +namespace 静态字段作业08 +{ + internal class Program + { + static void Main(string[] args) + { + //Main方法中,创建5个学生对象,每个学生执行输出学生信息的方法。 + //学生的老师变更, + //再执行每个学生执行输出学生信息的方法。 + + //提示: + //定义一个学生类(有哪些字段属性?修饰符是什么?自己考量定义,至少学生姓名要吧), + //定义一个有参构造方法用来初始化学生姓名。 + //学生类中定义一个成员方法,用来输出学生的信息。 + + + Student s1 = new Student("孙悟空"); + Student s2 = new Student("猪八戒"); + Student s3 = new Student("沙和尚"); + Student s4 = new Student("白龙马"); + s1.PrintStudent(); + s2.PrintStudent(); + s3.PrintStudent(); + s4.PrintStudent(); + + Console.WriteLine(); + + Student.ChangeTeacher("嫦娥姐姐"); + s1.PrintStudent(); + s2.PrintStudent(); + s3.PrintStudent(); + s4.PrintStudent(); + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\345\255\227\346\256\265\344\275\234\344\270\232/Student.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\345\255\227\346\256\265\344\275\234\344\270\232/Student.cs" new file mode 100644 index 0000000000000000000000000000000000000000..5bf6504fa568fd5b12150623791b9580702c6ef4 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\345\255\227\346\256\265\344\275\234\344\270\232/Student.cs" @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 静态字段作业08 +{ + internal class Student + { + private string name; + private static string teacher = "唐僧"; + public Student(string name) + { + this.name = name; + } + public void PrintStudent() + { + Console.WriteLine("大家好,我是{0},俺老师叫{1}", name, teacher); + } + + public static void ChangeTeacher(string newTeacher) + { + teacher = newTeacher; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/ArrayUtil.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/ArrayUtil.cs" new file mode 100644 index 0000000000000000000000000000000000000000..bdac800b535f59eff8b2751c1206f273acbe6abb --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/ArrayUtil.cs" @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 静态方法作业07 +{ + internal class ArrayUtil + { + public static bool Isarray(T[] array) + { + return array == null || array.Length == 0; + } + } +} diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/Program.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..90896f3c6b834c94ec34381ca21129110d1940a4 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/Program.cs" @@ -0,0 +1,23 @@ +namespace 静态方法作业07 +{ + internal class Program + { + static void Main(string[] args) + { + //1、写一个工具类StringUtil,在里面定义一个静态方法,用来判断字符串是否为空。 + //如果字符串是null,或者字符串是空"",或者字符串是N个空格" ",那这个方法返回true,否则返回false + //然后在主类中(有Main方法的类)调用测试。 + string str = ""; + Console.WriteLine(SrtringUtil.Istring(str)); + Console.WriteLine(""); + + + //2、写一个工具类ArrayUtil,在里面定义一个静态方法,用来判断数组是否为空。 + //如果数组是null,或者数组长度为0,那此方法返回true,否则返回false + //然后在主类中(有Main方法的类)调用测试。 + int[] arr = { 1, 2, 3 }; + Console.WriteLine(ArrayUtil.Isarray(arr)); + + } + } +} \ No newline at end of file diff --git "a/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/SrtringUtil.cs" "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/SrtringUtil.cs" new file mode 100644 index 0000000000000000000000000000000000000000..8f7e0211cb012527d407d42855d109cfb3fb60b7 --- /dev/null +++ "b/37\351\231\206\346\200\235\345\251\267/\351\235\231\346\200\201\346\226\271\346\263\225\344\275\234\344\270\232/SrtringUtil.cs" @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 静态方法作业07 +{ + internal class SrtringUtil + { + public static bool Istring(string str) + { + //IsNullOrEmpty方法 检查字符串是否为null或者空字符串 + //IsNullOrWhiteSpace方法 检查字符串是否为null或空字符串或仅有空字符组成 + //return string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value); + + + 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; + + } + } +}