C考核练习题2018含答案.pdf_第1页
C考核练习题2018含答案.pdf_第2页
C考核练习题2018含答案.pdf_第3页
C考核练习题2018含答案.pdf_第4页
C考核练习题2018含答案.pdf_第5页
已阅读5页,还剩26页未读 继续免费阅读

付费下载

下载本文档

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

文档简介

第 1 页 C#考核练习题(2018) 注:注:分成七个部分,每部分各6题。 抽题时每一部分抽取一题。合计7题。 备注:所有代码及其结果中,必须出现考生所在机号。不得出现任何 姓名、机号等相关信息。 一、程序阅读与调试一、程序阅读与调试 1、完善下面代码,从键盘上输入三个数,把中间数找出来,输出结果前输出机号,并在提 供机号的语句后加上注释。 (运行时,请输入:20,11,83) int a = Console.Read(); int b = Console.Read(); int c = Console.Read(); int max,min; max = ab ? a : b; min = a b ? b : a; max = a c ? a : c; min = b c ? c : b; Console.WriteLine(“机号:”+NUM); Console.WriteLine(“0,1,2的中间数为:3“, a,b,c,a+b+c-max-min); 答案:static void Main(string args) int a =int.Parse ( Console.ReadLine(); int b = int.Parse(Console.ReadLine(); int c = int.Parse(Console.ReadLine(); int max, min; string NUM = “F50308“;/F503室08号机 max = a b ? a : b; min = a b ? b : a; max = max c ? max : c; min = min c ? c : min ; Console.WriteLine(“机号为:“ + NUM); Console.WriteLine(“0,1,2的中间数为:3“, a, b, c, a + b + c - max - min); 2、完善下面代码,当 month 输入某一月份时,能正确输出该月份的天数,输出结果前输出 机号,并在提供机号的语句后加上注释。 (运行时,请输入:2) int month=Console.Read(); 第 2 页 int days = 0; switch (Month) case 2: days = 28; case 4: days = 30; case 6: days = 30; case 9: days = 30; case 11: days = 30; break; default: days = 31; break; Console.WriteLine(“机号:”+NUM); Console.WriteLine(days); 答案:static void Main(string args) int month = int.Parse(Console.ReadLine(); int days = 0; string NUM = “F50308“;/F503室08号机 switch (month) case 2: days = 28; break; case 4: case 6: case 9: case 11: days = 30; break; default: days = 31; break; Console.WriteLine(“机号:“ + NUM); Console.WriteLine(days); 3、完善如下程序:键入 10 个整数,统计其中正数(Zeng)、负数(Fu)和零(zero)的个数并 将三者输出。输出结果前输出机号,并在提供机号的语句后加上注释。 (运行时,请输入: 20,-6,33,-55,-11,0,78,0,11,-1) int num; int zeroNum ,ZengNum,FuNum; 第 3 页 for (i = 1; i = 0) ZengNum+; else if (num = 0) zeroNum+; else FuNum+; /for_end Console.WriteLine(“机号:”+NUM); Console.WriteLine(“正数:0、负数: 1、 零:2“, ZengNum, FuNum, zeroNum); 答案:static void Main(string args) int num; int zeroNum=0, ZengNum=0, FuNum=0; string NUM = “F50308“;/F503室08号机 for (int i = 1; i 0) ZengNum+; else if (num = 0) zeroNum+; else FuNum+; /for_end 第 4 页 Console.WriteLine(“机号:“ + NUM); Console.WriteLine(“正数:0、负数: 1、 零:2“, ZengNum, FuNum, zeroNum); 4 4、完善下面代码,当输入一个自然数 n 时,能正确输出 n 以内能被 3 整除且个位数为 6 的 所有整数,输出前输出你的机号,并在提供机号的语句后加上注释。(运行时输入 n=100)。 int n=Console.ReadLine(); intj; Console.WriteLine(“机号:”+NUM); for (int i = 0; i n) i = m; else i = n; for (j = i; ; j+) if (j % m = 0 break; Console.WriteLine(“机号:“ + NUM); Console.WriteLine(“最小公倍数是:0“, min); 6、完善下面代码,数组 a20存放了 20 个范围在1,30)的随机整数,方法 fun()找出有 重复的数字.输出结果前输出你的机号,并在提供机号的语句后加上注释。 using System; class Test void fun(int a) 第 6 页 for(i=1;i c ? max : c; min = a = 0 else if (s = )/空格 Space += 1; else/其他字符 Other += 1; string NUM = “F50308“;/F503室08号机 Console.WriteLine(“机号?:o“ + NUM); Console.WriteLine(“字母有:0个“,Eng ); Console.WriteLine(“数字有:0个“, Num); Console.WriteLine(“空格有:0个“, Space); 第 13 页 Console.WriteLine(“其他的:0个“, Other); Console.ReadKey(); 6 6编一个程序,利用循环语句和 Math 类中的 Pow()方法,求出 1 到 10 的各个 数的平方之和。 答案:static void Main(string args) int s = 0; string NUM =“F50308“;/F503室08号机 for (int i = 1; i = A string NUM = “F50308“;/F503室08号机 Console.WriteLine(“机号?:o“ + NUM); Console.WriteLine(“大写字?母?:o“+us+“,?小?写字?母?:o “+ls); 五、对象基础 1.1.编一个程序,定义类student和它的成员(机号,年龄和程序设计成绩),用类 student生成对象s,分别对对象s的成员赋值,然后输出对象s。 答案:class Student public string NUM; public int age; public int sc; class Program static void Main(string args) Student s = new Student(); s.NUM = “F50308“;/F503室08号机 s.age = 16; s.sc = 88; 第 17 页 Console.WriteLine(“机号?:o“ + s.NUM); Console.WriteLine(“年龄?:o“ + s.age); Console.WriteLine(“成绩:o“ + s.sc); 2.2.编一个程序,定义类(有机号,年龄,电话三个字段),再定义一个一维数组, 使数组元素为类, 存入数据, 然后依次输出,使用for循环语句进行输入输出操作。 答案:class Student public string NUM; public int age; public int tel; class Program static void Main(string args) string NUM = “F50308“;/F503室08号机 Console.WriteLine(“机号?:o“ + NUM); Student s = new Student3; for (int i = 0; i = 0) listBox1.Items.RemoveAt(listBox1.SelectedIndex); label3.Text = “学生人?数y:o“ + listBox1.Items.Count; private void button3_Click(object sender, EventArgs e) 第 26 页 listBox1.Items.Clear(); label3.Text = “学生人?数y:o“ + listBox1.Items.Count; private void button4_Click(object sender, EventArgs e) if (listBox1.SelectedIndex = 0) listBox1.Items.RemoveAt(listBox1.SelectedIndex ); label3.Text = “学生人?数y:o“ + listBox1.Items.Count; private void Form1_Load(object sender, EventArgs e) label3.Text = “学生人?数y:o“ + listBox1.Items.Count; 6.6.实现色彩变换的功能。 答案:public partial class Form1 : Form public Form1() InitializeComponent(); private void timer1_Tick(object sender, EventArgs e) Random rc = new Random();/随机生成数字,加时钟不断变化 int r, g, b; r = rc.Next(0, 256); textBox1.Text = r.ToString (); g = rc.Next(0, 256); textBox2.Text = g.ToString(); 第 27 页 b = rc.Next(0, 256); textBox3.Text = b.ToString(); pictureBox1.BackColor = Color.FromArgb(r, g, b); 七、GDI+与文件 1 1内切与对角线。创建一个窗体,该窗体画一个边长=100 的立方形和一个内切的圆以及对 角线。窗体标签为“内切与对角线”+机号。 答案:public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) Graphics g = this.CreateGraphics(); Pen mp = new Pen(Color.Red , 2); g.DrawRectangle(mp, 50, 50, 100, 100); mp = new Pen(Color.Blue , 2); g.DrawEllipse (mp,50,50,100,100); mp=new Pen (Color .Green,2); g.DrawLine(mp, 50, 50, 150, 150); 第 28 页 2 2圆和环。创建一个窗体,该窗体画一个半径=50 的圆,外面是宽度都为 50 的两个环。窗 体标签为“圆环”+机号。 答案:private void button1_Click(object sender, EventArgs e) Graphics g = this.CreateGraphics(); Brush br1 = new SolidBrush(Color.Green); int r1 = 300, r2 = 300, r3 = 200, p = 50; g.FillEllipse(br1, p, p, r1, r1); Brush br2 = new SolidBrush(Color.White); g.FillEllipse(br2, 100, 100, r3, r3); Brush br3 = new SolidBrush(Color.Red); g.FillEllipse(br3, 150, 150, 100, 100); 3 3锥。创建一个窗体,该窗体画一个锥形。窗体标签为“锥形”+机号。 第 29 页 答案:public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) Graphics g = this.CreateGraphics(); Pen mp = new Pen(Color.Red , 1); int p = 20, r = 10; for (int i = 1; i = 15; i+) g.DrawEllipse(mp, 150 - r / 2, p, r, r); r = r + 15; 4 4交通灯。创建一个窗体,该窗体画一个半径=80 的圆作为交通灯,自动变换颜色,间隔 时间为 500 毫秒。窗体标签为“交通灯”+机号。 答案:public partial class Form1 : Form Color y, r, g, t; public Form1() InitializeComponent(); y = Color.Yellow; g = Color.Green; r = Color.Red; t = Color.Black; 第 30 页 private void timer1_Tick(object sender, EventArgs e) Graphics gc = this.CreateGraphics(); Brush br = new SolidBrush(t); int radius = 80; gc.FillEllipse(br, 50, 50, radius, radius); t = r; r = g; g = y; y = t; 5 5编写一个控制台程序,分别将字符串“123”,“3.14159”,“hello,my friend”写入 文件 f1.txt,然后,将数据分别以整型、双精度型、字符型读出并显示。 答案:static void Main(string args) string s = “123“,“3.14159“,“hello,?my friend“; int n; double x; string str, fn = “D:f1.txt“; if(File .Exists (fn) File .Create (fn); File.WriteAllLines(fn, s); st

温馨提示

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

评论

0/150

提交评论