实验2面向对象程序设计.doc

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验2面向对象程序设计

实验二、面向对象程序设计 2.1 C#面向对象程序设计(一) 一、实验目的 1.理解C#语言是如何体现面向对象编程基本思想。 2.掌握类对象的定义。 3.了解类的封装方法,以及如何创建类和对象。 4.了解成员变量和成员方法的特性。 5.掌握静态成员的用法。 二、实验要求 1. 分析程序,上机验证结果。 2. 写出程序,并调试程序,要给出测试数据和实验结果。 3. 整理上机步骤,总结经验和体会。 4. 完成实验日志和上交程序。 三、实验内容 题目一:程序分析 (1)分析下面两个程序,确定那个程序好,说明理由。 程序要求:定义一个圆类,计算圆的面积和周长。 程序1: public class circle { public static void Main() { double radium, delimeter, square; const double 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(); } } 程序2: public class circle { double delimeter, square; const double pai = 3.1415926; public void calculate(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(); } } (2)分析程序,写出程序的运行结果,并上机进行验证。 Using System; 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 Display() { 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(); } } (3)分析程序,写出程序的运行结果,并上机进行验证。 public class Date { private int Year, Month, Day; public Date(int Year, int Month,int Day) { this.Year=Year; this.Month=Month; this.Day=Day; } public Date(System.DateTime dt) { Year = dt.Year; Month = dt.Month; Day = dt.Day; } public void DisplayDate() { Console.WriteLine({0}年{1}月{2}日,Year,Month,Day); } } public class Tester { public static void Main() { System.DateTime currentTime=System.DateTime.Now; Date dt=new Date(2008,7,18); dt.DisplayDate(); Date dt2 = new Date(currentTime); dt2.DisplayDate(); Console.ReadLine(); } } 题目二:程序编写 实现一个包含类属性方法的简单加法程序,并能显示

文档评论(0)

ktj823 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档