C#考试题库


初体验:C#与Java书写的一些不同

  • C#方法首字母习惯为大写
  • C#变量还是采用驼峰命名法,但是属性首字母在C#中推荐为大写
  • C#无需写get&set方法,在C#中优雅的使用属性实现与Java类似的效果
  • C#重写(覆写)增加virtual关键字限制派生类操作,并且派生类必须加上override关键字标记覆写方法
    • 接口的方法在派生类实现时不可使用override标记
    • 抽象方法在派生类实现时不可使用override标记
    • 接口方法的实现分为显式实现与隐式实现
    • 接口中不可以含有 字段 但可以存在属性
      • 接口中的 属性 需要在其实现类中设置其 value
  • C#中与Java中 instanceof 关键字类似的关键字为 is
  • C#中在子类构造方法中调用父类构造方法的方式为 子类构造方法:base(...)
  • C#集合获取元素使用和数组一样的方式,而Java则采用get方法等获取

一、简单题

1.

把输入的字符串中的内容逆置,并保存到新字符串,并输出新字符串的内容。

实现

 static void Main(string[] args){//注意:局部变量并不会被默认初始化,而成员变量则会被默认初始化。与Java相同。String str = String.Empty;String result = String.Empty;Console.Write("请输入需要倒置的字符串:");str = Console.ReadLine();for (int i=str.Length-1; i>=0;i-- ) {result += str[i];}Console.WriteLine("倒置结果为:{0}",result);                    }

输出

请输入需要倒置的字符串:aawe
倒置结果为:ewaa
请按任意键继续. . .

2.

已知三角形三条边长a,b,c,三边由用户输入,编程判断a、b、c的值是否构成三角形,如构成三角形,则计算并输出三角形的面积,否则输出“不能构成三角形”计算三角形面积公式为:
s=0.5*(a+b+c)
area=
求三角形的面积area。

实现

static void Main(string[] args){//三角形三边int a=0, b=0, c=0;Console.WriteLine("请依次输入三角形的三条边:");Console.Write("a=");a = Convert.ToInt32(Console.ReadLine());Console.Write("b=");b = Convert.ToInt32(Console.ReadLine());Console.Write("c=");c = Convert.ToInt32(Console.ReadLine());//判断是否为三角形if (checkTriangle(a, b, c)) {Console.WriteLine("该三角形面积为:{0}",Area(a,b,c));}else{Console.WriteLine("不能构成三角形!");}}/*** 参数:a,b,c 需要判断的三边 * 返回:true-yes false-no* */public static bool checkTriangle(int a, int b, int c) {           return a+b>c?(a+c>b?(b+c>a?true:false):false):false;}/*** 海伦公式* 参数:a,b,c 需要判断的三边 * 返回:面积(double)* */public static double Area(int a, int b, int c){return 0.5 * (a + b + c);}

输出

请依次输入三角形的三条边:
a=2
b=3
c=4
该三角形面积为:4.5
请按任意键继续. . .

3.

输入一个字符串str1,删除str1中其中所有的0-9的数字字符,输出处理后的字符串。

实现

 static void Main(string[] args){String str1 = String.Empty;Console.Write("请输入要处理的字符串:");str1 = Console.ReadLine();for (int i=0;i<str1.Length;i++) {if (str1[i] >= '0' && str1[i] <= '9'){//注意这里返回字符串str1 = str1.Remove(i,1);//长度发生变化i--;}}Console.WriteLine(str1);}

输出

请输入要处理的字符串:we22wed31sxc
wewedsxc
请按任意键继续. . .

4.

输入10个数,计算平均值,统计低于平均值数据个数并把低于平均值的数据输出

实现

const int N = 10;static void Main(string[] args){//4.输入10个数,计算平均值,统计低于平均值数据个数并把低于平均值的数据输出。int count = 0;float ave = 0f;int[] numbers = new int[N];for (int i=1;i<=N;i++ ){Console.Write("请输入第{0}个数:",i);numbers[i - 1] = Convert.ToInt32(Console.ReadLine());ave += numbers[i - 1];}//平均值ave /= N;Console.Write("低于平均值{0}的数有:",ave);foreach(int temp in numbers){if (temp < ave){Console.Write(" {0}",temp);count++;}}Console.WriteLine("个数为:{0}",count);}

输出

请输入第1个数:1
请输入第2个数:23
请输入第3个数:34
请输入第4个数:56
请输入第5个数:2
请输入第6个数:34
请输入第7个数:12
请输入第8个数:345
请输入第9个数:23
请输入第10个数:3
低于平均值53.3的数有: 1 23 34 2 34 12 23 3个数为:8
请按任意键继续. . .

5.

输入10个数,计算平均值,统计高于平均值数据个数并把高于平均值的数据输出。

实现

const int N = 10;static void Main(string[] args){//4.输入10个数,计算平均值,统计低于平均值数据个数并把低于平均值的数据输出。int count = 0;float ave = 0f;int[] numbers = new int[N];for (int i=1;i<=N;i++ ){Console.Write("请输入第{0}个数:",i);numbers[i - 1] = Convert.ToInt32(Console.ReadLine());ave += numbers[i - 1];}//平均值ave /= N;Console.Write("高于平均值{0}的数有:",ave);foreach(int temp in numbers){if (temp > ave){Console.Write(" {0}",temp);count++;}}Console.WriteLine("个数为:{0}",count);}

输出

请输入第1个数:1
请输入第2个数:2
请输入第3个数:3
请输入第4个数:4
请输入第5个数:5
请输入第6个数:6
请输入第7个数:7
请输入第8个数:8
请输入第9个数:9
请输入第10个数:10
高于平均值5.5的数有: 6 7 8 9 10个数为:5
请按任意键继续. . .

6.

输入一些整数,找出其中最大数和次最大数。

实现

 const int N = 10;static void Main(string[] args){//输入一些整数,找出其中最大数和次最大数。int[] array = new int[N];for (int i=0;i<array.Length ;i++ ){Console.Write("请输入第{0}个数:",i+1);array[i] = int.Parse(Console.ReadLine());}//调用Array类的Sort方法Array.Sort(array);Console.WriteLine("最大数为:{0} 次最大数为:{1}",array[array.Length-1],array[array.Length-2]);}

输出

请输入第1个数:33
请输入第2个数:2
请输入第3个数:45
请输入第4个数:2
请输入第5个数:324
请输入第6个数:43
请输入第7个数:23
请输入第8个数:2223
请输入第9个数:34
请输入第10个数:3
最大数为:2223 次最大数为:324
请按任意键继续. . .

7.

输入一些整数,找出其中最小数和次最小数。

实现

 const int N = 10;static void Main(string[] args){//输入一些整数,找出其中最大数和次最大数。int[] array = new int[N];for (int i=0;i<array.Length ;i++ ){Console.Write("请输入第{0}个数:",i+1);array[i] = int.Parse(Console.ReadLine());}//调用Array类的Sort方法Array.Sort(array);Console.WriteLine("最小数为:{0} 次最小数为:{1}",array[0],array[1]);}

输出

请输入第1个数:2
请输入第2个数:3
请输入第3个数:2
请输入第4个数:1
请输入第5个数:3
请输入第6个数:56
请输入第7个数:0
请输入第8个数:4
请输入第9个数:223
请输入第10个数:45
最小数为:0 次最小数为:1
请按任意键继续. . .

8.

输入若干有序的正整数,对于相同的数据只保留一个,输出保留的数据。例如,输入数据是: 2,2,2,3,3,4,5,5,6,6,8,8,9,9,9,10,10,10 最终的输出结果是: 2,3,4,5,6,8,9,10。

实现

 static void Main(string[] args){int num = 0;List<int> list = new List<int>();for (int i=1; ;i++ ){Console.Write("请输入第{0}个正整数[-1结束输入]:",i);num = Convert.ToInt32(Console.ReadLine());//题目要求正整数,因此通过判断-1来停止if (num == -1){break;}//判断是否重复if (list.Contains(num)){continue;}list.Add(num);}Console.Write("最终输出结果:");foreach (int temp in list ){Console.Write(" {0}",temp);}Console.Write("\n");}

输出

请输入第1个正整数[-1结束输入]:22
请输入第2个正整数[-1结束输入]:11
请输入第3个正整数[-1结束输入]:22
请输入第4个正整数[-1结束输入]:11
请输入第5个正整数[-1结束输入]:11
请输入第6个正整数[-1结束输入]:34
请输入第7个正整数[-1结束输入]:55
请输入第8个正整数[-1结束输入]:56
请输入第9个正整数[-1结束输入]:-1
最终输出结果: 22 11 34 55 56
请按任意键继续. . .

9.

输入一个字符串,判断如果全是数字,将其转换成为一个整数,若包含其他符号,给出错误提示。

实现

static void Main(string[] args){int strNumber=0;Console.Write("请输入要判断的字符串:");try{strNumber = Convert.ToInt32(Console.ReadLine());Console.WriteLine("已转换为数字:{0}",strNumber);}catch (Exception e){Console.WriteLine("输入错误,字符串中包含其他非数字字符!");}}

输出

请输入要判断的字符串:weuu33
输入错误,字符串中包含其他非数字字符!
请按任意键继续. . .
---------------------------
请输入要判断的字符串:232
已转换为数字:232
请按任意键继续. . .

10.

输入20个正整数,分别统计并输出其中的奇数和偶数的个数,并分类输出所有奇数和偶数。

实现

 const int N = 20;static void Main(string[] args){int num=0;//偶数集合List<int> evenNumList = new List<int>();//奇数集合List<int> oddNumList = new List<int>();for (int i=0;i<N ;i++ ){Console.Write("请输入第{0}个正整数:",i+1);num = Convert.ToInt32(Console.ReadLine());if (num % 2 == 0){evenNumList.Add(num);}else{oddNumList.Add(num);}}//偶数输出Console.Write("偶数个数:{0} 分别为:",evenNumList.Count);foreach (int temp in evenNumList){Console.Write("{0} ",temp);}Console.WriteLine();//奇数输出Console.Write("奇数个数:{0} 分别为:", oddNumList.Count);foreach (int temp in oddNumList){Console.Write("{0} ", temp);}Console.WriteLine();}

输出

请输入第1个正整数:1
请输入第2个正整数:2
请输入第3个正整数:3
请输入第4个正整数:4
请输入第5个正整数:5
请输入第6个正整数:6
请输入第7个正整数:7
请输入第8个正整数:8
请输入第9个正整数:9
请输入第10个正整数:10
请输入第11个正整数:11
请输入第12个正整数:12
请输入第13个正整数:13
请输入第14个正整数:14
请输入第15个正整数:15
请输入第16个正整数:16
请输入第17个正整数:17
请输入第18个正整数:18
请输入第19个正整数:19
请输入第20个正整数:20
偶数个数:10 分别为:2 4 6 8 10 12 14 16 18 20
奇数个数:10 分别为:1 3 5 7 9 11 13 15 17 19
请按任意键继续. . .

11.

从终端输入5个数,按从小到大的顺序输出。

实现

const int N = 5;static void Main(string[] args){int[] array = new int[N];for (int i=0;i<array.Length ;i++ ){Console.Write("请输入第{0}个数:",i+1);array[i] = Convert.ToInt32(Console.ReadLine());}Array.Sort(array);Console.Write("从小到大排序为:");foreach (int temp in array){Console.Write("{0} ",temp);}Console.WriteLine();}

输出

请输入第1个数:23
请输入第2个数:34
请输入第3个数:2
请输入第4个数:212
请输入第5个数:3
从小到大排序为:2 3 23 34 212
请按任意键继续. . .

12.

从键盘读入20个数据到数组中,统计其中负数的个数,并计算这些负数之和。

实现

const int N = 20;static void Main(string[] args){int count = 0;int sum = 0;int[] array = new int[N];for (int i=0;i<array.Length ;i++ ){Console.Write("请输入第{0}个数:",i+1);array[i] = Convert.ToInt32(Console.ReadLine());if (array[i] < 0){count++;sum += array[i];}}Console.WriteLine("负数个数为:{0} 负数和为:{1}",count,sum);}

输出

请输入第1个数:1
请输入第2个数:2
请输入第3个数:3
请输入第4个数:4
请输入第5个数:6
请输入第6个数:7
请输入第7个数:89
请输入第8个数:7
请输入第9个数:45
请输入第10个数:-1
请输入第11个数:12
请输入第12个数:3
请输入第13个数:-4
请输入第14个数:-32
请输入第15个数:4
请输入第16个数:45
请输入第17个数:4
请输入第18个数:3
请输入第19个数:2
请输入第20个数:3
负数个数为:3 负数和为:-37
请按任意键继续. . .

13.

求n以内(不包括n)不能同时被2和5整除(能被2或者5整除但不能同时被整除)的所有自然数之和的平方根s,n从键盘输入。

实现

 static void Main(string[] args){int n = 0;int sum = 0;Console.Write("请输入n=");n = Convert.ToInt32(Console.ReadLine());for (int i=0; i<n; i++){//不能同时被2和5整除(能被2或者5整除但不能同时被整除)if (((i%2==0)||(i%5==0))&&!((i%2==0)&&(i%5==0))){sum += i;}}Console.WriteLine("S={0}",Math.Sqrt(sum));}

输出

请输入n=100
S=50
请按任意键继续. . .

※14.

输入1~7之间的一个数字,输出它对应的星期几。例如输入1 输出Monday。

实现

//周 枚举enum Weekdays {Monday=1,Tuesday=2,Wednesday=3,Thursday=4,Friday=5,Saturday=6,Sunday=7};static void Main(string[] args){Console.Write("请输入1-7数字:");//typeof关键字用于获取Type对象,Enum.Parse用于解析出该Type类型与该值的Enum对象,但返回值为Object,详情见微软C#官方DocConsole.WriteLine($"今天是:{Enum.Parse(typeof(Weekdays), Console.ReadLine())}");}

输出

请输入1-7数字:3
今天是:Wednesday
请按任意键继续. . .

15.

个位数为8且能被4整除但不能被7整除的二位自然数共有多少个,统计个数,并输出这些数。

实现

static void Main(string[] args){int count = 0;//个位数为8且能被4整除但不能被7整除的二位自然数共有多少个,统计个数,并输出这些数。Console.Write("个位数为8且能被4整除但不能被7整除的二位自然数有:");for (int i=18;i<99;i+=10 ){if ((i % 4 == 0) && (i % 7 != 0)){count++;Console.Write($" {i}");}}Console.WriteLine($"\n个数为:{count}");}

输出

个位数为8且能被4整除但不能被7整除的二位自然数有: 48 68 88
个数为:3
请按任意键继续. . .

16.

输入一个字符串,用foreach语句计算输入的字符串的长度,并显示长度。

实现

static void Main(string[] args){int count = 0;String str = String.Empty;Console.Write("请输入字符串:");str = Console.ReadLine();foreach (char temp in str){count++;}Console.WriteLine($"字符串长度为:{count}");}

输出

请输入字符串:Jason
字符串长度为:5
请按任意键继续. . .

17.

输入7个数,分别统计其中正数、负数、零的个数。

实现

 const int N = 7;static void Main(string[] args){//0-正 1-负 2-零int[] signs = new int[3];int[] array = new int[N];for (int i=0;i<array.Length ;i++ ){Console.Write($"请输入第{i+1}个数:");array[i] = Convert.ToInt32(Console.ReadLine());if (array[i] > 0){signs[0]++;}else if (array[i]==0){signs[2]++;}else{signs[1]++;}}Console.WriteLine($"正数个数:{signs[0]} 负数个数:{signs[1]} 零个数:{signs[2]}");}

输出

请输入第1个数:1
请输入第2个数:-2
请输入第3个数:0
请输入第4个数:1
请输入第5个数:2
请输入第6个数:3
请输入第7个数:1
正数个数:5 负数个数:1 零个数:1
请按任意键继续. . .

※18.

计算:1/2+2/3-3/4+4/5……前50项。

实现

 const int N = 50;static void Main(string[] args){//和double sum=0;#region for (double i=1;i<=N;i++ ){//注意:从第二项开始一正一负if (i > 1){if (i % 2 == 0){sum += i / (i + 1);}else{sum -= i / (i + 1);}}else{sum += i / (i + 1);}}#endregionConsole.WriteLine($"1/2+2/3-3/4+4/5……前50项={sum}");}

输出

1/2+2/3-3/4+4/5……前50项=1.29714499628683
请按任意键继续. . .

19.

斐氏数列是公元13世纪数学家斐波拉契发明的。即:1,2,3,5,8,13,21,34,55,89,……,输出比144大的最小的那一项。

实现

static void Main(string[] args){List<int> list = new List<int>();list.Add(1);list.Add(2);//从第三项开始,每一项都是前两项和while (true){list.Add(list[list.Count-1]+list[list.Count-2]);if (list[list.Count - 1] > 144){break;}}Console.WriteLine($"比144大的最小的那一项:{list[list.Count-1]}");}

输出

比144大的最小的那一项:233
请按任意键继续. . .

20.

从终端输入一些整数,找出大于0的数,并输出这些数和他们的平均值。

实现

 static void Main(string[] args){double sum = 0;int temp = 0;List<int> list = new List<int>();for (int i=1; ;i++ ){Console.Write($"请依次输入第{i}个数[输入 非数字字符 结束输入]:");try{temp = Convert.ToInt32(Console.ReadLine());if (temp > 0){sum += temp;list.Add(temp);}}catch (Exception e) {break;}}Console.Write("大于0的数有:");foreach (int a in list){Console.Write($" {a}");}Console.WriteLine($"\n这些数的平均值为:{sum/list.Count}");}

输出

请依次输入第1个数[输入 非数字字符 结束输入]:1
请依次输入第2个数[输入 非数字字符 结束输入]:-3
请依次输入第3个数[输入 非数字字符 结束输入]:2
请依次输入第4个数[输入 非数字字符 结束输入]:exit
大于0的数有: 1 2
这些数的平均值为:1.5
请按任意键继续. . .

21.

接收用户输入的一个实数N,不使用计算绝对值函数编程计算输出该实数的绝对值。

实现

static void Main(string[] args){int n = 0;Console.Write("请输入要求绝对值的数:");n = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"{n}的绝对值为:{(n>=0?n:0-n)}");}

输出

请输入要求绝对值的数:-666
-666的绝对值为:666
请按任意键继续. . .

22.

接收用户输入的一个正整数N,求1-2+3-4…+N的值并输出。

实现

static void Main(string[] args){int n = 0;Console.Write("请输入N:");n = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"按照规律的计算和为:{returnSum(n)}");}static int returnSum(int n){int sum = 0;for (int i=1;i<=n ;i++ ){sum += (i%2==0?0-i:i);}return sum;}

输出

请输入N:5
按照规律的计算和为:3
请按任意键继续. . .

23.

接收用户输入的一个正整数N,计算1到N的立方和。

实现

static void Main(string[] args){int n = 0;Console.Write("请输入N:");n = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"1~{n}的立方和为:{returnSum(n)}");}//立方和=a^3+b^3+c^3....static double returnSum(int n){double sum = 0;for (int i=1;i<=n ;i++ ){sum += Math.Pow(i,3);}return sum;}

输出

请输入N:3
1~3的立方和为:36
请按任意键继续. . .

24.

接收用户输入的两个数,判断两个数是否能整除。

实现

         static void Main(string[] args){       double a=0,b=0;Console.Write("请依次输入两个数:");a = Convert.ToDouble(Console.ReadLine());b = Convert.ToDouble(Console.ReadLine());//a÷b  a为被除数  b为除数  意思为:b除aswitch (a % b == 0 ? 0 : (b % a == 0 ? 1 :2)){case 0:Console.WriteLine($"{b}可以整除{a}"); break;case 1:Console.WriteLine($"{a}可以整除{b}");break;default:Console.WriteLine($"不可整除"); break;}}

输出

请依次输入两个数:6
2
2可以整除6
请按任意键继续. . .

二、方法题

注意:这些方法要在主函数里面调用测试是否正确。

1.

回文是指顺读和倒读都一样的字符串。写一个方法,判断一个字符串str1,是否是回文,是回文返回true,否则返回false。例如字符串b是ag7ga是回文,而字符串abc6es就不是回文。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){String str1 = String.Empty;Console.Write("请输入要检测的字符串:");str1 = Console.ReadLine();Console.WriteLine($"{str1}{(CheckStr(str1)?"是":"不是")}回文");}//判断回文static bool CheckStr(String str){for (int i=0;i<str.Length/2;i++){if (str[i] != str[str.Length - i - 1]){return false;}}return true;}

输出

请输入要检测的字符串:ag7ga
ag7ga是回文
请按任意键继续. . .
-------------------------------
请输入要检测的字符串:abc6es
abc6es不是回文
请按任意键继续. . .

※2.

写一个方法,统计一个字符串中单词的个数,返回值为单词个数。规定单词之间由若干个空格隔开。例如若输入字符串" I am a student ",得到结果为 4。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){String str1 = String.Empty;Console.Write("请输入要检测的字符串:");str1 = Console.ReadLine();Console.WriteLine($"{str1}中有:{CheckStrWordCount(str1)}个单词");}//判断单词个数static int CheckStrWordCount(String str){//分隔符-这里仅使用空格作为分隔符char[] separator = {' '};/** Enum  ----使用了FlagsAttributes属性定义,即可将枚举视为位域。* StringSplitOptions.None                  -0 : 默认选项* StringSplitOptions.RemoveEmptyEntries    -1 :移除空字符串<==>""<==>String.Empty* StringSplitOptions.TrimEntries           -2 :修剪字符串并删除由空格组成的字符串<==>" "<==>空格组成* 而使用了FlagsAttributes属性定义,便可以使用3,即使用枚举值的和,表示StringSplitOptions.RemoveEmptyEntries & StringSplitOptions.TrimEntries* 注意:对于StringSplitOptions.TrimEntries 的使用需要查看该值是否存在,不然可能出现错误*/return str.Split(separator,StringSplitOptions.RemoveEmptyEntries).Length;}

输出

请输入要检测的字符串:I am a student
I am a student中有:4个单词
请按任意键继续. . .

※3.

写一个方法,判断的一个正整数是否是素数,返回值为布尔类型。要求编写应用程序,求1-100之间的所有素数。

实现

static void Main(string[] args){Console.Write("1~100之间所有的素数:");for (int i=1; i<=100; i++){if (checkNum(i))Console.Write("{0,3}",i);}Console.WriteLine();}/** 判断素数(质数)* true  - 素数* false - 非素数*/static bool checkNum(int num){//素数(质数)是指在大于1的自然数中,除了1和它本身以外不再有其他因数的自然数。//依据素数定义可知,其为大于1的自然数if (num <= 1){return false;}else{for (int i = 2; i < num; i++){if (num % i == 0)return false;}return true;}}

输出

1~100之间所有的素数:  2  3  5  7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
请按任意键继续. . .

※4.

输入一个字符串,统计字符串中英文字母、数字字符和其他它符号的个数并输出。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int enCount=0, numCount=0, othCount=0;String str = String.Empty;Console.Write("请输入字符串:");//接收字符串并将英文字符串转换为大写字符,方便统计str = Console.ReadLine().ToUpper();//注意:手动设置的引用数据类型需要在调用时也写上ref关键字checkStringCount(str,ref enCount,ref numCount,ref othCount);Console.WriteLine($"字符串中含有 英文字符:{enCount}个 数字字符:{numCount}个 其他字符:{othCount}个");}/** 统计字符串不同字符的数目,此处形参通过手动转为了引用类型*/static void checkStringCount(String str, ref int enCount, ref int numCount, ref int othCount){for (int i=0; i<str.Length; i++){//英文字符if (str[i] >= 'A' && str[i] <= 'Z'){enCount++;}else if (str[i] >= '0' && str[i] <= '9'){//数字字符numCount++;}else{//其他字符othCount++;}}}

输出

请输入字符串:I love you1
字符串中含有 英文字符:8个 数字字符:1个 其他字符:2个
请按任意键继续. . .

※5.

写一个方法,对正整数m求和,其中求和公式为s= 1/2+1/3+…+1/m,方法返回s的值。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int m = 0;Console.Write("请输入M=");m = Convert.ToInt32(Console.ReadLine());//输出并保留三位小数Console.WriteLine($"s= 1/2+1/3+…+1/{m}={caculateNum(m):0.000}");}/** 求和公式为s= 1/2+1/3+…+1/m,方法返回s的值*/static double caculateNum(int m){double sum = 0;//规律为:分子--循环次数   分母--循环次数+1for ( double i=1; i<=m; i++){sum += i / (i + 1);}return sum;}

输出

请输入M=100
s= 1/2+1/3+…+1/100=95.803
请按任意键继续. . .

6.

写一个方法,将一个字符串中所有英文字符后加一个$字符,并返回处理后的字符串。例如输入:A1B23CD45,则方法返回值为:A$1B23C23C23CD$45,要求编写应用程序,来检验方法的正确性。

实现

const String SIGN = "$";static void Main(string[] args){String str = String.Empty;Console.Write("请输入字符串:");str = Console.ReadLine();Console.WriteLine($"处理后的字符串为:{InsertStr(str)}");}/** 字符串中所有英文字符后加一个$字符,并返回处理后的字符串*/static String InsertStr(String str){for (int i=0; i<str.Length; i++){if((str[i] >= 'a' && str[i] <= 'z')||(str[i] >= 'A' && str[i] <= 'Z')){str = str.Insert(i+1,Program.SIGN);i++;}}return str;}

输出

请输入字符串:A1B23CD45
处理后的字符串为:A$1B$23C$D$45
请按任意键继续. . .

7.

写一个方法,删去所有字符串中的小写字符,其余字符不变。方法返回转变后的字符串。str=“AbC” 转变为串为=“AC”,要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){String str = String.Empty;Console.Write("请输入字符串:");str = Console.ReadLine();Console.WriteLine($"处理后的字符串为:{RemoveStr(str)}");}/** 删去所有字符串中的小写字符,其余字符不变*/static String RemoveStr(String str){for (int i=0; i<str.Length; i++){if (str[i]>='a'&&str[i]<='z'){str=str.Remove(i,1);i--;}}return str;}

输出

请输入字符串:AbC
处理后的字符串为:AC
请按任意键继续. . .

8.

写一个方法,对一个字符串,按如下规则加密:如果是英文字母则大写变小写、小写变大写,对非英文字符则保持不变。返回值为返回加密字符串。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){String str = String.Empty;Console.Write("请输入字符串:");str = Console.ReadLine();Console.WriteLine($"处理后的字符串为:{ChangeStr(str)}");}/** 英文字母则大写变小写、小写变大写,对非英文字符则保持不变*/static String ChangeStr(String str){StringBuilder stringBuilder = new StringBuilder(str);for (int i=0; i< stringBuilder.Length; i++){if (stringBuilder[i]>='a'&& stringBuilder[i]<='z'){//因为StringBuilder 是可变的,因此无需使用其返回的结果再赋值,注意与String的对比stringBuilder.Replace(stringBuilder[i], Char.ToUpper(stringBuilder[i]), i,1);} else if (stringBuilder[i] >= 'A' && stringBuilder[i] <= 'Z'){//因为StringBuilder 是可变的,因此无需使用其返回的结果再赋值,注意与String的对比stringBuilder.Replace(stringBuilder[i], Char.ToLower(stringBuilder[i]), i, 1);}}//常用此种方式转换为Stringreturn stringBuilder.ToString();}

输出

请输入字符串:I love you.
处理后的字符串为:i LOVE YOU.
请按任意键继续. . .

※※9.

写一个方法,求两个整数m和 n 的最大公约数,并作为返回值返回。要求编写应用程序,来检验方法的正确性。

注意:for循环体的执行顺序(判断):1->2->{}->3->2->{}->3->…

实现-1

static void Main(string[] args){int m = 0, n = 0;Console.Write("m=");m = Convert.ToInt32(Console.ReadLine());Console.Write("n=");n = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"{m}与{n}的最大公约数为:{MaxCommonFactorOfMath(FactorOfMath(m),FactorOfMath(n))}");}//求因数static List<int> FactorOfMath(int num){List<int> list = new List<int>();for (int i=1; i<=num; i++){if (num % i == 0)list.Add(i);}return list;}//比较出最大公因数static int MaxCommonFactorOfMath(List<int> a, List<int> b){List<int> list1 = null;List<int> list2 = null;//使用大的查找小的if (a.Count > b.Count){list1 = a;list2 = b;}else{list1 = b;list2 = a;}//倒序查找,因为要找最大的公因子,所以从最大开始找起for (int i=list1.Count-1;i>=0;i-- ){//使用这种方式会多走一次循环,也可以自己写循环直接判断返回if (list2.Contains(list1[i])){return list2[list2.IndexOf(list1[i])];}}//按照公因子定义,不可能出现正数没有公因子的情况(最低也会有公因子1),所以这里永远不会执行return -1;}

实现-2

 static void Main(string[] args){int m = 0, n = 0;Console.Write("m=");m = Convert.ToInt32(Console.ReadLine());Console.Write("n=");n = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"{m}与{n}的最大公约数为:{MaxCommonFactorOfMath(m, n)}");}/** 辗转相除法(欧几里德法)* 用较小数除较大数,再用出现的余数(第一余数)去除除数,再用出现的余数(第二余数)去除第一余数,如此反复,直到最后余数是0为止。如果是求两个数的最大公约数,那么最后的除数就是这两个数的最大公约数。*/static int MaxCommonFactorOfMath(int m, int n){int a=0, b=0, temp=0;a = m;b = n;while (a%b!=0){temp = a % b;a = b;b = temp;}return b;}

输出

m=18
n=27
18与27的最大公约数为:9
请按任意键继续. . .

※10.

写一个方法,求两个整数m和 n 的最小公倍数,并作为返回值返回。要求编写应用程序,来检验方法的正确性。

实现

 static void Main(string[] args){int m = 0, n = 0;Console.Write("m=");m = Convert.ToInt32(Console.ReadLine());Console.Write("n=");n = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"{m}与{n}的最小公倍数为:{MinCommonMutipleOfMath(m,n, MaxCommonFactorOfMath(m, n))}");}/** 最小公倍数=两数的乘积/最大公约(因)数,解题时要避免和最大公约(因)数问题混淆*/static Double MinCommonMutipleOfMath(double m, double n, double maxCommonFactor){return m * n / maxCommonFactor;}/** 辗转相除法(欧几里德法)* 用较小数除较大数,再用出现的余数(第一余数)去除除数,再用出现的余数(第二余数)去除第一余数,如此反复,直到最后余数是0为止。如果是求两个数的最大公约数,那么最后的除数就是这两个数的最大公约数。*/static int MaxCommonFactorOfMath(int m, int n){int a=0, b=0, temp=0;a = m;b = n;while (a%b!=0){temp = a % b;a = b;b = temp;}return b;}

输出

m=6
n=8
6与8的最小公倍数为:24
请按任意键继续. . .

11.

写一个方法,求s=1/a+1/aa+1/aaa+1/aaaa+1/aa…a的值,其中a是用户定义的数字。例如1/2+1/22+1/222+1/2222+1/22222(此时共有5个数相加),返回值为和s。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int a = 0, n = 0;Console.Write("a=");a = Convert.ToInt32(Console.ReadLine());Console.Write("需要的项数=");n = Convert.ToInt32(Console.ReadLine());//输出并保留六位小数Console.WriteLine($"S={returnSum(a,n):0.000000}");}static double returnSum(double a, int n){double sum = 0;for (int i=0; i<n ; i++){sum += 1 / (a);a = a * 10 + a;}return sum;}

输出

a=2
需要的项数=5
S=0.549997
请按任意键继续. . .

12.

写一个方法,判断一个数是否是完数,返回值为布尔类型。一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如6=1+2+3。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int a = 0;Console.Write("请输入要判断的数:");a = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"{a}{(CheckNum(FactorOfMath(a),a)?"是":"不是")}完数");}//判断是否为完数:一个数如果恰好等于它的真约数(除本身以外的因数)之和,这个数就称为“完数”static bool CheckNum(List<int> factorsList, int num){int sum = 0;foreach (int temp in factorsList){sum += temp;}return sum == num ?true:false;}//求除本身以外的因数static List<int> FactorOfMath(int num){List<int> list = new List<int>();//注意:这里根据题意没有包括本身,去掉该数本身,剩下的就是它的真约数for (int i = 1; i < num; i++){if (num % i == 0)list.Add(i);}return list;}

输出

请输入要判断的数:6
6是完数
请按任意键继续. . .

13.

写一个方法,求分数序列:2/1,1/3,3/4,4/7,7/11,11/18…的前10项之和,并返回。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int n = 0;Console.Write("请输入计算的项数N=");n = Convert.ToInt32(Console.ReadLine());//输出并保留六位小数Console.WriteLine($"计算{n}项的和为:{returnSum(n):0.000000}");}static double returnSum(int n){double temp = 0;//分子 分母 和double mol, den, sum;mol = 2;den = 1;sum = 0;for (int i=0; i<n; i++){sum += mol / den;//规律为:下一项分子为上一项分母,下一项分母为上一项分子与分母之和temp = mol;mol = den;den = temp + den;}return sum;}

输出

请输入计算的项数N=10
计算10项的和为:7.376255
请按任意键继续. . .

14.

写一个方法,求1+1/2!+1/3!+…+1/n!的和,并将和作为返回值返回,要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int n = 0;Console.Write("n=");n = Convert.ToInt32(Console.ReadLine());//输出并保留三位小数Console.WriteLine($"结果为:{returnResult(n):0.000}");}/** 返回1+1/2!+1/3!+...+1/n!的和*/static double returnResult(int n){double sum = 0;for (int i=1; i<=n; i++){sum += 1.0 / (returnMultiple(i));}return sum;}/** 返回阶乘*/static int returnMultiple(int num){int result = 1;for (int i=num;i>0;i-- ){result *= i;}return result;}

输出

n=3
结果为:1.667
请按任意键继续. . .

15.

写一个方法,对4位整数进行加密,加密规则如下:每位数字都加上7,然后用和除以10的余数代替该数字,再将第一位和第二位交换,第四位和第三位交换,该方法返回加密后的数字。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int num=0;Console.Write("请输入要处理的的数字:");num = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"{num}按照规则处理后为:{returnResult(num)}");}/** 每位数字都加上7,然后用和除以10的余数代替该数字,再将第一位和第二位交换,第四位和第三位交换,该方法返回加密后的数字。*/static int returnResult(int num){int a=0, b=0, c=0, d=0;//各位按规则加密a = (num / 1000 + 7) % 10;b = (num % 1000 / 100 + 7) % 10;c = (num % 1000 % 100 / 10 + 7) % 10;d = (num % 1000 % 100 % 10 + 7) % 10;//交换顺序return b*1000+a*100+d*10+c;}

输出

请输入要处理的的数字:1234
1234按照规则处理后为:9810
请按任意键继续. . .

16.

在歌星大奖赛中,有7个评委为参赛的选手打分,分数为1~100分。选手最后得分为:去掉一个最高分和一个最低分后其余5个分数的平均值。请编写一个方法实现。要求编写应用程序,来检验方法的正确性。

实现

//评委数const int N = 7;static void Main(string[] args){float[] scoreArray = new float[N];for (int i=0 ; i<scoreArray.Length ; i++ ){Console.Write($"请输入第{i+1}位评委的分数:");scoreArray[i] = Convert.ToInt32(Console.ReadLine());}Console.WriteLine($"去掉一个最高分和一个最低分后其余5个分数的平均值为:{returnAve(scoreArray)}");}static float returnAve(float[] array){float sum = 0;List<float> list = array.ToList<float>();//排序list.Sort();//删去最大、最小值list.RemoveAt(0);list.RemoveAt(list.Count-1);//求和foreach (float temp in list){sum += temp;}//返回平均值return sum / list.Count;}

输出

请输入第1位评委的分数:1
请输入第2位评委的分数:2
请输入第3位评委的分数:3
请输入第4位评委的分数:4
请输入第5位评委的分数:5
请输入第6位评委的分数:6
请输入第7位评委的分数:7
去掉一个最高分和一个最低分后其余5个分数的平均值为:4
请按任意键继续. . .

17.

写一个方法,在一个字符串中查找最长单词,单词之间用空格分隔,并将最长单词作为方法返回值返回。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){String str = String.Empty;Console.Write("请输入字符串:");str = Console.ReadLine();Console.WriteLine($"该字符串中最长的单词为:{MaxLengthWord(str)}");}/** 在一个字符串中查找最长单词,单词之间用空格分隔,并将最长单词作为方法返回值返回。*/static String MaxLengthWord(String str){int maxIdex = 0;char[] separator = {' '};//拆分并指定删除空字符串("")string[] vs = str.Split(separator,StringSplitOptions.RemoveEmptyEntries);for (int i=1;i<vs.Length ;i++ ){if (vs[i].Length > vs[maxIdex].Length)maxIdex = i;}return vs[maxIdex];}

输出

请输入字符串:I am   a    student and   a God
该字符串中最长的单词为:student
请按任意键继续. . .

18.

写一个方法,对于给定一个日期,返回该日为星期几。例如2002-3-28返回星期四。要求编写应用程序,来检验方法的正确性。

实现

 static void Main(string[] args){String dateStr = String.Empty;Console.Write("请输入时间字符串:");dateStr = Console.ReadLine();Console.WriteLine($"当天为:{ReturnDayName(dateStr)}");}/** 对于给定一个日期,返回该日为星期几。例如2002-3-28返回星期四。*/static String ReturnDayName(String str){String result = null;DateTime date = new DateTime();//使用TryParse 不会抛出异常if (DateTime.TryParse(str,out date)){switch (DateTime.Parse(str).DayOfWeek) {case DayOfWeek.Sunday: result = "星期天" ;break;case DayOfWeek.Monday: result = "星期一"; break;case DayOfWeek.Tuesday: result = "星期二"; break;case DayOfWeek.Wednesday: result = "星期三"; break;case DayOfWeek.Thursday: result = "星期四"; break;case DayOfWeek.Friday: result = "星期五"; break;case DayOfWeek.Saturday: result = "星期六"; break;}}return result;}

输出

请输入时间字符串:2002-3-28
当天为:星期四
请按任意键继续. . .

19.

写一个方法,随机产生10个[20,50]的正整数存放到数组中,并输出数组中的所有元素最大值、最小值、平均值及各元素之和。要求编写应用程序,来检验方法的正确性。

实现

const int N = 10;static void Main(string[] args){float ave = 0f;int max=0, min=0, sum=0;RandomResult(out max, out min, out ave, out sum);Console.WriteLine($"最大值:{max} 最小值:{min} 平均值:{ave} 元素之和:{sum}");}/** 随机产生10个[20,50]的正整数存放到数组中,并输出数组中的所有元素最大值、最小值、平均值及各元素之和。* 注意:使用out关键字必须在方法内为out关键字修饰的变量赋值*/private static void RandomResult(out int max, out int min, out float ave, out int sum){int[] vs = new int[N];int temp = 0;Random random = new Random();for (int i=0;i<vs.Length;i++){vs[i] = random.Next(20,52);temp += vs[i];}//排序Array.Sort(vs);min = vs[0];max = vs[vs.Length - 1];ave = (float)temp / vs.Length;sum = temp;}

输出

最大值:50 最小值:21 平均值:34.8 元素之和:348
请按任意键继续. . .

20.

已知一个数列的前两项分别为1,2,以后的各项都是其相邻的前两项之和,写一个方法,求计算并返回该数列前n项的平方根之和sum。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int n = 0;Console.Write("请输入n=");n = Convert.ToInt32(Console.ReadLine());//输出并保留六位小数Console.WriteLine($"前{n}项的平方根之和sum为:{ReturnResult(n):0.000000}");}/** 已知一个数列的前两项分别为1,2,以后的各项都是其相邻的前两项之和,写一个方法,求计算并返回该数列前n项的平方根之和sum。*/static double ReturnResult(int n){double sum = 0;List<int> list = new List<int>();list.Add(1);list.Add(2);sum += Math.Sqrt(list[0]) + Math.Sqrt(list[1]);for (int i=2;i<n;i++){list.Add(list[i-1]+list[i-2]);sum += Math.Sqrt(list[i]);}return sum;}

输出

请输入n=3
前3项的平方根之和sum为:4.146264
请按任意键继续. . .

21.

编写一个方法,判断一个数是否能被3整除但不能被7整除,编写应用程序,输出1-100以内的所有能被3整除但不能被7整除的数。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){Console.Write("1-100以内的所有能被3整除但不能被7整除的数:");for (int i = 1; i <= 100; i++){//输出并右对齐占3个字符if (CheckNum(i))Console.Write($"{i,3}");}Console.WriteLine();}/** 判断被3整除但不能被7整除的数。*/static bool CheckNum(int num){return (num % 3 == 0 && num % 7 != 0) ? true :false;}

输出

1-100以内的所有能被3整除但不能被7整除的数:  3  6  9 12 15 18 24 27 30 33 36 39 45 48 51 54 57 60 66 69 72 75 78 81 87 90 93 96 99
请按任意键继续. . .

22.

编写一个方法,计算1到n之间所有数的平方求和,要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int n = 0;Console.Write("请输入n=");n = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"1到{n}之间所有数的平方的和为:{ReturnResult(n)}");}/** 计算1到n之间所有数的平方求和。*/static double ReturnResult(int n){double sum = 0;for (int i=1;i<=n;i++){sum += Math.Pow(i, 2);}return sum;}

输出

请输入n=2
1到2之间所有数的平方的和为:5
请按任意键继续. . .

23.

编写一个方法,判断一个三位数是否等于其每位数字的立方和,例如153=1+125+27,要求编写应用程序,来检验方法的正确性。要求编写应用程序,来检验方法的正确性。

实现

 static void Main(string[] args){int num = 0;Console.Write("请输入要判断的三位数:");num = Convert.ToInt32(Console.ReadLine());if (num >= 100 && num <= 999)Console.WriteLine($"{num}{(CheckNum(num) ? "等" : "不等")}于其每位数字的立方和.");elseConsole.WriteLine("输入错误!");}/** 判断一个三位数是否等于其每位数字的立方和。*/static bool CheckNum(int num){int a= 0, b = 0, c = 0;a = num / 100;b = num % 100 / 10;c = num % 100 % 10 / 1;return (Math.Pow(a,3)+ Math.Pow(b, 3)+ Math.Pow(c, 3))==num;}

输出

请输入要判断的三位数:153
153等于其每位数字的立方和.
请按任意键继续. . .

[❓]24.

编写一个方法,判断一个数是否既能被3或者7整除,但同时不能被3和7整除,要求编写应用程序,来检验方法的正确性。要求编写应用程序,来检验方法的正确性。

实现

static void Main(string[] args){int num = 0;Console.Write("请输入要判断的数:");num = Convert.ToInt32(Console.ReadLine());Console.WriteLine($"{num}{(CheckNum(num) ? "符合" : "不符合")}要求.");}/** 判断一个数是否既能被3或者7整除,但同时不能被3和7整除*/static bool CheckNum(int num){return (num%3==0&&num%7==0&&num%(3*7)!=0);}

输出

请输入要判断的数:21
21不符合要求.
请按任意键继续. . .

三、类设计

1.

设计员工类(Worker)及其子类经理类(Manager),员工类包含私有字段name,salary;并设置其属性Name,Salary;经理类还有自己的私有成员字段bonus,及其对应属性Bonus;员工类、经理类都要有自己的无参、有参构造方法;
在main中创建一个员工数组(经理作为其一个元素),并为数组没个元素赋值,要求打印输出该员工数组的姓名和薪水信息。

实现

Worker类及其派生类

 //员工类class Worker{//姓名private String name;//属性public String Name{get { return name; }set { name = value; }}//薪资private String salary;public String Salary{get { return salary; }  set { salary = value; }}//属性//无参构造public Worker(){}public Worker(String name, String salary){this.Name = name;this.Salary = salary;}//重写ToStringpublic override String ToString(){return String.Format("姓名:{0} 薪资:{1}",this.Name,this.Salary);}}class Manager : Worker{private String bonus;public String Bonus{get { return bonus; }set { bonus = value; }}public Manager(){}public Manager(String name, String salary,String bonus):base(name,salary){//剩下的参数在这里赋值即可this.Bonus = bonus;}//重写ToStringpublic override String ToString(){return String.Format("姓名:{0} 薪资:{1} 津贴:{2}", this.Name, this.Salary,this.Bonus);}}

调用

static void Main(string[] args){Worker[] workers=new Worker[2];workers[0] = new Worker("小黑","3000");workers[1] = new Manager("L-Dragon", "30k+", "1k+");foreach (Worker temp in workers){Console.WriteLine(temp);}}

输出

姓名:小黑 薪资:3000
姓名:L-Dragon 薪资:30k+ 津贴:1k+
请按任意键继续. . .

2.

设计学生类(Student)及其子类研究生类(Graduate),学生类包含私有成员字段name,credit;并包含其属性Name,Credit;研究生类包含自己的私有变量postCredit;并包含其属性PostCredit,学生类(Student)及其子类研究生类(Graduate)要有自己的无参、有参构造方法;
现需创建一个研究生对象并设置其postcredit,另建立学生数组(研究生作为其一个元素),要求打印输出该学生数组的姓名和学分信息。

实现

Student类及其派生类

 internal class Student{private String name;private String credit;public Student(){}public Student(string name, string credit){this.name = name;this.credit = credit;}public string Name { get => name; set => name = value; }public string Credit { get => credit; set => credit = value; }public override string ToString(){return String.Format("姓名:{0} 学分:{1} ", this.Name, this.Credit);}}class Graduate:Student{private String postCredit;public Graduate(){}public Graduate(String name, String credit, string postCredit):base(name,credit){this.postCredit = postCredit;}public String PostCredit{get { return postCredit; }set { postCredit = value; }}public override string ToString(){return String.Format("姓名:{0} 学分:{1} 研究生学分:{2}",this.Name,this.Credit,this.PostCredit);}}

调用

static void Main(string[] args){Student[] students = new Student[2];students[0] = new Student("小黑","差");students[1] = new Graduate("L-Dragon","优秀","优秀");foreach (Student temp in students){ Console.WriteLine(temp);}}

输出

姓名:小黑 学分:差
姓名:L-Dragon 学分:优秀 研究生学分:优秀
Press any key to continue . . .

3.

定义一个名为Vehicles交通工具的基类:
该类中包含私有成员字段商标和颜色,并设置其相应的公有属性;
类中包含成员方法Run来模拟交通工具开动,该方法只输出“我已经开动了”信息;
类中包含成员方法ShowInfo来显示信息,该方法输出显示商标和颜色;
完成基类的无参有参构造方法,
编写Car小汽车类继承于Vehicles类,对于此类:
增加成员字段座位,并设置其相应的公有属性;
增加成员方法ShowCar,输出显示小汽车的信息;
覆盖父类的Run方法,输出显示“汽车开动了的信息”;
完成小汽车类的无参有参构造方法;
在main方法中测试以上各类。

实现

Vehicles及其派生类

internal class Vehicles{private String brand;private String color;public string Brand { get => brand; set => brand = value; }public string Color { get => color; set => color = value; }public Vehicles(){}public Vehicles(string brand, string color){this.brand = brand;this.color = color;}public virtual void Run(){Console.WriteLine("我已经开动了");}public void ShowInfo(){Console.WriteLine("商标:{0} 颜色:{1}",this.Brand,this.Color);}}class Car:Vehicles{private int seat;public int Seat { get => seat; set => seat = value; }public Car(){}public Car(String brand, String color, int seat):base(brand,color){this.seat = seat;}public void ShowCar(){Console.WriteLine($"我是{seat}座的小车");}public override void Run(){Console.WriteLine($"{Seat}座的汽车开动了");}}

调用

static void Main(string[] args){Vehicles vehicles = new Vehicles("百度无人车","蓝色");Car car = new Car("亚马逊无人车", "蓝色",4);vehicles.Run();vehicles.ShowInfo();car.Run();car.ShowInfo();}

输出

我已经开动了
商标:百度无人车 颜色:蓝色
4座的汽车开动了
商标:亚马逊无人车 颜色:蓝色
Press any key to continue . . .

4.

定义一个名为Vehicles交通工具的基类:
该类中包含私有成员字段商标和颜色,并设置其相应的公有属性;
类中包含成员方法run来模拟交通工具开动,该方法输出显示“我已经开动了”信息;
类中包含成员方法ShowInfo来显示信息,该方法输出显示商标和颜色
完成父类的无参有参构造方法;
编写Truck卡车类继承于Vehicles类对于此类:
增加成员字段载重,并设置其相应的公有属性;
增加成员方法showTruck,输出显示卡车的信息;
完成卡车类的无参有参构造方法;
覆盖父类的run方法,输出显示“开车开动了的信息”;
在main方法中测试以上各类。

实现

Vehicles类及其派生类

 internal class Vehicles{private String brand;private String color;public string Brand { get => brand; set => brand = value; }public string Color { get => color; set => color = value; }public Vehicles(){}public Vehicles(string brand, string color){this.brand = brand;this.color = color;}public virtual void Run(){Console.WriteLine("我已经开动了");}public void ShowInfo(){Console.WriteLine("商标:{0} 颜色:{1}",this.Brand,this.Color);}}class Truck:Vehicles{private int capacity;public int Capacity { get => capacity; set => capacity = value; }public Truck(){}public Truck(String brand, String color, int capacity):base(brand,color){this.Capacity=capacity;}public void ShowTruck(){Console.WriteLine($"我是载重{Capacity}吨的卡车");}public override void Run(){Console.WriteLine($"载重{Capacity}吨的卡车开动了");}}

调用

static void Main(string[] args){Vehicles vehicles = new Vehicles("百度无人车","蓝色");Truck truck = new Truck("大卡车", "蓝色",80);vehicles.Run();vehicles.ShowInfo();truck.Run();truck.ShowTruck();}

输出

我已经开动了
商标:百度无人车 颜色:蓝色
载重80吨的卡车开动了
我是载重80吨的卡车
Press any key to continue . . .

5.

创建一个名称为IVehicle的接口:
在接口中添加两个方法Start()和Stop()用以描述车辆的启动和停止。
创建Bike自行车类:
该类包含私有成员字段wheel车轮个数,并设置其相应的公有属性
完成该类的无参有参构造方法
实现IVehicle接口的两个方法;
创建Bus公共汽车类:
该类包含私有成员字段seat座位个数,并设置其相应的公有属性;
完成该类的无参有参构造方法;
实现IVehicle接口的两个方法;
在main方法中定义IVehicle数组,并存放Bike和Bus对象,来测试以上各类。
扩展: C#中字段与属性的区别

实现

接口及其实现类:

//接口 默认包含 public abstract,另外接口中不可以含有 字段 但可以存在属性interface IVehicle{void Start();void Stop();}//Bike类实现IVehicle接口class Bike : IVehicle {private int wheel;public int Wheel{get { return wheel; }set { wheel = value; }}public Bike() { }public Bike(int wheel) {this.wheel = wheel;}//隐式实现  -实现接口时,不要写override,注意与重写父类做区别public void Start() {Console.WriteLine("{0}轮自行车启动了...",this.wheel);}//隐式实现public void Stop(){Console.WriteLine("{0}轮自行车刹车了...", this.wheel);}}//Bus类实现IVehicle接口class Bus : IVehicle {private int seat;public int Seat{get { return seat; }set { seat = value; }}public Bus() {}public Bus(int seat) {this.seat = seat;}//隐式实现public void Start(){Console.WriteLine("{0}坐公交车启动了...", this.seat);}//隐式实现public void Stop(){Console.WriteLine("{0}坐公交车刹车了...", this.seat);}//------------------与题目无关,仅供扩展学习---------------------------显式实现 -不加 访问修饰符,另外在调用时也必须上转型为其接口类型才可以调用//void IVehicle.Stop()//{//    //...//}}

调用:

static void Main(string[] args){IVehicle[] vehicles = new IVehicle[2];vehicles[0] = new Bike(2);vehicles[1] = new Bus(4);//如果实现类似Java instanceof 关键字效果,在C#中可以使用is判断foreach (IVehicle temp in vehicles){temp.Start();temp.Stop();}}

输出

2轮自行车启动了...
2轮自行车刹车了...
4坐公交车启动了...
4坐公交车刹车了...
请按任意键继续. . .

6.

定义一个宠物类(Pet):
该类包括两个方法:叫Cry(),吃东西Eat();
该类中定义私有的成员字段name姓名和age年龄,并设置其相应的公有属性;
完成该类的无参有参构造方法;
定义宠物的子类狗(Dog):
覆盖父类的Cry(),Eat()方法;增加方法看门GuardEntrance()
完成该类的无参有参构造方法;
定义宠物的子类猫(Cat):
覆盖父类的Cry(),Eat()方法;
增加猫自己独有的方法捉老鼠HuntMice();
完成该类的无参有参构造方法;
在main中定义两个Pet变量,pet1,pet2,采用引用转型实例化Dog,Cat,分别调用Pet的Cry(),Eat();将Pet强制转换为具体的Dog,Cat,在调Dog的GuardEntrance(),Cat的HuntMice()。

实现

Pet类及其派生类:

//Pet类 如果不想被其他类继承,可添加sealed关键字成为密封类class Pet{private int age;public int Age{get { return age; }set { age = value; }}private String name;public String Name{get { return name; }set { name = value; }}public Pet() { }public Pet(int age, String name) {this.age = age;this.name = name;}//注意:如果允许该方法被子类重写,需要加上 virtual 修饰符,另外abstrat关键字已包含virtualpublic virtual void Cry() {Console.WriteLine("{0}岁的宠物{1}叫了...",this.age,this.name);}public virtual void Eat() {Console.WriteLine("{0}岁的宠物{1}吃东西了...",this.age,this.name);}}//Dog类继承Pet类class Dog : Pet {//无参构造方法public Dog() { }//创建有参构造方法并调用并将参数传递给了父类的构造方法public Dog(int age,String name):base(age,name) { //注意:如果还存在子类新增属性,则可以在这里赋值}public override void Cry() {Console.WriteLine("{0}岁的狗{1}叫了...", this.Age, this.Name);}//注意:重写父类方法需要在父类允许的情况下并添加重写修饰 override ,如果不添加则在使用父类调用的情况下默认使用父类的Eat方法public override void Eat(){//注意:不可直接引用父类private私有属性,但是其设置了公开属性访问器,所以可以通过访问器操作Console.WriteLine("{0}岁的狗{1}吃东西了...", this.Age, this.Name);}public void GuardEntrance() {Console.WriteLine("{0}岁的狗{1}在看门...", this.Age, this.Name);}}//Cat类继承Pet类class Cat : Pet {public Cat() {}public Cat(int age, String name) : base(age, name) {}public override void Cry(){Console.WriteLine("{0}岁的猫{1}叫了...", this.Age, this.Name);}public override void Eat(){Console.WriteLine("{0}岁的猫{1}吃东西了...", this.Age, this.Name);}public void HuntMice() {Console.WriteLine("{0}岁的猫{1}在捉老鼠...", this.Age, this.Name);}}

调用:

 static void Main(string[] args){Pet pet1 = new Dog(2, "小黑");Pet pet2 = new Cat(1, "小花");//宠物狗pet1.Cry();pet1.Eat();((Dog)pet1).GuardEntrance();//宠物猫pet2.Cry();pet2.Eat();((Cat)pet2).HuntMice();}

输出

2岁的狗小黑叫了...
2岁的狗小黑吃东西了...
2岁的狗小黑在看门...
1岁的猫小花叫了...
1岁的猫小花吃东西了...
1岁的猫小花在捉老鼠...
请按任意键继续. . .

7.

创建一个名称为IShape的接口:
在接口中添加求面积方法Area()和求体积方法Volumn()。
定义一个立方体的类Prog:
字段包括长、宽、高;并定义相应属性;
方法包括:构造方法(初始化立方体的长宽高);
实现接口IShape;
在main中创建一个立方体对象,计算并显示其面积和体积。

实现

IShape接口及其实现类

internal interface IShape{double Area();double Volumn();}class Prog : IShape{private double length;private double width;private double height;public double Length { get => length; set => length = value; }public double Width { get => width; set => width = value; }public double Height { get => height; set => height = value; }public Prog(){}public Prog(double length, double width, double height){Length = length;Width = width;Height = height;}public double Area(){return 2 * (length*width+length*height+height*width);}public double Volumn(){return length * width * height;}}

调用

 static void Main(string[] args){Prog prog = new Prog(2,3,2);Console.WriteLine($"面积:{prog.Area()} 体积:{prog.Volumn()}");}

输出

面积:32 体积:12
Press any key to continue . . .

8.

创建一个名称为IShape的接口:
在接口中添加求面积方法Area()和求体积方法Volumn()。
定义一个球的类Ball:
字段包括半径;并定义相应属性;
方法包括:构造方法(初始化球的半径);
实现接口IShape;
在main中创建一个球对象,计算并显示其面积和体积。

实现

IShape接口及其实现类

 internal interface IShape{double Area();double Volumn();}class Ball : IShape { private double radius;public Ball(double radius){this.Radius = radius;}public double Radius { get => radius; set => radius = value; }public double Area(){return Math.PI * Math.Pow(radius * 2, 2);}public double Volumn(){return 4 / 3 * Math.PI * Math.Pow(radius,3);}}

调用

static void Main(string[] args){IShape shape = new Ball(5);Console.WriteLine($"面积:{shape.Area():0.000} 体积:{shape.Volumn():0.000}");}

输出

面积:314.159 体积:392.699
Press any key to continue . . .

9.

创建一个名称为Square的类:
该类中定义私有的成员字段edge,并设置其相应的公有属性;
完成该类的无参有参构造方法;
该类包含方法Circumference(周长)和面积(Area);
定义子类正方体Cube类:
完成该类的无参有参构造方法;
实现该类的面积(Area)和体积(Volumn)方法。
在main中创建正方形对象,计算并显示其周长和面积;创建正方体对象,计算并显示其面积和体积。

实现

Square抽象类及其派生类

//正方形internal class Square{private double edge;public double Edge { get => edge; set => edge = value; }public Square(){}public Square(double edge){Edge = edge;}public double Circumference(){return edge * 4;}public virtual double Area(){return Math.Pow(edge,2);}}//正方体class Cube : Square{public Cube(){}public Cube(double edge) : base(edge){}public override double Area(){return Math.Pow(Edge,2)*6;}public double Volumn(){return Math.Pow(Edge,2)*Edge;}}

调用

static void Main(string[] args){Square square = new Square(2);Cube cube = new Cube(2);Console.WriteLine($"正方形 面积:{square.Area():0.000} 周长:{square.Circumference():0.000}");Console.WriteLine($"正方体 面积:{cube.Area():0.000} 体积:{cube.Volumn():0.000}");}

输出

正方形 面积:4.000 周长:8.000
正方体 面积:24.000 体积:8.000
Press any key to continue . . .

10.

创建一个名称为Circle的类:
该类中定义私有的成员字段radius,并设置其相应的公有属性;
完成该类的无参有参构造方法;
该类包含方法Circumference(周长)和面积(Area);
定义子类圆柱体Cylinder类:
字段包括高;并定义相应属性;
完成该类的无参有参构造方法;
实现该类的面积(Area)和体积(Volumn)方法。
在main中创建圆类对象,计算并显示其周长和面积;创建圆柱体对象,计算并显示其面积和体积。

实现

Circle类及其派生类

 internal class Circle{private double radius;public double Radius { get => radius; set => radius = value; }public Circle(){}public Circle(double radius){this.radius = radius;}public double Circumference(){return Math.PI * 2 * radius;}public virtual double Area(){return Math.Pow(radius,2)*Math.PI;}}class Cylinder : Circle{private double height;public Cylinder(){}public Cylinder(double radius, double height) : base(radius){this.height = height;}public double Height { get => height; set => height = value; }public override double Area(){//在C#中使用base实现与Java中super关键字的效果return base.Area()*2+base.Circumference()*height;}public double Volumn(){return Math.Pow(Radius,2)*Math.PI*height;}}

调用

static void Main(string[] args){Circle circle = new Circle(2);Cylinder cylinder = new Cylinder(2,2);Console.WriteLine($"圆 面积:{circle.Area():0.000} 周长:{circle.Circumference():0.000}");Console.WriteLine($"圆柱 面积:{cylinder.Area():0.000} 体积:{cylinder.Volumn():0.000}");}

输出

圆 面积:12.566 周长:12.566
圆柱 面积:50.265 体积:25.133
Press any key to continue . . .

11.

创建一个Student类,要求:
(1)封装学生的姓名、性别和成绩等信息;
(2)通过构造函数给姓名和性别信息赋值;
(3)成绩信息通过属性进行读写,对成绩赋值时,如果成绩大于100分赋值100,小于0分赋值0;
(4)具有一个判断成绩等级的方法;
在main中使用Student类。

实现

Student类

internal class Student{private String name;private String sex;private int score;public Student(){}public Student(string name, string sex){this.name = name;this.sex = sex; }public string Name { get => name; set => name = value; }public string Sex { get => sex; set => sex = value; }public int Score { get => score; set => score = (value>100)?100:(value<0?0:value); }public void CheckScoreGrade(){Console.WriteLine($"{sex}同学{name}的{score}分成绩为{(score >= 80 ? "优秀" : (score < 80 && score >= 60 ? "及格" : "不及格"))}");}}

调用

static void Main(string[] args){Student student = new Student("小黑","男");student.Score = 88;student.CheckScoreGrade();}

输出

男同学小黑的88分成绩为优秀
Press any key to continue . . .

12.

创建一个List类,可以存储整数、实数、字符数据等,并具有可以添加、删除、获取指定位置的元素、获取元素的个数、获取所有元素等方法。并在main中进行相关测试。

实现

class List{private readonly static ArrayList arrayList=new ArrayList();//更优雅的使用属性 获取元素个数public int Size { get => arrayList.Count; }public List(){}public void Add(Object obj){arrayList.Add(obj);}public void Remove(int index){arrayList.RemoveAt(index);}public Object Get(int index){return arrayList[index];}//获取元素个数//public int Count()//{//    return arrayList.Count;//}public ArrayList GetAll(){return arrayList;}}

输出

第一次获取所有数据: 1 1.223 你好 h
元素个数为:4获取第一个数据:1第二次获取所有数据: 1 你好 h
元素个数为:3
Press any key to continue . . .

13.

输入若干学生的学号、姓名、英语、数学、语文、物理、化学、生物成绩,并求出总分和平均分,按总分从高到低排序。要求:设计一个学生类Student,所有学生对象存储到数组中,按总分排序,并输出最后结果。

实现

在这里插入代码片

输出

在这里插入代码片

14.

输入若干学生的学号、姓名、英语、数学、语文、物理、化学、生物成绩,并求出总分和平均分,按总分从高到低排序。要求:设计一个学生类Student,所有学生对象存储到集合中,按总分排序,并输出最后结果。

实现

Student类

internal class Student{private String stuNumber;private String name;private float englishScore;private float mathScore;private float chineseScore;private float physicsScore;private float chemistryScore;private float biologyScore;private float sum;private float ave;public string StuNumber { get => stuNumber; set => stuNumber = value; }public string Name { get => name; set => name = value; }//注意:属性如果采用expression-bodied形式,则只能执行一条语句public float EnglishScore { get => englishScore; set { englishScore = value; sum += value; } }public float MathScore { get => mathScore; set { mathScore = value;sum += value; } }public float ChineseScore { get => chineseScore; set { chineseScore = value;sum += value; } }public float PhysicsScore { get => physicsScore; set { physicsScore = value;sum += value; } }public float ChemistryScore { get => chemistryScore; set { chemistryScore = value;sum += value; } }public float BiologyScore { get => biologyScore; set { biologyScore = value; sum += value; } }public float Sum { get => sum; set => sum = value; }public float Ave { get => ave; set => ave = value; }public Student(){}public Student(string stuNumber, string name, float englishScore, float mathScore, float chineseScore, float physicsScore, float chemistryScore, float biologyScore){this.stuNumber = stuNumber;this.name = name;this.englishScore = englishScore;this.mathScore = mathScore;this.chineseScore = chineseScore;this.physicsScore = physicsScore;this.chemistryScore = chemistryScore;this.biologyScore = biologyScore;Sum += englishScore;Sum += mathScore;Sum += physicsScore;Sum += chemistryScore;Sum += chineseScore;Sum += biologyScore;Ave = Sum / 6;}public override string ToString(){return String.Format("学号{0} 姓名:{1} 英语:{2} 数学:{3} 语文:{4} 化学:{5} 物理:{6} 生物:{7} 平均分:{8} 总分:{9}",stuNumber,Name,englishScore,mathScore,chineseScore,chemistryScore,physicsScore,biologyScore,ave,sum);}}

调用

//学生位数const int N = 3;static void Main(string[] args){Student[] students = new Student[N];for (int i=0;i<students.Length ;i++ ){Student student = new Student();Console.Write($"请输入第{i+1}个学生的学号:");student.StuNumber = Console.ReadLine();Console.Write($"请输入第{i + 1}个学生的姓名:");student.Name = Console.ReadLine();Console.Write($"请输入第{i + 1}个学生的英语成绩:");student.EnglishScore = float.Parse(Console.ReadLine());Console.Write($"请输入第{i + 1}个学生的数学成绩:");student.MathScore = float.Parse(Console.ReadLine());Console.Write($"请输入第{i + 1}个学生的语文成绩:");student.ChineseScore = float.Parse(Console.ReadLine());Console.Write($"请输入第{i + 1}个学生的物理成绩:");student.PhysicsScore = float.Parse(Console.ReadLine());Console.Write($"请输入第{i + 1}个学生的生物成绩:");student.BiologyScore = float.Parse(Console.ReadLine());Console.Write($"请输入第{i + 1}个学生的化学成绩:");student.ChemistryScore = float.Parse(Console.ReadLine());students[i] = student;}/*** Value Meaning Less than 0 x is less than y. 0 x equals y. Greater* than 0 x is greater than y.*/Array.Sort(students, (a, b) => { return (int)(a.Sum-b.Sum); });Console.WriteLine("按总分排名:");//隐式类型本地变量 var 关键字指示编译器通过初始化语句右侧的表达式推断变量的类型。foreach (var student in students){Console.WriteLine(student);}}

输出

请输入第1个学生的学号:3
请输入第1个学生的姓名:3
请输入第1个学生的英语成绩:3
请输入第1个学生的数学成绩:3
请输入第1个学生的语文成绩:3
请输入第1个学生的物理成绩:3
请输入第1个学生的生物成绩:3
请输入第1个学生的化学成绩:3
请输入第2个学生的学号:3
请输入第2个学生的姓名:2
请输入第2个学生的英语成绩:2
请输入第2个学生的数学成绩:2
请输入第2个学生的语文成绩:2
请输入第2个学生的物理成绩:2
请输入第2个学生的生物成绩:2
请输入第2个学生的化学成绩:2
请输入第3个学生的学号:1
请输入第3个学生的姓名:1
请输入第3个学生的英语成绩:1
请输入第3个学生的数学成绩:1
请输入第3个学生的语文成绩:1
请输入第3个学生的物理成绩:1
请输入第3个学生的生物成绩:1
请输入第3个学生的化学成绩:1
按总分排名:
学号1 姓名:1 英语:1 数学:1 语文:1 化学:1 物理:1 生物:1 平均分:0 总分:6
学号3 姓名:2 英语:2 数学:2 语文:2 化学:2 物理:2 生物:2 平均分:0 总分:12
学号3 姓名:3 英语:3 数学:3 语文:3 化学:3 物理:3 生物:3 平均分:0 总分:18
Press any key to continue . . .

15.

设计一个抽象类Calculate,该类包括:
(1)optA、optB、optC三个double类型的字段;
(2)带有两个double类型参数的构造函数(给optA和optB赋值);
(3)计算三个数和的平方根SqrtForSum抽象方法,该方法带有三个double类型的参数,返回值类型为double;
(4)设计一个继承Calculate的派生类Cal,该类包含一个带有三个double类型参数的构造函数,并重写SqrtForSum方法;
(5)在main中进行相关数据验证。

实现

Caculate抽象类及其派生类

internal abstract class Caculate{private double optA;private double optB;private double optC;protected Caculate(){}protected Caculate(double optA, double optB){this.OptA = optA;this.OptB = optB;}public double OptA { get => optA; set => optA = value; }public double OptB { get => optB; set => optB = value; }public double OptC { get => optC; set => optC = value; }public abstract double SqrtForSum(double optA, double optB, double optC);}class Cal : Caculate{public Cal(){//会默认调用父类的无参方法}public Cal(double optA, double optB,double optC) : base(optA, optB){this.OptC = optC;}public override double SqrtForSum(double optA, double optB, double optC){return Math.Pow(optA,3)+ Math.Pow(optB, 3)+ Math.Pow(optC, 3);}}

调用

static void Main(string[] args){Caculate cal = new Cal(1,2,3);Console.WriteLine("结果为:"+cal.SqrtForSum(cal.OptA,cal.OptB,cal.OptC));}

输出

结果为:36
Press any key to continue . . .

16.

设计一个程序,模拟银行存取款业务,要求如下:
(1)定义一个接口IBankAccount,包含三个成员,存款方法PayIn,取款方法WithDraw和余额属性Banlance;
(2)定义一个派生接口ITransfer,基接口为IBankAccount,包含一个转账方法Tansfer;
(3)定义一个类Account,继承ITransfer,并实现类该接口的所有成员;
在main中实现存款、取款、转账、显示余额等操作。

实现

接口IBankAccount及其派生接口与实现类

 public interface IBankAccount{//接口默认包含关键字 public abstract//接口中不可以含有字段,但可以含有属性double Banlance { get; set; }void PayIn(double money);bool WithDraw(double money);}public interface ITransfer : IBankAccount{bool Tansfer(double money,Account account);}public class Account : ITransfer{private String account;private double banlance;public Account(){}public Account(string account, double banlance){this.account = account;this.banlance = banlance;}//防止出现负数public double Banlance { get => banlance; set { banlance=(value < 0 ?0:value); } }//存钱public void PayIn(double money){this.Banlance+=money;}public bool Tansfer(double money, Account account){//判断余额是否可以转账if (this.Banlance >= money){this.Banlance -= money;try{account.Banlance += money;return true;}catch (Exception ex){//如果转账失败,则恢复本账户余额this.Banlance += money;return false;}}else{return false;}}//取钱public bool WithDraw(double money){if (this.Banlance >= money){this.Banlance-=money;return true;}else{return false;}}public override string ToString(){return String.Format("账号:{0} 余额:{1}美元",account,banlance);}}

调用

static void Main(string[] args){Account account_1 = new Account("884955189",1000);Account account_2 = new Account("945955189", 800);//显示信息Console.WriteLine("-----初始信息-------");Console.WriteLine(account_1+"\n"+account_2);//向account_1存钱200美元account_1.PayIn(200);//显示信息Console.WriteLine("------向account_1存钱200美元--------");Console.WriteLine(account_1 + "\n" + account_2);//account_2向account_1转账300美元account_2.Tansfer(300,account_1);//显示信息Console.WriteLine("------account_2向account_1转账300美元--------");Console.WriteLine(account_1 + "\n" + account_2);//account_2取款200美元account_2.WithDraw(200);//显示信息Console.WriteLine("------account_2取款200元--------");Console.WriteLine(account_1 + "\n" + account_2);}

输出

-----初始信息-------
账号:884955189 余额:1000美元
账号:945955189 余额:800美元
------向account_1存钱200美元--------
账号:884955189 余额:1200美元
账号:945955189 余额:800美元
------account_2向account_1转账300美元--------
账号:884955189 余额:1500美元
账号:945955189 余额:500美元
------account_2取款200元--------
账号:884955189 余额:1500美元
账号:945955189 余额:300美元
Press any key to continue . . .

四、windows程序设计题

注:由于该类型题目重复点太多,所以着重做第一题。

1.

在数据库Exam中,包括教师信息表Teachers,其表结构如表所示

表 Teacher(教师信息表)

字段名 类型 宽度 是否空 备注
ID int 4 非空 主键,自增长
Code varchar 10 非空 教工号
Name varchar 10 非空 姓名
Birthday Datetime 8 出生日期
Position varchar 18 非空 职位如教授、副教授等
Email varchar 50 电子邮件

请完成数据库的建立,并利用NET环境创建Window程序TeacherManage,在该系统中实现对教师信息的添加和查询,具体要求如下:

  1. 在主窗体添加需要的菜单栏、工具栏和状态栏,并设置相应的项。
  2. 添加窗体,实现添加教师信息功能,在该窗体,设置相应的控件,录入教师信息,单击“添加”按钮实现将录入信息添加到数据库的表中;
  3. 查询窗体要求根据教工号进行查询,将查询到的详细信息显示到对应的控件中;
  4. 窗体要求设计整洁,控件使用合理,各功能的实现尽量全面、完整。

目录结构

├─Program.cs                 //main method
├─view                       //winform view
|  ├─AddView.cs
|  ├─AddView.Designer.cs
|  ├─AddView.resx
|  ├─MainView.cs
|  ├─MainView.Designer.cs
|  ├─MainView.resx
|  ├─QueryView.cs
|  ├─QueryView.Designer.cs
|  └QueryView.resx
├─utils                     //common utility
|   └R.cs                   //global static config
├─sql                       //sql script
|  └SQLSyntax.sql
├─model                     //entity class
|   └Teacher.cs
├─dao                       //database access class
|  ├─IDAO.cs
|  ├─mysql                  //mysql database ----[off]
|  ├─mssql                  //mysql database ----[on]
|  |   └TeacherDAOImpl.cs
├─control                   //controller
|    ├─AddViewController.cs
|    ├─MainViewController.cs
|    └QueryViewController.cs

效果图

主界面

添加

删除

源代码

项目地址:https://bitbucket.org/b84955189/teacherinformationsystem_1/


下载

题库DOC

期末入门题库-C#实现相关推荐

  1. matlab将常值函数转换为变量,MATLAB与科学计算期末复习题题库15.11.12

    MATLAB 与科学计算期末复习题题库(第一部分) 一.填空 1.MATLAB 的主界面是一个高度集成的工作环境,有四个不同职责分工的窗口,分别 为 . . .和 窗口. 2.MATLAB 的值,应在 ...

  2. 《金融学》期末小题库

    <金融学>期末小题库 前言 写一下期末的小题库,方便考前热身. 金融范畴篇 第一章 货币的本质 第二章 货币制度 第三章 信用.利息和利率 第四章 外汇与汇率 金融市场与金融机构篇 第五章 ...

  3. python 入门题库————python语句和基础数理

    python 入门题库 python 题库 Python使用符号_______表示注释 Python不支持的数据类型有 查看python版本的命令是 在Python中,print(type(16/4) ...

  4. 阿里云服务器ECS入门题库

    Apsara Clouder云计算专项技能认证:云服务器ECS入门题库 题库一 多选题 题库二 多选题 题库三 多选题 保证及格,不保证100分!!! 保证及格,不保证100分!!! 保证及格,不保证 ...

  5. C语言入门题库——温度转换

    C语言入门题库--温度转换 Description:将输入的摄氏温度C转化为华氏温度F和绝对温度K. 温度转换公式为: F=9/5C+32 K=273.16+C Input:输入仅一行,输入一个摄氏温 ...

  6. C语言入门题库——分段函数

    C语言入门题库--分段函数 Description:按下表计算y值,x值由键盘输入.(x,y均为float类型) x y 0<=x<10 sinx 10<=x<20 cosx ...

  7. Apsara Clouder云计算专项技能认证:云服务器ECS入门题库

    Apsara Clouder云计算专项技能认证:云服务器ECS入门题库备份一下: 以下加粗的部分为正确答案,本人得分90分(60分及格),如有错误,也欢迎指正. 2022-02-6修正:多选18答案( ...

  8. c语言期末上机题库,上海海事大学C语言期末上机题库.doc

    上海海事大学C语言期末上机题库.doc 试卷编号:9619所属语言:C语言试卷方案:练习1试卷总分:100分共有题型:5种一.填空 共8题 (共计8分)第1题 (1.0分) 题号:84写出语句 b=( ...

  9. c语言编程入门题库,级程序设计基础题库(c语言)(..更新).doc

    级程序设计基础题库(c语言)(..更新).doc 14级<程序设计基?础>题库100?道 1.总共抽10?道题,按题型:顺序(1道).分支(1道).单循环(2道).多循环(1道).数组(1 ...

最新文章

  1. C++ sizeof 运算符的使用
  2. Bitcoin ABC首席开发者回应有关比特币现金的提问(二)
  3. 使用fis优化web站点
  4. android阿里滑块验证码,在Android App中接入HTML5滑块验证
  5. java注释和注解_深入理解JAVA注解(Annotation)以及自定义注解
  6. 战略管理只是高层的事?
  7. nsis打包php项目加环境,NSIS制作安装文件全攻略(一) zz
  8. Atitit usrQBM2331 参数格式化规范
  9. geoserver服务发布矢量地图流程
  10. shiro简单配置教程
  11. 终于能在Linux下用firefox使用支付宝了!!!
  12. mysql 设置 utc_关于时间:MySQL应该将其时区设置为UTC吗?
  13. 中南林业科技大学Java实验报告十二:数据库系统设计 - 从0到1搭建java可视化学生管理系统源代码
  14. 计算机网络协议测试技术分析
  15. AIMP3音乐播放器的漂亮皮肤-IAMP和Minimal Gray
  16. java实现word文件合并
  17. 机械臂的力矩前馈控制
  18. OpenCv图像处理之resize(缩放)、transpose、rotate(旋转)、flip(翻转)介绍
  19. Apache和tomcat服务器使用ajp_proxy模块
  20. Windows 10 -Jmeter 5.4.1安装与JDK配置

热门文章

  1. 傲慢与偏见之 - 谷歌中国逆袭史
  2. 算法题目:寻找迷失的数字。
  3. 【android】深入理解在Android
  4. Mac中禁用向日葵(Oray)控制端自启动
  5. 对qps、tps、rt、并发数、吞吐量、限流、熔断和降级的了解
  6. php微信退款 v3版,微信支付-JSAPI支付V3-查询退款
  7. 利用Python实现四则运算
  8. Stam的流体solver学习笔记
  9. 最大似然位同步算法总结
  10. 7-4 list 存储动物对象 (10 分)