配色: 字号:
C#
2015-06-07 | 阅:  转:  |  分享 
  


姓名学号专业班级

课程名称.NET程序设计实验名称熟悉面向对象编程实验日期

同组人员指导教师

得分



实验内容

1、创建一个Windows窗体应用程序,定义个长方体类,该类包含长、宽、高字段和属性,在窗体类定义中声明长方体类对象,通过文本框设置对象的值,通过标签框输出对象的值。

2、创建一个Windows窗体应用程序,定义个长方体类,该类包含长、宽、高字段和属性,在窗体类定义中声明长方体类对象,通过文本框设置对象的长、宽、高值,通过标签框输出对象的体积和周长值。

二、界面(设计和运行状态的截图)

1、类和对象运行结果如下:





















privatevoidbutton1_Click(objectsender,EventArgse)

{

doublelen=double.Parse(txtLength.Text);

doublewid=double.Parse(txtWidth.Text);

doublehig=double.Parse(txtHigh.Text);

cuboid1.Length=len;

cuboid1.Width=wid;

cuboid1.High=hig;

lblInfo.Text="对象值设置完毕!";

}

privatevoidbutton2_Click(objectsender,EventArgse)

{

lblInfo.Text="长方体的长:"+cuboid1.Length+"宽:"+cuboid1.Width+

"高:"+cuboid1.High;

}

}

}

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

namespaceWindowsApplication2

{

publicpartialclassForm1:Form

{

publicForm1()

{

InitializeComponent();

}

classCuboid

{

privatedoublelength;

privatedoublewidth;

privatedoublehigh;

publicdoubleLength{get{returnlength;}set{length=value;}}

publicdoubleWidth{get{returnwidth;}set{width=value;}}

publicdoubleHigh{get{returnhigh;}set{high=value;}}

publicdoubleVolume

{

get{returnlengthwidthhigh;}

}

publicdoubleSurfaceArea

{

get{return2(lengthwidth+lengthhigh+widthhigh);}

} 2、字段和属性运行结果如下:



代码

如下:

1、usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

namespaceWindowsApplication2

{

publicpartialclassForm1:Form

{

publicForm1()

{

InitializeComponent();

}

classCuboid

{

privatedoublelength;

privatedoublewidth;

privatedoublehigh;

publicdoubleLength{get{returnlength;}set{length=value;}}

publicdoubleWidth{get{returnwidth;}set{width=value;}}

publicdoubleHigh{get{returnhigh;}set{high=value;}}

}

Cuboidcuboid1=newCuboid();

}

Cuboidcuboid1=newCuboid();



privatevoidbutton1_Click(objectsender,EventArgse)

{

doublelen=double.Parse(txtLength.Text);

doublewid=double.Parse(txtWidth.Text);

doublehig=double.Parse(txtHigh.Text);

cuboid1.Length=len;

cuboid1.Width=wid;

cuboid1.High=hig;

lblInfo.Text="对象值设置完毕!";

}



privatevoidbutton2_Click(objectsender,EventArgse)

{

lblInfo.Text="长方体的体积是:"+cuboid1.Volume+";表面积是:"+

+cuboid1.SurfaceArea;

}

}

}

调试程序心得总结

通过本次实验使我加深了对类和对象的理解以及它们的使用。在做本次实验时,首先要设计界面,把里面的窗体设计好,其次是代码设计,在代码设计中,要用到基类和派生类等。本次实验我会通过文本框设置对象的值,通过标签框输出对象的值等。在这次试验我学到了很多东西,感觉不是很难,对一些简单的操作操作起来觉得很顺手,而且这个实验的两个内容都差不多,只要会做了一个,另一个自然就会了,这次的实验让我进一步熟悉了这些基本的操作。











献花(0)
+1
(本文系稻草人之书首藏)