Csharp编程题
- 格式:doc
- 大小:45.00 KB
- 文档页数:9
C#考试一、不定项选择题,(每小题2分,共20分,)1.下列选项中,()是引用类型。
a)enum类型b)struct类型c)string类型 d)int类型2.以下描述错误的是()a)在C++中支持抽象类而在C#中不支持抽象类。
b)C++中可在头文件中声明类的成员而在CPP文件中定义类的成员,在C#中没有头文件并且在同一处声明和定义类的成员。
c)在C#中可使用new 修饰符显式隐藏从基类继承的成员。
d)在C#中要在派生类中重新定义基类的虚函数必须在前面加Override。
3.声明一个委托public delegate int myCallBack(int x); 则用该委托产生的回调方法的原型应该是()。
a)void myCallBack(int x) ;b)int receive(int num) ;c)string receive(int x) ;d)不确定的;4.下列描述错误的是()a)类不可以多重继承而接口可以;b)抽象类自身可以定义成员而接口不可以;c)抽象类和接口都不能被实例化;d)一个类可以有多个基类和多个基接口;5.下列关于构造函数的描述正确的是()a)构造函数可以声明返回类型。
b)构造函数不可以用private修饰c)构造函数必须与类名相同d)构造函数不能带参数6.以下是一些C#中的枚举型的定义,其中错误的用法有()a)public enum var1{ Mike = 100, Nike = 102, Jike } b)public enum var1{ Mike = 100, Nike, Jike }c)public enum var1{ Mike=-1 , Nike, Jike } d)public enum var1{ Mike , Nike , Jike }7.int[][] myArray3=new int[3][]{new int[3]{5,6,2},new int[5]{6,9,7,8,3},new int[2]{3,2}}; myArray3[2][2]的值是()。
模拟测试题一、选择题(单选)1.short类型的变量在内存中占据的位数是 B 。
A. 8B. 16C. 32D.642.对于int[4, 5]型的数组a,数组元素a [2, 3]存储在数组第C 个位置上A. 11B. 12C. 14D. 153.设int型变量x、y、z的值分别为2、3、6,那么执行完语句(z −= y −= x −= z)后它们的值为 C 。
A. 3, 1, -4B. 3, 1, -1C. -4, 7, -1D. 4, 7, -44.以下说法中不正确的 CA. 构造函数和析构函数都不能有返回值B. 构造函数可以是静态的C. 一个类只能有一个构造函数D. 一个类只能有一个析构函数5.以下不属于Object类型的成员方法的是 B 。
A. ToString()B. Dispose()C. Finalize()D. GetType()6.设double型变量x表示一个角度,那么将其转换为弧度的表达式为 C 。
A. x * 180 / Math.PIB. x * 360 / Math.PIC. x * Math.PI / 180D. x * Math.PI / 3607.令object x = 100,那么下列表达式会引发异常的是 A 。
A. int i = x;B. string s = (string)x;C. bool b = x is string;D. object o = x as string;8.下列能够被创建对象的是 C 。
A. 接口B. 抽象类C. 委托D. 只有私有构造函数的类9.关于接口和抽象类,那么说法中正确的是 B 。
A. 接口不能创建对象,而抽象类可以B. 接口不能包含字段,而抽象类可以C. 抽象类中的方法必须是抽象方法D. 接口中的方法也可以有实现代码10.关于finally代码段,那么说法正确的是 D 。
A. 仅在程序正常时执行B. 仅在程序发生异常时执行C. 在程序发生异常时会被跳过D. 无论程序是否发生异常都会被执行11.下列类型中,不支持IEnumerable<T>接口的是 A 。
VisualCSharp练习Visual C#综合练习1、分析下列程序中类MyClass 的定义class BaseClass{public int i;}class MyClass:BaseClass{public new int i;}则下列语句在Console 上的输出为_______.MyClass y = new MyClass();BaseClass x = y;x.i = 100;Console.WriteLine(“ {0}, {1}”,x.i,y.i);A. 0, 0B. 100, 100C. 0, 100D. 100, 02、哪个命名空间中的类和接⼝⽤于创建Web应⽤程序的页⾯?()A. System.Drawing开发者可以在程序中实现任何有关绘图,图形或图像的操作B. System.IO该命名空间包含了⽤开读写⽂件的类型C. System.Web.UID. System.Web.Service该命名⽤⽣成使⽤xml System.Web.Service3、下列哪个类型的对象是/doc/bf16409411.html 在⾮连接模式下处理数据内容的主要对象?()A. CommandB. ConnectionC. DataAdapterD. DataSet4、已知在某Windows Form 应⽤程序中,主窗⼝类为Form1, 程序⼊⼝为静态⽅法From1.Main.如下所⽰:public class Form1 : System.Windows.Forms.Form{ //其他代码static void Main(){//在此添加合适代码}}则在Main ⽅法中打开主窗⼝的正确代码是: ()A. Application.Run(new Form1());B. Application.Open(new Form1());C. (new Form1()).Open();D. (new Form1()).Run();5、关于/doc/bf16409411.html窗体应⽤程序,下列说法哪些是正确的?A. Web 窗体是在浏览器中进⾏解释执⾏的B. Web 窗体程序中脚本和代码必须严格分开C. Web 窗体程序产⽣的HTML页⾯只能运⾏于IE浏览器D. Web 窗体程序的代码可以使⽤任何⼀种.NET兼容的编程语⾔编写6、在/doc/bf16409411.html中,通过执⾏ Command 对象的ExecuteReader ⽅法返回的DataReader 对象是⼀种( ).A 可向前向后的只读的结果集B 只向前的可读可写的结果集C 可向前向后的可读可写的结果集D 只向前的只读的结果集7、在/doc/bf16409411.html,将⽤户在DataSet 中进⾏的改动保存到数据源中,应使⽤下列哪个⽅法?( )A.DataAdapter 对象的Fill ⽅法B.DataAdapter 对象的Update ⽅法C.DataSet 对象的AcceptChanges ⽅法D.DataSet 对象的RejectChanges ⽅法8、变量menuItem1 引⽤⼀个菜单项对象,为使该菜单项变为”灰⾊不可选”状态, 应对menuItem1的哪个属性进⾏操作?( )A. EnabledB. CheckedC. VisibleD. Text9、在Windows Form 程序中,对某 ComboBox 对象有以下要求:控件的列表框部分总是可见的, 且⽤户可以编辑⽂本框控件的⽂本. 则该ComboBox对象的DropDownStyle 属性应设置为ComboBoxStyle 枚举类型中的( )值.A DropDownB DropDownListC SimpleD Edit10、以下的C#代码,试图⽤来定义⼀个接⼝:public interface IFile{int A;int delFile(){A = 3;}void disFile();}关于以上的代码,以下描述错误的是( )(A)以上的代码中存在的错误包括:不能在接⼝中定义变量,所以int A代码⾏将出现错误;(B)以上的代码中存在的错误包括:接⼝⽅法delFile是不允许实现的,所以不能编写具体的实现函数;(C)代码void disFile();声明⽆错误,接⼝可以没有返回值;(D)代码void disFile();应该编写为void disFile(){};11. ⽤⿏标右击⼀个控件时出现的菜单⼀般称为: ()A. 主菜单B. 菜单项C. 快捷菜单D. ⼦菜单12. 变量openFileDialog1 引⽤⼀个OpenFileDialog 对象.为检查⽤户在退出对话框时是否单击了”打开”按钮,应检查openFileDialog1.ShowDialog()的返回值是否等于_______;A. DialogResult.OKB. DialogResult.YesC. DialogResult.NoD. DialogResult.Cancel13.dataTable 是数据集myDataSet 中的数据表对象.有10条记录,调⽤下列代码后.DataTable 中还有哪⼏条记录?( )(假设dataTable 打开后,未进⾏其他操作)dataTable.Row[9].Delete();myDataSet.AcceptChanges();A 1B 9C 0D 1014. 在/doc/bf16409411.html窗⼝中,( )窗⼝提供了连接到本地或远程计算机上数据库并进⾏管理的功能.A⼯具箱B资源视图C解决⽅案源管理器D服务器资源管理器15.显⽰消息框时,MessageBoxIcon 枚举中的Error 成员可在消息框中添加⼀个图标,该图标的形状是( ).A.iB.?C.χD.!16.SQL语句“delete from department”,需要SqlCommand对象的哪⼀个⽅法在执⾏?(A) ExecuteNonQuery() (B) ExecuteScalar()(C) ExecuteReader() (D) ExecuteXmlReader()17. ⽤⿏标右击⼀个控件时出现的菜单⼀般称为:A. 主菜单B. 菜单项C. 快捷菜单D. ⼦菜单18. Windows Form 应⽤程序中,要求下压按钮控件Button1 有以下特性:正常情况下,该按钮是扁平的,当⿏标指针移动到它上⾯时,按钮升⾼。
序号试题描述选择A 架构是一种_____。
程序设计语言架构是一种编程工具正确架构不是一种集成开发环境正确架构是一种语言正确是一种平台正确223335Visual Studio .NET是一种语言正确223336对于.NET架构不正确的说法有_____。
程序设计语言223337“的IDE”中IDE是指_____。
.NET的接口函数库223338“的IDE”中IDE是集成开发环境正确223339“的IDE”中IDE是程序开发平台正确223340“的IDE”中IDE不是的安装程序正确223341“的IDE”中IDE是编程工具软件正确223342“的IDE”中IDE是程序设计语言正确223480对于“的IDE”中IDE的说法错误的是_____。
.NET的接口函数库223481C#是一种:程序设计语言223482C#是一种集成开发环境正确223483C#是一种面向对象的程序设计语言正确223484C#是一种集成开发环境正确223485C#是不是一种面向过程的语言正确223486C#是不是一种面向对象的设计语言正确223487对于C#是的说法错误的是_____。
程序设计语言223488声明类的关键字是_____。
class 223489不是声明类的关键字是_____。
class 223490声明类的关键字是class。
正确223491声明类的关键字是int。
正确223492声明类的关键字不是float。
正确223493声明类的关键字是public。
正确223604声明类的关键字不是private。
正确223605声明类的关键字是protect。
正确223606C#中源代码文件的扩展名是________。
.cs223607C#中源代码文件的扩展名是.cs正确223608C#中源代码文件的扩展名不是.cs正确223609C#中源代码文件的扩展名不是.doc正确223610C#中源代码文件的扩展名是.exe正确223611C#中源代码文件的扩展名不是________。
Csharp⾯试题c#⾯试问题 [转]1.传⼊某个属性的set⽅法的隐含参数的名称是什么?value,它的类型和属性所声名的类型相同。
2.如何在C#中实现继承?在类名后加上⼀个冒号,再加上基类的名称。
3.C#⽀持多重继承么?不⽀持。
可以⽤接⼝来实现。
4.被protected修饰的属性/⽅法在何处可以访问?在继承或间接继承与这个类的⼦类中可以访问。
5.私有成员会被继承么?会,但是不能被访问。
所以看上去他们似乎是不能被继承的,但实际上确实被继承了。
6.请描述⼀下修饰符protected internal。
被protected internal修饰的属性/⽅法只能在它的在同⼀个程序集(Assembly)中的⼦类被访问。
7.C#提供⼀个默认的⽆参数构造函数,当我实现了另外⼀个有⼀个参数的构造函数时候,还想保留这个⽆参数的构造函数。
这样我应该写⼏个构造函数?两个,⼀旦你实现了⼀个构造函数,C#就不会再提供默认的构造函数了,所以需要⼿动实现那个⽆参数构造函数。
8.C#中所有对象共同的基类是什么?System.Object.9.重载和覆写有什么区别?重载提供了对⼀个⽅法签名的不同参数调⽤的实现。
覆写提供了⼦类中改变⽗类⽅法⾏为的实现。
10.在⽅法定义中,virtual有什么含意?被virtual修饰的⽅法可以被⼦类覆写。
11.能够将⾮静态的⽅法覆写成静态⽅法么?不能,覆写⽅法的签名必须与被覆写⽅法的签名保持⼀致,除了将virtual改为override。
12.可以覆写私有的虚⽅法么?不可以,甚⾄⼦类中⽆法访问⽗类中的私有⽅法。
13.能够阻⽌某⼀个类被其他类继承么?可以,使⽤关键字sealed。
14.能够实现允许某个类被继承,但不允许其中的某个⽅法被覆写么?可以,标记这个类为public,并标记这个⽅法为sealed。
15.什么是抽象类(abstract class)?⼀种不可以被实例化的类。
抽象类中⼀般含有抽象⽅法,当然也可有具体实现。
C练习题一、基础语法1. 声明一个整型变量并赋值为10。
2. 声明一个浮点型变量并赋值为3.14。
3. 声明一个字符串变量并赋值为"Hello, World!"。
4. 声明一个布尔变量并赋值为true。
5. 创建一个名为`MyClass`的类,并在其中声明一个名为`myField`的私有整型字段。
6. 在`MyClass`类中添加一个构造函数,接受一个整型参数并赋值给`myField`字段。
7. 在`MyClass`类中添加一个名为`PrintField`的方法,打印出`myField`字段的值。
二、控制结构8. 编写一个程序,使用`if`语句判断一个整数变量是否大于0。
9. 编写一个程序,使用`switch`语句根据整数变量的值输出对应的星期名称。
10. 编写一个程序,使用`for`循环打印1到10的数字。
11. 编写一个程序,使用`foreach`循环遍历一个整数数组并打印每个元素。
12. 编写一个程序,使用`while`循环计算1到10的阶乘。
三、函数和方法13. 编写一个名为`Add`的方法,接受两个整数参数并返回它们的和。
14. 编写一个名为`Multiply`的方法,接受两个整数参数并返回它们的乘积。
15. 编写一个名为`PrintNumbers`的方法,接受一个整数参数,打印从1到该参数的所有数字。
16. 编写一个名为`ReverseString`的方法,接受一个字符串参数并返回其反转后的字符串。
17. 编写一个名为`FindMax`的方法,接受一个整数数组参数并返回数组中的最大值。
四、面向对象18. 创建一个名为`Person`的类,包含姓名和年龄两个属性。
19. 在`Person`类中添加一个构造函数,接受姓名和年龄作为参数。
20. 在`Person`类中添加一个名为`PrintInfo`的方法,打印出该人的姓名和年龄。
21. 创建一个`Student`类,继承自`Person`类,并添加一个名为`Grade`的属性。
《C#程序设计》——编程题(上机操作题)1、从键盘输入一个正整数,按数字的相反顺序输出。
2、从键盘上输入两个整数,由用户回答它们的和,差,积,商和取余运算结果,并统计出正确答案的个数。
3、写一条for语句,计数条件为n从100~200,步长为2;然后再用while语句实现同样的循环。
4、编写一段程序,运行时向用户提问“你考了多少分?(0~100)”,接受输入后判断其等级并显示出来。
判断依据如下:等级={优(90~100分);良(80~89分);中(60~69分);差(0~59分);}5、输入一个整数,将各位数字反转输出。
6、使用穷举法并分别用for、while、do…while循环语句求出1~100之间的质数。
7、求出1~1000之间的所有能被7整除的数,并计算和输出每5个的和。
8、编写一个控制台程序,分别输出1~100之间的平方、平方根、自然对数、e指数的数学用表。
9、设计一个包含多个构造函数的类,并分别用这些构造函数实例化对象。
10、编写一个矩形类,私有数据成员为举行的长(len)和宽(wid),无参构造函数将len和wid设置为0,有参构造函数设置和的值,另外,类还包括矩形的周长、求面积、取举行的长度、取矩形的长度、取矩形的宽度、修改矩形的长度和宽度为对应的形参值等公用方法。
11、编写一个类,要求带有一个索引器可以存储100个整型变量。
12、编写一个类Cal1,实现加、减两种运算,然后,编写另一个派生类Cal2,实现乘、除两种运算。
13、建立三个类:居民、成人、官员。
居民包含身份证号、姓名、出生日期,而成人继承自居民,多包含学历、职业两项数据;官员则继承自成人,多包含党派、职务两项数据。
要求每个类中都提供数据输入输出的功能。
14、编写一个类,其中包含一个排序的方法Sort(),当传入的是一串整数,就按照从小到大的顺序输出,如果传入的是一个字符串,就将字符串反序输出。
15、设计一个类,要求用事件每10秒报告机器的当前时间。
一、基本数据类型1.什么是公用类型系统。
2.什么是字面量。
3.C#中基本数据类型包括哪几种?4.C#中的值类型包括哪几种?5.C#中简单类型共有多少个数值类型?分别是什么?6.什么是布尔类型?7.什么是枚举类型?声明格式是什么?8.什么是结构类型?声明格式是什么?9.引用类型包括哪几种类型?分别是什么?10.解释什么是堆栈。
11.什么是装箱、拆箱?用简单示例演示装箱、拆箱操作。
12.什么是常量?怎样指定常量数据类型?13.C#采用的是那种字符编码?在Unicode编码中找出所有的汉字。
14.C#支持哪两种字符串常量?分别是什么?怎样定义。
15.C#中怎样声明“符号常量”。
16.用流程图画出逻辑运算符&&和||的运算执行流程。
17.位运算符主要分为哪两种?分别是什么?18.下面是用位运算符编写的一个简单的加密解密程序,请分别为每一行代码注释。
using System;class Encode{public static void Main(){char ch1 = ‟o‟, ch2 = ‟k‟;int key = 0x1f;Console.WriteLine(“明文: ” + ch1 + ch2);ch1 = (char)(ch1 ^ key);ch2 = (char)(ch2 ^ key);Console.WriteLine(“密文: ” + ch1 + ch2);ch1 = (char)(ch1 ^ key);ch2 = (char)(ch2 ^ key);Console.WriteLine(“解码: ” + ch1 + ch2);}}19、c#中主要有哪三种形式?分别是什么?怎样定义?20、声明一个多维数组对象并进行初始化。
21、声明一个不规则数组对象并进行初始化。
22、引用变量的默认值在默认情况下是什么?二、流程语句1、从键盘输入学生的百分制成绩,换算成等第制成绩。
(要求用switch()语句)2、用while()语句求1-100之间所有整数的和。
C#复习题2
1、定义接口用什么关键字?interface
2、数类型(decimal)和浮点类型都可以表示小数,它们的区别是?小数点的精度不同
3、在switch语句中,每个语句标号所含关键字case后面的表达式必须是常量表达式还是
变量表达式?常量
4、我们可以使用什么语句来结束所在循环语句中循环体的一次执行?Continue
5、什么是交错数组,也可以称呼它为什么数组?数组中的数组
6、静态构造函数在第一个实例创建前被自动调用,一共执行多少次?1次
7、请编写程序实现:将学生成绩100制评分为‘优’、‘良’、‘中’、‘及格’和‘不及格’
的等级制。
用if语句或case语句编写
8、一个窗体中可以有多个弹出式菜单吗?可以
9、编写代码时,可否在同一行书写多个语句?如果可以,请问用什么符号隔开?可以,用
分号隔开。
1.编一个程序,打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。
例如, 153=1*1*1+5*5*5+3*3*3,所以153是“水仙花数”。
for (int n = 100; n <= 999; n++){//Console.WriteLine(n);int bai = n / 100;int shi = n / 10 % 10;int ge = n % 10;if (n == bai * bai * bai + shi * shi * shi + ge * ge * ge){Console.WriteLine(n);}}Console.ReadLine();2.编写一个程序,用while语句,求出1+(1+2)+(1+2+3)+...+(1+2+3+...+10)之和。
//2. 编写一个程序,用while语句,求出1+(1+2)+(1+2+3)+...+(1+2+3+...+10)之和。
int i=1;int sum1=0, sum=0;while (i <=10){sum1 = sum1 + i;sum = sum + sum1;i++;}Console.WriteLine(sum );Console.ReadLine();3.编一个程序,输入二个正整数,求出它们的最大公约数。
// //3. 编一个程序,输入二个正整数,求出它们的最大公约数。
int shizi1, shizi2, k;Console.WriteLine("请输入两个正整数");//输入两个数shizi1 = int.Parse(Console.ReadLine());//讲输入的数转换成整形shizi2 = int.Parse(Console.ReadLine());k = shizi1 < shizi2 ? shizi1 : shizi2;while (!(shizi1 % k == 0 && shizi2 % k == 0))//循环测试两个数的最大公约数k--;Console.WriteLine("最大公约数为{0}", k);//打印最大公约数Console.ReadLine();4.编一个程序,用while循环语句,从键盘输入10个数,要求找出最大数和次大数。
CSP-J2024(入门组)第一轮试题及参考答案1.32位int类型的存储范围是()A.-2147483647~+2147483647B.-2147483647~+2147483648C.-2147483648~+2147483647D.-2147483648~+21474836482.计算(148-10102)*D 16-11012的结果,并选择答案的十进制值:()A.13B.14C.15D.163.某公司有10名员工,分为3个部门:A部门有4名员工,B 部门有3名员工、C 部门有3名员工。
现需要从这10名员工中选出4名组成一个工作组,且每个部门至少要有1人。
问有多少种选择方式?()A.120B.126C.132D.2384.以下哪个序列对应数组0至8的4位二进制格雷码(Gray code)?A.0000,0001,0011,0010,0110,0111,0101,1000B.0000,0001,0011,0010,0110,0111,0100,0101C.0000,0001,0011,0010,0100,0101,0111,0110D.0000,0001,0011,0010,0110,0111,0101,01005.记1Kb位1024字节(byte),1MB 位1024KB,那么1MB 是多少二进制位(bit)?A.1000000B.1048576C.8000000D.83886086.以下哪个不是C++中的基本数据类型?A.intB.floatC.structD.char7.以下哪个不是C++中的循环语句?A.forB.whileC.do-whileD.repeat-untill8.在C/C++中,(char)('a'+13)与下面的哪一个值相等()A.'m'B.'n'C.'zD.'3'9.假设有序表中有1000个元素,则用二分法查找元素x 最多需要比较()次A.25B.10C.7 D.110.下面哪一个不是操作系统名字()A.NotepadB.LinuxC.WindowsD.macOS11.在无向图中,所有顶点的度数之和等于()A.图的边数B.图的边数的两倍C.图的定点数D.图的定点数的两倍12.已知二叉树的前序遍历为[A,B,D,E,C,F,G],中序遍历为[D,B,E,A,F,C,G],求二叉树的后序遍历的结果是()A.[D,E,B,F,G,C,A]B.[D,E,B,F,G,A,C]C.[D,B,E,F,G,C,A]D.[D,E,B,F,G,A,C]13.给定一个空栈,支持入栈和出栈操作。
TThe safer , easier way to help you pass any IT exams.Exam : 70-536CSharpTitle :Version : DemoTS: Framework 2.0-Application DevelopFoundation1.You are developing an application that stores data about your company's sales and technical support teams.You need to ensure that the name and contact information for each person is available as a single collection when a user queries details about a specific team. You also need to ensure that the data collection guarantees type safety.Which code segment should you use?A. Hashtable team = new Hashtable();team.Add(1, "Hance");team.Add(2, "Jim");team.Add(3, "Hanif");team.Add(4, "Kerim");team.Add(5, "Alex");team.Add(6, "Mark");team.Add(7, "Roger");team.Add(8, "Tommy");B. ArrayList team = new ArrayList();team.Add("1, Hance");team.Add("2, Jim");team.Add("3, Hanif");team.Add("4, Kerim");team.Add("5, Alex");team.Add("6, Mark");team.Add("7, Roger");team.Add("8, Tommy");C. Dictionary<int, string> team =new Dictionary<int, string>();team.Add(1, "Hance");team.Add(2, "Jim");team.Add(3, "Hanif");team.Add(4, "Kerim");team.Add(5, "Alex");team.Add(6, "Mark");team.Add(7, "Roger");team.Add(8, "Tommy");D. string[] team =new string[] {"1, Hance","2, Jim", "3, Hanif","4, Kerim", "5, Alex","6, Mark", "7, Roger","8, Tommy"};Answer: C2.You are working on a debug build of an application.You need to find the line of code that caused an exception to be thrown.Which property of the Exception class should you use to achieve this goal?A. DataB. MessageC. StackTraceD. SourceAnswer: C3.You are writing a method that returns an ArrayList named al.You need to ensure that changes to the ArrayList are performed in a thread-safe manner. Which code segment should you use?A. ArrayList al = new ArrayList();lock (al.SyncRoot){return al;}B. ArrayList al = new ArrayList();lock (al.SyncRoot.GetType()){return al;}C. ArrayList al = new ArrayList();Monitor.Enter(al);Monitor.Exit(al);return al;D. ArrayList al = new ArrayList();ArrayList sync_al = ArrayList.Synchronized(al);return sync_al;Answer: D4.You are writing a custom dictionary. The custom-dictionary class is named MyDictionary.You need to ensure that the dictionary is type safe.Which code segment should you use?A. class MyDictionary : Dictionary<string, string>B. class MyDictionary : HashTableC. class MyDictionary : IDictionaryD. class MyDictionary { ... }Dictionary<string, string> t =new Dictionary<string, string>();MyDictionary dictionary = (MyDictionary)t;Answer: A5.You are instantiating a variable to store only strings. The variable is named messageStore.You need to ensure that string messages are read and processed in the order in which they are received. Which code segment should you use?A. Stack<string> messageStore = new Stack<string>();messageStore.Push("This is a test message...");B. Stack messageStore = new Stack();messageStore.Push("This is a test message...");C. Queue messageStore = new Queue();messageStore.Enqueue("This is a test message...");D. Queue<string> messageStore = new Queue<string>();messageStore.Enqueue("This is a test message...");Answer: D6.You are developing an application to assist the user in conducting electronic surveys. The survey consists of 25 true-or-false questions.You need to perform the following tasks:øInitialize each answer to true.øMinimize the amount of memory used by each survey.Which storage option should you choose?A. BitVector32 answers = new BitVector32(1);B. BitVector32 answers = new BitVector32(-1);C. BitArray answers = new BitArray (1);D. BitArray answers = new BitArray(-1);Answer: B7.You are creating a class named Age.You need to ensure that the Age class is written such that collections of Age objects can be sorted. Which code segment should you use?A. public class Age {public int Value;public object CompareTo(object obj) {if (obj is Age) {Age _age = (Age) obj;return pareTo(obj);}throw new ArgumentException("object not an Age");}}B. public class Age {public int Value;public object CompareTo(int iValue) {try {return pareTo(iValue);} catch {throw new ArgumentException ("object not an Age");}}}C. public class Age : IComparable {public int Value;public int CompareTo(object obj) {if (obj is Age) {Age _age = (Age) obj;return pareTo(_age.Value);}throw new ArgumentException("object not an Age");}}D. public class Age : IComparable {public int Value;public int CompareTo(object obj) {try {return pareTo(((Age) obj).Value);} catch {return -1;}}}Answer: C8.You are creating a class named Temperature. The Temperature class contains a public field named F. The public field F represents a temperature in degrees Fahrenheit.You need to ensure that users can specify whether a string representation of a Temperature instance displays the Fahrenheit value or the equivalent Celsius value.Which code segment should you use?A. public class Temperature : IFormattable {public int F;public string ToString(string format, IFormatProvider fp) {if ((format == "F")|| (format == null)) return F.ToString();if (format == "C") return ((F - 32) / 1.8).ToString();throw new FormatException("Invalid format string");}}B. public class Temperature : ICustomFormatter {public int F;public string Format(string format, object arg,IFormatProvider fp) {if (format == "C") return ((F - 32) / 1.8).ToString();if (format == "F") return arg.ToString();throw new FormatException("Invalid format string");}}C. public class Temperature {public int F;public string ToString(string format, IFormatProvider fp) {The safer , easier way to help you pass any IT exams.if (format == "C") {return ((F - 32) / 1.8).ToString();} else {return this.ToString();}}}D. public class Temperature {public int F;protected string format;public override String ToString() {if (format == "C")return ((F - 32) / 1.8).ToString();return F.ToString();}}Answer: A9.You write the following code.public delegate void FaxDocs(object sender, FaxArgs args);You need to create an event that will invoke FaxDocs.Which code segment should you use?A. public static event FaxDocs Fax;B. public static event Fax FaxDocs;C. public class FaxArgs : EventArgs {private string coverPageInfo;public FaxArgs(string coverInfo) {this.coverPageInfo = coverPageInfo;}public string CoverPageInformation {The safer , easier way to help you pass any IT exams.get {return this.coverPageInfo;}}}D. public class FaxArgs : EventArgs {private string coverPageInfo;public string CoverPageInformation {get {return this.coverPageInfo;}}}Answer: A10.You need to write a multicast delegate that accepts a DateTime argument.Which code segment should you use?A. public delegate int PowerDeviceOn(bool result,DateTime autoPowerOff);B. public delegate bool PowerDeviceOn(object sender,EventArgs autoPowerOff);C. public delegate void PowerDeviceOn(DateTime autoPowerOff);D. public delegate bool PowerDeviceOn(DateTime autoPowerOff);Answer: C11.You develop a service application named FileService. You deploy the service application to multiple servers on your network.You implement the following code segment. (Line numbers are included for reference only.)01 public void StartService(string serverName){02 ServiceController crtl = new03 ServiceController("FileService");04 if (crtl.Status == ServiceControllerStatus.Stopped){05 }06 }You need to develop a routine that will start FileService if it stops. The routine must start FileService on the server identified by the serverName input parameter.Which two lines of code should you add to the code segment? (Each correct answer presents part of the solution. Choose two.)A. Insert the following line of code between lines 03 and 04:crtl.ServiceName = serverName;B. Insert the following line of code between lines 03 and 04:crtl.MachineName = serverName;C. Insert the following line of code between lines 03 and 04: = serverName;D. Insert the following line of code between lines 04 and 05:crtl.Continue();E. Insert the following line of code between lines 04 and 05:crtl.Start();F. Insert the following line of code between lines 04 and 05:crtl.ExecuteCommand(0);Answer: BE12.You are developing a routine that will periodically perform a calculation based on regularly changing values from legacy systems. You write the following lines of code. (Line numbers are included for reference only.)01 bool exitLoop = false;02 do {0304 exitLoop = PerformCalculation();05 } while (!exitLoop);You need to write a code segment to ensure that the calculation is performed at 30-second intervals. You must ensure that minimum processor resources are used between the calculations.Which code segment should you insert at line 03?A. Thread.Sleep(30000);B. Thread.SpinWait(30000);C. Thread thrdCurrent = Thread.CurrentThread;thrdCurrent.Priority = ThreadPriority.BelowNormal;D. Thread thrdCurrent = Thread.CurrentThread;thrdCurrent.Priority = ThreadPriority.Lowest;E. Thread.SpinWait(30);Answer: A13.You are developing an application to perform mathematical calculations. You develop a class named CalculationValues. You write a procedure named PerformCalculation that operates on an instance of the class.You need to ensure that the user interface of the application continues to respond while calculations are being performed. You need to write a code segment that calls the PerformCalculation procedure to achieve this goal.Which code segment should you use?A. private void PerformCalculation() {...}private void DoWork(){CalculationValues myValues = new CalculationValues();Thread newThread = new Thread(new ThreadStart(PerformCalculation));newThread.Start(myValues);}B. private void PerformCalculation() {...}private void DoWork(){CalculationValues myValues = new CalculationValues();ThreadStart delStart = newThe safer , easier way to help you pass any IT exams.ThreadStart(PerformCalculation);Thread newThread = new Thread(delStart);if (newThread.IsAlive) {newThread.Start(myValues);}}C. private void PerformCalculation (CalculationValues values) {...}private void DoWork(){CalculationValues myValues = new CalculationValues();Application.DoEvents();PerformCalculation(myValues);Application.DoEvents();}D. private void PerformCalculation(object values) {...}private void DoWork(){CalculationValues myValues = new CalculationValues();Thread newThread = new Thread(new ParameterizedThreadStart(PerformCalculation));newThread.Start(myValues);}Answer: D14.You need to write a code segment that will create a common language runtime (CLR) unit of isolation within an application.Which code segment should you use?A. AppDomainSetup mySetup =AppDomain.CurrentDomain.SetupInformation;mySetup.ShadowCopyFiles = "true";B. System.Diagnostics.Process myProcess;myProcess = new System.Diagnostics.Process();C. AppDomain domain;domain = AppDomain.CreateDomain("MyDomain");D. ponent myComponent;myComponent = new ponent();Answer: C15.You need to write a code segment that will assign the name of the configuration file that the current application domain uses to a string variable named configFile.Which two code segments should you use to achieve the goal? (Each correct answer presents a complete solution. Choose two.)A. AppDomain domain = AppDomain.CurrentDomain;configFile =domain.GetData("APP_CONFIG_FILE").ToString();B. AppDomain domain = AppDomain.CurrentDomain;AppDomainSetup setup = domain.SetupInformation;configFile = setup.ConfigurationFile;C. AppDomain domain = AppDomain.CurrentDomain;AppDomainSetup setup = new AppDomainSetup();configFile = setup.ConfigurationFile;D. AppDomainSetup setup = new AppDomainSetup();AppDomain domain = AppDomain.CreateDomain("current",null, setup);configFile = setup.ConfigurationFile;Answer: AB16.You are developing an application that dynamically loads assemblies from an application directory.You need to write a code segment that loads an assembly named Assembly1.dll into the current application domain.Which code segment should you use?A. AppDomain domain = AppDomain.CurrentDomain;string myPath = bine(domain.BaseDirectory,"Assembly1.dll");Assembly asm = Assembly.LoadFrom(myPath);B. AppDomain domain = AppDomain.CurrentDomain;string myPath = bine(domain.BaseDirectory,"Assembly1.dll");Assembly asm = Assembly.Load(myPath);C. AppDomain domain = AppDomain.CurrentDomain;string myPath = bine(domain.DynamicDirectory,"Assembly1.dll");Assembly asm = AppDomain.CurrentDomain.Load(myPath);D. AppDomain domain = AppDomain.CurrentDomain;Assembly asm = domain.GetData("Assembly1.dll");Answer: A17.You need to write a code segment that will add a string named strConn to the connection string section of the application configuration file.Which code segment should you use?A. Configuration myConfig =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);myConfig.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("ConnStr1", strConn));myConfig.Save();B. Configuration myConfig =ConfigurationManager.OpenExeConfiguration(The safer , easier way to help you pass any IT exams.ConfigurationUserLevel.None);myConfig.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("ConnStr1", strConn));ConfigurationManager.RefreshSection("ConnectionStrings");C. ConfigurationManager.ConnectionStrings.Add(new ConnectionStringSettings("ConnStr1", strConn));ConfigurationManager.RefreshSection("ConnectionStrings");D. ConfigurationManager.ConnectionStrings.Add(new ConnectionStringSettings("ConnStr1", strConn));Configuration myConfig =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);myConfig.Save();Answer: A18.You are creating an application that retrieves values from a custom section of the application configuration file. The custom section uses XML as shown in the following block.<ProjectSection name="Project1"><role name="administrator" /><role name="manager" /><role name="support" /></ProjectSection>You need to write a code segment to define a class named Role. You need to ensure that the Role class is initialized with values that are retrieved from the custom section of the configuration file.Which code segment should you use?A. public class Role : ConfigurationElement {internal string _ElementName = "name";[ConfigurationProperty("role")]The safer , easier way to help you pass any IT exams.public string Name {get {return ((string)base["role"]);}}}B. public class Role : ConfigurationElement {internal string _ElementName = "role";[ConfigurationProperty("name", RequiredValue = true)]public string Name {get {return ((string)base["name"]);}}}C. public class Role : ConfigurationElement {internal string _ElementName = "role";private string _name;[ConfigurationProperty("name")]public string Name {get {return _name;}}}D. public class Role : ConfigurationElement {internal string _ElementName = "name";private string _name;[ConfigurationProperty("role", RequiredValue = true)]public string Name {The safer , easier way to help you pass any IT exams.get {return _name;}}}Answer: B19.You create a class library that is used by applications in three departments of your company. The library contains a Department class with the following definition.public class Department {public string name;public string manager;}Each application uses a custom configuration section to store department-specific values in the application configuration file as shown in the following code.<Department><name>Hardware</name><manager>Amy</manager></Department>You need to write a code segment that creates a Department object instance by using the field values retrieved from the application configuration file.Which code segment should you use?A. public class deptElement : ConfigurationElement {protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) {Department dept = new Department(); = ConfigurationManager.AppSettings["name"];dept.manager =ConfigurationManager.AppSettings["manager"];return dept;The safer , easier way to help you pass any IT exams.}}B. public class deptElement: ConfigurationElement {protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) {Department dept = new Department(); = reader.GetAttribute("name");dept.manager = reader.GetAttribute("manager");}}C. public class deptHandler : IConfigurationSectionHandler {public object Create(object parent, object configContext,System.Xml.XmlNode section) {Department dept = new Department(); = section.SelectSingleNode("name").InnerText;dept.manager =section.SelectSingleNode("manager").InnerText;return dept;}}D. public class deptHandler : IConfigurationSectionHandler {public object Create(object parent, object configContext,System.Xml.XmlNode section) {Department dept = new Department(); = section.Attributes["name"].Value;dept.manager = section.Attributes["manager"].Value;return dept;}}Answer: CThe safer , easier way to help you pass any IT exams.20.You create a class that is derived from the Installer class. The class you create is used to perform a component installation.The component installation overwrites the value of a registry key. You create a method named GetRegValue that returns the current value of the registry key.You need to add a code segment that preserves the original value of the registry key if the component is uninstalled.Which code segment should you use?A. private void BeforeUninstallEventHandler(object sender, InstallEventArgs e) {e.SavedState.Add("original RegValue", GetRegValue());}B. private void CommittedEventHandler(object sender, InstallEventArgs e) {e.SavedState.Add("original RegValue", GetRegValue());}C. public override void Uninstall(IDictionary savedState) {base.Uninstall(savedState);savedState.Add("original RegValue", GetRegValue());}D. protected override void OnBeforeInstall(IDictionary savedState) {base.OnBeforeInstall(savedState);savedState.Add("original RegValue", GetRegValue());}Answer: D。
一、单项选择题(每小题2分,共20分)1.在类作用域中能够通过直接使用该类的()成员名进行访问。
A. 私有B. 公用C. 保护D. 任何2.小数类型(decimal)和浮点类型都可以表示小数,正确说法:( )A. 两者没有任何区别B. 小数类型比浮点类型取值范围大C.小数类型比浮点类型精度高D. 小数类型比浮点类型精度低3.能作为C#程序的基本单位是( )。
A. 字符B. 语句C. 函数D. 源程序文件4. 可用作C#程序用户标识符的一组标识符是( )。
A. void define +WORDB. a3_b3 _123 YNC. for -abc CaseD. 2a DO sizeof5.引用类型主要有4种:类类型、数组类型、接口类型和()。
A.对象类型B.字符串类型C.委托类型D.整数类型6.加载窗体时触发的事件是( )。
A. ClickB.LoadC.GotFoucsD.DoubleClick7.改变窗体的标题,需修改的窗体属性是( )。
A. TextB. NameC.TitleD. Index8.在C#中定义接口时,使用的关键字是( )。
A.interfaceB.:C.classD.overrides9.在类的成员中,用于存储属性值的是( )。
A. 属性B. 方法C. 事件D.成员变量10.在C#中,定义派生类时,指定其基类应使用的语句是( )。
A.InheritsB.:C.ClassD.Overrides11.类的以下特性中,可以用于方便地重用已有的代码和数据的是( ).A.多态B.封装C.继承D.抽象12.在Array类中,可以对一维数组中的元素进行排序的方法是( )。
A.Sort()B.Clear()C.Copy()D.Reverse()13.将变量从字符串类型转换为数值类型可以使用的类型转换方法是( )。
A.Str()harC.CStr()D.int.Parse();14.数据类型转换的类是( )。
csharp习题答案C#习题答案C#是一种广泛应用于软件开发的编程语言,它的强大功能和灵活性使得它成为了许多开发者的首选。
然而,在学习过程中,我们常常会遇到一些难题,需要寻找答案来解决。
在本文中,我将为大家提供一些常见C#习题的答案,希望能够帮助到大家。
1. 如何在C#中实现两个整数的交换?在C#中,可以使用临时变量来实现两个整数的交换。
具体代码如下所示:```int a = 10;int b = 20;int temp = a;a = b;b = temp;```通过使用一个临时变量temp,我们可以将a的值赋给temp,然后将b的值赋给a,最后将temp的值赋给b,从而实现两个整数的交换。
2. 如何判断一个字符串是否是回文字符串?回文字符串是指正序和倒序排列都相同的字符串。
在C#中,可以使用以下代码来判断一个字符串是否是回文字符串:```string str = "level";string reverseStr = "";for (int i = str.Length - 1; i >= 0; i--){reverseStr += str[i];}if (str == reverseStr){Console.WriteLine("是回文字符串");}else{Console.WriteLine("不是回文字符串");}```通过将字符串倒序排列,并与原字符串进行比较,如果相同则是回文字符串,否则不是。
3. 如何统计一个字符串中某个字符出现的次数?在C#中,可以使用以下代码来统计一个字符串中某个字符出现的次数:```string str = "Hello World";char targetChar = 'o';int count = 0;foreach (char c in str){if (c == targetChar){count++;}}Console.WriteLine("字符'{0}'在字符串中出现的次数为:{1}", targetChar, count); ```通过遍历字符串中的每个字符,如果字符与目标字符相同,则计数器count加1。
1/在C#中,下列代码的运行结果是(C)Using System;Class Text{Static void Main(){Try{Int a=10;Int b=0;Int c=a/b;Console..wrtie(c);}Catch{Console.write(“出现错误”);}Finally{Console.write(“运行结束”);}}}a)运行结束b)10 运行结束c)出现错误;运行结束d)出现错误2/关于以下C#代码,说法正确的是(C)Class MylAnimals{Private int bodyTemp=98;Public int BodyTemp{Get{Return bodyTemp; //1}}}Public class Test{Static void Main(){MyAnimals a=new MyAnimals();Console.WriteLine(a.BodyTemp); //2a.BodyTemp=56; //3}}a)代码1错误b)代码2错误c)代码3错误d)代码无错误3/在C#中,某程序在一个类中编写了两个同名的方法,代码如下,请问该代码的运行结果是()。
Public class Musician{Public void Song(){Console.WriteLine(“放了你我做不到”);}Public void Song(string musicName){Console.WriteLine(musicName);}Static void Main(){Musician musician=new Musician();Sing musicName=”李景我还是觉的你最好,因为你皮比猪白、肉比猪嫩。
”musician.Song(“主要是现在猪肉还是挺贵的啊”);}}a)放了你我做不到b)李景我还是觉的你最好,因为你皮比猪白、肉比猪嫩。
c)主要是现在猪肉还是挺贵的啊\d)没有输出4/在C#中,为了防止用户没有保存操作的结果而无意关了窗体,一般在窗体的Closing事件中添加(A)代码。
一、单项选择题(每小题2分,共20分)1.在类作用域中能够通过直接使用该类的()成员名进行访问。
A. 私有B. 公用C. 保护D. 任何2.小数类型(decimal)和浮点类型都可以表示小数,正确说法:( )A. 两者没有任何区别B. 小数类型比浮点类型取值范围大C.小数类型比浮点类型精度高D. 小数类型比浮点类型精度低3.能作为C#程序的基本单位是( )。
A. 字符B. 语句C. 函数D. 源程序文件4. 可用作C#程序用户标识符的一组标识符是( )。
A. void define +WORDB. a3_b3 _123 YNC. for -abc CaseD. 2a DO sizeof5.引用类型主要有4种:类类型、数组类型、接口类型和()。
A.对象类型B.字符串类型C.委托类型D.整数类型6.加载窗体时触发的事件是( )。
A. ClickB.LoadC.GotFoucsD.DoubleClick7.改变窗体的标题,需修改的窗体属性是( )。
A. TextB. NameC.TitleD. Index8.在C#中定义接口时,使用的关键字是( )。
A.interfaceB.:C.classD.overrides9.在类的成员中,用于存储属性值的是( )。
A. 属性B. 方法C. 事件D.成员变量10.在C#中,定义派生类时,指定其基类应使用的语句是( )。
A.InheritsB.:C.ClassD.Overrides11.类的以下特性中,可以用于方便地重用已有的代码和数据的是( ).A.多态B.封装C.继承D.抽象12.在Array类中,可以对一维数组中的元素进行排序的方法是( )。
A.Sort()B.Clear()C.Copy()D.Reverse()13.将变量从字符串类型转换为数值类型可以使用的类型转换方法是( )。
A.Str()harC.CStr()D.int.Parse();14.数据类型转换的类是( )。
《C#程序设计》——编程题(上机操作题)1、从键盘输入一个正整数,按数字的相反顺序输出。
2、从键盘上输入两个整数,由用户回答它们的和,差,积,商和取余运算结果,并统计出正确答案的个数。
3、写一条for语句,计数条件为n从100~200,步长为2;然后再用while语句实现同样的循环。
4、编写一段程序,运行时向用户提问“你考了多少分?(0~100)”,接受输入后判断其等级并显示出来。
判断依据如下:等级={优(90~100分);良(80~89分);中(60~69分);差(0~59分);}5、输入一个整数,将各位数字反转输出。
6、使用穷举法并分别用for、while、do…while循环语句求出1~100之间的质数。
7、求出1~1000之间的所有能被7整除的数,并计算和输出每5个的和。
8、编写一个控制台程序,分别输出1~100之间的平方、平方根、自然对数、e指数的数学用表。
9、设计一个包含多个构造函数的类,并分别用这些构造函数实例化对象。
10、编写一个矩形类,私有数据成员为举行的长(len)和宽(wid),无参构造函数将len和wid设置为0,有参构造函数设置和的值,另外,类还包括矩形的周长、求面积、取举行的长度、取矩形的长度、取矩形的宽度、修改矩形的长度和宽度为对应的形参值等公用方法。
11、编写一个类,要求带有一个索引器可以存储100个整型变量。
12、编写一个类Cal1,实现加、减两种运算,然后,编写另一个派生类Cal2,实现乘、除两种运算。
13、建立三个类:居民、成人、官员。
居民包含身份证号、姓名、出生日期,而成人继承自居民,多包含学历、职业两项数据;官员则继承自成人,多包含党派、职务两项数据。
要求每个类中都提供数据输入输出的功能。
14、编写一个类,其中包含一个排序的方法Sort(),当传入的是一串整数,就按照从小到大的顺序输出,如果传入的是一个字符串,就将字符串反序输出。
15、设计一个类,要求用事件每10秒报告机器的当前时间。
16、编写一个窗体程序,用菜单命令实现简单的加、减、乘、除四则运算,并将结果输出到对话框。
17、编写一个具有主菜单和快捷菜单的程序,实现文本文件的打开、修改和保存。
18、在label控件中随机输入20个1~1000之间的整数,求出其中所有的素数的和。
19、编写一个程序,通过使用主菜单和工具栏按钮实现与Window记事本间的文本数据拷贝。
20、仿照word中的“文件打开”对话框界面,编制一个自己的文件打开模式对话框。
21、自己编写一个控件,使得该控件放置在窗体上之后,可以通过拖动四个顶点随意地改变控件的形状。
(提示:在控件的Paint事件过程中编写外观绘制代码)22、编写一个程序,将一幅位图显示在一个图片框中,对位图惊醒45度旋转后,将图中所有的红色替换为黑色,然后存盘。
23、编写一个控制台程序,分别将字符串“hello,my friend”写入文件f1.txt,然后,将数据分别以整型、布尔型、双精度型、字符型读出并显示。
24、编写一个程序,模拟DOS系统中的COPY CON命令功能。
25、分别用Socket 类和TC PListener/TCPClient 类建立一个通过TCP协议进行文件传输的程序。
26、利用网络流实现一个利用UDP协议进行聊天的程序,并使一端采用UTF-8编码,另一端则采用Unicode解码。
27. 创建一个带有3个子线程的程序,第一个线程序启动10毫秒后,第二个线程再启动,然后再等10毫秒后第三个线程启动,每一个线程从1~1000循环输出线程的名称和计数,当3个线程结束时要输出各自的结束信息,然后,主线程结束。
28. 制作一个程序模拟图书馆中的书籍借阅操作,有两个人几乎同时查阅某一本书是否还有(用两个线程访问同一个变量),如果有,就将书的数量减1,如果没有输出“书籍已经全部借出”。
用3个线程同步的方法分别实现程序。
编写一个自定义类Employee,要求:A.该类包含连接到access 的Northwind数据库的公用方法。
B.该类包含若干个字段用来存储从“雇员表”中读取的若干字段的值。
C.该类包含在表中移动记录指针的方法。
D.该类包含修改字段值的方法。
E.该类包含将字段值显示出来的方法。
30. 编写一个程序,从键盘上输入3个数,输出这3个数的积及它们的和。
要求编写成控制台应用程序。
31.编写一个程序,输入梯形的上底,下底和高,输出梯形的面积。
要求编写成Window应用程序。
32. 编写一个进行加减乘除四则运算的程序,要求:输入两个单精度数,然后输入一个运算符号,输出两个单精度数进行运算后的结果。
要求编写为控制台程序。
33. 兔子繁殖问题。
设有一对新生的兔子,从第三个月开始他们每个月都生一对兔子,新生的兔子从第三个月开始又每个月生一对兔子。
按此规律,并假定兔子没有死亡,20个月后共有多少个兔子?要求编写为控制台程序。
34. 编写程序,把由10个元素组成的一维数组逆序存放再输出。
35. 编写程序,统计4X5二维数组中奇数的个数和偶数的个数。
36. 编写一个求整数任意位数字的过程,过程的调用形式为:digit(n,k),其功能是取出数n从右边起的第K位数字,例如:digit(1234,3)=2, digit(1234,4)=1, digit(1234,6)=0。
37. 编写一个应用程序用来输入的字符串进行加密,对于字母字符串加密规则如下:‘a’→’d’‘b’→’e’‘w’→’z’……‘x’→’a’‘y’→’b’‘z’→’c’‘A’→’B’‘B’→’E’‘W’→’Z’……‘X’→’A’‘Y’→’B’‘Z’→’C’对于其他字符,不进行加密。
38. 定义一个车辆(Vehicle)基类,具有Run、Stop等方法,具有Speed(速度)、MaxSpeed (最大速度)、Weight(重量)等域。
然后以该类为基类,派生出bicycle、car等类。
并编程对该派生类的功能进行验证。
39. 编写出一个通用的人员类(Person),该类具有姓名(Name)、年龄(Age)、性别(Sex)等域。
然后对Person 类的继承得到一个学生类(Student),该类能够存放学生的5门课的成绩,并能求出平均成绩,要求对该类的构造函数进行重载,至少给出三个形式。
最后编程对student类的功能进行验证。
40. 编写一个冒泡法排序程序,要求在程序中能够捕获到数组下标越界的异常。
41.编写一个计算器程序,要求在程序中能够捕获到被0除的异常与算术运算溢出的异常。
42.制作一个简单计算器程序。
程序运行时通过按钮输入运算公式,单击【计算】按钮得到计算结果。
43. 编写一个能够浏览文本文件和图象文件查看程序。
44. 编写一个能同时播放视频文件和背景音乐的程序,要求背景音乐和视频文件都能循环播放。
用MMControl控件设计一个能够播放音乐、MIDI文件的播放器,要求具有自动重播和显示进度的功能。
45 编程输出1~100中能被3整除但不能被5整除的数,并统计有多少个这样的数。
46. 编程输出1000以内的所有素数。
47. 编写一个程序,对输入的4个整数,求出其中最大值和最小值。
48. 分别用for,while,do…while语句编写程序,实现求前n个自然数之和。
49. 编程输出九九乘法表。
50. 定义一个行数和列数相等的二维数组,并执行初始化,然后计算该数级两条对角线上的元素值之和。
51. 建立一个一维数组,使用该数组列出所学习的课程名称。
52. 编写一个包含学生基本资料的结构类型数据(要求包括姓名,性别,年龄,身高,体重等)。
53. 编写程序,将一年中12个月,建立一个枚举类型数据,并对其进行调用。
54. 在窗体上建立一个标签,一个文本框,一个命令按钮,标签的text属性设置为“VC#程序设计”,设计一个程序,单击命令按钮,将标签上的信息显示在文本框中。
55. 设计一个简单的计算器,在文本框中,显示输入值和计算结果,用命令按钮做为数字键和功能键。
56. 在窗体上建立一个列表框,一个文本框和一个命令按钮,在列表框中列有本班10个同学的姓名,当选中某个学生姓名后,单击此命令按钮,则在文本框中显示该学生的籍贯。
57. 用定时器控件按秒计时,在窗体上创建一个标签,程序执行后在标签内显示经过的秒。
58. 编写程序在E盘下新建一文本文件,并对该文件进行复制,移动,写入,读出操作59. 编写一个程序,其中对于每种数据类型,都声明两个变量,并分别将值10和1.879赋给它们。
60. 编写一个程序,检查变量的值是否大于65。
如果是,则打印文本“THE V ALUE IS GREATER THAN 65!”61. 编写一个程序,检查一个字符变量的值是否为T或t。
62. 编写一行代码,将long变量MyLong的值赋给short变量MyShort。
63. 编写一行代码,将int变量IntVal的赋给short变量ShortVal。
64. 编写一行代码,将decimal变量DecVal的值赋给long变量LongVal。
65. 编写一行代码,将int变量ch的值赋给字符变量char V al。
66. 编写一个从99数到1的while语句。
67. 编写一条根据变量name的值执行不同操作的switch语句。
如果该变量的值为Robert,则打印消息”Hi Bob”;如果为Richard,则打印消息“Hi Rich”;如果为Barbara,则打印消息“Hi Barb”;如果为Kalee,则打印消息“You Go Girl!”;对于其他情况,则打印“Hix”,其中x为变量name的值。
67. 编写一个掷筛子100次的程序,并打印出各种点数的出现次数。
68. 创建一个类,它存储一个int数据成员MyNumber,并给该数据成员创建属性,当该数据成员被存储时,将其乘以100;当其被读取时,将其除以100。
69. 编写一个die类,它存储筛子的面数(sides)以及当前掷筛子得到的点数(value)。
70. 编写公有方法xyz的方法头,该方法接受两个参数,不返回任何值。
71. 为方法myMethod编写方法头。
该方法接受三个参数。
第一个名为myVal,其数据类型为double,并按值传递;第二个是一个输出变量,名为myOutput;第三。
个是按引用传递的,数据类型为int,名为myRerence。
另外该方法是公有的,其返回类型为byte。
72. 创建一程序,该程序包括一个筛子类,后者有三个数据成员,即筛子的面数,筛子的点数以及包含随机数类的静态数据成员。
为这个类声明一个名为roll()的成员方法,它以随机的方式返回下一次掷筛子得的点数。
73. 为教师编写一个程序,该程序使用一个数组存储30个学生的考试成绩,并给各个数组元素指定一个1-100的随机值,然后计算平均成绩。