diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\270\200/\346\226\260\345\273\272 DOCX \346\226\207\346\241\243.docx" "b/10\346\236\227\347\216\211\346\225\217/\344\270\200/\346\226\260\345\273\272 DOCX \346\226\207\346\241\243.docx" new file mode 100644 index 0000000000000000000000000000000000000000..dfe0b8f9b04cd2c3a347f2523860244de09bf04d Binary files /dev/null and "b/10\346\236\227\347\216\211\346\225\217/\344\270\200/\346\226\260\345\273\272 DOCX \346\226\207\346\241\243.docx" differ diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\270\203/\351\235\231\346\200\201\345\255\227\346\256\265.md" "b/10\346\236\227\347\216\211\346\225\217/\344\270\203/\351\235\231\346\200\201\345\255\227\346\256\265.md" new file mode 100644 index 0000000000000000000000000000000000000000..0ba8ab409a3d7293599a913381cd4c3948b320df --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\344\270\203/\351\235\231\346\200\201\345\255\227\346\256\265.md" @@ -0,0 +1,44 @@ +```c# +namespace ConsoleApp4 +{ + //静态字段存储的值在所有实例化之间是共享的 + internal class Program + { + public static string techer = "唐僧"; + static void Main(string[] args) + { + Student student=new Student("孙悟空"); + Console.Write($"我的老师叫{techer}\n"); + Student student1 = new Student("猪八戒"); + Console.Write($"我的老师叫{techer}\n"); + Student student2 = new Student("沙和尚"); + Console.Write($"我的老师叫{techer} \n"); + Student student3 = new Student("白龙马"); + Console.Write($"我的老师叫{techer} \n"); + techer = "嫦娥姐姐"; + Student student6 = new Student("孙悟空"); + Console.Write($"我的老师叫{techer}\n"); + Student student7 = new Student("猪八戒"); + Console.Write($"我的老师叫{techer}\n"); + Student student8 = new Student("沙和尚"); + Console.Write($"我的老师叫{techer} \n"); + Student student9 = new Student("白龙马"); + Console.Write($"我的老师叫{techer} \n"); } + } + /*定义一个学生类(有哪些字段属性?修饰符是什么?自己考量定义,至少学生姓名要吧),定义一个有参构造方法用来初始化学生姓名。学生类中定义一个成员方法,用来输出学生的信息。 + +Main方法中,创建5个学生对象,每个学生执行输出学生信息的方法。 +学生的老师变更, +再执行每个学生执行输出学生信息的方法。*/ + public class Student + { + string name; + public string Name { get; set; } + public Student(string name) { + this.Name= name; + Console.WriteLine($"大家好,我是{this.Name},"); + } + } +} +``` + diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\270\203/\351\235\231\346\200\201\346\226\271\346\263\225.md" "b/10\346\236\227\347\216\211\346\225\217/\344\270\203/\351\235\231\346\200\201\346\226\271\346\263\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..c916c9c416986a6853f7838f7d1339254fe21ca3 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\344\270\203/\351\235\231\346\200\201\346\226\271\346\263\225.md" @@ -0,0 +1,48 @@ +```c# +namespace ConsoleApp2 +{ + internal class Program + { + static void Main(string[] args) + { + string str = " "; + Console.WriteLine(StringUtil.Two(str)); + int[] num=new int[10]; + Console.WriteLine(ArrayUtil.One(num)); + } + } + /*1、写一个工具类StringUtil,在里面定义一个静态方法,用来判断字符串是否为空。 +如果字符串是null,或者字符串是空"",或者字符串是N个空格" ",那这个方法返回true,否则返回false +然后在主类中(有Main方法的类)调用测试。*/ + public class StringUtil + { + public static bool Two(string str) + { + char[] arrchar = str.ToCharArray(); + if (str == null || str == "") + { + return true; + } + foreach (char c in arrchar) + { + if(c!=' ') + { + return false; + } + } + return true; + } + } + /*2、写一个工具类ArrayUtil,在里面定义一个静态方法,用来判断数组是否为空。 +如果数组是null,或者数组长度为0,那此方法返回true,否则返回false +然后在主类中(有Main方法的类)调用测试。*/ + public class ArrayUtil + { + public static bool One(int[] num) + { + if(num == null||num.Length==0) return true; return false; + } + } +} +``` + diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\270\211/Untitled.md" "b/10\346\236\227\347\216\211\346\225\217/\344\270\211/Untitled.md" new file mode 100644 index 0000000000000000000000000000000000000000..7dd45bfda34aee73b483a7a3bb525d295d893aba --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\344\270\211/Untitled.md" @@ -0,0 +1,291 @@ +```c# +internal class Program + { + static void Main(string[] args) + { + //1.求圆的面积 + //const double PI= 3.14; + //Console.WriteLine("请输入半径的值"); + //double r = Convert.ToDouble(Console.ReadLine()); + //double result = PI * r * r; + //Console.WriteLine($"圆的面积是{result}"); + + //2.编写一个程序,请用户输入一个四位整数, + //将用户输入的四位数的千位、百位、十位和个位分别显示出来, + //如5632,则显示“用户输入的千位为5,百位为6,十位为3,个位为2” + //Console.WriteLine("请输入一个四位整数:"); + //int num = Convert.ToInt32(Console.ReadLine()); + //int ge, shi, bai, qian, wang; + //ge = num % 10; + //shi = num / 10 % 10; + //bai = num / 100 % 10; + //qian = num / 1000; + //Console.WriteLine($"千位是{qian},百位是{bai},十位是{shi},个位是{ge}"); + + //3.用户输入三个数,找出最大的数,打印输出。 + //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("请输入一个数n:"); + //int n = Convert.ToInt32(Console.ReadLine()); + //int product = 1; + //for (int i = 1; i <= n; i++) + //{ + // product *= i; + //} + //Console.WriteLine($"{n}的阶乘是{product}"); + + //5.接受用户输入的一个数n,求n到1所有数的阶乘和;n!+(n-1!)+(n-2)!+……+1! + //Console.WriteLine("请输入一个数n:"); + //int n = Convert.ToInt32(Console.ReadLine()); + //int sum = 0; + //for(int i = n; i >= 1; i--) + //{ + // int prodocut = 1; + // for(int j = i; j >= 1; j--) + // { + // prodocut *= j; + // } + // sum += prodocut; + //} + //Console.WriteLine($"{n}-1的阶乘和是{sum}"); + + //6.根据用户输入的菱形边长,打印菱形;如边长为3,行数为5 + //Console.WriteLine("请输入菱形的边长:"); + //int n = Convert.ToInt32(Console.ReadLine()); + + //int mid = n / 2 + 1; //菱形中间行 + //int spacecount = mid - 1; //空格的数量 + //int starcount = 1; //星号的数量 + + ////打印上半部分菱形 + //for (int i = 1; i <= mid; i++) + //{ + // for (int j = 1; j <= spacecount; j++) + // { + // Console.Write(" "); + // } + + // for (int j = 1; j <= starcount; j++) + // { + // Console.Write("*"); + // } + + // Console.WriteLine(); + // spacecount--; + // starcount += 2; + //} + + //spacecount = 1; + //starcount = n - 2; //底部菱形的星号数量 + + ////打印下半部分菱形 + //for (int i = 1; i <= mid - 1; i++) + //{ + // for (int j = 1; j <= spacecount; j++) + // { + // Console.Write(" "); + // } + + // for (int j = 1; j <= starcount; j++) + // { + // Console.Write("*"); + // } + + // Console.WriteLine(); + // spacecount++; + // starcount -= 2; + //} + + //7.用循环打印九九乘法表(用二维数组保存字符串后再打印) + //string[,] table = new string[9, 9]; + //for (int i = 0; i < 9; i++) + //{ + // for (int j = 0; j < i + 1; j++) + // { + // table[i, j] = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1); + // // Console.Write(table[i, j].PadRight(10)); + // } + // // Console.WriteLine(); + //} + //for (int i = 0; i < 9; i++) + //{ + // for (int j = 0; j < i + 1; j++) + // { + // Console.Write(table[i, j].PadRight(10)); + // } + // Console.WriteLine(); + //} + + //8.用户输入正方形边长,用*打印出空心正方形 + //Console.WriteLine("请输入正方形的边长:"); + //int square=Convert.ToInt32(Console.ReadLine()); + //for (int i = 0; i < square; i++) + //{ + // for (int j = 0; j < square; j++) + // { + // if (i == 0 || i == square - 1 || j == 0 || j == square - 1) + // { + // Console.Write("* "); + // } + // else + // { + // Console.Write(" "); + // } + // } + // Console.WriteLine(); + //} + + //9.用户输入正方形边长,用*打印出实心正方形 + //Console.WriteLine("请输入正方形的边长:"); + //int square = Convert.ToInt32(Console.ReadLine()); + //for(int i = 0; i < square; i++) + //{ + // for(int j = 0; j < square; j++) + // { + // Console.Write("* "); + // } + // Console.WriteLine(); + //} + + //10.输入一行字符串,分别统计出其中英文字母、数字、空格的个数。 + //Console.WriteLine("请输入一行字符串:"); + //string str=Convert.ToString(Console.ReadLine()); + //int letter = 0; + //int digit = 0; + //int space = 0; + //foreach(char c in str) + //{ + // if (char.IsLetter(c)) + // { + // letter++; + // } + // else if (char.IsDigit(c)) + // { + // digit++; + // } + // else if (char.IsWhiteSpace(c)) + // { + // space++; + // } + //} + //Console.WriteLine($"英文字母个数为{letter},数字个数为{digit},空格个数为{space}"); + + //11.在 Main 方法中创建一个 double 类型的数组, + //并在该数组中存入 5 名学生的考试成绩, + //计算总成绩和平均成绩。(要求使用foreach语句实现该功能) + //double[] score = new double[5] { 66, 69, 22, 75, 86 }; + //double sum = 0; + //double avg = 0; + //foreach(double scores in score) + //{ + // sum += scores; + //} + //avg = sum / score.Length; + //Console.WriteLine($"总成绩是{sum},平均成绩是{avg}"); + + //12.定义一个方法,实现一维数组的排序功能,从大到小排序。(不要用Array类的方法) + //int[] a = { 10, 16, 98, 62, 45, 33, 11 }; + //for(int i = 0; i < a.Length; i++) + //{ + // for (int j = 0; j < a.Length - i - 1; j++) + // { + // if (a[j] > a[j + 1]) + // { + // int temp = a[j]; + // a[j] = a[j + 1]; + // a[j + 1] = temp; + // } + // } + //} + //Console.WriteLine("排序后的结果是:"); + //foreach(int b in a) + //{ + // Console.Write(b+" "); + //} + //Console.WriteLine(); + + //13.实现查找数组元素索引的功能。定义一个数组, + //然后控制台输入要查找的元素,返回输入值在数组中最后一次出现的位置。 + //若是找不到,请打印找不到。(不要用Array类的方法 + //int[] arr = new int[] { 1, 3, 5, 7, 3, 9, 2 }; + //Console.WriteLine("请输入要查找的元素:"); + //int target = Convert.ToInt32(Console.ReadLine()); + //int index = -1; + //for (int i = 0; i < arr.Length; i++) + //{ + // if (arr[i] == target) + // { + // index = i; + // } + //} + //if (index == -1) + //{ + // Console.WriteLine("找不到该元素"); + //} + //else + //{ + // Console.WriteLine("该元素最后一次出现的位置是:" + index); + //} + + //14.14.在 Main 方法中创建一个字符串类型的数组,并存入 5 个值, + //然后将数组中下标是偶数的元素输出。 + + //string[] str = { "aaa", "bbb", "ccc", "ddd", "eee", "fff" }; + //for(int i = 0; i < str.Length; i = i + 2) + //{ + // Console.WriteLine(str[i]); + //} + + //15.用二维数组存放数据,实现杨辉三角形的打印; + //定义一个二维数组来存储杨辉三角形的数据 + //int[][] yanghui = new int[10][]; + //for (int i = 0; i < 10; i++) + //{ + // yanghui[i] = new int[i + 1]; + //} + + ////计算杨辉三角形的数据 + //for (int i = 0; i < yanghui.Length; i++) + //{ + // for (int j = 0; j < yanghui[i].Length; j++) + // { + // if (j == 0 || j == i) + // { + // yanghui[i][j] = 1; + // } + // else + // { + // yanghui[i][j] = yanghui[i - 1][j - 1] + yanghui[i - 1][j]; + // } + // } + //} + + ////打印杨辉三角形 + //for (int i = 0; i < yanghui.Length; i++) + //{ + // for (int j = 0; j < yanghui[i].Length; j++) + // { + // Console.Write(yanghui[i][j] + " "); + // } + // Console.WriteLine(); + //} + } + } +} +``` \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\271\235/Program.cs" "b/10\346\236\227\347\216\211\346\225\217/\344\271\235/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..562baff91d66eca4a5de9af6e81633dab06955da --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\344\271\235/Program.cs" @@ -0,0 +1,74 @@ +using System.Xml.Linq; + +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("-------------------------------"); + programmer pg = new programmer(); + pg.name = "周艳"; + pg.ip = "龙岩"; + pg.salary = 5000; + pg.position = "主管"; + pg.dx = 5000; + pg.way(); + Console.WriteLine("-------------------------------"); + programmer pg2 = new programmer(); + pg2.name = "刘倩倩"; + pg2.ip = "泉州"; + pg2.salary = 2000; + pg2.position = "程序员"; + pg2.dx = 5000; + pg2.way(); + Console.WriteLine("-------------------------------"); + dustman dt = new dustman(); + dt.name = "琳琳"; + dt.ip = "厦门"; + dt.salary = 3000; + dt.position = "部长"; + dt.way2(); + Console.WriteLine("-------------------------------"); + dustman dt2 = new dustman(); + dt2.name = "林秀清"; + dt2.ip = "广西"; + dt2.salary = 1000; + dt2.position = "清洁工"; + dt2.way2(); + } + } + internal class dustman : info + { + //秘书和清洁员 + public int salary; + public string position; + + public void way2() + { + Console.WriteLine("姓名:{0}", name); + Console.WriteLine("地址;{0}", ip); + Console.WriteLine("薪水:{0}", salary); + Console.WriteLine("职位:{0}", position); + } + } + internal class info + { + public string name; + public string ip; + } + //程序员和主管 + internal class programmer : info + { + public int salary; + public string position; + public int dx; + public void way() + { + Console.WriteLine("姓名:{0}", name); + Console.WriteLine("地址;{0}", ip); + Console.WriteLine("薪水:{0}", salary + dx * 0.5); + Console.WriteLine("职位:{0}", position); + } + } +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\271\235/two.cs" "b/10\346\236\227\347\216\211\346\225\217/\344\271\235/two.cs" new file mode 100644 index 0000000000000000000000000000000000000000..979ece8397fe74f6ecab6c7068949ad0039a43d4 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\344\271\235/two.cs" @@ -0,0 +1,53 @@ +using System.Xml.Linq; + +namespace ConsoleApp2 +{ + internal class Program + { + static void Main(string[] args) + { + specialty specialty1 = new specialty(); + specialty1.name = "xiao"; + specialty1.age = 17; + specialty1.degree = "专科"; + specialty1.spec = "java"; + specialty1.wayone(); + Console.WriteLine("-------------------------------------------"); + Undergraduate un1 = new Undergraduate(); + un1.name = "liu"; + un1.age = 22; + un1.degree = "本科"; + un1.drec = "网络技术"; + un1.waytwo(); + } + } + internal class Undergraduate : student + { + public string drec; + public void waytwo() + { + Console.WriteLine("学生姓名;{0}", name); + Console.WriteLine("学生年龄;{0}", age); + Console.WriteLine("学生学历;{0}", degree); + Console.WriteLine("学生专业;{0}", drec); + } + } + internal class specialty : student + { + public string spec; + public void wayone() + { + Console.WriteLine("学生姓名:{0}", name); + Console.WriteLine("学生年龄:{0}", age); + Console.WriteLine("学生学历:{0}", degree); + Console.WriteLine("学生专业:{0}", spec); + } + + } + internal class student + { + public string name;//姓名 + public int age;//年龄 + public string degree;//学位 + } +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\272\214/work.md.txt" "b/10\346\236\227\347\216\211\346\225\217/\344\272\214/work.md.txt" new file mode 100644 index 0000000000000000000000000000000000000000..a48b5c00a97a565a01ade7142959183699c3fe9e --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\344\272\214/work.md.txt" @@ -0,0 +1,119 @@ +namespace 基础语法巩固 +{ + 1. + //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"); + // } + //} + + 2. + //internal class Homework3 + //{ + // static void Main(string[] args) + // { + // Console.WriteLine("true"); + // Console.WriteLine("false"); + // } + // } + + 3. + //internal class Homework4 + //{ + // static void Main(string[] args) + // { + // sbyte num1 = -128; + // byte num2 = 127; + // Console.WriteLine(num1); + // Console.WriteLine(num2); + + // short num3 = -32768; + // short num4 = 32767; + // Console.WriteLine(num3); + // Console.WriteLine(num4); + + // int num5 = -2147483648; + // int num6 = 2147483647; + // Console.WriteLine(num5); + // Console.WriteLine(num6); + + // long num7 = -2147483649; + // long num8 = 2147483648; + // Console.WriteLine(num7); + // Console.WriteLine(num8); + // } + //} + + 4. + //internal class Homwork5 + //{ + // 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); + // } + //} + + 5. + //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); + // } + //} + + 6. + //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 diff --git "a/10\346\236\227\347\216\211\346\225\217/\344\272\224/\351\207\215\350\275\275.md" "b/10\346\236\227\347\216\211\346\225\217/\344\272\224/\351\207\215\350\275\275.md" new file mode 100644 index 0000000000000000000000000000000000000000..21696069f801ccdcf7d561b9ee825f75fc035d6b --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\344\272\224/\351\207\215\350\275\275.md" @@ -0,0 +1,68 @@ +```c# +namespace ConsoleApp1 +{ + + internal class Program + { + static void Main(string[] args) + { + GetArea getArea= new GetArea(); + double roond=getArea.One(3); + double heigh=getArea.One(3, 2); + Console.WriteLine($"圆的面积为{roond};长方形的面积为:{heigh}"); + SumUtils sum=new SumUtils(); + sum.One(3, 4); + sum.One(2.1, 7.6); + sum.One("add","declean"); + sum.One(10); + } + } + /*1. 定义一个计算图形面积的类,类中定义2个计算面积的方法(重载,方法名相同),分别计算圆面积和长方形面积两个方法。 +提示:计算圆的面积传半径,计算长方形面积传长和宽。*/ + public class GetArea + { + public double One(int r) + { + return r * 3.14 * r; + } + public double One(int h,int w) + { + return h* w; + } + } + /*2.创建一个名为计算工具类 SumUtils,在类中定义4个方法: + 计算两个整数相加、 + 两个小数相加、 + 两个字符串相加、 + 以及从 1 到指定整数的和的方法。 +在 Main 方法中分别调用定义好的方法。 + +提示:根据题目要求,分别定义 3 个带两个参数的方法,以及一个带一个整型参数的方法, + 四个方法名相同。*/ + public class SumUtils + { + public void One(int a,int b) + { + Console.WriteLine($"两个整数相加{a+b}"); + } + public void One(double a,double b) + { + Console.WriteLine($"两个小数相加{a + b}"); + } + public void One(string a,string b) + { + Console.WriteLine($"两个整数相加{a + b}"); + } + public void One(int a) + { + int sum = 0; + for(int i = 1; i <= a; i++) + { + sum += i; + } + Console.WriteLine($"以及从 1 到指定整数的和{sum}"); + } + } +} +``` + diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\205\253/\347\273\247\346\211\2771.md" "b/10\346\236\227\347\216\211\346\225\217/\345\205\253/\347\273\247\346\211\2771.md" new file mode 100644 index 0000000000000000000000000000000000000000..35d7885255ad15c4b9201341976d2b2551f013e6 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\205\253/\347\273\247\346\211\2771.md" @@ -0,0 +1,128 @@ +```c# +using System.Xml.Linq; + +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + Student stu1= new Student("周艳",1,"女","350527404146","1815963465","软件技术","大一"); + Console.WriteLine(stu1); + Teacher tec = new Teacher("林玉敏",1,"女","5875416418","151985698547","专业课老师","1100605614"); + Console.WriteLine(tec); + } + } + /*编号(Id)、姓名(Name)、性别(Sex)、身份证号(Cardid)、联系方式(Tel)*/ + class Person + { + public string Name { get; set; } + public int Id { get; set; } + public string Sex { get; set; } + public string Cardid { get; set; } + public string Tel { get; set; } + public Person(string name,int id,string sex,string cardid,string tel) + { + this.Cardid = cardid; + this.Name = name; + this.Tel = tel; + this.Name = name; + this.Id = id; + } + public Person() { } + } + class Student : Person + { + public string Major { get; set; } + public string Grade { get; set; } + public Student(string name, int id, string sex, string cardid, string tel,string major, string grade):base(name,id,sex,cardid,tel) + { + Major = major; + Grade = grade; + } + + public override string ToString() + { + return $"学生编号:{Id} \n姓名:{Name} \n性别:{Sex}\n身份证号码:{Cardid} \n联系方式:{Tel}\n专业:{Major}\n年级:{Grade} "; + } + } + class Teacher : Person + { + public string Title { get; set; } + public string Wageno { get; set; } + public Teacher(string name, int id, string sex, string cardid, string tel, string title, string wageno): base(name, id, sex, cardid, tel) + { + Title = title; + Wageno = wageno; + } + public override string ToString() + { + return $"老师编号:{Id} \n姓名:{Name} \n性别:{Sex}\n身份证号码:{Cardid} \n联系方式:{Tel}\n老师职称:{Title}\n工资号:{Wageno}"; + } + } +} +``` + +```c# +namespace ConsoleApp2 +{ + internal class Program + { + static void Main(string[] args) + { + Son alk = new Son("埃落克", "埃洛克是一名来自末日边境的勇士。他是圣约英雄中名副其实的拳术好手。他用毁灭性的符文魔法和无情的拳术攻击消灭敌人。","小林",10000,600,200); + Son tl = new Son("泰拉", "泰拉是为复仇而来的勇者。她挥舞法杖将愤怒转化为强大的元素魔法和攻击力因此战无不胜。", "小周", 1100, 700, 600); + Son lks = new Son("卢卡斯", "卢卡斯是一名彬彬有礼的剑客,能控制源质能量。他一手持剑战斗,另一手辅助攻击。","小陆",900,500,700); + Son lf = new Son("洛菲", "洛菲是一名攻击迅猛且擅长传送魔法的时空旅行者,喜欢利用她的幻象伙伴迷惑、吸引并摧毁敌人。","小周",800,300,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; + } + } + } + public class Hero + { + //字段:角色名字,角色介绍,角色昵称,攻击力,防御力,速度。 + public string Name { get; set; } + public string Desc { get; set; } + public string User { get; set; } + public int Attack { get; set; } + public int Def { get; set; } + public int Speed { get; set; } + public Hero(string name, string desc, string user, int attack, int def, int speed) + { + Name = name; + Desc = desc; + User = user; + Attack = attack; + Def = def; + Speed = speed; + } + public Hero() { } + } + class Son : Hero + { + public Son(string name, string desc, string user, int attack, int def, int speed) : base(name, desc, user, attack, def, speed) + { + Console.WriteLine($"您选择的是:{name}\n英雄描述:{desc} \n 昵称:{user} \n攻击力:{attack}\n 防御力:{def}\n 速度:{speed}"); + } + public void Choose(string one,string two,string three) + { + Console.WriteLine($"请选择您要使用的英雄能力:1.{one}2.{two}3.{three}"); + int num = Convert.ToInt32(Console.ReadLine()); + switch (num) + { + case 1: Console.WriteLine($"您使用了{one}"); break; + case 2: Console.WriteLine($"您使用了{two}"); break; + case 3: Console.WriteLine($"您使用了{three}"); break; + } + } + } +} +``` + diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\205\253/\347\273\247\346\211\2772.md" "b/10\346\236\227\347\216\211\346\225\217/\345\205\253/\347\273\247\346\211\2772.md" new file mode 100644 index 0000000000000000000000000000000000000000..03c468ef1f76bc2a3d7a05d22ae104dd518b252d --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\205\253/\347\273\247\346\211\2772.md" @@ -0,0 +1,345 @@ +```c# +namespace ConsoleApp2 +{ + internal class Program + { + static void Main(string[] args) + { + Programmer pro=new Programmer("周艳","云南"); + pro.Wage(10000, 0.05m); + Management mn=new Management("林玉敏","福建"); + mn.Wage(20000,0.5m); + Secretary se = new Secretary("林磊", "福建"); + Dustman du = new Dustman("小续集", "中国"); + + } + } + /*一、 雇员系统,定义雇员基类,共同的属性,姓名、地址和出生日期(可有可无), + * 子类:程序员,秘书,高层管理,清洁工,他们有不同的工资算法, + * 其中高级主管和程序员采用底薪加提成的方式, + * 高级主管和程序员的底薪分别是5000元和2000元 , + * 秘书和清洁工采用工资的方式,工资分别是3000和1000, */ + class Person + { + public string Name { get; set; } + public string Address { get; set; } + public Person() { } + public Person(string name, string address) + { + Name = name; + Address = address; + } + } + internal class Programmer : Person + { + public Programmer() + { + + } + + public Programmer(string name, string address):base(name,address) + { + + } + public void Wage(decimal sale,decimal ratio) + { + decimal wage = 2000 + sale * ratio; + Console.WriteLine($"{Name}程序员的工资为:{wage}"); + } + } + class Management : Person + { + public Management() + { + + } + + public Management(string name, string address) : base(name, address) + { + + } + public void Wage(decimal sale, decimal ratio) + { + decimal wage = 5000 + sale * ratio; + Console.WriteLine($"{Name}高层管理的工资为:{wage}"); + } + } + class Secretary : Person + { + public Secretary() + { + + } + + public Secretary(string name, string address) : base(name, address) + { + Console.WriteLine($"{Name}秘书的工资为:3000"); + } + + } + class Dustman : Person + { + public Dustman() + { + + } + + public Dustman(string name, string address) : base(name, address) + { + Console.WriteLine($"{Name}清洁工的工资为:1000"); + } + + } +} +``` + +```c# +namespace ConsoleApp3 +{ + internal class Program + { + static void Main(string[] args) + { + Specialty sp= new Specialty("王雷",17,"专科","java"); + Console.WriteLine(sp); + Undergraduate under = new Undergraduate("刘文",22,"本科","网络技术"); + Console.WriteLine(under); + } + } + /*二、 设计一个学生类Student, +包括的属性有姓名name,年龄age,学位degree。 +由学生类Student + +每个类都有相关数据的输出方法。最后在一个测试类中对设计的类进行测试。 +要求测试结果如下: +姓名:王雷 年龄:17 学位:专科 专业:java +姓名:刘文 年龄:22 学位:本科 研究方向:网络技术 +*/ + class Student + { + public string Name { get; set; } + public int Age { get; set; } + public string Degree { get; set; } + public Student() { } + public Student(string name, int age, string degree) + { + Name = name; + Age = age; + Degree = degree; + } + } + /*派生出专科生类Specialty和本科生类Undergraduate +专科生类包含的属性有专业spec, +本科生类包括的属性有研究方向drec。*/ + class Specialty : Student + { + public string Spec { get; set; } + public Specialty() { } + public Specialty(string name, int age, string degree,string spec):base(name,age,degree) + { + Spec = spec; + } + public override string ToString() + { + return $"姓名:{Name}\n年龄:{Age}\n学位:{Degree}\n专业:{Spec}"; + } + } + class Undergraduate : Student + { + public string Drec { get; set; } + public Undergraduate() { } + public Undergraduate(string name, int age, string degree, string drec) : base(name, age, degree) + { + Drec = drec; + } + public override string ToString() + { + return $"姓名:{Name}\n年龄:{Age}\n学位:{Degree}\n研究方向:{Drec}"; + } + } +} +``` + +```c# +namespace ConsoleApp4 +{ + internal class Program + { + static void Main(string[] args) + { + Triangle tr = new Triangle(3,4,5,4); + Round r = new Round(4); + Quadrangle qu = new Quadrangle(5, 6, 9, 10); + } + } + /*三、 图形类: + 求周长,面积(三角形, 四边形, 圆形) +*/ + class Triangle + { + public int W { get; set; } + public int B { get; set; } + public int C { get; set; } + public int H { get; set; } + public Triangle(int w, int h,int b,int c) + { + W = w; + B = b; + C = c; + H = h; + Console.WriteLine($"三角形的面积为:{(double)(w*h/2)} 三角形的周长为{W+B+C}"); + } + } + class Quadrangle + { + public int A { get; set; } + public int B { get; set; } + public int C { get; set; } + public int H { get; set; } + public Quadrangle(int a, int b, int c, int h) + { + A = a; + B = b; + C = c; + H = h; + Console.WriteLine($"四角形的面积为:不会求 四角形的周长为{A+H+ B + C}"); + } + } + class Round + { + public int A { get; set; } + public Round(int a) + { + A = a; + Console.WriteLine($"圆形的面积为:{(double)(a*3.14*a)} 圆形的周长为{(double)(2*a*3.14)}"); + } + } +} +``` + +```c# +namespace ConsoleApp3 +{ + /* + 四、员工类Employee + 字段:姓名,工作年限,月薪、 + +组长(GroupLeader): 月薪+1000*年限 +客户经理(AccountManager):月薪+1000*年限*分红(基础分红*3) +求组长,经理的年薪。 + */ + internal class Program + { + static void Main(string[] args) + { + GroupLeader gr = new GroupLeader("小周", 5, 3000); + Console.WriteLine(gr); + AccountManager ac = new AccountManager("小林",10,6000); + Console.WriteLine(ac); + } + } + class Employee + { + public string Name { get; set; } + public int Year { get; set; } + public double Money { get; set; } + public Employee(string name, int year, double money) + { + Name = name; + Year = year; + Money = money; + } + } + class GroupLeader: Employee + { + public GroupLeader(string name, int year, double money):base(name,year,money) + { + Name = name; + Year = year; + Money = money; + } + public override string ToString() + { + return $"组长{Name}工作了年{Year}月薪{Money+1000*Year}"; + } + } + class AccountManager : Employee + { + public int Base { + get + { + return 1000; + } + } + public AccountManager(string name, int year, double money) : base(name, year, money) + { + Name = name; + Year = year; + Money = money; + } + public override string ToString() + { + //经理(Manager) :月薪+1000*年限*基础分红;需要增加一个 字段:基础分红1000 + return $"员工{Name}工作了年{Year}月薪{Money+1000*Year*Base}"; + } + } +} +``` + +```c# +namespace ConsoleApp4 +{ + /*五、设计一个汽车类Vehicle,包含的属性有汽车品牌brand、车轮个数wheels和车重weight。 +每个类都有构造方法和输出相关数据的方法。*/ + internal class Program + { + static void Main(string[] args) + { + + Car car=new Car("小车",4,1000,4); + Console.WriteLine(car); + Truck truck = new Truck("卡车", 10, 1000, 3000); + Console.WriteLine(truck); + } + } + class Vehicle + { + public string Brand { get; set; } + public int Wheels { get;set; } + public int Weight { get; set;} + public Vehicle(string brand, int wheels, int weight) + { + Brand = brand; + Wheels = wheels; + Weight = weight; + } + } + //小车类Car是Vehicle的子类,其中包含的属性有载人数loader。 + class Car : Vehicle + { + public int Loader { get; set; } + public Car(string brand, int wheels, int weight,int loader):base(brand,wheels,weight) + { + Loader = loader; + } + public override string ToString() + { + return $"汽车品牌{Brand}、车轮个数{Wheels}和车重{Weight}载人数{Loader}"; + } + } + //卡车类Truck是Car类的子类,其中包含的属性有载重量payload。 + class Truck : Vehicle + { + public int Payload { get; set; } + public Truck(string brand, int wheels, int weight, int payload) : base(brand, wheels, weight) + { + Payload = payload; + } + public override string ToString() + { + return $"汽车品牌{Brand}、车轮个数{Wheels}和车重{Weight}载重量{Payload}"; + } + } +} +``` + diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\205\255/\346\236\204\351\200\240.md" "b/10\346\236\227\347\216\211\346\225\217/\345\205\255/\346\236\204\351\200\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..00724116f014d56ce6c00abbf9332f4327f8ae50 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\205\255/\346\236\204\351\200\240.md" @@ -0,0 +1,37 @@ +```c# +namespace ConsoleApp2 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + } + } + /*定义一个员工类,存放用户的工号、姓名、性别、学历和部门信息; +定义两个构造函数: +一个是无参构造函数,学历默认为专科; +一个有参构造函数,根据参数对类的属性进行初始化。*/ + public class Empleeyer + { + int id; + string name; + string sex; + string study; + string info; + public Empleeyer() + { + this.study = "专科"; + } + public Empleeyer(int id, string name, string sex, string study, string info) + { + this.id = id; + this.name = name; + this.sex = sex; + this.study = study; + this.info = info; + } + } +} +``` + diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\215\201/Program.cs" "b/10\346\236\227\347\216\211\346\225\217/\345\215\201/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7a14bdd7353ed82bc181b7b25cfb41a44b7f18ae --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\215\201/Program.cs" @@ -0,0 +1,102 @@ +namespace ConsoleApp3 +{ + internal class Program + { + static void Main(string[] args) + { + //有四种动物,使用代码的继承关系来表示动物之间的关系 + //1.动物类:具有动物的共同属性:腿,重量等;共同行为:吃,叫,睡 + //2.猫科类:具有猫科动物的共同属性:胡须等,共同能力:夜视能力 + //3.鸟类:具有鸟类的共同行为:飞行 + //4.定义老虎、猫、老鹰、燕子四个子类,并且在这些子类中重写Animal 中吃和叫的方法 + laohu laohu = new laohu(); + laohu.name = "老虎"; + laohu.jiao = 4; + laohu.zhongliang = 5; + laohu.zhonglei = "猫科"; + laohu.gongtong = "夜视能力"; + laohu.way1(); + cat cat = new cat(); + cat.name = "猫"; + cat.jiao = 4; + cat.zhongliang = 5; + cat.zhonglei = "猫科"; + cat.gongtong = "夜视能力"; + cat.way1(); + niao niao = new niao(); + niao.name = "老鹰"; + niao.jiao = 2; + niao.zhongliang = 5; + niao.zhonglei = "鸟科"; + niao.gongtong = "飞行"; + niao.way1(); + yanzi yanzi = new yanzi(); + yanzi.name = "燕子"; + yanzi.jiao = 2; + yanzi.zhongliang = 5; + yanzi.zhonglei = "鸟类"; + yanzi.gongtong = "飞行"; + yanzi.way1(); + } + } + internal class animal + { + public string name; + public int jiao; + public int zhongliang; + public string zhonglei; + public string gongtong; + public virtual void way1() + { + Console.WriteLine("动物名字:{0}", name); + Console.WriteLine("它的脚有几条:{0}", jiao); + Console.WriteLine("它的重量:{0}KG", zhongliang); + Console.WriteLine("它的种类:{0}", zhonglei); + Console.WriteLine("它的能力:{0}", gongtong); + } + } + internal class laohu : animal + { + public override void way1() + { + Console.WriteLine("动物名字:{0}", name); + Console.WriteLine("它的脚有几条:{0}", jiao); + Console.WriteLine("它的重量:{0}KG", zhongliang); + Console.WriteLine("它的种类:{0}", zhonglei); + Console.WriteLine("它的能力:{0}", gongtong); + } + } + internal class cat : animal + { + public override void way1() + { + Console.WriteLine("动物名字:{0}", name); + Console.WriteLine("它的脚有几条:{0}", jiao); + Console.WriteLine("它的重量:{0}KG", zhongliang); + Console.WriteLine("它的种类:{0}", zhonglei); + Console.WriteLine("它的能力:{0}", gongtong); + } + } + internal class niao : animal + { + public override void way1() + { + Console.WriteLine("动物名字:{0}", name); + Console.WriteLine("它的脚有几条:{0}", jiao); + Console.WriteLine("它的重量:{0}KG", zhongliang); + Console.WriteLine("它的种类:{0}", zhonglei); + Console.WriteLine("它的能力:{0}", gongtong); + } + } + internal class yanzi : animal + { + public override void way1() + { + Console.WriteLine("动物名字:{0}", name); + Console.WriteLine("它的脚有几条:{0}", jiao); + Console.WriteLine("它的重量:{0}KG", zhongliang); + Console.WriteLine("它的种类:{0}", zhonglei); + Console.WriteLine("它的能力:{0}", gongtong); + } + } +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\215\201/two.cs" "b/10\346\236\227\347\216\211\346\225\217/\345\215\201/two.cs" new file mode 100644 index 0000000000000000000000000000000000000000..92f336a59222503e036ea81f1316cb9e7b27c689 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\215\201/two.cs" @@ -0,0 +1,91 @@ +using System.Xml.Linq; +using static 虚方法.chengxuyuan; + +namespace 虚方法 +{ + internal class Program + { + static void Main(string[] args) + { + //1.定义一个员工类,作为基类,包含姓名,性别,年龄等属性;包含一个方法代表工作的行为 + + //2.定义一个医生类,继承员工类,重写工作的方法,描述医生的具体工作 + + //3.定义一个程序员类,继承员工类,重写工作方法,描述程序员具体工作 + + //4.定义一个清洁工类,继承员工类,重写工作方法,描述清洁工的具体工作 + + //5.在主方法中为每个类实例化一个对象,用每个对象调用工作方法; + yisheng yisheng = new yisheng(); + yisheng.name = "林磊"; + yisheng.age = 1; + yisheng.mingzu = "汉"; + yisheng.gongzuo = "医生"; + yisheng.sex = "男"; + yisheng.way1(); + Console.WriteLine("------------------------------"); + chengxuyuan chengxuyuan = new chengxuyuan(); + chengxuyuan.name = "磊"; + chengxuyuan.age = 3; + chengxuyuan.mingzu = "汉"; + chengxuyuan.gongzuo = "程序员"; + chengxuyuan.sex = "男"; + chengxuyuan.way1(); + Console.WriteLine("------------------------------"); + qingjiegong qingjiegong = new qingjiegong(); + qingjiegong.name = "lei"; + qingjiegong.age = 5; + qingjiegong.mingzu = "汉"; + qingjiegong.gongzuo = "清洁工"; + qingjiegong.sex = "女"; + qingjiegong.way1(); + } + } + internal class yisheng : yuangong + { + public override void way1() + { + Console.WriteLine("姓名:{0}", name); + Console.WriteLine("性别:{0}", sex); + Console.WriteLine("年龄:{0}", age); + Console.WriteLine("工作:{0}", gongzuo + "它的职责是帮助病人"); + Console.WriteLine("名族:{0}", mingzu); + } + } + internal class chengxuyuan : yuangong + { + public override void way1() + { + Console.WriteLine("姓名:{0}", name); + Console.WriteLine("性别:{0}", sex); + Console.WriteLine("年龄:{0}", age); + Console.WriteLine("工作:{0}", gongzuo + "它的职责是修复代码"); + Console.WriteLine("名族:{0}", mingzu); + } + internal class qingjiegong : yuangong + { + public override void way1() + { + Console.WriteLine("姓名:{0}", name); + Console.WriteLine("性别:{0}", sex); + Console.WriteLine("年龄:{0}", age); + Console.WriteLine("工作:{0}", gongzuo + "它的职责是打扫卫生"); + Console.WriteLine("名族:{0}", mingzu); + } + } + } + internal class yuangong + { + public string name;//姓名 + public string sex;//性别 + public int age;//年龄 + public string gongzuo;//工作 + public string mingzu;//名族 + public virtual void way1() + { + Console.WriteLine("姓名:{0}", name); + Console.WriteLine("性别:{0}", sex); + Console.WriteLine("年龄:{0}", age); + } + } +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\270\200/Program.cs" "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\270\200/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..91565502bccd31d4e098d5a738b4dcb4e291f100 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\270\200/Program.cs" @@ -0,0 +1,99 @@ +namespace ConsoleApp4 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("请输入一个整数"); + int num1 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入一个整数"); + int num2 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入一个操作符"); + string fu = Console.ReadLine(); + Calculate calculate = null; + + if (fu == "+") + { + calculate = new jiafa(num1, num2); + } + else if (fu == "-") + { + calculate = new jianfa(num1, num2); + } + else if (fu == "*") + { + calculate = new chengfa(num1, num2); + } + else if (fu == "/") + { + calculate = new chufa(num1, num2); + } + + } + + public static void Calculate(Calculate calculate) + { + calculate.DisplayResult(); + } + + } + internal class Calculate + { + protected int num1; + protected int num2; + public Calculate(int num1, int num2) + { + this.num1 = num1; + this.num2 = num2; + } + public virtual void DisplayResult() + { + Console.WriteLine("num1+num2={0}", num1 + num2); + Console.WriteLine("num1-num2={0}", num1 - num2); + Console.WriteLine("num1*num2={0}", num1 * num2); + Console.WriteLine("num1/num2={0}", num1 / num2); + } + + } + internal class jiafa : Calculate + { + public jiafa(int num1, int num2) : base(num1, num2) + { + } + public override void DisplayResult() + { + Console.WriteLine("num1+num2={0}", num1 + num2); + } + } + internal class jianfa : Calculate + { + public jianfa(int num1, int num2) : base(num1, num2) + { + } + public override void DisplayResult() + { + Console.WriteLine("num1-num2={0}", num1 - num2); + } + } + internal class chengfa : Calculate + { + public chengfa(int num1, int num2) : base(num1, num2) + { + } + public override void DisplayResult() + { + Console.WriteLine("num1*num2={0}", num1 * num2); + } + } + internal class chufa : Calculate + { + public chufa(int num1, int num2) : base(num1, num2) + { + } + public override void DisplayResult() + { + Console.WriteLine("num1/num2={0}", num1 / num2); + } + } +} +} diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\270\211/Program.cs" "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\270\211/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b1303f856194a5770b2f38f12e2328451cdadf09 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\270\211/Program.cs" @@ -0,0 +1,307 @@ +namespace ConsoleApp6 +{ + internal class Program + { + static void Main(string[] args) + { + //一 + //1.循环遍历的方法 + //一 + //1.循环遍历的方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int CountClass = 0; + //int CountCode = 0; + + //foreach(char c in text) + //{ + // if (c == '类') + // { + // CountClass++; + // } + // else if (c == '码') + // { + // CountCode++; + // } + //} + + //Console.WriteLine($"类的个数:{CountClass}"); + //Console.WriteLine($"码的个数:{CountCode}"); + + //2.使用Replace方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int countClass = text.Length - text.Replace("类","").Length; + //int countCode = text.Length - text.Replace("码", "").Length; + + //Console.WriteLine($"类的个数:{countClass}"); + //Console.WriteLine($"码的个数:{countCode}"); + + //3.使用Split()方法来实现 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + //string[] words = text.Split(' ', '、', ',', '。', ':', ';'); + + //int countClass = 0; + //int countCode = 0; + + //foreach (string c in words) + //{ + // if (c == "类") + // { + // countClass++; + // } + // else if (c == "码") + // { + // countCode++; + // } + + // Console.WriteLine(c); + //} + + //Console.WriteLine("类的个数: " + countClass); + //Console.WriteLine("码的个数: " + countCode); + + //二 + string text = "C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。"; + + int countSpace = text.Length - text.Replace(" ", "").Length; + string newText = text.Replace(" ", ""); + + Console.WriteLine("空格的个数" + countSpace); + Console.WriteLine(newText); + //一 + //1.循环遍历的方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int CountClass = 0; + //int CountCode = 0; + + //foreach(char c in text) + //{ + // if (c == '类') + // { + // CountClass++; + // } + // else if (c == '码') + // { + // CountCode++; + // } + //} + + //Console.WriteLine($"类的个数:{CountClass}"); + //Console.WriteLine($"码的个数:{CountCode}"); + + //2.使用Replace方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int countClass = text.Length - text.Replace("类","").Length; + //int countCode = text.Length - text.Replace("码", "").Length; + + //Console.WriteLine($"类的个数:{countClass}"); + //Console.WriteLine($"码的个数:{countCode}"); + + //3.使用Split()方法来实现 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + //string[] words = text.Split(' ', '、', ',', '。', ':', ';'); + + //int countClass = 0; + //int countCode = 0; + + //foreach (string c in words) + //{ + // if (c == "类") + // { + // countClass++; + // } + // else if (c == "码") + // { + // countCode++; + // } + + // Console.WriteLine(c); + //} + + //Console.WriteLine("类的个数: " + countClass); + //Console.WriteLine("码的个数: " + countCode); + + //二 + string text = "C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。"; + + int countSpace = text.Length - text.Replace(" ", "").Length; + string newText = text.Replace(" ", ""); + + Console.WriteLine("空格的个数" + countSpace); + Console.WriteLine(newText); + //一 + //1.循环遍历的方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int CountClass = 0; + //int CountCode = 0; + + //foreach(char c in text) + //{ + // if (c == '类') + // { + // CountClass++; + // } + // else if (c == '码') + // { + // CountCode++; + // } + //} + + //Console.WriteLine($"类的个数:{CountClass}"); + //Console.WriteLine($"码的个数:{CountCode}"); + + //2.使用Replace方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int countClass = text.Length - text.Replace("类","").Length; + //int countCode = text.Length - text.Replace("码", "").Length; + + //Console.WriteLine($"类的个数:{countClass}"); + //Console.WriteLine($"码的个数:{countCode}"); + + //3.使用Split()方法来实现 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + //string[] words = text.Split(' ', '、', ',', '。', ':', ';'); + + //int countClass = 0; + //int countCode = 0; + + //foreach (string c in words) + //{ + // if (c == "类") + // { + // countClass++; + // } + // else if (c == "码") + // { + // countCode++; + // } + + // Console.WriteLine(c); + //} + + //Console.WriteLine("类的个数: " + countClass); + //Console.WriteLine("码的个数: " + countCode); + + //二 + string text = "C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。"; + + int countSpace = text.Length - text.Replace(" ", "").Length; + string newText = text.Replace(" ", ""); + + Console.WriteLine("空格的个数" + countSpace); + Console.WriteLine(newText); + //一 + //1.循环遍历的方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int CountClass = 0; + //int CountCode = 0; + + //foreach(char c in text) + //{ + // if (c == '类') + // { + // CountClass++; + // } + // else if (c == '码') + // { + // CountCode++; + // } + //} + + //Console.WriteLine($"类的个数:{CountClass}"); + //Console.WriteLine($"码的个数:{CountCode}"); + + //2.使用Replace方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int countClass = text.Length - text.Replace("类","").Length; + //int countCode = text.Length - text.Replace("码", "").Length; + + //Console.WriteLine($"类的个数:{countClass}"); + //Console.WriteLine($"码的个数:{countCode}"); + + //3.使用Split()方法来实现 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + //string[] words = text.Split(' ', '、', ',', '。', ':', ';'); + + //int countClass = 0; + //int countCode = 0; + + //foreach (string c in words) + //{ + // if (c == "类") + // { + // countClass++; + // } + // else if (c == "码") + // { + // countCode++; + // } + + // Console.WriteLine(c); + //} + + //Console.WriteLine("类的个数: " + countClass); + //Console.WriteLine("码的个数: " + countCode); + + //二 + string text = "C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。"; + + int countSpace = text.Length - text.Replace(" ", "").Length; + string newText = text.Replace(" ", ""); + + Console.WriteLine("空格的个数" + countSpace); + Console.WriteLine(newText); + + + //2.使用Replace方法 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + + //int countClass = text.Length - text.Replace("类","").Length; + //int countCode = text.Length - text.Replace("码", "").Length; + + //Console.WriteLine($"类的个数:{countClass}"); + //Console.WriteLine($"码的个数:{countCode}"); + + //3.使用Split()方法来实现 + //string text = "与其他面向对象语言一样,C# 语言也具有面向对象语言的基本特征,即封装、继承、 多态。封装:就是将代码看作一个整体,例如使用类、方法、接口等。在使用定义好的类、 方法、接口等对象时不必考虑其细节,只需要知道其对象名以及所需要的参数即可,也是一种提升代码安全性的方法。继承:是一种体现代码重用性的特性,减少代码的冗余,但在 C# 语言中仅支持单继承。多态:不仅体现了代码的重用性,也体现了代码的灵活性,它主要通过继承和实现接口的方式,让类或接口中的成员表现出不同的作用。"; + //string[] words = text.Split(' ', '、', ',', '。', ':', ';'); + + //int countClass = 0; + //int countCode = 0; + + //foreach (string c in words) + //{ + // if (c == "类") + // { + // countClass++; + // } + // else if (c == "码") + // { + // countCode++; + // } + + // Console.WriteLine(c); + //} + + //Console.WriteLine("类的个数: " + countClass); + //Console.WriteLine("码的个数: " + countCode); + + //二 + string text = "C# (英 文名为 CSharp) 是 微 软开发的一种 面向对 象的 编程 语言。C# 语言具备了面向对象 语言 的特 征, 即封装、继承、多态,并且添加了 事件和委托,增强了 编程的灵 活性。C# 语 言是 一种安全的、稳定的、简 单 的、面向对象的编程 语言 ,其语 法与 C++ 类似,但在编程过 程中要比 C++ 简单;它不仅去掉了 C++ 和 Java 语 言中的一些复杂特性,还提 供了可视化 工具,能够高效地 编写程序。C# 是运行 在.NE T平台之上的 编程 语言。"; + + int countSpace = text.Length - text.Replace(" ", "").Length; + string newText = text.Replace(" ", ""); + + Console.WriteLine("空格的个数" + countSpace); + Console.WriteLine(newText); + + } + } +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\272\214/Program.cs" "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\272\214/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..492b21e41460375654b1bc9e8d1e5aeb3e74512c --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\344\272\214/Program.cs" @@ -0,0 +1,89 @@ +namespace ConsoleApp5 +{ + internal class Program + { + static void Main(string[] args) + { + Dog dog = new Dog(); + dog.Eat(); + dog.Swim(); + Console.WriteLine("----------------"); + Duck duck = new Duck(); + duck.Eat(); + duck.Swim(); + Console.WriteLine("----------------"); + Cat cat = new Cat(); + cat.Eat(); + cat.Climb(); + Console.WriteLine("----------------"); + Monkey monkey = new Monkey(); + monkey.Eat(); + monkey.Climb(); + } + } + internal abstract class Animal + { + public abstract void Eat(); + + public virtual void Sleep() + { + Console.WriteLine("动物正在睡觉"); + } + } + internal class Cat : Animal, IClimb + { + public override void Eat() + { + Console.WriteLine("小猫在吃鱼"); + } + + public void Climb() + { + Console.WriteLine("小猫会爬树"); + } + } + internal class Dog : Animal, ISwim + { + public override void Eat() + { + Console.WriteLine("小狗正在吃骨头"); + } + + public void Swim() + { + Console.WriteLine("小狗会爬树"); + } + } + internal class Duck : Animal, ISwim + { + public override void Eat() + { + Console.WriteLine("鸭子正在吃稻谷"); + } + + public void Swim() + { + Console.WriteLine("鸭子会游泳"); + } + } + internal interface IClimb + { + void Climb(); + } + internal interface ISwim + { + void Swim(); + } + internal class Monkey : Animal, IClimb + { + public override void Eat() + { + Console.WriteLine("小猴吃香蕉"); + } + public void Climb() + { + Console.WriteLine("小猴会爬树"); + } + } + +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\215\201\345\233\233/Program.cs" "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\345\233\233/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..072fc85f4c569e2fb44da16723be3e6b8f03b84d --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\215\201\345\233\233/Program.cs" @@ -0,0 +1,108 @@ +using System.Data; + +namespace ConsoleApp7 +{ + internal class Program + { + static void Main(string[] args) + { + //server = 服务器名称 / 数据库的实例名; uid = 登录名; pwd = 密码; database = 数据库名称 + string constor = "server=DESKTOP-R34AU67;uid=sa;pwd=123456;database=Library"; + + SqlConnection con = null; + + try + { + con = new SqlConnection(constor); + + SqlCommand cmd = new SqlCommand(); + + cmd.Connection = con; + + con.Open(); + + //添加 + cmd.CommandText = "insert into LibraryInfo(bookId,bookName) values(8,'朝花夕拾')"; + + int result = cmd.ExecuteNonQuery(); + + if (result > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功,result:{result}"); + Get(); + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + + //删除 + cmd.CommandText = "delete from LibraryInfo where bookId=7;"; + result = cmd.ExecuteNonQuery(); + + if (result > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功,result:{result}"); + + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + + //修改 + cmd.CommandText = "update LibraryInfo set bookName='呼兰河传' where bookId=3"; + result = cmd.ExecuteNonQuery(); + + if (result > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功,result:{result}"); + + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + + } + catch (Exception ex) + { + Console.WriteLine("出现异常" + ex.Message); + } + finally + { + if (con != null) + { + con.Close(); + } + } + } + + public static void Get() + { + string constor = "server=DESKTOP-R34AU67;uid=sa;pwd=123456;database=Library"; + + string sql = "select * from LibraryInfo"; + + //1.创建数据库适配器 + SqlDataAdapter adapter = new SqlDataAdapter(sql, constor); + + //2.定义一个DataSet数据集对象,保存执行数据库查询后的结果集; + DataSet ds = new DataSet(); + + //3.Fill(集合对象):填充,将查询的结果集填充到集合对象中进行保存 + adapter.Fill(ds, "LibraryInfo"); + + //遍历行集合 + if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) + { + foreach (DataRow it in ds.Tables[0].Rows) + { + Console.WriteLine($"书本编号:{it[0]},书名:{it[1]}"); + } + } + } + + + } +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\345\233\233/Untitled.md" "b/10\346\236\227\347\216\211\346\225\217/\345\233\233/Untitled.md" new file mode 100644 index 0000000000000000000000000000000000000000..f21323e4b103f8b4a1eb95257ea09581e48ba92e --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\345\233\233/Untitled.md" @@ -0,0 +1,99 @@ +```c# +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + //1 + User user=new User(); + user.Print(); + //2 + string name=Console.ReadLine(); + string info=Console.ReadLine(); + string sex=Console.ReadLine(); + int age=Convert.ToInt32(Console.ReadLine()); + int id=int.Parse(Console.ReadLine()); + Students students=new Students(id,name,sex,info,age); + students.Print(); + //3 + string nameb=Console.ReadLine(); + string publicb=Console.ReadLine(); + string authorb=Console.ReadLine(); + double price=Convert.ToDouble(Console.ReadLine()); + int idb=int.Parse(Console.ReadLine()); + Book book=new Book(id,nameb,publicb,authorb,price); + book.Print(); + } + } + //1. 定义一个用户类,存放用户的账号、用户名和密码属性; + //在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息;然后在主方法调用输出; + public class User + { + public int Id { get; set; } + public string Name { get; set; } + public string Password { get; set; } + public void Print() + { + Console.WriteLine($"账号{Id}、用户名{Name}和密码属性{Password}"); + } + } + /*2. 定义一个学生类,存放学生的学号、姓名、性别、年龄、专业信息; + 对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + 在学生类中定义一个方法输出学生信息。 + 在主方法实例化对象,赋值并输出*/ + public class Students + { + public int Id; + public string Name; + public string Sex; + public string Info; + public int Age { + get { + if(Age<0&&Age>128) return 0; + else return Age; + } + set { Age = value; } + } + public Students(int id,string name,string sex,string info,int age) { + this.Id = id; + this.Name = name; + this.Sex = sex; + this.Info = info; + this.Age = age; + } + public string Print() + { + return $"学号{this.Id}、姓名{this.Name}、性别{this.Sex}、年龄{this.Age}、专业信息{this.Info}"; + } + } + /*3.定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; +对价格进行赋值限制,小于0价格,赋值为0 +在图书类中定义一个方法输出图书信息; +在主方法实例化对象,赋值并输出*/ + public class Book + { + public int Id; + public string Name; + public double Price { + get { if (Price < 0) return 0; else return Price; } + set { Price = value; } + } + public string Public; + public string Author; + public Book(int id, string name, string publics, string author,double price) + { + this.Id = id; + this.Name = name; + this.Author = author; + this.Public = publics; + this.Price = price; + } + public string Print() + { + return $"图书的编号{this.Id}、书名{this.Name}、价格{this.Price}、出版社{this.Public}、作者信息{this.Author}"; + } + } +} +``` + diff --git "a/10\346\236\227\347\216\211\346\225\217/\351\241\271\347\233\256/Program.cs" "b/10\346\236\227\347\216\211\346\225\217/\351\241\271\347\233\256/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9cfa03021736631658e898e2b1ae339068d8c393 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\351\241\271\347\233\256/Program.cs" @@ -0,0 +1,189 @@ +using System.Data.SqlClient; +using System.Xml.Linq; + +namespace 学生 +{ + internal class Program + { + public static SqlConnection con = new SqlConnection("server=CODER-HMZXZEHOT\\SQLEXPRESS;database=Tes;uid=sa;pwd=123456"); + static void Main(string[] args) + { + try + { + con.Open(); + while (true) + { + Console.WriteLine("欢迎来到学生管理系统,请选择您的操作:\n1.班级操作2.学生操作3.退出"); + int num = Convert.ToInt32(Console.ReadLine()); + if (num == 3) + { + Console.WriteLine("感谢您的使用,再见"); + break; + } + switch (num) + { + case 1: Find1(); break; + case 2: Find2(); break; + default: Console.WriteLine("没有该操作"); break; + } + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally { con.Close(); } + } + public static void Find1() + { + while (true) + { + Console.WriteLine("请选择您的操作:\n1.增加功能2.删除功能3.修改功能4.查询功能5.退出"); + int num = Convert.ToInt32(Console.ReadLine()); + if (num == 5) + { + Console.WriteLine("感谢您的使用,再见"); + break; + } + switch (num) + { + case 1: Add(); break; + case 2: Delete(); break; + case 3: Updata(); break; + case 4: View(); break; + default: Console.WriteLine("没有该操作"); break; + } + } + } + public static void Find2() + { + + } + // 增加功能: + + //​ 1) 要求接收用户输入班级名称 + + //​ 2)然后去查询数据库中的班级表是否存在该班级名称 + + //​ 3)存在就提示“班级名称重复,添加班级信息失败” + + //​ 4)不存在,就将班级信息保存到数据库的班级信息表中; + static public void Add() + { + Console.WriteLine("请输入您要添加的班级名称:"); + string cname = Console.ReadLine(); + int num = Check(cname); + //存在该班级 + if (num > 0) + { + Console.WriteLine("班级名称重复,添加班级信息失败"); + } + else + { + string a = "insert into Class(cname)values('{0}')"; + a = string.Format(a, cname); + SqlCommand add = new SqlCommand(a, con); + int result = add.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine("添加成功"); + } + } + } + public static int Check(string cname) + { + string sql = "select*from Class where cname='{0}'"; + sql = string.Format(sql, cname); + 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; + } + // 删除功能: + + //​ 1)要求用户输入要删除的班级编号; + + //​ 2)根据班级编号删除数据库中的班级信息 + + //​ 3)如果删除成功提示成功,如果没有要删除的班级编号数据提示删除失败 + public static void Delete() + { + Console.WriteLine("请输入您要删除的班级编号:"); + int id = Convert.ToInt32(Console.ReadLine()); + int num = Check(id); + if (num > 0) + { + string a = "delete from Class where cname={0}"; + a = string.Format(a, id); + SqlCommand add = new SqlCommand(a, con); + int result = add.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine("删除成功"); + } + } + else + { + Console.WriteLine("删除失败"); + } + } + // 修改功能: + + //​ 1)要求用户输入修改信息,需要修改的班级编号,以及修改后的班级名称信息; + + //​ 2)根据用户输入的信息修改班级信息表的数据; + + //​ 3)如果有对应的班级编号信息,提示修改成功,没有提示修改失败 + public static void Updata() + { + Console.WriteLine("请输入要修改的班级编号:"); + int id = Convert.ToInt32(Console.ReadLine()); + int num = Check(id); + if (num > 0) + { + Console.WriteLine("修改后的班级名称:"); + string cname = Console.ReadLine(); + string a = "update Class set cname='{0}' where id={1};"; + a = string.Format(a, cname, id); + SqlCommand add = new SqlCommand(a, con); + int result = add.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine("修改成功"); + } + } + else + { + Console.WriteLine("修改失败"); + } + + } + public static void View() + { + string sql = "select*from Class"; + SqlCommand com = new SqlCommand(sql, con); + SqlDataReader read = com.ExecuteReader(); + int num = com.ExecuteNonQuery(); + read.Close(); + } + } +} \ No newline at end of file diff --git "a/10\346\236\227\347\216\211\346\225\217/\351\241\271\347\233\256/SQLQuery1.sql" "b/10\346\236\227\347\216\211\346\225\217/\351\241\271\347\233\256/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..a926a0ca98df14f436404ac56ca9c76c76c26494 --- /dev/null +++ "b/10\346\236\227\347\216\211\346\225\217/\351\241\271\347\233\256/SQLQuery1.sql" @@ -0,0 +1,24 @@ +create database Tes; +go +use Tes +go +create table Class( +id int identity primary key, +cname nvarchar(50) +); +insert into Class(cname) values('һ'),(''),(''); + +go +create table Student( +id int, +sname nvarchar(50), +sex char(5), +age int, +cid int +foreign key (cid) references Class(id) +); +insert into Student values(13,'','Ů',18,1),(21,'','Ů',20,2),(33,'','',18,3); +go +select*from Class +select*from Student +