C#编程环境实验报告3Word文件下载.docx
《C#编程环境实验报告3Word文件下载.docx》由会员分享,可在线阅读,更多相关《C#编程环境实验报告3Word文件下载.docx(20页珍藏版)》请在冰豆网上搜索。
![C#编程环境实验报告3Word文件下载.docx](https://file1.bdocx.com/fileroot1/2022-11/16/e9713059-8213-4913-b8be-35130638a24b/e9713059-8213-4913-b8be-35130638a24b1.gif)
实验日期
2013-4-2
实验成绩
实验目的、要求及内容
一、实验目的:
1.加深理解面向对象编程的概念,如类、对象、实例化等
2.熟练掌握类的声明格式,特别是类的成员定义、构造函数、初始化对象等。
3.熟练掌握方法的声明,理解并学会使用方法的参数传递、方法的重载等。
二、实验内容:
操作实验3-1,3-2,3-3及其自己完成题目
实验环境
地点:
3421机房
OS:
Wxp
C#环境:
1、VS2008
2、.NetFramework3.5
算法描述及实验步骤
实验3-1操作:
1)阅读程序
2)编辑、编译和运行程序
3)自己完成:
(1)分析静态成员total_rects和total_rect_area的值及构造函数的调用次序。
(2)将注释1和注释2的花括号去掉,运行结果将发生什么变化?
为什么?
实验3-2操作:
将上述程序中classTest32中的三个方法:
(1)voidsortTitle(Card[]book,int[]index)
(2)voidsortAuthor(Card[]book,int[]index)
(3)voidsortTotal(Card[]book,int[]index)
改写成一个方法sort(Card[]book,int[]index)其中增加的参数method指示按什么字段排序。
重新修改、编译和运行程序,观察运行结果。
实验3-3操作:
2)自己完成:
(1)修改Card类,增加每日食用额度不超过5000的限制功能。
(2)再次修改Card类,要求对银行卡进行操作前必须验证用户密码,并且在输入密码时屏幕上用“*”掩码显示。
为简单起见,初始密码设为123456.
调试过程及实验结果
实验3-1:
实验3-2
实验3-3
心得体会
通过这次实践,我觉得我学到了很多东西,不光光是在知识层面上的,整体都有了进一步的了解,更是认识到编程的不容易,一个看似简单的程序,原来也有这么多的代码,但是那么一个复杂的代码,如果深入研究后你会发现其实各个代码之间都是有联系的,一个看上去巨大的程序实际上是由若干个函数、方法、类等组成的。
以前对于那些小的程序尚能敲一敲,看得懂。
对于大的程序就很容易感到束手无策。
我觉得在问题面前我们应该先要冷静地分析一下,将大问题分解成一个个的小问题,再各个击破。
虽然成功地完成了程序,但是自己本身尚有许多不足之处,需要进一步的学习和巩固。
不管是做什么都要有坚韧不拔的意志,在遇到困难的时候要懂得坚持,也要学会分析问题、解决问题。
同时,很多的东西,理解了,可是在实现的时候还是有很多的错误发生,在以后的练习和实践中,应该多动手,遇到问题多思考,即使方案不是最优的也要想办法自己解决,然后和好的方案进行比较,从中找出自己的差距在哪里。
最后感谢老师在实验中对我们的指导
附录
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
classCRect
{
privateinttop,bottom,left,right;
publicstaticinttotal_rects=0;
publicstaticlongtotal_rect_area=0;
publicCRect()
{
left=top=right=bottom=0;
total_rects++;
total_rect_area+=getHeight()*getWidth();
Console.WriteLine("
CRect()Constructingrecanglenumber{0}"
total_rects);
Totalrectangleareasis:
{0}"
total_rect_area);
}
publicCRect(intx1,inty1,intx2,inty2)
left=x1;
top=y1;
right=x2;
bottom=y2;
CRect(int,int,int,int)Constructingrectanglenumber{0}"
publicCRect(CRectr)
left=r.left;
right=r.right;
top=r.top;
bottom=r.bottom;
CRect(CRect&
)Constructingrectanglenumber{0}"
publicintgetHeight()
{returntop>
bottom?
top-bottom:
bottom-top;
publicintgetWidth()
returnright>
left?
right-left:
left-right;
publicstaticintgetTotalRects()
{returntotal_rects;
publicstaticlonggetTotalRectArea()
{returntotal_rect_area;
}
publicclassTest31
publicstaticvoidMain()
CRectrect1=newCRect(1,3,6,4),rect2=newCRect(rect1);
Rectangle2:
Height:
rect2.getHeight());
Width:
rect2.getWidth());
CRectrect3=newCRect();
Console.Write("
rect3.getWidth());
total_rects={0}"
CRect.total_rects);
total_rect_area={0}"
CRect.total_rect_area);
Console.Read();
total_rect_area);
{returntop>
bottom?
top-bottom:
bottom-top;
{returnright>
left?
right-left:
left-right;
publicclassTest31
CRectrect1=newCRect(1,3,6,4),rect2=newCRect(rect1);
rect2.getHeight());
rect2.getWidth());
{//注释1
CRectrect3=newCRect();
Rectangle3:
rect3.getHeight());
rect3.getWidth());
}//注释2
CRect.total_rects);
total_rest_area={0}"
CRect.total_rect_area);