




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、一、选择题1、能作为C#程序的基本单位是( )。A. 字符 B. 语句 C. 函数 D. 源程序文件答案:B2、将变量从字符串类型转换为数值类型可以使用的类型转换方法是( )。A.Str() B.Cchar C.CStr() D.int.Parse();答案:D3、数据类型转换的类是( )。A.Mod B.Convert C. Const D. Single答案:B4、字符串连接运算符包括&和( )。A. + B. - C. * D. /答案:A 5、先判断条件的当循环语句是( )。A. do.while B. while C. while.do D. do .loop答案:B6、下面
2、几个函数,()是重载函数. 1.void f1(int) 2.int f1(int) 3.int f1(int,int) 4.float k(int)A.四个全 B.1 和 4 C.2 和 3 D.3和4答案:C8、以下的C代码:static void Main(string args) Console.WriteLine("运行结果: 0",Console.ReadLine(); Console.ReadLine(); 代码运行结果为( )。A.在
3、控制台窗口显示“运行结果:”B.在控制台窗口显示“运行结果:0”C.在控制台窗口显示“运行结果:,ConsoleReadLine”D.如果用户在控制台输入“ A”,那么程序将在控制台显示“运行结果:A”答案:D9、在C#中定义一个数组,正确的代码为( )。A.int arraya = new int5; B.int arraya = new int5;C.int arraya = new int; D.int5 arraya = new int;答案:B10、在C#中,下列代码运行后,变量Max的值是( )(选择一项)Int a=5,b=10,c=15,Max=0;
4、160; Max = a>b?a:b; Max = c<Max?c:Max;A.0 B.5 C.10 D.15答案:C11、在C#中,关于continue和break,以下说法正确的是( )A break是中断本次循环 B continue是中断本次循环,进入一下次的循环C break是中断本次循环,进入一下次的循环 D continue是中断整个循环答案:A12、在C#中,关于while和dowhile,以下说法正确的是(
5、)A while先执行然后判断条件是否成立 B while最少的循环次数是1次C dowhile先执行然后判断条件是否成立 D dowhile最少的循环次数是0次答案:C13、在C#中,下列变量定义与赋值正确的是( )A int a=同学 B float a=老师 C double a=教室 D char a=学答案:D14、表达式 “abcde”= =”abcde”+”2006”的值为( )ATrue2006 B. true C. false D. 0答案:C15、在C#中
6、定义类时,使用的关键字是( )A、interface B、intC、classD、overrides答案:C二.写出下列程序的结果 1、 int y = 1,x; if (y!=0) x = 5; else if (y < 0 ) x = 4; else x = 3; Console.WriteLine("x=0”, x); 答案:5 2、 int x, y = 0; do x = y+; Console.WriteLine(x); while (y < 6); 答案:153、class Test static void Main( ) int x=5; int y=x-
7、 -; Console.WriteLine("y=0", y); y=- -x; Console.WriteLine("y=0", y); 答案:5,54、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;
8、0; for (int i = 0; i < 8; i+) switch (ai % 3) case 0: s0 += Test.ai; break; case 1: s1 += Test.ai; break; case 2: s2 += Test.ai; break;
9、0; Console.WriteLine(s0 + " " + s1 + " " + s2); 答案:9+12+135、using System;class Test public static void Main () int s=0, i=1; for (; ; i+) if (s>50) break; if
10、(i%2=0) s+=i; Console.writeLine ("i, s=" + i + "," + s); 答案:14,S=2+4+6.+14,566、写出下列函数的功能。static float FH() float y=0,n=0; int x = Convert.ToInt32(Console.ReadLine(); /从键盘读入整型数据赋给x while (x!=-1) &
11、#160; n+; y+=x; x = Convert.ToInt32(Console.ReadLine(); if (n=0) return y; else return y/n; 答案:从键盘中输入输入整型数只要不是-1就求和,不输入数就返回0,否则求这几个数的的平均值。7、using System;class Test public static void Main () int a =2,4,6,8,
12、10,12,14,16,18; for (int i=0; i<9; i+) Console.write(“ ”+ai); if (i+1)%3=0) Console.writeLine(); 答案:2 4 6 8 10 12 14 16 18三、编程题 (全部把功能写到自定义函数里)1、编一个程序,从键盘上输入三个数,用三元运
13、算符(? :)把最大数找出来。答案: Console.Write("请输入三个数:"); int a=int.Parse(Console.ReadLine(); int b = int.Parse(Console.ReadLine(); int c = int.Parse(Console.ReadLine(); int max = a; int s= Max(a,b,c); Console.WriteLine("结果为:0",s); Console.ReadKey(); static int Max(int a,int b,int c) int max;
14、 max= a > b ? a : b; max = max> c ? max : c; return max; 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
15、' && c <= 'Z') c = Convert.ToChar(c + 32); return c ; 3、输入一个字符,判定它是什么类型的字符(大写字母,小写字母,数字或者其它字符)答案: Console.Write("输入字符"); char c = char.Parse(Console.ReadLine(); Console.WriteLine("0", Judge(c); Console.ReadKey(); static int Judge(char c) int b; if (c >=
16、'A' && c <= 'Z') b = 0; else if (c >= 'a' && c <= 'z') b = 1; else if (c >= 48 && c <= 57) b = 2; else b = 3; return b; 4、编一个程序,输入一个正数,对该数进行四舍五入到个位数的运算。例如,实数12.56经过四舍五入运算,得到结果13;而12.46经过四舍五入运算,得到结果12。答案: Console.Write("输入一个正
17、数:"); double a = double.Parse(Console.ReadLine(); Console.WriteLine("0",Count(a); Console.ReadKey(); static int Count(double a) int b = (int)a; if (a >= 0) if (a - b >= 0.5) b = b + 1; return b; 5、编一个程序,输入0100之间的一个学生成绩分数,用switch语句输出成绩等第(成绩优秀(90-100),成绩良好(80-89),成绩及格(60-79)和成绩不及格
18、(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 && s <= 10) a = 0; else if (s >= 8&& s < 9) a = 1; else if (s >= 6 && s < 8) a = 2; else a
19、 = 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(&
20、quot;sum="); double sum = 1; Console.WriteLine("0", Sum(); Console.ReadKey(); static double Sum() double sum = 1; 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("和为:");
21、 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.Read
22、Key(); static int Max() int sum = 0; int k=1; while(sum<2000) 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+; retur
23、n; 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、编一个程序,利用for循环语句,求出1!+2!+3!+.+10!的和。答案: int sum = 0; Console
24、.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
25、("请输入字符:"); 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(stri=c) a+; return a; 15、编一个程序,输入一个整数,判定它为几位数。例如,99是2位数,-100是3位数。答案: Cons
26、ole.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; if (a > 0) b = a; while (b >= 10) b = b / 10; c+; return c; 四、面向对象1、定义一个车辆(Vehicle)基类,具有Run、Stop等方法,具有Speed(速度)、MaxSpeed(最大速度)、Weight(重量)等域。
27、然后以该类为基类,派生出Bicycle、Car等类。并编程对该派生类的功能进行验证。答案:基类: class Vehicle public double Speed; public double Maxspeed; public double Weight; public void Run() Console.WriteLine("我跑。"); public void Stop() Console.WriteLine("我停。"); 派生类: class Bicycle:Vehicle class Car:Vehicle 对派生类功能的验证: stati
28、c 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("输入字符:"
29、;); string str=Console.ReadLine(); while (str.Length<= 3) str = Console.ReadLine(); Console.Write("字符串的个数:"); Console.WriteLine("0", str.Length); int index = str.IndexOf('a'); if(index>=0) Console.Write("出现字符a的位置:"); Console.WriteLine("0", index)
30、; else 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.Sp
31、lit('m'); for (int i = 0; i < str2.Length; i+) Console.Write("分割后的字符串:"); Console.WriteLine(str2i); Console.ReadKey(); 3、编写一个控制台应用程序,完成下列功能,并写出运行程序后输出的结果。1)创建一个类A,在A中编写一个可以被重写的带int类型参数的方法MyMethod,并在该方法中输出传递的整型值后加10后的结果。2)再创建一个类B,使其继承自类A,然后重写A中的MyMethod方法,将A中接收的整型值加50, 3)在Main方法中
32、分别创建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); B b = new B(); b.MyMethod(8); Console.Read
33、Key();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 voi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度高端运动场馆深度清洁及智能化管理服务合同
- 2025年度高新技术企业专利检索及深度分析报告定制服务合同
- 加盟入股合同
- DB61-T 5064-2023 铁尾矿陶粒混凝土预制构件应用技术规程
- 护士基础护理学三基知识考试题附答案
- 2024年驾照C1证考试科目一必考题库和答案
- 2024年X医院工作总结暨2025年工作计划
- 毕业论文答辩计算机专业
- 投资专业 毕业论文
- 护理不良事件报告制度及流程试题(附答案)
- 2025年《数据采集与处理》课程标准
- 混凝土垫层厚度强度检测要求
- EXCEL实操应用培训
- DB32/T 4322-2022家政职业经理人培训规范
- 脊髓电刺激护理
- 国家职业技术技能标准 6-21-07-01 工艺品雕刻工 劳社厅发20031号
- 培训班合伙人合同协议
- 外包合同补充协议
- 全景回顾2024年系统规划与管理师考试试题及答案
- 2025年碳排放管理员职业技能鉴定考试题库及答案
- 必修二英语单词表人教版
评论
0/150
提交评论