面向对象程序设计编程 实验 上机

面向对象程序设计编程 实验 上机

ID:47162166

大小:57.00 KB

页数:5页

时间:2019-08-14

面向对象程序设计编程 实验 上机_第1页
面向对象程序设计编程 实验 上机_第2页
面向对象程序设计编程 实验 上机_第3页
面向对象程序设计编程 实验 上机_第4页
面向对象程序设计编程 实验 上机_第5页
资源描述:

《面向对象程序设计编程 实验 上机》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、面向对象程序设计编程上机作业题目:(1)调试构造函数Pen()例题usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceConsoleApplication2{classPen{publicstringColor;privateintPrice;publicPen(){Color="BLACK";Price=5;}publicvoidSetPrice(intnewPrice){Price=newPrice;}publicintGetPrice()

2、{returnPrice;}publicvoidSetColor(stringnewColor){Color=newColor;}publicstringGetColor(){returnColor;}}classTest{publicstaticvoidMain(){PenmyPen=newPen();Console.WriteLine("Thepriceis{0}",myPen.GetPrice());Console.WriteLine("TheColoris{0}",myPen.Color);}}}(2)调试构造函数重载Pe

3、n()例题usingSystem;classPen{publicstringColor;privateintPrice;publicPen(){Color="BLACK";Price=5;}publicPen(stringnewColor,intnewPrice){Color=newColor;Price=newPrice;}publicvoidSetPrice(intnewPrice){Price=newPrice;}publicvoidSetPrice(){Price=5;}publicintGetPrice(){return

4、Price;}publicvoidSetColor(stringnewColor){Color=newColor;}publicstringGetColor(){returnColor;}}classTest{publicstaticvoidMain(){PenmyPen=newPen();PenhisPen=newPen("GREEN",8);Console.WriteLine("Thepriceis{0}",myPen.GetPrice());Console.WriteLine("TheColoris{0}",myPen.Co

5、lor);Console.WriteLine("Thepriceis{0}",hisPen.GetPrice());Console.WriteLine("TheColoris{0}",hisPen.GetColor());hisPen.SetPrice();Console.WriteLine("Thepriceis{0}",hisPen.GetPrice());}}(3)使用重载方法求5和5.65的平方。usingSystem;usingSystem.Collections.Generic;usingSystem.Text;nam

6、espaceConsoleApplication8{classProgram{publicclassapp{publicintapp1(intx){returnx*x;}publicdoubleapp1(doubley){returny*y;}}staticvoidMain(string[]args){appx=newapp();Console.WriteLine("5的平方是{0}",x.app1(5));Console.WriteLine("5.65的平方是{0}",x.app1(5.65));}}}(4)将运算符++和--进

7、行重载,使之可对字符型数据进行运算,即:对一个字符型变量a,当a=’L’时a++(或++a)的值为’M’,a--(或--a)的值为’K’usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceConsoleApplication6{publicclasscharTest{privatecharch;publiccharTest(){this.ch='';}publiccharTest(charval){this.ch=val;}publicchar

8、c{get{returnthis.ch;}set{this.ch=value;}}staticpubliccharTestoperator++(charTestorig){charTestResult=newcharTest();Result.ch

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。