diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.png" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.png" new file mode 100644 index 0000000000000000000000000000000000000000..6982e4118b12598ae6eb1f7989c569190390b994 Binary files /dev/null and "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.png" differ diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..f837a2e691c4de579a6f93e82997cb319c4a02cb --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,335 @@ +```c# +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + Student s1 = new Student(); + s1.id = 1; + s1.name = "星黛露"; + s1.sex = '兔'; + s1.cardid = 350922204; + s1.tel = 149274293; + s1.major = "软件技术"; + s1.grade = 22; + s1.print(); + Console.WriteLine("------------------------------------------------"); + Teacher t1 = new Teacher(); + t1.id = 7; + t1.name = "谢老师"; + t1.sex = '女'; + t1.cardid = 29235754; + t1.tel = 32879825; + t1.title = "专业课老师"; + t1.wageno = 3; + t1.print(); + Console.WriteLine("------------------------------------------------"); + hero1 h1 = new hero1(); + h1.Id = 1; + h1.Name = "埃洛克"; + h1.Attack = 666; + h1.Defence = 453; + h1.Speed = 343; + h1.j1 = "碎石打击"; + h1.j2 = "烈焰锚钩"; + h1.j3 = "战斗咆哮"; + h1.print(); + Console.WriteLine("------------------------------------------------"); + hero2 h2=new hero2(); + h2.Id = 2; + h2.Name = "泰拉"; + h2.Attack = 679; + h2.Defence = 868; + h2.Speed = 788; + h2.n1 = "巨浪冲击"; + h2.n2 = "元素突击"; + h2.n3 = "复仇杀戮"; + h2.print(); + Console.WriteLine("------------------------------------------------"); + hero3 h3=new hero3(); + h3.Id = 3; + h3.Name = "卢卡斯"; + h3.Attack = 666; + h3.Defence = 453; + h3.Speed = 343; + h3.G1 = "减速陷阱"; + h3.G2 = "能量浪潮"; + h3.G3 = "旋风剑舞"; + h3.print(); + Console.WriteLine("------------------------------------------------"); + hero4 h4=new hero4(); + h4.Id = 4; + h4.Name = "洛菲"; + h4.Attack = 666; + h4.Defence = 453; + h4.Speed = 343; + h4.k1 = "能量精灵"; + h4.k2 = "暗影传送"; + h4.k3 = "时空迸裂"; + h4.print(); + Console.WriteLine("------------------------------------------------"); + } + } +} +//英雄父类 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Hero + { + // 二、使用类来描述游戏中的角色。 + //在很多RPG游戏中,第一次打开游戏,都会先让你创建自己的“英雄”,或者自己要扮演的角色。 + //这些英雄或者角色都是我们游戏中的“对象”,所以在开发的时候,我们需要针对每个角色都要写相应的类来描述。 + //见英雄文件夹的图片。 + //分析1: 角色具有以下信息(简单数据) + //字段:角色名字,角色介绍,角色昵称,攻击力,防御力,速度。 + //方法:每个角色都有三个不同的攻击技能。 + //分析2:四个英雄的公共数据?公共数据向上抽取,抽象成一个Hero类,然后四个英雄继承这个Hero类,然后编写各自特有的类成员。 + private int id; + private string name; + private string introduce; + private int attack; + private int defence; + private int speed; + + public int Id { get => id; set => id = value; } + public string Name { get => name; set => name = value; } + public string Introduce { get => introduce; set => introduce = value; } + public int Attack { get => attack; set => attack = value; } + public int Defence { get => defence; set => defence = value; } + public int Speed { get => speed; set => speed = value; } + public void print() + { + Console.WriteLine($"编号:{Id}"); + Console.WriteLine($"姓名:{Name}"); + Console.WriteLine($"介绍:{Introduce}"); + Console.WriteLine($"攻击力:{Attack}"); + Console.WriteLine($"防御值:{Defence}"); + Console.WriteLine($"速度{Speed}"); + } + } +} + +//英雄子类1 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace ConsoleApp1 +{ + internal class hero1:Hero + { + public string j1; + public string j2; + public string j3; + public string J1 { get; set; } + public string J2 { get; set; } + public string J3 { get; set; } + public void print() { + Console.WriteLine($"编号:{Id}"); + Console.WriteLine($"姓名:{Name}"); + Console.WriteLine($"介绍:{Introduce}"); + Console.WriteLine($"攻击力:{Attack}"); + Console.WriteLine($"防御值:{Defence}"); + Console.WriteLine($"速度:{Speed}"); + Console.WriteLine($"技能1:{j1}"); + Console.WriteLine($"技能2:{j2}"); + Console.WriteLine($"技能3:{j3}"); + } + } +} +//英雄子类2 +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ConsoleApp1 +{ + internal class hero2:Hero + { + public string n1; + public string n2; + public string n3; + public string N1 { get; set; } + public string N2 { get; set; } + public string N3 { get; set; } + public void print() + { + Console.WriteLine($"编号:{Id}"); + Console.WriteLine($"姓名:{Name}"); + Console.WriteLine($"介绍:{Introduce}"); + Console.WriteLine($"攻击力:{Attack}"); + Console.WriteLine($"防御值:{Defence}"); + Console.WriteLine($"速度:{Speed}"); + Console.WriteLine($"技能1:{n1}"); + Console.WriteLine($"技能2:{n2}"); + Console.WriteLine($"技能3:{n3}"); + } + } +} +//英雄子类3 +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ConsoleApp1 +{ + internal class hero3:Hero + { + public string g1; + public string g2; + public string g3; + public string G1 { get; set; } + public string G2 { get; set; } + public string G3 { get; set; } + public void print() + { + Console.WriteLine($"编号:{Id}"); + Console.WriteLine($"姓名:{Name}"); + Console.WriteLine($"介绍:{Introduce}"); + Console.WriteLine($"攻击力:{Attack}"); + Console.WriteLine($"防御值:{Defence}"); + Console.WriteLine($"速度:{Speed}"); + Console.WriteLine($"技能1:{G1}"); + Console.WriteLine($"技能2:{G2}"); + Console.WriteLine($"技能3:{G3}"); + } + } +} +//英雄子类4 +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ConsoleApp1 +{ + internal class hero4:Hero + { + public string k1; + public string k2; + public string k3; + public string K1 { get; set; } + public string K2 { get; set; } + public string K3 { get; set; } + public void print() + { + Console.WriteLine($"编号:{Id}"); + Console.WriteLine($"姓名:{Name}"); + Console.WriteLine($"介绍:{Introduce}"); + Console.WriteLine($"攻击力:{Attack}"); + Console.WriteLine($"防御值:{Defence}"); + Console.WriteLine($"速度:{Speed}"); + Console.WriteLine($"技能1:{k1}"); + Console.WriteLine($"技能2:{k2}"); + Console.WriteLine($"技能3:{k3}"); + } + } +} +//个人类 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class School + { +// 一、 假设要完成一个学校的校园管理信息系统,在员工管理系统中有不同的人员信息,包括学生信息、教师信息等。 +//学生的字段:编号(Id)、姓名(Name)、性别(Sex)、身份证号(Cardid)、联系方式(Tel)、专业(Major)、年级(Grade) +//教师的字段:编号(Id)、姓名(Name),性别 (Sex)、身份证号(Cardid)、联系方式(Tel)、职称(Title)、工资号(Wageno) +//方法一: +//为学生信息、教师信息创建两个类,并在两个类中分别定义属性和方法: +//学生类中定义编号(Id)、姓名(Name)、性别(Sex)、身份证号(Cardid)、联系方式(Tel)、专业(Major)、年级(Grade)7 个属性,并定义一个方法在控制台输出这些属性的值。 + +//教师类(Teacher)中定义编号(Id)、姓名(Name),性别 (Sex)、身份证号(Cardid)、联系方式(Tel)、职称(Title)、工资号(Wageno),并将上述属性输岀到控制台。 +//方法二: +//将 Student 类和 Teacher 类中共有的 属性抽取出来定义为一个类Person,并让Student和Teacher继承Person +//每个类都要有一个输出属性的方法。 +//每个类都要有初始化数据的有参构造方法。 + + public int id { get; set; } + public string name { get; set; } + public char sex { get; set; } + public int cardid { get; set; } + public int tel { get; set; } + public void print() { + Console.WriteLine($"编号:{id}"); + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"性别:{sex}"); + Console.WriteLine($"身份证号:{cardid}"); + Console.WriteLine($"联系方式:{tel}"); + } + } +} +//学生类 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Student:School + { + public string major { get; set; } + public int grade { get; set; } + public void print() { + Console.WriteLine($"编号:{id}"); + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"性别:{sex}"); + Console.WriteLine($"身份证号:{cardid}"); + Console.WriteLine($"联系方式:{tel}"); + Console.WriteLine($"专业:{major}"); + Console.WriteLine($"年级:{grade}"); + } + } +} +//教师类 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Teacher:School + { + public string title { get; set; } + public int wageno { get; set; } + public void print() { + Console.WriteLine($"编号:{id}"); + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"性别:{sex}"); + Console.WriteLine($"身份证号:{cardid}"); + Console.WriteLine($"联系方式:{tel}"); + Console.WriteLine($"职称:{title}"); + Console.WriteLine($"工资号:{wageno}"); + } + } +} + +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..84c9bb04757ad743dd52d78f63664ea43fdeed94 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,240 @@ +```c# +using System.Drawing; +using System.Globalization; +using System.Threading.Channels; +using System; + +namespace ConsoleApp3 +{ + internal class Program + { + static void Main(string[] args) + { + //1.求圆的面积 + //要求用户输入半径的值,打印出以此值为半径的圆的面积 + //求圆的面积的公式:πr²。 + //圆周率π定义成常量取3.14。 + //r由用户输入并存入一个变量中此变量用double比较合适,因为用户可能会输入小数。 + Console.WriteLine("请输入圆的半径"); + double a = double.Parse(Console.ReadLine()); + Console.WriteLine("圆的面积为" + a * a * 3.14); + + //2.编写一个程序,请用户输入一个四位整数,将用户输入的四位数的千位、百位、十位和个位分别显示出来,如5632,则显示“用户输入的千位为5,百位为6,十位为3,个位为2” + Console.WriteLine("请输入一个四位数"); + int b = int.Parse(Console.ReadLine()); + Console.WriteLine("这个四位数的千位为" + b / 1000); + Console.WriteLine("这个四位数的百位为" + b / 100 % 10); + Console.WriteLine("这个四位数的十位为" + b / 10 % 10); + Console.WriteLine("这个四位数的个位为" + b % 10); + + //3.用户输入三个数,找出最大的数,打印输出。 + Console.WriteLine("请输入第一个数字"); + int first = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入第二个数字"); + int second = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入第三个数字"); + int thrid = int.Parse(Console.ReadLine()); + if (first > second && first > thrid) { + Console.WriteLine("最大的数字为" + first); + } else if (second > first && second > thrid) { + Console.WriteLine("最大的数字为" + second); + } else if (thrid > second && thrid > first) { Console.WriteLine("最大的数字为" + thrid); }; + + //4.接受用户输入一个数n,求这个数的阶乘;5! = 5 * 4 * 3 * 2 * 1; + Console.WriteLine("请输入一个数字"); + int num = int.Parse(Console.ReadLine()); + int final = 1; + for (int i = 1; i <= num; i++) { + final = final * i; + }; + Console.WriteLine("这个数的阶乘为"+final); + Console.ReadKey(); + //5.接受用户输入的一个数n,求n到1所有数的阶乘和;n! + (n - 1!) + (n - 2)! +……+1! + Console.WriteLine("请输入一个数字"); + int n = int.Parse(Console.ReadLine()); + int result = 1; + int sum = 0; + for(int i = 1; i <= n; i++) + { + result = result * i; + sum += result; + }; + Console.WriteLine("这个数的阶乘和为" + sum); + Console.ReadKey(); + //6.根据用户输入的菱形边长,打印菱形;如边长为3,行数为5; + Console.WriteLine("请输入菱形边长(大于2)"); + int length = Convert.ToInt32(Console.ReadLine()); + for (int i = 1; i <= length; i++) + { + for (int j = 1; j <= length - i; j++) + { + Console.Write(" "); + } + for (int k = 1; k <= 2 * i - 1; k++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + for (int i = length-1; i >= 1; i--) + { + for (int j = 1; j <= length - i; j++) + { + Console.Write(" "); + } + for (int k = 1; k <= 2 * i - 1; k++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + + + //7.用循环打印九九乘法表(用二维数组保存字符串后再打印) + for (int i = 1; i <= 9; i++) { + for (int j = 1; j <= i; j++) { + Console.Write($"{i}*{j}={i*j}\t"); + }; + Console.WriteLine(); + }; + Console.ReadKey(); + + + //8.输入一行字符串,分别统计出其中英文字母、数字、空格的个数。 + Console.WriteLine("请输入一行字符串"); + int word = 0; + int count = 0; + int kong = 0; + char[] str = Console.ReadLine().ToCharArray(); + foreach (char i in str) + { + if (i >= 'a' && i <= 'z' || i >= 'A' && i <= 'Z') + word++; + else if (i >= '0' && i <= '9') + + count++; + else if (i == ' ') + kong++; + + } + Console.WriteLine("字母有"+word+"个"+"数字有"+count+"个"+"空格有"+kong+"个"); + Console.ReadLine(); + //9.在 Main 方法中创建一个 double 类型的数组,并在该数组中存入 5 名学生的考试成绩,计算总成绩和平均成绩。(要求使用foreach语句实现该功能) + double[] scores = { 98, 89, 87, 93, 94 }; + double sum2 = 0; + double avg = 0; + foreach (double d in scores) { + sum2 = sum2 + d; + } + avg = sum2 / scores.Length; + Console.WriteLine("这五位学生的总成绩为"+sum2+"\t"+"平均分为"+avg); + + //10.定义一个方法,实现一维数组的排序功能,从大到小排序。(不要用Array类的方法) + int[] arr = { 56, 35, 47,98, 76 }; + for (int i = 0; i < arr.Length; i++) { + for (int j = 0; j < arr.Length - i - 1; j++) { + if (arr[j] > arr[j + 1]) { + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } + Console.WriteLine("升序排序后的结果为" ); + foreach (int x in arr) + { + Console.Write(x + "\t"); + } + Console.WriteLine(); + + + + //11.实现查找数组元素索引的功能。定义一个数组,然后控制台输入要查找的元素,返回输入值在数组中最后一次出现的位置。若是找不到,请打印找不到。(不要用Array类的方法) + int[] z = new int[5]{ 12, 34, 56, 32, 67 }; + Console.WriteLine("请输入你要查找的元素"); + int h = int.Parse(Console.ReadLine()); + int index = getDataIndex(z,h); + if (index == -1) + { + Console.WriteLine("找不到"); + } + else { + Console.WriteLine(index); + } + Console.ReadKey(); + //12.在 Main 方法中创建一个字符串类型的数组,并存入 5 个值,然后将数组中下标是偶数的元素输出。 + int[] arr3 = {12,34,43,54,42}; + for (int i = 0; i <= arr3.Length; i++) { + if (arr3[i] % 2 == 0) + { + Console.WriteLine("偶数为" + arr3[i]); + } + } + + + //13.用户输入正方形边长,用* 打印出空心正方形。 + Console.WriteLine("请输入空心正方形边长"); + int chang = int.Parse(Console.ReadLine()); + for (int i = 0; i < chang; i++) + { + for (int j = 0; j < chang; j++) + { + if (i == 0 || i == chang - 1) + { + Console.Write("*"); + } + else if (j == 0 || j == chang - 1) + { + Console.Write("*"); + } + else + { + Console.Write(" "); + } + } + Console.Write("\n"); + } + + + + //14.用户输入正方形边长,用* 打印出实心正方形。 + Console.WriteLine("请输入实心正方形边长"); + int bian = int.Parse(Console.ReadLine()); + if (bian > 1) + { + for (int i = 1; i <= bian; i++) + { + for (int j = 1; j <= bian; j++) + { + Console.Write("*"); + } + Console.WriteLine(); + } + } + else + { + Console.WriteLine("数字请大于1"); + } + + + //15.用二维数组存放数据,实现杨辉三角形的打印; + int[,] arr4 = new int[10, 10]; + for (int i = 0; i < 10; i++) + { + for (int j = i; j >= 0; j--) + { + if (j == 0 || j == i) + { + arr4[i, j] = 1; + } + else + { + arr4[i, j] = arr4[i - 1, j - 1] + arr4[i - 1, j]; + } + Console.Write(arr4[i, j] + "\t"); + } + Console.WriteLine(); + } + +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..62cc162619fc8545fa0763eb5c78118729dc6de8 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,251 @@ +```c# +using System.Security.Cryptography; + +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + cat c1 = new cat("加菲猫", 2, 8, "黄色", 6); + c1.nightvision(); + c1.Eat(); + Console.WriteLine("------------------------------------"); + bird b1 = new bird("安小鸟", 2, 45, "白色"); + b1.fly(); + Console.WriteLine("------------------------------------"); + fox f1 = new fox("玲娜贝儿", 2, 6, "粉色"); + f1.Eat(); + Console.WriteLine("------------------------------------"); + dog d1 = new dog("玉桂狗", 2, 7, "蓝色"); + d1.Sleep(); + d1.nightvision(); + Console.WriteLine("------------------------------------"); + pig p1 = new pig("猪猪侠", 2, 15, "红色"); + p1.Scream(); + p1.fly(); + Console.WriteLine("------------------------------------"); + rabbit r1 = new rabbit("美乐蒂", 2, 6, "粉白色"); + r1.Scream(); + r1.fly(); + Console.WriteLine("------------------------------------"); + doctor o1 = new doctor(); + o1.Name = "陈医生"; + o1.Sex = '男'; + o1.Age = 22; + o1.work(); + Console.WriteLine("------------------------------------"); + programmer e1 = new programmer(); + e1.Name = "玲酱"; + e1.Sex = '女'; + e1.Age = 19; + e1.work(); + Console.WriteLine("------------------------------------"); + cleaner g1 = new cleaner(); + g1.Name = "朝夕"; + g1.Sex = '男'; + g1.Age = 33; + g1.work(); + + +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Override + { + //4. 定义狐狸、狗、猪、兔子四个子类,并且在这些子类中重写Animal中吃和叫的方法; + } + internal class fox:cat { + public fox(string name, int leg, int weight, string color) + { + base.Name = name; + base.Leg = leg; + base.weight = weight; + base.Color = color; + } + public fox() { } + public override void Eat() + { + base.Eat(); + Console.WriteLine($"{Name}爱吃星黛露"); + } + } + internal class dog:cat { + public dog(string name, int leg, int weight, string color) + { + base.Name = name; + base.Leg = leg; + base.weight = weight; + base.Color = color; + } + public dog() { } + public override void Sleep() { + base.Sleep(); + Console.WriteLine($"{Name}爱和美乐蒂一起睡觉"); + } + } + internal class pig : bird { + public pig(string name, int leg, int weight, string color) + { + base.Name = name; + base.Leg = leg; + base.weight = weight; + base.Color = color; + } + public pig() { } + public override void Scream() { + base.Scream(); + Console.WriteLine($"{Name}叫bond,GG bond"); + } + } + internal class rabbit : bird{ + public rabbit(string name, int leg, int weight, string color) + { + base.Name = name; + base.Leg = leg; + base.weight = weight; + base.Color = color; + } + public rabbit() { } + public override void Scream() + { + base.Scream(); + Console.WriteLine($"{Name}叫melody"); + } + } + +} + + using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Animal + { + // 有四种动物,使用代码的继承关系来表示动物之间的关系 + //1. 动物类:具有动物的共同属性:腿,重量等;共同行为:吃,叫,睡 + //2. 猫科类:具有猫科动物的共同属性:胡须等,共同能力:夜视能力 + //3. 鸟类:具有鸟类的共同行为:飞行 + public string Name { get; set; } + public int Leg { get; set; } + public int weight { get; set; } + public string Color { get; set; } + public Animal(string name, int leg, int weight, string color) + { + Name = name; + Leg = leg; + this.weight = weight; + Color = color; + } + public Animal() { } + public virtual void Eat() { + Console.WriteLine($"{Name}爱吃榴莲千层,蟹黄堡,铜锣烧"); + } + public virtual void Sleep() { + Console.WriteLine($"{Name}趴着睡觉"); + } + public virtual void Scream() { + Console.WriteLine($"{Name}我会叫"); + } + } + internal class cat : Animal { + + public int bread { get; set; } + public cat(string name,int leg,int weight,string color,int bread) + { + base.Name = name; + base.Leg = leg; + base.weight = weight; + base.Color= color; + this.bread = bread; + } + public cat() { } + public void nightvision() { + Console.WriteLine($"{Name}在夜里行动自如"); + } + } + internal class bird:Animal { + public bird(string name, int leg, int weight, string color) + { + base.Name = name; + base.Leg = leg; + base.weight = weight; + base.Color = color; + } + public bird() { } + public void fly() { + Console.WriteLine($"{Name}会冰嬉,在冰上飞"); + } + } +} + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ConsoleApp1 +{ + internal class employee + { + // 一.员工系统 + //1. 定义一个员工类,作为基类,包含姓名,性别,年龄等属性;包含一个方法代表工作的行为 + + //2. 定义一个医生类,继承员工类,重写工作的方法,描述医生的具体工作 + + //3. 定义一个程序员类,继承员工类,重写工作方法,描述程序员具体工作 + + //4. 定义一个清洁工类,继承员工类,重写工作方法,描述清洁工的具体工作 + + //5. 在主方法中为每个类实例化一个对象,用每个对象调用工作方法; + public string Name { get; set; } + public Char Sex { get; set; } + public int Age { get; set; } + public employee(string name, char sex, int age) + { + Name = name; + Sex = sex; + Age = age; + } + public employee() { } + public virtual void work() { + Console.WriteLine($"卑微打工人{Name}开始工作了"); + } + } + internal class doctor:employee { + public override void work() + { + base.work(); + Console.WriteLine($"{Name}妙手回春,药到命除"); + } + } + internal class programmer : employee { + public override void work() + { + base.work(); + Console.WriteLine($"程序员{Name}键盘敲烂,收入过万"); + } + } + internal class cleaner : employee + { + public override void work() + { + base.work(); + Console.WriteLine($"清洁工{Name}打扫卫生"); + } + } +} +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232 .md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232 .md" new file mode 100644 index 0000000000000000000000000000000000000000..a68889962e8ad683b8c5f0107ac730146811c7a6 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232 .md" @@ -0,0 +1,103 @@ +```c# +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("善学如春起之苗"); + Console.WriteLine("不见其增,日有所长"); + Console.WriteLine("假学如磨刀之石"); + Console.WriteLine("不见其损,年有所亏"); + Console.WriteLine("加油吧!少年"); + Console.WriteLine("J"); + Console.WriteLine("A"); + Console.WriteLine("V"); + Console.WriteLine("A"); + Console.WriteLine("!"); + } + } + internal class Program1 + { + static void Main(string[] args) + { + Console.WriteLine("true"); + Console.WriteLine("false"); + } + } + + internal class Program2 { + static void Main(string[] args) + { + sbyte a = -128; + Console.WriteLine(a); + byte b = 127; + Console.WriteLine(b); + short c = -32768; + Console.WriteLine(c); + short d = 32767; + Console.WriteLine(d); + int e = -2147483648; + Console.WriteLine(e); + int f = 2147483647; + Console.WriteLine(f); + long g = -2147483649; + Console.WriteLine(g); + long h = 2147483648; + Console.WriteLine(h); + } + } + + internal class Program3 { + static void Main(string[] args) + { + float i = -3.14F; + Console.WriteLine(i); + float j = 3.14F; + Console.WriteLine(j); + double k = -3.4; + Console.WriteLine(k); + double l = 3.4; + Console.WriteLine(l); + } + } + + internal class Program4 + { + static void Main(string[] args) + { + int a = 10; + int b = 20; + int temp = 10; + a = b; + b=temp; + Console.WriteLine("a的值是" + a); + Console.WriteLine("b的值是"+ b); + } + } + internal class Program5 + { + static void Main(string[] args) { + int x = 100; + int y = 200; + Console.WriteLine("x和y的和为" + (x + y)) ; + Console.WriteLine("x和y的差为"+(x-y)); + Console.WriteLine("x和y的积为" + (x * y)); + Console.WriteLine("x和y的商为" +(x / y)); + } + } + internal class Program6 + { + static void Main(string[] args) + { + double x = 100.8; + double y = 20.6; + Console.WriteLine("x和y的和为" + (x + y)); + Console.WriteLine("x和y的差为" + (x - y)); + Console.WriteLine("x和y的积为" + (x * y)); + Console.WriteLine("x和y的商为" + (x / y)); + } + } +} +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..8d54ad8e8f701ddf00ce17c476d7bd02811ec792 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,367 @@ +```c# +namespace 类和属性作业 +{ + internal class User + { +## 练习 + + // 一.定义一个用户类 + //1.定义字段存放用户的账号、用户名和密码; + //2.在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息; + //3.在用户类中定义一个 登录身份辨认的方法:规则为用户名为“admin”和密码为“123456”时返回“管理员”,否则返回“普通用户”; + //4.在主方法中实例化用户类的对象,然后对其账号、用户名和密码赋值 + //5.在主方法中用实例化的对象调用方法,输出用户对象的信息和身份(管理员或者普通用户) + public int id; + public string name; + public int password; + public void show() + { + Console.WriteLine("该用户的账号为:" + id); + Console.WriteLine("该用户的用户名为:" + name); + Console.WriteLine("该用户的密码为:" + password); + } + public string Identity() + { + if (name == "admin" && password == 123456) + { + return "管理员"; + } + else + { + return "普通用户"; + } + } + //二.定义一个学生类 + //1.定义字段存放学生的学号、姓名、性别、年龄、专业信息; + //2.对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; + //3.在学生类中定义一个方法输出学生信息。 + //4. 在主方法实例化学生对象,赋值并输出 + + internal class student + { + private int no; + private string name; + private int sex; + private int age; + private string major; + public int No + { + get + { + return no; + } + set + { + no = value; + } + } + public string Name + { + get + { + return name; + } + set + { + name = value; + } + } + public int Sex + { + get + { + return sex; + } + set + { + sex = value; + } + } + public int Age + { + get + { + return age; + } + set + { + if (age < 0 || age > 128) + { + age = 0; + } + else + { + age = value; + } + } + } + public string Major + { + get + { + return major; + } + set + { + major = value; + } + } + public void Show() + { + Console.WriteLine("该学生的学号为:" + no); + Console.WriteLine("该学生的姓名为:" + name); + Console.WriteLine("该学生的性别为:" + sex); + Console.WriteLine("该学生的年龄为:" + age); + Console.WriteLine("该学生的专业信息为:" + major); + } + } +// 三.定义一个图书类 + //1.定义字段存放图书的编号、书名、价格、出版社、作者信息; + //2.对价格进行赋值限制,小于0价格,赋值为0 + //3.在图书类中定义一个方法输出图书信息; + //4.在主方法实例化对象,赋值并输出 + internal class book { + public int no; + public string name; + private int price; + public string publisher; + public string author; + public int Price { + get { + return price; + } + set { + if (price < 0) + { + price = 0; + } + else { + price = value; + } + } + } + public void Show() { + Console.WriteLine($"编号:{no}"); + Console.WriteLine($"书名:{name}"); + Console.WriteLine($"价格:{price}"); + Console.WriteLine($"出版社:{publisher}"); + Console.WriteLine($"作者信息:{author}"); + } + } + //四.定义一个敌人类 +//1. 定义可以存放敌人的血量、攻击力和魔法值字段; +//2.要求敌人的血量、攻击力和魔法值都只能设置为大于等于0的值;如果小于0则将字段值设置为0 +//3.在类中定义方法代表敌人具有攻击和逃跑的行为 +//4.在主方法中实例化2个敌人对象,为属性赋值,并输出对象的属性值; +//5.使用一个对象调用攻击方法,使用一个对象调用逃跑方法 +internal class enemy { + public string name; + private int blood; + private int shoot; + private int magic; + public int Blood { + get { + return blood; + } + set + { + if (blood < 0) + { + blood = 0; + } + else { + blood = value; + } + } + } + public int Shoot + { + get + { + return shoot; + } + set + { + if (shoot < 0) + { + shoot = 0; + } + else + { + shoot = value; + } + } + } + public int Magic + { + get + { + return magic; + } + set + { + if (magic < 0) + { + magic = 0; + } + else + { + magic = value; + } + } + } + public void attack() { + Console.WriteLine($"{name}正在发起攻击"); + } + public void run() { + Console.WriteLine($"{name}已逃跑"); + } +} + +//五.定义英雄类(Hero) +//1.英雄类中的属性包括:姓名、攻击力、防御力、生命值和魔法值; +//2.方法包括:攻击、介绍。 +//3.在主方法中实例化英雄对象,赋值并调用方法 +internal class hero { + public string name; + public int attack; + public int defense; + public int life; + public int magic; + public void shoot() { + Console.WriteLine($"{name}正在发起攻击"); + } + public void introduce() { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"攻击力:{attack}"); + Console.WriteLine($"防御力:{defense}"); + Console.WriteLine($"生命值:{life}"); + Console.WriteLine($"魔法值:{magic}"); + } +} internal class Count + { + //1. 定义一个计算图形面积的类,类中定义2个计算面积的方法(重载,方法名相同),分别计算圆面积和长方形面积两个方法。 + + public double mianji(int r) + { + return 3.14 * r * r; + } + public float mianji(float a, float b) + { + return (float)a * (float)b; + } + + } + // 2.创建一个名为计算工具类 SumUtils,在类中定义4个方法: + // 计算两个整数相加、 + // 两个小数相加、 + // 两个字符串相加、 + // 以及从 1 到指定整数的和的方法。 + //在 Main 方法中分别调用定义好的方法。 + internal class SumUtils + { + public int sum(int a, int b) + { + return a + b; + } + public Double sum(double c, double d) + { + return c + d; + } + public string sum(string e, string f) + { + return e + f; + } + public int Sum1(int c) + { + int sum1 = 0; + for (int i = 0; i <= c; i++) + { + sum1 = sum1 + i; + } + return sum1; + } + +} + + + +Prpgram.cs + namespace 类和属性作业 +{ + internal class Program + { + static void Main(string[] args) + { + User u1 = new User(); + u1.id=2344; + u1.name = "admin"; + u1.password = 123456; + u1.show(); + Console.WriteLine("-----------------------------------------------------------------------------"); + student s1 = new student(); + s1.No = 7; + s1.Name = "郑玉玲"; + s1.Sex = 1; + s1.Age = 19; + s1.Major = "软件技术"; + s1.Show(); + Console.WriteLine("------------------------------------------------------------------------------------"); + enemy e1 = new enemy(); + e1.Blood = 999; + e1.Shoot = 888; + e1.Mofa = 1400; + enemy e2 = new enemy(); + e2.Blood = 908; + e2.Shoot = 2342; + e2.Mofa = 344; + Count c1 = new Count(); + Console.WriteLine($"圆的面积为:{c1.mianji(3)}"); + Console.WriteLine($"长方形的面积为:{c1.mianji(5,6)}"); + Console.WriteLine("----------------------------------------------------"); + SumUtils s1 = new SumUtils(); + Console.WriteLine($"这两个整数的和为:{s1.sum(4,7)}"); + Console.WriteLine($"这两个小数的和为:{s1.sum(3.2,5.7)}"); + Console.WriteLine($"这两个字符串的和为:{s1.sum("玲娜贝儿","星黛露")}"); + Console.WriteLine($"和为:{s1.Sum1(6)}"); + Console.WriteLine("----------------------------------------------------"); + book b1 = new book(); + b1.no = 1; + b1.name = "追风筝的人"; + b1.Price = 232; + b1.publisher = "新华出版社"; + b1.author = "YULING"; + b1.Show(); + Console.WriteLine("----------------------------------------------------"); + enemy e1 = new enemy(); + e1.name = "超人强"; + e1.Blood = 999; + e1.Shoot = 445; + e1.Magic = 786; + enemy e2 = new enemy(); + e2.name = "猪猪侠"; + e2.Blood = 797; + e2.Shoot = 789; + e2.Magic = 799; + Console.WriteLine("e1的血量为:"+e1.Blood+"\t"+"攻击力为:"+e1.Shoot+"\t"+"魔法值为:"+e1.Magic); + Console.WriteLine("e2的血量为:" + e2.Blood+"\t"+"攻击力为:" + e2.Shoot+"\t"+ "魔法值为:" + e2.Magic); + e1.run(); + e2.attack(); + Console.WriteLine("----------------------------------------------------"); + hero h1 = new hero(); + h1.name = "陈"; + h1.attack = 693; + h1.defense = 797; + h1.life = 786; + h1.magic = 686; + h1.shoot(); + hero h2 = new hero(); + h2.name = "召玺"; + h2.attack = 693; + h2.defense = 797; + h2.life = 786; + h2.magic = 686; + h2.introduce(); + Console.WriteLine("----------------------------------------------------"); +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..041b8ec0e9483d5667e3daff568b5125ff342251 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,356 @@ +```c# +using static System.Net.Mime.MediaTypeNames; + +namespace ConsoleApp1 +{ + internal class Program + { + public static void Main(string[] args) + { + programmer p1 = new programmer("小郑","福建省宁德市","2004年03月",4000); + p1.print(); + Console.WriteLine("------------------------------------------------------------------"); + mannger m1 = new mannger("丹丹", "福建省龙岩市", "2003年10月", 3000); + m1.print(); + Console.WriteLine("------------------------------------------------------------------"); + mishu a1 = new mishu("coco","福建省福州市","2004年04月",3000); + a1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + cleaner c1 = new cleaner("Lily", "福建省厦门市", "2004年5月", 1000); + c1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + san s1 = new san(3,7,5); + s1.mj = (3 + 7 + 5) / 2; + s1.zc = 3 + 7 + 5; + s1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + si i1 = new si(5,6); + i1.mj = i1.c * i1.k; + i1.zc=(i1.c+i1.k)*2; + i1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + yuan y1 = new yuan(5); + y1.mj = y1.r * y1.r * 3.14; + y1.zc = 2 * 3.14 * y1.r; + y1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + groupleader g1= new groupleader("玲酱",4,8000); + g1.wage = g1.mwage + 1000 * g1.age; + g1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + manager n1 = new manager("玺子", 7, 9000,20); + n1.wage=n1.mwage + 1000 * n1.age*n1.bpay; + n1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + AccountManager d1 = new AccountManager("cc",7887,6,60); + d1.wage=d1.wage + 1000 * d1.age*d1.bpay; + d1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + car f1 = new car("帕拉梅拉",4,2199,4); + f1.print(); + Console.WriteLine("-------------------------------------------------------------------"); + Truck t1 = new Truck("帕拉梅拉", 4, 2199, 4000); + t1.print(); + } + } +} + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ConsoleApp1 +{ + internal class employee + { + // 一、雇员系统,定义雇员基类,共同的属性,姓名、地址和出生日期(可有可无),子类:程序员,秘书,高层管理,清洁工,他们有不同的工资算法, + // 其中高级主管和程序员采用底薪加提成的方式,高级主管和程序员的底薪分别是5000元和2000元 ,秘书和清洁工采用工资的方式,工资分别是3000和1000, + public string name; + public string address; + public string birthday; + } + internal class programmer:employee { + int bpay=2000; + private int add; + + public int Add { get; set; } + public programmer (){ + } + public programmer(string name,string address,string birhtday,int add) { + base.name= name; + base.address= address; + base.birthday= birhtday; + this.add= add; + } + public void print() { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"底薪:{bpay}"); + Console.WriteLine($"加成:{add}"); + Console.WriteLine($"总工资:{bpay+add}"); + } + } + internal class mannger : employee { + int bpay = 5000; + private int add; + + public int Add { get => add; set => add = value; } + public mannger() + { + } + public mannger(string name, string address, string birhtday, int add) + { + base.name = name; + base.address = address; + base.birthday = birhtday; + this.add = add; + } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"底薪:{bpay}"); + Console.WriteLine($"加成:{add}"); + Console.WriteLine($"总工资:{bpay + add}"); + } + } + internal class mishu:employee { + public int wage { get; set; } + public mishu() + { + } + public mishu(string name, string address, string birhtday, int wage) + { + base.name = name; + base.address = address; + base.birthday = birhtday; + this.wage = wage; + } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"总工资:{wage}"); + } + } + internal class cleaner: employee { + public int wage { get; set; } + public cleaner() { } + public cleaner(string name,string address,string birthday,int wage) { + base.name = name; + base.address = address; + base.birthday = birthday; + this.wage = wage; + } + public void print() + { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"地址:{address}"); + Console.WriteLine($"出生日期:{birthday}"); + Console.WriteLine($"总工资:{wage}"); + } + } +} + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class graph + { + //三、图形类: + // 求周长,面积(三角形, 四边形, 圆形) + public double zc { get; set; } + public double mj { get; set; } + public void print() { + Console.WriteLine($"面积:{mj}"); + Console.WriteLine($"周长:{zc}"); + } + } + internal class san : graph { + public san() { } + public san(double b1, double b2, double b3) + { + this.b1 = b1; + this.b2 = b2; + } + + public double b1 { get; set; } + public double b2 { get; set; } + public double b3 { get; set; } + public void print() { + base.print(); + } + } + internal class si : graph { + public si(double c, double k) + { + this.c = c; + this.k = k; + } + + public double c { get; set; } + public double k { get; set; } + public void print() { + base.print(); + } + } + internal class yuan:graph{ + public yuan(double r) + { + this.r = r; + } + + public double r { get; set; } + public void print() { + base.print(); + } + } +} + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Vehicle + { + //五、设计一个汽车类Vehicle,包含的属性有汽车品牌brand、车轮个数wheels和车重weight。 + //小车类Car是Vehicle的子类,其中包含的属性有载人数loader。 + //卡车类Truck是Car类的子类,其中包含的属性有载重量payload。 + //每个类都有构造方法和输出相关数据的方法。 + public string brand { get; set; } + public int wheels { get; set; } + public int weight { get; set; } + public void print() + { + Console.WriteLine($"品牌:{brand}"); + Console.WriteLine($"车轮数量:{wheels}"); + Console.WriteLine($"车重:{weight}"); + } + } + internal class car : Vehicle + { + public car(string brand, int wheels, int weight, int loader) + { + base.brand = brand; + base.wheels = wheels; + base.weight = weight; + this.loader = loader; + } + + public int loader { get; set; } + public void print() + { + base.print(); + Console.WriteLine($"载人数:{loader}"); + } + } + internal class Truck:Vehicle + { + public int payload { get; set; } + public Truck(string brand, int wheels, int weight, int payload) + { + base.brand = brand; + base.wheels = wheels; + base.weight = weight; + this.payload = payload; + } + public void print (){ + base.print(); + Console.WriteLine($"可载重量:{payload}"); + } + } +} + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class staff + { + //四、员工类Employee + // 字段:姓名,工作年限,月薪、 + + //组长(GroupLeader): 月薪 + 1000 * 年限 + //经理(Manager) :月薪 + 1000 * 年限 * 基础分红;需要增加一个 字段:基础分红1000 + //客户经理(AccountManager):月薪 + 1000 * 年限 * 分红(基础分红 * 3) + + //求组长,经理的年薪。 + public string name { get; set; } + public int age { get; set; } + public int mwage { get; set; } + public void print() { + Console.WriteLine($"姓名:{name}"); + Console.WriteLine($"年限:{age}"); + Console.WriteLine($"月薪:{mwage}"); + } + } + internal class groupleader : staff { + public groupleader(string name, int age, int mwage) + { + this.name = name; + this.age = age; + this.mwage = mwage; + } + + public int wage { get; set; } + public void print() { + base.print(); + } + } + internal class manager:staff{ + public manager(string name, int age, int mwage,int bpay) + { + this.name = name; + this.age = age; + this.mwage = mwage; + } + public int wage { get; set; } + public int bpay { get; set; } + public void print() + { + base.print(); + } + } + internal class AccountManager:staff { + public AccountManager(string name, int age, int mwage, int bpay) + { + this.name = name; + this.age = age; + this.mwage = mwage; + this.bpay = bpay; + } + + public int bpay { get; set; } + public int wage { get; set; } + public void print() + { + base.print(); + } + } +} + +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..c3ba1fec20fe6740804dc0e631637e031e853af3 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,82 @@ +```c# +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class ArrUtils + { + //2、写一个工具类ArrayUtil,在里面定义一个静态方法,用来判断数组是否为空。 + //如果数组是null,或者数组长度为0,那此方法返回true,否则返回false + //然后在主类中(有Main方法的类)调用测试。 + + public static Boolean Isnull(int[] sc) + { + if (sc == null || sc.Length == 0) + { + return true; + } + else + { + return false; + } + } + } +} + + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class StringUtil + { + // 1、写一个工具类StringUtil,在里面定义一个静态方法,用来判断字符串是否为空。 + //如果字符串是null,或者字符串是空"",或者字符串是N个空格" ",那这个方法返回true,否则返回false + //然后在主类中(有Main方法的类)调用测试。 + public static Boolean Pandaun(string str) + { + if (str == null || str == " ") + { + return true; + } + char[] arrchar = str.ToCharArray(); + for (int i = 0; i < arrchar.Length; i++) + { + if (arrchar[i] != ' ') + { + return false; + } + } + return true; + } + + } +} + + +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + string arr = " "; + Console.WriteLine(StringUtil.Pandaun(arr)); + int[]sc= { 34, 53, 64, 74 }; + Console.WriteLine(ArrUtils.Isnull(sc)); + + + } + } +} +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Animals.cs" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Animals.cs" new file mode 100644 index 0000000000000000000000000000000000000000..ed570c089017df8b1b8eeaf0553ee0390009b301 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Animals.cs" @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业 +{ + internal abstract class Animals + { + public string name; + public string Name { get; set; } + public abstract void Eat(); + public void Sleep() { + Console.WriteLine($"{name}爱睡觉"); + } + // 1、猫、狗、鸭、猴,(吃、睡觉、游泳、爬树) + //所有动物都有吃的方法 + //狗和鸭会游泳,不会爬树 + //猫和猴不会游泳会爬树 + //将吃的方法定义在父类方法中,将游泳和爬树的技能定义为接口 + //所有子类继承父类后,再去继承相应的接口实现技能 + } + internal class Cat : Animals, IClimb + { + + public override void Eat() { + Console.WriteLine($"{name}爱吃鱼干"); + } + public void Climb() { + Console.WriteLine($"{name}会爬树"); + } + } + + internal interface IClimb + { + void Climb(); + } + internal interface ISwim + { + void Swim(); + } + + internal class Dog : Animals,ISwim + { + public override void Eat() + { + Console.WriteLine($"{name}爱吃骨头"); + } + public void Swim() { + Console.WriteLine($"{name}会游泳"); + } + } + internal class Duck : Animals + { + public override void Eat() + { + Console.WriteLine($"{name}爱吃蚯蚓"); + } + public void Swim() + { + Console.WriteLine($"{name}会游泳"); + } + } + internal class Monky : Animals { + public override void Eat() + { + Console.WriteLine($"{name}爱吃香蕉桃子"); + } + public void Climb() + { + Console.WriteLine($"{name}会爬树"); + } + } + +} + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Car.cs" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Car.cs" new file mode 100644 index 0000000000000000000000000000000000000000..56bbd4c00d4a56f3e063c22ae6883406b50a6302 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Car.cs" @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业 +{ + //2、蝙蝠战车的例子 + //定义一个父类表示车的共同属性特征行为:品牌名Brand,会跑Run方法 + //定义一个飞的功能接口类IFly:定义飞的方法Fly + //然后定义蝙蝠战车类继承Cat类和飞的接口 + //在主方法实例化蝙蝠战车的对象,并为品牌名赋值,调用跑和飞的方法 + internal abstract class Car + { + public string brand; + public abstract void Run(); + public void Fly() { + Console.WriteLine($"{brand}飞很高"); + } + } + internal interface IFly { + void Fly(); + } + internal class batpod : Car, IFly + { + public override void Run() + { + Console.WriteLine($"{brand}车跑很快"); + } + + } + } + + + + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Program.cs" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..cb01c5a0d239ca2732f216301bed3135a58ce7ea --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Program.cs" @@ -0,0 +1,57 @@ +namespace 接口作业 +{ + internal class Program + { + static void Main(string[] args) + { + Cat c1 = new Cat(); + c1.name = "玛丽猫"; + c1.Eat(); + c1.Sleep(); + c1.Climb(); + Console.WriteLine("----------------------------"); + Dog d1 = new Dog(); + d1.name = "玉桂狗"; + d1.Eat(); + d1.Sleep(); + d1.Swim(); + Console.WriteLine("---------------------------------"); + Duck duck = new Duck(); + duck.name = "唐老鸭"; + duck.Eat(); + duck.Sleep(); + duck.Swim(); + Console.WriteLine("---------------------------------"); + Monky monky = new Monky(); + monky.name = "孙悟空"; + monky.Eat(); + monky.Sleep(); + monky.Climb(); + Console.WriteLine("---------------------------------"); + batpod b1 = new batpod(); + b1.brand = "蝙蝠战车"; + b1.Run(); + b1.Fly(); + Console.WriteLine("---------------------------------"); + Brid brid = new Brid(); + brid.name = "小鸟"; + brid.Eat(); + brid.Fly(); + brid.Takeoff(); + brid.Land(); + Superman Superman = new Superman(); + Superman.name = "蜘蛛侠"; + Superman.Eat(); + Superman.Takeoff(); + Superman.Fly(); + Superman.Land(); + Plane Plane = new Plane(); + Plane.name = "乐迪"; + Plane.Transport(); + Plane.Takeoff(); + Plane.Fly(); + Plane.Land(); + + } + } +} \ No newline at end of file diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Spb.cs" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Spb.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9a8c57a21ae66eda84e746530f21c73244d33784 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/Spb.cs" @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 接口作业 +{ + // 1.飞机是交通工具类,有运输载人的功能; + //2.小鸟和超人都是动物类,都有吃的方法; + //3.小鸟有自己的特有方法,下蛋; + //4.超人、小鸟、飞机都有飞的功能,可以定义飞的接口:飞的接口有起飞、飞行中、着陆的方法; + //5.超人、小鸟、飞机除了继承各自的父类后,还要继承飞的接口,实现飞的接口的方法; + internal class Vechile + { + public string name; + public void Transport() { + Console.WriteLine("运输载人"); + } + public void Takeoff() + { + Console.WriteLine("起飞"); + + } + public void Fly() + { + Console.WriteLine("飞行中"); + } + public void Land() + { + Console.WriteLine("着陆"); + } + } + internal class Animal + { + public string name; + public void Eat() { + Console.WriteLine($"{name}我会吃"); + } + public void Takeoff() + { + Console.WriteLine("起飞"); + + } + public void Fly() + { + Console.WriteLine("飞行中"); + } + public void Land() + { + Console.WriteLine("着陆"); + } + } + internal interface ITakeoff{ + void Takeoff(); + } + internal interface Ifly + { + void fly(); + } + internal interface ILand { + void Land(); + } + internal class Brid : Animal,ITakeoff,IFly,ILand + { + public void Layeggs() { + Console.WriteLine("下蛋"); + } + } + internal class Superman:Animal, ITakeoff, IFly, ILand + { + + } + internal class Plane:Vechile, ITakeoff, IFly, ILand + { + + } +} diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/Program.cs" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..246ef5b712a7d859225e15be99441901b0d075b8 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/Program.cs" @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace c_连接数据库 +{ + internal class Program + { + static void Main(string[] args) + { + string constr = "server=CODER-NCUGOHYEL;uid=sa;pwd=123456;database=studentinfo"; + SqlConnection sql = null; + try + { + sql = new SqlConnection(constr); + SqlCommand cmd = new SqlCommand("insert into sinfo(id,name,sex,phonenumber) values (1,'罗总监',1,'13850074566')"); + cmd.Connection = sql; + sql.Open(); + int result = cmd.ExecuteNonQuery(); + if (result > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功;result:{result}"); + + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + cmd.CommandText = "insert into sinfo(id,name,sex,phonenumber)values (7,'陈召玺',1,'18750395576')"; + int second = cmd.ExecuteNonQuery(); + if (second > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功;result:{result}"); + + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + cmd.CommandText = "insert into sinfo(id,name,sex,phonenumber)values (10,'玺子',1,'17940304592')"; + cmd.Connection = sql; + int thrid = cmd.ExecuteNonQuery(); + if (thrid > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功;result:{result}"); + + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + cmd.CommandText = "delete from sinfo where id=1"; + int fin = cmd.ExecuteNonQuery(); + if (fin > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功;result:{result}"); + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + cmd.CommandText = "update sinfo set name='玲酱' where id=7"; + int zh = cmd.ExecuteNonQuery(); + if (zh > 0) + { + Console.WriteLine($"执行{cmd.CommandText}语句成功;result:{result}"); + } + else + { + Console.WriteLine($"执行{cmd.CommandText}语句失败,result:{result}"); + } + } + + catch (Exception e) + { + Console.WriteLine("出现异常:" + e.Message); + } + finally + { + if (sql != null) + sql.Close(); + } + Console.ReadKey(); + Getdata(); + } + public static void Getdata() + { + string constr = "server=CODER-NCUGOHYEL;uid=sa;pwd=123456;database=studentinfo"; + String frist = "select * from sinfo"; + + SqlDataAdapter adapter = new SqlDataAdapter(); + + DataSet ds = new DataSet(); + + adapter.Fill(ds, "server=CODER-NCUGOHYEL;uid=sa;pwd=123456;database=studentinfo"); + + if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) + { + foreach (DataRow item in ds.Tables[0].Rows) + { + Console.WriteLine($"学号:{item[0]} 姓名:{item[1]} 性别:{item[2]} 电话号码:{item[3]}"); + } + } + } + } + } \ No newline at end of file diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..0fd105a198b7c76e3cce97eb9da297d4aaf7d4a0 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,193 @@ +```c# +using System.ComponentModel; +using System.Security.Cryptography.X509Certificates; +using static ConsoleApp1.Calculate; +namespace ConsoleApp1 +{ + internal class Program + { + static void Main(string[] args) + { + // 一、编写一个控制台应用程序,接受用户输入的两个整数和一个操作符, + // 以实现对两个整数的加、减、乘、除运算,并显示出计算结果。 + //3、根据用户输入的操作符,实例化相应的类,完成运算并输出结果。 + Console.WriteLine("请输入第一个整数"); + int a = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入第二个整数"); + int b = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("请输入操作符"); + string sign = Console.ReadLine(); + Calculate calculate = null; + if (sign == "+") + { + Add a1 = new Add(a, b); + a1.DisplayResult(); + } + else if (sign == "-") + { + Sub s1 = new Sub(a, b); + s1.DisplayResult(); + } + else if (sign == "*") + { + Mul m1 = new Mul(a, b); + m1.DisplayResult(); + } + else if (sign == "/") { + Div d1 = new Div(a, b); + } + //4、在主类中添加一个方法,形参为父类对象,根据传递实参的类型,调用方法,实现计算和显示结果。 + Shape shape = null; + Calculate(calculate); + Shape(shape); + Console.WriteLine("请输入圆的半径"); + Circle b1 = new Circle(); + b1.GetArea(); + Console.WriteLine("请输入正方形的边长"); + Square x1= new Square(); + x1.GetArea(); + } + public static void Calculate(Calculate calculate) + { + calculate.DisplayResult(); + } + public static void Shape(Shape shape) + { + shape.GetArea(); + } + } + } + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Calculate + { + //1、创建Calculate基类,其中包含两个整型的protected成员,用以接收用户输入的两个整数。 + protected int a; + protected int b; + + public Calculate(int a, int b) + { + this.a = a; + this.b = b; + } + + //定义一个DisplayResult()虚方法,计算并输出结果。 + public virtual void DisplayResult() { + Console.WriteLine($"{a}"); + } + //2、定义四个类继承自Calculate类,分别重写DisplayResult()方法, + //实现两个整数的加、减、乘、除运算,并输出结果。 + internal class Add: Calculate{ + public Add(int a, int b) : base(a, b) + { + this.a = a; + this.b = b; + } + + public override void DisplayResult() { + Console.WriteLine($"{a}+{b}={a+b}"); + } + } + internal class Sub: Calculate + { + public Sub(int a, int b) : base(a, b) + { + this.a = a; + this.b = b; + } + + public override void DisplayResult() + { + Console.WriteLine($"{a}-{b}={a - b}"); + } + } + internal class Mul: Calculate + { + public Mul(int a, int b) : base(a, b) + { + this.a = a; + this.b = b; + } + + public override void DisplayResult() + { + Console.WriteLine($"{a}*{b}={a * b}"); + } + } + internal class Div: Calculate + { + public Div(int a, int b) : base(a, b) + { + this.a = a; + this.b = b; + } + + public override void DisplayResult() + { + Console.WriteLine($"{a}/{b}={a/b}"); + } + } + } +} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + internal class Shape + { + //二、创建一个Shape(形状)类,此类包含一个名为color的数据成员, + //用于存储颜色,这个类还包含一个名为GetArea()的虚方法(这个方法是用来获取形状面积的)。 + //基于这个Shape,创建两个子类:Circle(圆形类)和Square(正方形类), + // Circle类中包含radius(半径)的数据成员,Square类中包含sideLen(边长)的数据成员, + // 这两个子类都去重写父类的GetArea()方法,各自去实现计算自己的面积。 + + //在主类中添加一个方法,参数类型就是Shape,方法体中,用形参去调用GetArea()方法。 + //main方法中去测试这个方法。 + public string color; + public virtual void GetArea() { + Console.WriteLine(); + } + } + internal class Circle : Shape { + public int r; + public Circle() { } + public Circle(int r) + { + this.r = r; + } + + public override void GetArea() + { + int r = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine($"3.14*{r}*{r}"); + } + } + internal class Square : Shape { + public int x; + public Square() { } + public Square(int x) + { + this.x = x; + } + + public override void GetArea() + { + int x= Convert.ToInt32(Console.ReadLine()); + Console.WriteLine($"{x}*{x}"); + } + + } +} +``` + diff --git "a/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232.md" "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..2bffefcd65a73a3c43f7f15251ac62db7d13ad48 --- /dev/null +++ "b/07\351\203\221\347\216\211\347\216\262/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,201 @@ +```c# +namespace 第三次作业 +{ + internal class Program + { + static void Main(string[] args) + { + //第一个作业 + Console.WriteLine("用户信息为:"); + User u1 = new User(); + u1.id = "库洛米"; + u1.uname = "库洛米"; + u1.password = "fe2"; + u1.printmsg(); + Console.WriteLine("--------------------------------------------------------------------------------------------"); + //第二个作业 + Console.WriteLine("学生信息为:"); + Student student = new Student(); + student.No = 7; + student.Name = "玲娜贝儿"; + student.Sex = 1; + student.Age = 19; + student.Major = "软件技术"; + student.printmsg(); + Console.WriteLine("--------------------------------------------------------------------------------------------"); + //第三个作业 + Console.WriteLine("图书信息为:"); + book b1 = new book(); + b1.No = 1; + b1.Bname = "月亮与六便士"; + b1.Price = 56; + b1.Publisher = "新华出版社"; + b1.Author = "毛姆"; + b1.printmsg(); + } + } +} + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Markup; + +namespace 第三次作业 +{ +//1. 定义一个用户类,存放用户的账号、用户名和密码属性; +// 在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息;然后在主方法调用输出; + internal class User + { + public string id; + public string uname; + public string password; + public void printmsg() { + Console.WriteLine("用户账号:"+id); + Console.WriteLine("用户姓名:" + uname); + Console.WriteLine("用户密码:" + password); + } +} +//2. 定义一个学生类,存放学生的学号、姓名、性别、年龄、专业信息; +// 对年龄字段进行赋值的安全性设置,如果是非法值(小于0或者大于128岁),该年龄值为0; +// 在学生类中定义一个方法输出学生信息。 +// 在主方法实例化对象,赋值并输出 + internal class Student { + private int no; + private string name; + private int sex; + private int age; + private string major; + public int No + { + get + { + return no; + } + set + { + no = value; + } + } + public string Name + { + get + { + return name; + } + set + { + name = value; + } + } + public int Sex { get; set; } + public int Age + { + get + { + return age; + } + set + { + if (0 < value && value < 128) + { + age = value; + } + else { + age = 0; + } + } + } + public string Major + { + get + { + return major; + } + set + { + major = value; + } + } + public void printmsg() { + Console.WriteLine("学号:" + no); + Console.WriteLine("姓名:" + name); + Console.WriteLine("性别:" + sex); + Console.WriteLine("年龄:" + age); + Console.WriteLine("专业信息:" + major); + } + } + // 3.定义一个图书类,存放图书的编号、书名、价格、出版社、作者信息; + //对价格进行赋值限制,小于0价格,赋值为0 + //在图书类中定义一个方法输出图书信息; + //在主方法实例化对象,赋值并输出 + internal class book { + private int no; + private string bname; + private int price; + private string publisher; + private string author; + public int No { + get { + return no; + } + set { + no = value; + } + } + public string Bname { + get { + return bname; + } + set { + bname = value; + } + } + public int Price { + get { + return Price; + } + set { + if (price < 0) + { + price = 0; + } + else { + price = value; + } + } + } + public String Publisher + { + get { + return publisher; + } + set { + publisher = value; + } + } + public string Author + { + get + { + return author; + } + set + { + author = value; + } + } + public void printmsg() { + Console.WriteLine("图书编号为:"+No); + Console.WriteLine("图书名称为:" + bname); + Console.WriteLine("图书价格为:" + price); + Console.WriteLine("图书出版社为:" + publisher); + Console.WriteLine("图书作者为:" + author); + } + } + } + +``` +