.net实用教程课后实验

上传人:飞*** 文档编号:2123129 上传时间:2017-07-20 格式:DOC 页数:58 大小:848KB
返回 下载 相关 举报
.net实用教程课后实验_第1页
第1页 / 共58页
.net实用教程课后实验_第2页
第2页 / 共58页
.net实用教程课后实验_第3页
第3页 / 共58页
.net实用教程课后实验_第4页
第4页 / 共58页
.net实用教程课后实验_第5页
第5页 / 共58页
点击查看更多>>
资源描述

《.net实用教程课后实验》由会员分享,可在线阅读,更多相关《.net实用教程课后实验(58页珍藏版)》请在金锄头文库上搜索。

1、C#程序设计一、实验名称:C#实验二、实验目的:通过上机实际操作将平时课堂所学具体实现,通过该实验来检查自己的学习成功,并且发现平时学习中没有注意到的问题并解决之,从而加深对该门课程的以及 C#语言的了解。三、实验步骤:实验一:C#编程环境实验目的:1. 熟悉掌握 C#开发环境的安装与配置2. 熟悉开发环境,编写控制台和窗口两个版本的 hello world 范例程序实验内容:实验 1-1:编写一个控制台程序,并且输出 “hello world!”相关主要代码:using System;using System.Collections.Generic;using System.Text;nam

2、espace hello_worldclass SY1_2static void Main(string args)Console.WriteLine(Hello World!);抓图结果:实验 1-2:编写一个 Windows 应用程序,并且输出“hello world! ”相关主要代码:namespace hello_world2 public partial class Form1 : Formpublic Form1()InitializeComponent();private void Form1_Load(object sender, EventArgs e)MessageBox.

3、Show(Hello World, Message from C#);抓图结果:实验二:C#编程基础实验目的:1.熟悉掌握 C#的各种数据类型,常量、变量的表达形式;2.熟悉掌握 C#的运算符和表达式;3.熟悉掌握 C#的语言,会使用顺序、选择、循环等语句结构编写程序;4.熟悉掌握 C#的数组,学会数组的定义、初始化以及数组的应用。实验内容:实验 2-1:有红、黄、黑、白四色球各一个,放置在一个编号为 1、2、3、4 的四个盒子中,每个盒子放置一只球,它们的顺序不知。甲、乙、丙三人猜测放置顺序如下:甲:黑球在 1 号盒子,黄球在 2 号盒子;乙:黑球在 2 号盒子,白球在 3 号盒子;丙:红球

4、在 2 号盒子,白球在 4 号盒子。结果证明甲、乙、丙三人各猜中了一半,给出四色球放置在盒中的情况。相关的主要代码:using System;using System.Collections.Generic;using System.Text;namespace SY2_1 class Programstatic void Main(string args)int a, b, c, d;for(a=1;a k) & 0x01) = 0)k+; i+;p = p + 2;Console.WriteLine(2到64之间的素数有);Console.Write(0,4, 2);p = 3; w =

5、1;for (i = 0; i i & 0x01) != 0)Console.Write(0,3, p);p += 2;Console.WriteLine();Console.Read();抓图结果:实验 2-3:根据给出的公式编程计算兀的值,直至所加项小于 1E-10 为止。相关主要代码:using System;using System.Collections.Generic;using System.Text;namespace SY2_3class Programstatic void Main(string args)double sum = 0.5, t, t1, t2, t3,

6、p = 0.5 * 0.5;int odd = 3, even = 2, k;t = t1 = t2 = 1.0;t3= 1/2.0 ;while (t1e-10) even+=2;t2=1.0/odd ;t1=t1*(odd-2)/(even -2);odd+=2;t3=t3* (1/2.0)*(1/2.0) ;t = t1 * t3 * t2; sum+=t;Console .WriteLine (nPI=0,10:f8,sum *6);Console .Read ();抓图结果:实验 2-4:编程进行卡布列克运算。所谓卡布列克运算,是指任意一个四位数,只要它们各个位上的数字不全相同,就有

7、这样的规律:1) 把组成这个四位数的四个数字由大到小排列,形成由这四个数字构成的最大数字2) 把组成这个四位数的四个数字由小到大排列,形成由这四个数字构成的最小的四位数3) 求出以上两数之差,得到一个新的四位数重复以上过程,总能得到最后的结果是 6174。相关的主要代码:using System;using System.Collections.Generic;using System.Text;namespace SY2_4class Programstatic void Main(string args)Console.Write(请输入一个4位整数);string s = Console

8、.ReadLine();int num = Convert.ToInt32(s);int each = new int4;int max, min, i, j, temp; while (num != 6174 & num != 0)i = 0;while (num != 0) each i+=num%10; num=num/10;for(i=0;i=each j+1)temp=each j;each j=each j+1;each j+1=temp;min= each 0*1000+each 1*100+each 2*10+each 3 ;max= each 3*1000+each 2*10

9、0+each 1*10+each 0 ;num = max -min ;Console .WriteLine (0-1=2,max,min,num);Console .Read();抓图的结果:实验 2-5:数列 A=1,1,3,7,17,41有以下性质:a =a =1;ij1a =a +2a (i1)i2i对于给定的 n,数列的各个元素值由数列 A 的元素生成即以 a / a 的分数形式表示,然1ii后对其进行排序相关的主要代码:using System;using System.Collections.Generic;using System.Text;namespace SY2_5cla

10、ss Programstatic void Main(string args)int A = new int11;int ,Fraction=new int2,11;float B=new float 10;int i,n,j,pos,temp;float ftemp;A0=A1=1;Console .Write (n请输入n(n bottom ? top - bottom : bottom - top);public int getWidth()return right left ? right - left : left - right;public static int getTotal

11、Rects() return total_rects;public static long getTotalRectangle()return total_rect_area;public class Test3_1static void Main(string args)CRect rect1 = new CRect(1, 3, 6, 4), rect2 = new CRect(rect1);/拷贝构造,通过重载Console.Write(Rectangle 2:Height:0, rect2.getHeight();Console.WriteLine(,Width:0, rect2.get

12、Width();CRect rect3 = new CRect();Console.Write(Rectangle 3:Height:0, rect3.getHeight();Console.WriteLine(,Width:0, rect3.getWidth();Console.Write(Total_rects=0, CRect.total_rects);Console.WriteLine(,total_rect_area=0, CRect.total_rect_area);Console.Read();抓图的结果:实验 3-2:设计一个图书卡片类 Card,用来保存图书馆卡片分类记录。这

13、个类的成员包括书名、作者、馆藏数量。至少提供两个方法,store 书的入库处理,show 显示图书信息,程序运行时,可以从控制台上输入需要入库图书的总量,根据这个总数创建 Card 对象数组,然后输入数据,最后可以选择按书名、作者、入库量排序相关的主要代码:using System;using System.Collections.Generic;using System.Text;namespace SY3_2class Cardprivate string title, author;private int total;public Card()title = ;author = ;tot

14、al = 0;public Card(string title, string author, int total)this.title = title;this.author = author;this.total = total;public void store(ref Card card)/使用ref关键字进行引用传递,似乎是它的拷贝构造title = card.title;author = card.author;total = card.total;public void show()Console.WriteLine(Title:0,Author:1,Total:2, title

15、, author, total);public string Title/Title的属性可读可写get return title; set title = value; public string Authorget return author; set author = value; public string Totalget return Total; set total = int.Parse (value); public class Test3_2static void Main(string args)Test3_2 T = new Test3_2();Card books;int index;int i, k;Card card = new Card();Console.Write(请输入需要入库图书的总数:);string sline = Console.ReadLine();int num = int.Parse(sline);books =

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 研究报告 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号