C#上机考试题目大全和答案.doc_第1页
C#上机考试题目大全和答案.doc_第2页
C#上机考试题目大全和答案.doc_第3页
C#上机考试题目大全和答案.doc_第4页
C#上机考试题目大全和答案.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

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

文档简介

用visual studio 2005做的(1)编程输出1到100中能被3整除但不能被5整除的数,并统计有多少个这样的数。(2)创建一个控制台应用程序,编写一个函数将十进制数转换成二进制数。程序可以让用户一直进行转换,直到输入0为止。程序中要对格式转换异常进行处理。(3)创建一个类,它存储一个int数据成员MyNumber,并给该数据成员创建属性,当该数据成员被存储时,将其乘以100;当其被读取时,将其除以100。(4)设计一个类,要求用事件每10秒报告机器的当前时间。(5)编写一个程序接受用户输入的字符。如果输入的字符是0-9数字中的一个,则显示“您输入了一个数字”,否则显示“这不是一个数字”。(6)编写一个程序,该程序使用一个数组存储30个学生的考试成绩,并给各个数组元素指定一个1-100的随机值,要求利用索引来对数组中的元素进行赋值和显示。然后计算平均成绩。(7)编写一个windows应用程序,能将窗体背景颜色1秒钟变换一次。(8)通过方法重载,使用同一个方法名print分别执行输出整数、双精度数与字符串的功能。1.using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1 class Program static void Main(string args) int sum = 0; Console.WriteLine(能被3整除但不能被5整除的数 ); for (int i = 1; i = 0; j-) Console.Write(sj); Console.WriteLine(); else return; catch (Exception ) Console.Write(格式转换错误); 3.using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication3 class MyClass int MyNumber; public int mynumber get return MyNumber / 100; set MyNumber = value * 100; static void Main(string args) Console.Write(请输入任意一个数:); int a = Convert.ToInt32(Console.ReadLine(); MyClass m = new MyClass(); Console.Write(结果为:); m.mynumber = a; Console.WriteLine(0, m.mynumber); 4.using System;using System.Collections.Generic;using System.Text;using System.Threading;namespace ConsoleApplication4 class ClassA public void TimerHandlerA(object obj, EventArgs e) / Event handler Console.WriteLine(DateTime.Now.ToLongTimeString(); class Program static void Main() ClassA ca = new ClassA(); / Create the class object. MyTimerClass mc = new MyTimerClass(); / Create the timer object. mc.Elapsed += ca.TimerHandlerA; / Add handler A - instance. Thread.Sleep(100000); public class MyTimerClass public event EventHandler Elapsed; private void OnOneSecond(object obj, EventArgs e) if (Elapsed != null) Elapsed(obj, e); private System.Timers.Timer MyPrivateTimer; / Private timer public MyTimerClass() / Constructor MyPrivateTimer = new System.Timers.Timer(); / Create the private timer. MyPrivateTimer.Elapsed += OnOneSecond; / Attach our event handler. MyPrivateTimer.Interval = 10000; / 1 second interval. / Property Enabled is of type bool, and turns the timer on and off. MyPrivateTimer.Enabled = true; / Start the timer. 5.using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1 class Program static void Main(string args) int a; Console.Write(请输入一个字符:); a = Convert.ToInt32(Console.ReadLine(); switch (a) case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: Console.WriteLine(您输入了一个数字); break; default: Console.WriteLine(这不是一个数字); break; 6.using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication2 class CMyclass public float a; public CMyclass() a = new float30; public float thisint index get return aindex; set aindex=value; class Program static void Main(string args) float avg=0; CMyclass m=new CMyclass(); Random n=new Random(); for(int i=0;i30;i+) mi=n.Next(100); for (int i = 0; i 30; i+) Console.Write(0, mi); Console.WriteLine(); float sum=0; for(int i=0;i 255 | j 255 |k 255) i = 100; j=50; k=200; 8.using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication4 class Myclass public int print(int x) return x; public double print(double x) return x; public string print(string x) return x; class Program static void Main(string args) Myclass m = new Myclass(); int a; Console.WriteLine(请输入一个整数:); a = Convert.ToInt32(Console.ReadLine(); Console.WriteLine(int a=0,a,m.print(a); double b; Console.WriteLine(请输入一个双精度数:); b = Convert.ToDouble(Console .ReadLine ()

温馨提示

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

评论

0/150

提交评论