C#实验题目和报告11

上传人:飞*** 文档编号:53058217 上传时间:2018-08-27 格式:PDF 页数:9 大小:285.07KB
返回 下载 相关 举报
C#实验题目和报告11_第1页
第1页 / 共9页
C#实验题目和报告11_第2页
第2页 / 共9页
C#实验题目和报告11_第3页
第3页 / 共9页
C#实验题目和报告11_第4页
第4页 / 共9页
C#实验题目和报告11_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《C#实验题目和报告11》由会员分享,可在线阅读,更多相关《C#实验题目和报告11(9页珍藏版)》请在金锄头文库上搜索。

1、.NET 程序设计实验报告班级: 10 计科 1 班姓名:孙 毅学号: 3110005859 教师:蒋艳荣广东工业大学2013 年 3 月 28 日第一次实验:内容:完成下面的实验一和二。地点:工学一号馆415 时间: 2013-3-28 实验环境与工具: (1)计算机及操作系统:PC机, WindowsXP (2)程序开发平台:Visual Studio 2005/2008/2010 实验一简单程序设计一实验目的1熟悉 Visual Studio.NET 的IDE界面。2学会使用帮助系统,在编写程序时使“ 动态帮助 ” 始终打开,注意观察“ 动态帮助 ” 窗 口中内容的变化。 二实验内容1模

2、仿书中的例子,编写“ Hello, C#! ” 程序。2在 “ 帮助 ” 菜单下选择 “ 对,帮助 ? 的帮助 ” ,阅读其中的内容,学习帮助的使用。 三源程序using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 classProgram staticvoid Main( string args) System.Console.WriteLine(“Hello, C#!“); Console.ReadKey(); 四调

3、试和运行结果实验二 C#.NET 面向对象程序设计实验一实验目的1理解面向对象思想,体会面向对象思想在编程中的应用。2掌握 Visual C#.NET 类的创建(成员,方法,属性),类的继承,类的多态性及类的方法的重载。二实验内容题目 1:(1)为某公司创建一个类来建立员工 的人事记录:包括员工的姓名、性别、工资、到公司的日期、部门以及联系方式等信息。构建该类,并做出适当的测试。源程序:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleAp

4、plication2 publicclasscompany publicstring name; string sex; int salary; DateTime InDate; string department; int phone; classtest staticvoid Main() company one = new company (); one.name = “ 番禺“; Console.WriteLine(“员工姓名: 0“ , one.name); Console.ReadKey(); 运行结果:(2)从上面的类中派生出一个类,来记录公司干部 的情况。包括职位、提职时间、管

5、理的员工人数及姓名。源程序:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 public class company public string name; public string sex; public int salary; public DateTime InDate; public string department; public int phone; public class Ganbu : co

6、mpany public string job; public DateTime increasedate; public int number; public string yname; class test static void Main() Ganbu one = new Ganbu(); one.name = “番禺“; one.job = “经理“; one.increasedate = Convert.ToDateTime(“2013/04/09“); one.yname = “丫发、丫雨、丫敏 “; Console.WriteLine(“干部姓名: 0“, one.name);

7、 Console.WriteLine(“干部职位: 0“, one.job); Console.WriteLine(“干部提职时间: 0“, one.increasedate); Console.WriteLine(“干部管理的员工: 0“, one.yname); Console.ReadKey(); 运行结果:题目 2:定义一个类,具有如下功能。用户从键盘输入一个1-9999 之间的数,程序将判断这个数是几位数, 并判断这个数是否回文数。回文数是指将数含有的数字逆序排列后得到的数和原数相同,例如12121,4224,6778776 等都是回文数。1)程序具有判断用户的输入是否为合法整数的功

8、能。对非法输入(例如含有字母)要进行处理。2)要判断输入数的位数,并输出相关信息。3)要判断是否回文数。源程序:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 class Number public string str; public bool a(string str) if (str.Length 4) return false; for (int i = 0; i str.Length; i+) if (

9、!Char.IsNumber(str, i) return false; return true; public bool b(string str) for (int i = 0; i str.Length / 2; i+) if (stri != strstr.Length - i - 1) return false; return true; class Program static void Main(string args) Number num = new Number(); num.str = Console.ReadLine(); while (!num.a(num.str)

10、Console.WriteLine(“该数字为非法整数, 请重输 “); num.str = Console.ReadLine(); Console.WriteLine(“该数字为合法整数 n 输入数字位数为:0“, num.str.Length); if (num.b(num.str) Console.WriteLine(“该数是回文数。“); else Console.WriteLine(“该数不是回文数。“); Console.ReadKey(); 运行结果:题目 3:定义一个类 Fraction,用来实现如下功能:相加两个分数,并将它们的和以化简后的分数形式表现出来。程序使用类Frac

11、tion来存放分数的分子和分母,具有方法Reduce来化简结果。源程序:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 class Fraction public int A; / 分子public int B; / 分母public Fraction(int A, int B) this.A = A; this.B = B; public void Reduce() int m, n, t, r = 0; m

12、= A; n = B; if (m n) t = m; m = n; n = t; do r = m % n; m = n; n = r; while (r != 0); A /= m; B /= m; public void Display() Console.WriteLine(“0/1“, A, B); class Program static void Main(string args) int a1, b1, a2, b2; Console.WriteLine(“ 第一个分数的分子:“); b1 = Convert.ToInt32(Console.ReadLine(); Consol

13、e.WriteLine(“ 第一个分数的分母:“); a1 = Convert.ToInt32(Console.ReadLine(); Fraction num1 = new Fraction(b1, a1); Console.WriteLine(“ 分数为: “); num1.Display(); Console.WriteLine(“=“); Console.WriteLine(“ 第二个分数的分子:“); b2 = Convert.ToInt32(Console.ReadLine(); Console.WriteLine(“ 第二个分数的分母:“); a2 = Convert.ToInt32(Console.ReadLine(); Fraction num2 = new Fraction(b2, a2); Console.WriteLine(“ 分数为: “); num2.Display(); Console.WriteLine(“=“); Fraction num = new Fraction(b1 * a2 + b2 * a1, a1 * a2); Console.WriteLine(“ 它们的和为:“); num.Reduce(); num.Display(); Console.ReadKey(); 运行结果:

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

当前位置:首页 > 商业/管理/HR > 其它文档

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