C#基础试题(附答案)_第1页
C#基础试题(附答案)_第2页
C#基础试题(附答案)_第3页
C#基础试题(附答案)_第4页
C#基础试题(附答案)_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

精品文档 1欢迎下载 一 选择题 1 能作为 C 程序的基本单位是 A 字符 B 语句 C 函数 D 源程序文件 答案 B 2 将变量从字符串类型转换为数值类型可以使用的类型转换方法是 A Str B Cchar C CStr D int Parse 答案 D 3 数据类型转换的类是 A Mod B Convert C Const D Single 答案 B 4 字符串连接运算符包括 Console ReadLine 代码运行结果为 A 在控制台窗口显示 运行结果 B 在控制台窗口显示 运行结果 0 C 在控制台窗口显示 运行结果 Console ReadLine D 如果用户在控制台输入 A 那么程序将在控制台显示 运行结果 A 答案 D 9 在 C 中定义一个数组 正确的代码为 A int arraya new int 5 B int arraya new int 5 C int arraya new int D int 5 arraya new int 答案 B 精品文档 2欢迎下载 10 在 C 中 下列代码运行后 变量 Max 的值是 选择一项 Int a 5 b 10 c 15 Max 0 Max a b a b Max c Max c Max A 0 B 5 C 10 D 15 答案 C 11 在 C 中 关于 continue 和 break 以下说法正确的是 A break 是中断本次循环 B continue 是中断本次循环 进入一下次 的循环 C break 是中断本次循环 进入一下次的循环 D continue 是中断整个循环 答案 A 12 在 C 中 关于 while 和 do while 以下说法正确的是 A while 先执行然后判断条件是否成立 B while 最少的循环次数是 1 次 C do while 先执行然后判断条件是否成立 D do while 最少的循环次数是 0 次 答案 C 13 在 C 中 下列变量定义与赋值正确的是 A int a 同学 B float a 老师 C double a 教室 D char a 学 答案 D 14 表达式 abcde abcde 2006 的值为 A True2006 B true C false D 0 答案 C 15 在 C 中定义类时 使用的关键字是 A interface B intC classD overrides 答案 C 二 写出下列程序的结果 1 int y 1 x if y 0 x 5 else if y 0 x 4 精品文档 3欢迎下载 else x 3 Console WriteLine x 0 x 答案 5 2 int x y 0 do x y Console WriteLine x while y 6 答案 15 3 class Test static void Main int x 5 int y x Console WriteLine y 0 y y x Console WriteLine y 0 y 答案 5 5 4 class Test public static void Main static int a 1 2 3 4 5 6 7 8 int s0 s1 s2 s0 s1 s2 0 for int i 0 i 50 break if i 2 0 s i Console writeLine i s i s 答案 14 S 2 4 6 14 56 6 写出下列函数的功能 static float FH float y 0 n 0 int x Convert ToInt32 Console ReadLine 从键盘读入整型数据赋给 x while x 1 n y x x Convert ToInt32 Console ReadLine if n 0 return y else 精品文档 5欢迎下载 return y n 答案 从键盘中输入输入整型数只要不是 1 就求和 不输入数就返回 0 否则求这几个数 的的平均值 7 using System class Test public static void Main int a 2 4 6 8 10 12 14 16 18 for int i 0 i b a b max max c max c return max 精品文档 6欢迎下载 2 编一个程序 输入一个字符 如果是大写字母 就转换成小写字母 否则不转换 答案 Console Write 输入字符 char c char Parse Console ReadLine char s Change c Console WriteLine 0 s Console ReadKey static char Change char c if c A return b 5 编一个程序 输入 0 100 之间的一个学生成绩分数 用 switch 语句输出成绩等第 成绩优秀 90 100 成绩良好 80 89 成绩及格 60 79 和成绩不及格 59 以下 答案 static void Main string args Score Console ReadKey static void Score int score int Parse Console ReadLine int s score 10 int a if s 9 else a 3 switch a case 0 Console WriteLine 成绩优秀 break break case 1 Console WriteLine 成绩良好 break case 2 Console WriteLine 成绩及格 break default Console WriteLine 成绩不及格 break 6 编一个程序 用 while 循环语句来计算 1 1 2 2 3 3 4 99 100 之和 答案 Console Write sum double sum 1 Console WriteLine 0 Sum Console ReadKey static double Sum double sum 1 精品文档 9欢迎下载 double i 1 while i 100 sum i i 1 i i 1 return sum 7 编写一个程序 用 while 语句 求出 1 1 2 1 2 3 1 2 3 10 之和 答案 int sum 0 Console Write 和为 Console WriteLine 0 Sum Console ReadKey static int Sum int sum 0 int i 1 int a 0 while i 10 a a i sum sum a i i 1 return sum 8 有关系式 1 1 2 2 3 3 k k 2000 编一个程序 求出满足此关系式的 k 的最大值 答案 int sum 0 Console WriteLine 最大值为 0 Max Console ReadKey static int Max int sum 0 int k 1 while sum 2000 精品文档 10欢迎下载 sum k k k return k 1 9 编写一个程序 要求用 while 循环语句 打印 1 到 100 的正整数 每行打印 5 个数 每 列右对齐 答案 Quee Console ReadKey static void Quee for int i 1 i 100 i Console Write 0 i if i 5 0 Console WriteLine i return 10 编一个程序 利用二重 for 循环语句 打印出九九乘法口诀表 答案 Chengfabiao Console ReadKey static void Chengfabiao for int i 1 i 9 i for int j 1 j i j Console Write 0 1 2 j i i j Console WriteLine return 精品文档 11欢迎下载 11 编一个程序 利用 for 循环语句 求出 1 2 3 10 的和 答案 int sum 0 Console WriteLine 0 Sum Console ReadKey static int Sum int sum 0 int a 1 for int i 1 i 10 i a a i sum sum a return sum 13 编一个程序 定义一个字符串变量 输入字符串 然后再输入一个字符 在字符串中 查找该字符出现的次数 答案 Console Write 请输入字符串 string str Console ReadLine Console Write 请输入字符 char c char Parse Console ReadLine int s Str str c Console WriteLine 0 s Console ReadKey static int Str string str char c int a 0 for int i 0 i str Length i if str i c a return a 精品文档 12欢迎下载 15 编一个程序 输入一个整数 判定它为几位数 例如 99 是 2 位数 100 是 3 位数 答案 Console WriteLine 0 Math Console ReadKey static int Math int a int Parse Console ReadLine int b 0 int c 1 if a 0 b a while b 10 b b 10 c return c 四 面向对象 1 定义一个车辆 Vehicle 基类 具有 Run Stop 等方法 具有 Speed 速度 MaxSpeed 最大速度 Weight 重量 等域 然后以该类为基类 派生出 Bicycle Car 等类 并编程对该派生类的功能进行验证 答案 基类 class Vehicle public double Speed public double Maxspeed public double Weight public void Run Console WriteLine 我跑 public void Stop 精品文档 13欢迎下载 Console WriteLine 我停 派生类 class Bicycle Vehicle class Car Vehicle 对派生类功能的验证 static void Main string args Bicycle p new Bicycle p Run Car c new Car c Stop Console ReadKey 2 写一个控制台应用程序 接收一个长度大于 3 的字符串 完成下列功能 1 输出字符串的长度 2 输出字符串中第一个出现字母 a 的位置 3 在字符串的第 3 个字符后面插入子串 hello 输出新字符串 4 将字符串 hello 替换为 me 输出新字符串 5 以字符 m 为分隔符 将字符串分离 并输出分离后的字符串 答案 Console Write 输入字符 string str Console ReadLine while str Length 0 Console Write 出现字符a的位置 Console WriteLine 0 index else 精品文档 14欢迎下载 Console WriteLine 字符串中不含字符a string str1 hello str Substring 3 Console Write 出现新字符串 Console WriteLine str1 str1 str1 Replace hello me Console Write 替换后的字符串 Console WriteLine str1 string str2 str1 Split m for int i 0 i str2 Length i Console Write 分割后的字符串 Console WriteLine str2 i Console ReadKey 3 编写一个控制台应用程序 完成下列功能 并写出运行程序后输出的结果 1 创建一个类 A 在 A 中编写一个可以被重写的带 int 类型参数的方法 MyMethod 并在该方法中输出传递的整型值后加 10 后的结果 2 再创建一个类 B 使其继承自类 A 然后重写 A 中的 MyMethod 方法 将 A 中接收的整型 值加 50 3 在 Main 方法中分别创建 A 和类 B 的对象 并分别调用 MyMethod 方法 答案 并输出结果 class A public virtual void MyMethod int num num 10 Console WriteLine 0 num class B A public override void MyMethod int num num 50 Console WriteLine 0 num A a new A a MyMethod 3 精品文档 15欢迎下载 B b new B b MyMethod 8 Console ReadKey 4 编写一个类Calculate1 实现加 减两种运算 然后 编写另一个派生类Calculate2 实现乘 除两种运算 class Calculate1 public virtual void Mix int a int b Console Write 运算符为 string s Console ReadLine int c if s c a b Console WriteLine 0 c else if s c a b Console WriteLine 0 c public override void Mix int a int b Console Write 运算符为 string s Console ReadLine int c if s c a b Console WriteLine 0 c else if s c a b Console WriteLine 0 c Calculate1 c new Calculate1 c Mix 3 4 精品文档 16欢迎下载 Calulate2 d new Calulate2 d Mix 8 4 Co

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论