




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
江西理工大学软件学院计算机类课程实验报告课程名称: C#程序设计教程 班 级: 11级软会(4)班 姓 名: 黄健 学 号: 11222122 江西理工大学软件学院15实验 三 实验名称面向对象编程实验日期2013-4-2实验成绩实验目的、要求及内容一、 实验目的:1 加深理解面向对象编程的概念,如类、对象、实例化等2 熟练掌握类的声明格式,特别是类的成员定义、构造函数、初始化对象等。3 熟练掌握方法的声明,理解并学会使用方法的参数传递、方法的重载等。二、 实验内容:操作实验3-1,3-2,3-3及其自己完成题目实验环境地点:3421机房OS:WxpC#环境:1、VS2008 2、.NetFramework3.5算法描述及实验步骤实验3-1操作:1) 阅读程序2) 编辑、编译和运行程序3) 自己完成:(1)分析静态成员total_rects和total_rect_area的值及构造函数的调用次序。 (2)将注释1和注释2的花括号去掉,运行结果将发生什么变化?为什么?实验3-2操作:1) 阅读程序2) 编辑、编译和运行程序3) 自己完成:将上述程序中class Test32中的三个方法:(1) void sortTitle(Card book,int index)(2) void sortAuthor(Card book,int index)(3) void sortTotal(Card book,int index)改写成一个方法sort(Card book,int index)其中增加的参数method指示按什么字段排序。重新修改、编译和运行程序,观察运行结果。实验3-3操作:1) 阅读程序2) 自己完成:(1)修改Card类,增加每日食用额度不超过5000的限制功能。 (2)再次修改Card类,要求对银行卡进行操作前必须验证用户密码,并且在输入密码时屏幕上用“*”掩码显示。为简单起见,初始密码设为123456. 调试过程及实验结果实验3-1: 实验3-2实验3-3心得体会 通过这次实践,我觉得我学到了很多东西,不光光是在知识层面上的,整体都有了进一步的了解,更是认识到编程的不容易,一个看似简单的程序,原来也有这么多的代码,但是那么一个复杂的代码,如果深入研究后你会发现其实各个代码之间都是有联系的,一个看上去巨大的程序实际上是由若干个函数、方法、类等组成的。以前对于那些小的程序尚能敲一敲,看得懂。对于大的程序就很容易感到束手无策。我觉得在问题面前我们应该先要冷静地分析一下,将大问题分解成一个个的小问题,再各个击破。 虽然成功地完成了程序,但是自己本身尚有许多不足之处,需要进一步的学习和巩固。不管是做什么都要有坚韧不拔的意志,在遇到困难的时候要懂得坚持,也要学会分析问题、解决问题。 同时,很多的东西,理解了,可是在实现的时候还是有很多的错误发生,在以后的练习和实践中,应该多动手,遇到问题多思考,即使方案不是最优的也要想办法自己解决,然后和好的方案进行比较,从中找出自己的差距在哪里。 最后感谢老师在实验中对我们的指导附 录实验3-1:using System;using System.Collections.Generic;using System.Linq;using System.Text;class CRect private int top, bottom, left, right; public static int total_rects = 0; public static long total_rect_area = 0; public CRect() left = top = right = bottom = 0; total_rects+; total_rect_area += getHeight() * getWidth(); Console.WriteLine(CRect() Constructing recangle number0, total_rects); Console.WriteLine(Total rectangle areas is:0, total_rect_area); public CRect(int x1, int y1, int x2, int y2) left = x1; top = y1; right = x2; bottom = y2; total_rects+; total_rect_area += getHeight() * getWidth(); Console.WriteLine(CRect(int,int,int,int) Constructing rectangle number0, total_rects); Console.WriteLine(Total rectangle areas is:0, total_rect_area); public CRect(CRect r) left = r.left; right = r.right; top = r.top; bottom = r.bottom; total_rects+; total_rect_area += getHeight() * getWidth(); Console.WriteLine(CRect(CRect&) Constructing rectangle number0, total_rects); Console.WriteLine(Total rectangle areas is:0, total_rect_area); public int getHeight() return top bottom ? top-bottom : bottom-top; public int getWidth() return right left ? right-left : left-right; public static int getTotalRects() return total_rects; public static long getTotalRectArea() return total_rect_area; public class Test31 public static void Main() CRect rect1 = new CRect(1, 3, 6, 4), rect2 = new CRect(rect1); Console.WriteLine(Rectangle 2:Height:0, rect2.getHeight(); Console.WriteLine(,Width:0, rect2.getWidth(); CRect rect3 = new CRect(); Console.Write(Rectangle 2:Height:0, rect2.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(); public static int getTotalRects() return total_rects; public static long getTotalRectArea() return total_rect_area; public class Test31 public static void Main() CRect rect1 = new CRect(1, 3, 6, 4), rect2 = new CRect(rect1); Console.WriteLine(Rectangle 2:Height:0, rect2.getHeight(); Console.WriteLine(,Width:0, rect2.getWidth(); CRect rect3 = new CRect(); Console.Write(Rectangle 2:Height:0, rect2.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(); 附 录 Console.WriteLine(Total rectangle areas is:0,total_rect_area); public int getHeight() return topbottom?top-bottom:bottom-top; public int getWidth() return rightleft?right-left:left-right; public static int getTotalRects() return total_rects; public static long getTotalRectArea() return total_rect_area; public class Test31 public static void Main() 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.getWidth(); /注释1 CRect rect3=new CRect(); Console.Write(Rectangle 3:Height:0,rect3.getHeight(); Console.WriteLine(,Width:0,rect3.getWidth(); /注释2 Console.Write(total_rects=0,CRect.total_rects); Console.WriteLine(,total_rest_area=0,CRect.total_rect_area); Console.Read(); 【3-2】using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1 class Card private string title, author; private int total;附 录 public Card() title = ; author = ; total = 0; public Card(string title, string author, int total) this.title = title; this.author = author; this.total = total; public void store(ref Card card) title = card.title; author = card.author; total = card.total; public void show() Console .WriteLine (Title:0,author:1,total:2,title,author ,total ); public string Title get return title; set title = value; public string Author get return author; set author = value; public int Total get return total; set total = value; public class Test32 public static void Main() Test32 T=new Test32 (); Card books; int index; 附 录 int i,k; Card card=new Card (); Console .Write (请输入需要入库图书的总数;); string sline=Console .ReadLine (); int num=int .Parse (sline); books=new Card num; for (i=0;inum ;i+) books i=new Card (); index=new int num; for (i=0;inum;i+) Console .Write (请输入书名:); card .Title =Console .ReadLine (); Console .Write (请输入作者:); card .Author=Console .ReadLine (); Console .Write (请输入入库量:); sline=Console .ReadLine (); card .Total =int .Parse (sline); books i.store (ref card ); indexi=i ; Console .Write (请选择按什么关键字排序(1.按书名,2.按作者,3.按入库量); sline =Console .ReadLine (); int choice=int .Parse (sline); switch(choice) case 1: T .sortTitle(books ,index); break ; case 2: T .sortAuthor(books,index); break ; case 3: T .sortTotal(books,index); break; for (i=0;inum ;i+) k=indexi; (booksk).show(); Console .Read (); 附 录 void sortTitle(Card book,int index) int i,j,m,n,temp; for (m=0;mindex .Length -1;m+) for (n=0;n0) temp =index n;index n=index n+1;index n+1=temp ; void sortAuthor(Card book,int index) int i,j,m,n,temp; for (m=0;mindex .Length -1;m+) for (n=0;n0) temp =index n;index n=index n+1;index n+1=temp ; void sortTotal(Card book,int index) int i,j,m,n,temp; for (m=0;mindex .Length -1;m+) for (n=0;nbook j.Total) temp =index n;index n=index n+1;index n+1=temp ; 附 录 【3-3】using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3 class Card long cardNo; decimal balance; int currentNum; static int number; decimal currentMoney; public Card() currentMoney=new decimalnumber; public Card(long No,decimal Balance) cardNo=No; balance=Balance; currentMoney=new decimalnumber; public void store(decimal Money,out int status) if (currentNum=number) status=0; return; if(balance+Money0) status=-1; return; currentMoneycurrentNum=Money; balance+=Money; currentNum+; status=1; 附 录 public void show() Console .WriteLine(卡号:0,当前余额:1,当日发生业务次数:2,cardNo,balance,currentNum); for(int i=0;icurrentNum;i+) Console.WriteLine(当日存款/取款的情况:0,currentMoneyi); static public int Number set number=value; public long CardNo get return cardNo ; public class Test33 public static void Main() Test33 T=new Test33 (); Card person; int Num,status,k; long CardNo; decimal Balance,Money; Console .Write (请输入允许当日存款或取款的总次数:); string sline=Console .ReadLine (); Card .Number =int .Parse (sline); Console .Write (请输入某银行发出的储蓄卡总数:); sline =Console .ReadLine (); Num =int.Parse (sline ); person =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025房地产项目环境保护与绿化咨询中介服务合同范本
- 2025年新能源产业担保合同要素与风险控制
- 2025年度高端别墅庭院搭棚设计与施工合同
- 2025年出国定居养老与退休规划服务合同
- 2025版能源项目委托担保合同模板
- 2025版电动汽车充电站配电柜销售合同
- 2025年物流代签合同委托书全新范本
- 2025房地产营销合作合同:海外地产项目营销推广服务
- 2025年度办公场地租赁与专业安保服务合同
- 2025年度高端网约车司机入职服务协议范本
- 奥维互动地图使用介绍课件
- 小学语文新课程标准最新版2022
- 室外雨污水、消防管网施工方案
- 传染病学总论-人卫最新版课件
- (中职)计算机组装与维修电子课件(完整版)
- (高职)旅游景区服务与管理电子课件完整版PPT全书电子教案
- 部编版七年级语文上册教案(全册)
- 高处作业吊篮安装验收表(范本模板)
- 《汉服》PPT课件(完整版)
- 某国有企业精细管理降本增效经验交流汇报材料企业降本增效.doc
- 主要负责人任职证明
评论
0/150
提交评论