实验二面向对象程序设计.docx

上传人:rrsccc 文档编号:10016217 上传时间:2021-04-11 格式:DOCX 页数:7 大小:68.72KB
返回 下载 相关 举报
实验二面向对象程序设计.docx_第1页
第1页 / 共7页
实验二面向对象程序设计.docx_第2页
第2页 / 共7页
实验二面向对象程序设计.docx_第3页
第3页 / 共7页
实验二面向对象程序设计.docx_第4页
第4页 / 共7页
实验二面向对象程序设计.docx_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《实验二面向对象程序设计.docx》由会员分享,可在线阅读,更多相关《实验二面向对象程序设计.docx(7页珍藏版)》请在三一文库上搜索。

1、资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。实验二、面向对象程序设计2.1 C#面向对象程序设计(一 )一、实验目的1. 理解 C#语言是如何体现面向对象编程基本思想。2. 掌握类对象的定义。3. 了解类的封装方法 , 以及如何创立类和对象。4. 了解成员变量和成员方法的特性。5. 掌握静态成员的用法。二、实验要求1. 分析程序 , 上机验证结果。2. 写出程序 , 并调试程序 , 要给出测试数据和实验结果。3. 整理上机步骤 , 总结经验和体会。4. 完成实验日志和上交程序。三、实验内容题目一 :程序分析( 1)分析下面两个程序,确定那个程序好,说明理由。程序要求 :定义一

2、个圆类 ,计算圆的面积和周长。程序 1:public class circlepublic 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, de

3、limeter, square);Console.ReadLine();程序 2:public class circledouble 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,del资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。imeter,square);public static

4、void Main()double radium;circle cir = new circle();radium = Convert.ToInt32(Console.ReadLine(); cir.calculate(radium);Console.ReadLine();( 2)分析程序 ,写出程序的运行结果,并上机进行验证。Using System;public class studentsstring id,name;int age;public students(string id,string name,int age )this.id = id;this.name = name;资

5、料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。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 Dateprivate in

6、t 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 Testerpubl

7、ic static void Main()资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。System.DateTime currentTime=System.DateTime.Now;Date dt=new Date( ,7,18);dt.DisplayDate();Date dt2 = new Date(currentTime);dt2.DisplayDate();Console.ReadLine();题目二 :程序编写( 1) 实现一个包含类属性方法的简单加法程序, 并能显示结果。( 2) 实现一个 Person 类 , 要求 : 属性包含姓名、 年龄、 身份证号、 工作、

8、 工资等 , 并显示各属性的值。2.2 C# 面向对象程序设计(二)一、实验目的1.2.掌握构造函数和析构函数的含义与作用、 定义方式和实现 , 能够根据要求正确定义和重载构造函数。能够根据给定的要求定义类并实现类的成员函数。理解类的成员的访问控制的含义,公有、私有和保护成员的区别。资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。3. 掌握参数传递的用法。4. 掌握属性的作用和使用。二、 实验要求1. 分析程序 , 上机验证结果。2. 写出程序 , 并调试程序 , 要给出测试数据和实验结果。3. 整理上机步骤 , 总结经验和体会。4. 完成实验日志和上交程序。三、实验内容题目一 :程序分析( 1) 分析程序 , 写出程序的运行结果, 并上机进行验证 , 然后回答后面问题。public class BankAccountstatic int totalAccountNumber=0;string BankAccountId;double initialDepositAmount = 0.00;public BankAccount(string myId)this.BankAccountId = myId;this.initialDepositAmount = 0.00;totalAccountNumber+;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1