ImageVerifierCode 换一换
格式:DOCX , 页数:27 ,大小:22.30KB ,
资源ID:27265353      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/27265353.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C#应用开发技术习题.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C#应用开发技术习题.docx

1、C#应用开发技术习题C#应用开发技术习题C#应用开发技术习题1.用enum定义字节类型的方位常量,打印出某一方位并将此方位值转化为字节类型,字符串类型值。分析输出结果的原因。回答以下问题:Enum的缺省类型是什么?直接输出myDirection和(byte)myDirection有何区别。class Variables enum orientation : byte north = 1, south = 2, east = 3, west = 4 static void Main(string args) byte directionByte; string directionString;

2、orientation myDirection = orientation.north; Console.WriteLine(myDirection = 0, myDirection); directionByte = (byte)myDirection; directionString = Convert.ToString(myDirection); Console.WriteLine(byte equivalent = 0, directionByte); Console.WriteLine(string equivalent = 0, directionString);Console.R

3、eadLine(); 2建立使用关系运算符和逻辑运算符的程序文件。Main方法中实例代码如下static void Main(string args) Console.WriteLine(Enter an integer:); int myInt = Convert.ToInt32(Console.ReadLine(); Console.WriteLine(Integer less than 10? 0, myInt 10); Console.WriteLine(Integer between 0 and 5? 0, (0 = myInt) & (myInt = 5); Console.Wri

4、teLine(Bitwise AND of Integer and 10 = 0, myInt & 10); Console.ReadLine(); 编译运行该程序。并尝试myInt输入不同范围整数,非10和10时的输出差异。3 .从键盘输入两个数进行比较,并定义一个字符串变量,当数1小于数2时,字符串变量为“less than”,当当数1等小于数2时字符串变量为“equal to”,当数1大于数2时字符串变量为“greater than”。static void Main(string args) string comparison; Console.WriteLine(Enter a nu

5、mber:); double var1 = Convert.ToDouble(Console.ReadLine(); Console.WriteLine(Enter another number:); double var2 = Convert.ToDouble(Console.ReadLine(); if (var1 var2) comparison = less than; else if (var1 = var2) comparison = equal to; else comparison = greater than; Console.WriteLine(The first numb

6、er is 0 the second number., comparison); Console.ReadLine(); 4.定义三个常量字符串“karli”,angelina,ploppy,并从键盘输入一个名字,当名字与“karli”相同时输出我们的名字相同,当和angelina名字相同时输出你的名字太性感了,当和ploppy相同时输出这名字真傻。static void Main(string args) const string myName = karli; const string sexyName = angelina; const string sillyName = ploppy

7、; string name; Console.WriteLine(What is your name?); name = Console.ReadLine(); switch (name.ToLower() case myName: Console.WriteLine(You have the same name as me!); break; case sexyName: Console.WriteLine(My, what a sexy name you have!); break; case sillyName: Console.WriteLine(Thats a very silly

8、name.); break; Console.WriteLine(Hello 0!, name); Console.ReadLine();5 for 循环语句练习(1) 程序功能要求:按5 度的增量打印出一个从摄氏温度到华氏温度的转换表。static void Main(string args) double Fa,Cel; Cel =0; for(Cel=0;Cel100;Cel+=5) Fa = Cel * 9/5; Console.WriteLine(Fa);Console.ReadLine(); (2)自行改造以上程序。6. while 循环语句练习(1)程序功能要求:运行程序后从键盘

9、输入数字1/2/3 后,可显示抽奖得到的奖品:恭喜你得了一辆汽车;不错啊,一台笔记本电脑;没白来,一个MP3;如果输入其它数字或字符显示“没有奖品给你!”。示例代码如下: int choice; choice = Convert.ToInt32(Console.ReadLine(); while (choice = 1) Console.WriteLine(恭喜你得了一辆汽车); break; while (choice = 2) Console.WriteLine(不错啊,一台笔记本电脑); break; while (choice = 3) Console.WriteLine(没白来,一个

10、MP3); break; while (choice != 1 & choice != 2 & choice != 3) Console.WriteLine(没有奖品给你); break; (2)改造以上程序实现此功能;尝试将choice=1或2或3中的“=”改为一个“=”,看效果如何?并分析错误。7dowhile 循环语句练习 程序功能要求:输入你现有的存款和当前的年利率及你期望将来得到的存款,计算出存款多少年后才可以变成你期望的存款额。注意,若为一年输出year为year,若为多年输出year为years。参考代码如下:static void Main(string args) doubl

11、e balance, interestRate, targetBalance; Console.WriteLine(What is your current balance?); balance = Convert.ToDouble(Console.ReadLine(); Console.WriteLine(What is your current annual interest rate (in %)?); interestRate = 1 + Convert.ToDouble(Console.ReadLine() / 100.0; Console.WriteLine(What balanc

12、e would you like to have?); targetBalance = Convert.ToDouble(Console.ReadLine(); int totalYears = 0; do balance *= interestRate; +totalYears; while (balance targetBalance); Console.WriteLine(In 0 year1 youll have a balance of 2., totalYears, totalYears = 1 ? : s, balance); 8使用if.else 语句编写以下程序(1)程序功能

13、要求:使用if.else 语句构造多分支,判断某一年是否为闰年。闰年的条件是符合下面二者之一:能被4 整除,但不能被100 整除;能被4 整除,又能被100 整除。9使用switch 语句编写以下程序在不同温度时显示不同的解释说明:有点冷,多穿衣服;正合适,出去玩吧;太热了,开空调。10. 用dowhile语句实现程序功能:求12+100 之和,并将求和表达式与所求的和显示出来。11. 定义一个圆类,计算圆的面积和周长public class circle public static void Main() double radium, delimeter, square; const dou

14、ble pai = 3.1415926; radium = Convert.ToInt32(Console.ReadLine(); delimeter = 2 * pai * radium; square = pai * pai * radium; Console.WriteLine(delimeter=0,square=1, delimeter, square); Console.ReadLine(); 或者:public class circle double delimeter, square; const double pai = 3.1415926; public void calc

15、ulate(double rad) delimeter = 2 * pai * rad; square = pai * pai * rad; Console.WriteLine(delimeter=0,square=1,delimeter,square); public static void Main() double radium; circle cir = new circle(); radium = Convert.ToInt32(Console.ReadLine(); cir.calculate(radium); Console.ReadLine(); 请比较以上两个程序,看起来后一

16、个程序把问题复杂化了,是不是不如第一个程序好,它从设计思想上有什么优势么?12. 程序要求如下:其中有3个数据成员有学号、姓名、年龄,以及若干成员函数。同时编写主函数使用这个类,实现对学生数据的赋值和输出。要求:使用成员函数实现对数据的输出;使用构造函数实现对数据的输入。 参考代码如下:public class students string id,name; int age; public students(string id,string name,int age ) this.id = id; this.name = name; this.age = age; public void D

17、isplay() Console.WriteLine(id=0,name=1,age=2,id,name,age); public static void Main() /string id, name; /int age; students stu = new students(0001,zhangsan,16); stu.Display(); Console.ReadLine(); 以上程序使用了构造方法,请回答关键字this有何作用,你能将成员函数Display修改成别的代码也实现响应的功能么?13. 编写帐户类,对每一账号赋值帐户并设置初始化存款为0.00元,设计一变量统计账号生成的数

18、目。public class BankAccount static int totalAccountNumber=0; string BankAccountId; double initialDepositAmount = 0.00; public BankAccount(string myId) this.BankAccountId = myId; this.initialDepositAmount = 0.00; totalAccountNumber+; public void displayid() Console.WriteLine(mbaid=0,initialDepositAmou

19、nt=1,this.BankAccountId,this.initialDepositAmount); public static void display() Console.WriteLine(totalAccountNumber=0, totalAccountNumber); public class Tester public static void Main() BankAccount mba = new BankAccount(37000001); BankAccount mba2 = new BankAccount(3700002); BankAccount mba3 = new

20、 BankAccount(); BankAccount mba4 = new BankAccount(3700004); / Console.WriteLine(mba2ID=0, mba2.BankAccountId); mba2.displayid(); BankAccount.display(); Console.ReadLine(); 请回答问题:(1)按你自己的算法修改以上程序,比如可只输出生成的账户数。(2)把注释去掉后会怎样,为什么?(3)为什么display用类名直接引用,可以用对象来引用么?尝试输出结果。(4)类的静态变量和非静态变量的引用区别。判断一下语句的正确性:静态方法

21、只能使用静态变量,不能使用实例变量。因为对象实例化之前,实例变量不可用。这个观点真确么?()类的静态变量只有一个版本,所有实例对象引用的都是同一个版本。()对象实例化后,每个实例变量都被制作了一个副本,它们之间互不影响。()14. 程序首先给整型变量x 和y 赋初值3,5,然后使用传值调用方式调用方法对x 和y 做乘方并及输出x 和y 的乘方值,最后输出x和y得值。再将此方法给为对象调用加ref修饰查看输出结果差异。参考代码如下:public class Power / public void MyPower(ref int x, ref int y) public void MyPower(

22、int x, int y) x = 1; y = 2; Console.WriteLine(x=0,y=1, x, y); Console.WriteLine(x*x=0,y*y=1,x*x,y*y); public class Tester public static void Main() int x, y; x = 3; y = 5; Power mp = new Power(); / mp.MyPower(ref x,ref y); mp.MyPower(x,y); Console.WriteLine(x=0,y=1,x,y); Console.ReadLine(); 思考:(1)将响

23、应的注释修改再调试查看结果,分析原因。(2)将Main中x和y赋初值去掉,结果会怎样?如果Main中加ref,类Power的方法中参数前不加ref又会有何变化?说明了什么?3)如果不想对x作无用的初始化,直接作参数传递,怎么实现?15. 编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班级和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师类数据操作类teacher的基类。参考代码如下:public class person string ID, name; public void personin(

24、string id,string name) this.ID = id; this.name = name; public void displayin() Console.WriteLine(编号:0,ID); Console.WriteLine(名字:0, name); public class student : person string classname; int grads; public student(string classname, int grads) this.classname = classname; this.grads = grads; public void

25、 displays() Console.WriteLine(班级:0,成绩:1,classname,grads); public class teacher : person string title,department; public teacher(string title, string department) this.title = title; this.department = department; public void displayt() Console.WriteLine(职称:0,部门::1, title, department); public class Tes

26、ter static void Main() student su = new student(0601,69); su.personin(s00001,Tom); su.displayin(); su.displays(); teacher tc = new teacher(lecture, IM); tc.personin(t0001,LiLi); tc.displayin(); tc.displayt(); Console.ReadLine(); 将以上程序尝试改成通过调用基类构造方法的方式来初始化编号和姓名,并总结调用基类构造方法的应用要点。参考代码如下:public class pe

27、rson string ID, name; public person(string id,string name) this.ID = id; this.name = name; public void displayin() Console.WriteLine(编号:0,ID); Console.WriteLine(名字:0, name); public class student : person string classname; int grads; public student(string sid,string sname, string classname, int grads

28、):base(sid,sname) this.classname = classname; this.grads = grads; public void displays() Console.WriteLine(班级:0,成绩:1,classname,grads); public class teacher : person string title, department; public teacher(string tid, string tname,string title, string department):base(tid,tname) this.title = title; this.department = department; public void displayt() Console.WriteLine(职称:0,部门::1, title, department); public class Tester static void Main() student su = new student(s00001,Tom,0601,69); su.displayin(); su.displays(); teacher tc = new teacher(t0001,LiLi,lecture, IM); tc.displayin(); tc.displayt(

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1