2022年面向对象程序设计编程实验上机 .pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年面向对象程序设计编程实验上机 .pdf》由会员分享,可在线阅读,更多相关《2022年面向对象程序设计编程实验上机 .pdf(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、1 / 5 面向对象程序设计编程上机作业题目:(1)调试构造函数 Pen()例题using System 。using System.Collections.Generic。using System.Text。namespace ConsoleApplication2 class Pen publicstring Color 。privateint Price 。public Pen() Color=BLACK。 Price=5。 publicvoid SetPrice(int newPrice) Price=newPrice。 publicint GetPrice() return Pric
2、e 。 publicvoid SetColor(string newColor) Color=newColor 。 publicstring GetColor() return Color 。 class Test publicstaticvoidMain() Pen myPen=newPen() 。Console .WriteLine(The price is 0,myPen.GetPrice()。Console .WriteLine(The Color is 0,myPen.Color)。 (2)调试构造函数重载 Pen()例题using System 。class Pen publics
3、tring Color 。privateint Price 。public Pen() Color = BLACK。 Price = 5。 public Pen( string newColor, int newPrice) Color = newColor。 Price = newPrice。精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 1 页,共 5 页2 / 5 publicvoid SetPrice(int newPrice) Price = newPrice。 publicvoid SetPrice() Price = 5。 publi
4、cint GetPrice() return Price。 publicvoid SetColor(string newColor) Color = newColor。 publicstring GetColor() return Color 。 class Test publicstaticvoidMain() Pen myPen = new Pen() 。Pen hisPen = new Pen( GREEN , 8) 。Console .WriteLine(The price is 0, myPen.GetPrice()。Console .WriteLine(The Color is 0
5、, myPen.Color)。Console .WriteLine(The price is 0, hisPen.GetPrice()。Console .WriteLine(The Color is 0, hisPen.GetColor()。 hisPen.SetPrice()。Console .WriteLine(The price is 0, hisPen.GetPrice()。 (3)使用重载方法求5 和 5.65 的平方。using System 。using System.Collections.Generic。using System.Text。namespace ConsoleA
6、pplication8 class Program publicclassapp publicint app1( int x) return x * x。 publicdouble app1( double y) return y * y。 staticvoidMain( string args) app x = newapp() 。Console .WriteLine(5 的平方是 0 , x.app1(5)。Console .WriteLine(5.65 的平方是 0 , x.app1(5.65)。 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -
7、第 2 页,共 5 页3 / 5 (4)将运算符 +和- - 进行重载,使之可对字符型数据进行运算,即:对一个字符型变量a,当 a=L时 a+(或+a)的值为 M , a- -(或- -a)的值为 Kusing System 。using System.Collections.Generic。using System.Text。namespace ConsoleApplication6 publicclasscharTest privatechar ch 。public charTest() this .ch = 。 public charTest(char val) this .ch = v
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年面向对象程序设计编程实验上机 2022 面向 对象 程序设计 编程 实验 上机
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内