C#程序题集合-程序填空题(38页).doc
《C#程序题集合-程序填空题(38页).doc》由会员分享,可在线阅读,更多相关《C#程序题集合-程序填空题(38页).doc(39页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-五 程序填空题(红色位置为空,红色文字为答案)(1)字符及其ASCII码转换using System;namespace L2_1 class L2_1 static void Main() Console.Write(请输入一个字符: ); char ch = Console.ReadKey().KeyChar; Console.WriteLine(rn字符0的ASCII代码为1, ch, (int)ch); Console.Write(请输入一个整数:); int i = int.Parse(Console.ReadLine(); Console.WriteLine(ASCII码0对应的
2、字符为1, i, (char)i); (2) 字符串加密和解密using System;namespace L5_2 class L5_2 static void Main() Console.WriteLine(请输入一个字符串:); string text = Console.ReadLine(); Console.Write(请输入加密字符:); int key = Console.Read(); string text1 = ; foreach (char ch in text) text1 += (char)(ch key); Console.WriteLine(加密后的字符串为:
3、+ text1); string text2 = ; foreach (char ch in text1) text2 += (char)(ch key); Console.WriteLine(解密后的字符串为: + text2); (3) 坐标点类public class CzPoint private double x; private double y; public double X get return x; set x = value; public double Y get return y; set y = value; public CzPoint(double x, dou
4、ble y) this.x = x; this.y = y; public void Move(double dx, double dy) x += dx; y += dy; public static bool operator =(CzPoint p1, CzPoint p2) return (p1.x = p2.x) & (p1.y = p2.y); public static bool operator !=(CzPoint p1, CzPoint p2) return (p1.x != p2.x) & (p1.y != p2.y); (4) 通过方法交换两个变量的值using Sys
5、tem;namespace P3_1class FormalParametersSamplepublic static void Main()double x = 5;double y = 10;CzMath c = new CzMath(); Console.WriteLine(交换前x=0, y=1, x, y); /c.Swap(x, y); c.Swap(ref x, ref y); Console.WriteLine(交换后x=0, y=1, x, y);class CzMath public void Swap(ref double x, ref double y) double
6、temp = x; x = y; y = temp; (5)排序输出三个数并求和using System;namespace P3_6 class VariableInitiationSample static void Main() double sum; CzMath.Output(out sum, 1, 2.5, 5); class CzMath /交换两个数的值 public static void Swap(ref double x, ref double y) double temp = x; x = y; y = temp; /排序输出三个数并求和 public static v
7、oid Output(out double sum, params double array) sum = 0; if (array.Length != 3) return; sum = array0 + array1 + array2; if (array0 array1) Swap(ref array0, ref array1); if (array1 array2) Swap(ref array1, ref array2); if (array0 array1) Swap(ref array0, ref array1); Console.WriteLine(0 1 2, array0,
8、array1, array2); Console.WriteLine(sum); (6)闰年测试using System;namespace P4_11class LogicalConditionOperationpublic static void Main()int year; Console.WriteLine(请输入一个年份:); if (int.TryParse(Console.ReadLine(), out year)if (year % 400) = 0 | (year % 4) = 0 & (year % 100) != 0)Console.WriteLine(闰年);else
9、Console.WriteLine(非闰年); (7)using System;namespace P4_12 class Test public static void Main() BankCard card2 = new BankCard(); card2.m_id = 002; CreditCard cc = card2 as CreditCard; if (cc != null) cc.Borrow(50); else Console.WriteLine(0并非信用卡, card2.m_id); class BankCard public string m_id; class Cre
10、ditCard : BankCard public uint m_debit; public void Borrow(uint x) m_debit = m_debit - x; Console.WriteLine(信用卡0: 贷款1元, m_id, x); (8)using System;namespace P4_3 class Test static void Main() Weekday day = Weekday.Sunday; Console.Write(day); enum Weekday Sunday, Monday, Tuesday, Wednesday, Thursday,
11、Friday, Saturday (9)using System;namespace P5_1class Teststatic void Main()Console.WriteLine(请输入之间的一个分数:);int x = int.Parse(Console.ReadLine();switch (x)case 5:Console.WriteLine(优秀);break;case 4:Console.WriteLine(良好);break;case 3:Console.WriteLine(及格);break;default: /3分以下均不及格Console.WriteLine(不及格);b
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 程序 集合 填空 38
限制150内