欢迎来到天天文库
浏览记录
ID:928701
大小:57.00 KB
页数:5页
时间:2017-09-25
《面向对象程序设计编程 实验 上机》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、面向对象程序设计编程上机作业题目:(1)调试构造函数Pen()例题usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceConsoleApplication2{classPen{publicstringColor;privateintPrice;publicPen(){Color="BLACK";Price=5;}publicvoidSetPrice(intnewPrice){Price=newPrice;}publicintGetPri
2、ce(){returnPrice;}publicvoidSetColor(stringnewColor){Color=newColor;}publicstringGetColor(){returnColor;}}classTest{publicstaticvoidMain(){PenmyPen=newPen();Console.WriteLine("Thepriceis{0}",myPen.GetPrice());Console.WriteLine("TheColoris{0}",myPen.Color);}}}(2)调试
3、构造函数重载Pen()例题usingSystem;classPen{publicstringColor;privateintPrice;publicPen(){Color="BLACK";Price=5;}publicPen(stringnewColor,intnewPrice){Color=newColor;Price=newPrice;}publicvoidSetPrice(intnewPrice){Price=newPrice;}publicvoidSetPrice(){Price=5;}publicintGetPr
4、ice(){returnPrice;}publicvoidSetColor(stringnewColor){Color=newColor;}publicstringGetColor(){returnColor;}}classTest{publicstaticvoidMain(){PenmyPen=newPen();PenhisPen=newPen("GREEN",8);Console.WriteLine("Thepriceis{0}",myPen.GetPrice());Console.WriteLine("TheColo
5、ris{0}",myPen.Color);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;
6、usingSystem.Text;namespaceConsoleApplication8{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
7、(5.65));}}}(4)将运算符++和--进行重载,使之可对字符型数据进行运算,即:对一个字符型变量a,当a=’L’时a++(或++a)的值为’M’,a--(或--a)的值为’K’usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceConsoleApplication6{publicclasscharTest{privatecharch;publiccharTest(){this.ch='';}publiccharTest(char
8、val){this.ch=val;}publiccharc{get{returnthis.ch;}set{this.ch=value;}}staticpubliccharTestoperator++(charTestorig){charTestResult=newcharTest();Result.ch
此文档下载收益归作者所有