C#程序题更新Word文档格式.docx

上传人:b****5 文档编号:17478877 上传时间:2022-12-06 格式:DOCX 页数:8 大小:217.48KB
下载 相关 举报
C#程序题更新Word文档格式.docx_第1页
第1页 / 共8页
C#程序题更新Word文档格式.docx_第2页
第2页 / 共8页
C#程序题更新Word文档格式.docx_第3页
第3页 / 共8页
C#程序题更新Word文档格式.docx_第4页
第4页 / 共8页
C#程序题更新Word文档格式.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

C#程序题更新Word文档格式.docx

《C#程序题更新Word文档格式.docx》由会员分享,可在线阅读,更多相关《C#程序题更新Word文档格式.docx(8页珍藏版)》请在冰豆网上搜索。

C#程序题更新Word文档格式.docx

圆)和Square<

矩形),实现图形面积<

Area)和周长<

Circumference)的计算。

p1EanqFDPw

staticvoidMain(string[]args>

{

CirclecirObj=newCircle(1d>

SquaresquObj=newSquare(2d,3d>

Console.WriteLine("

圆的面积:

{0},圆的周长:

{1}"

cirObj.Area(>

cirObj.Circumference(>

>

DXDiTa9E3d

长方形的面积:

{0},长方形的周长:

squObj.Area(>

squObj.Circumference(>

RTCrpUDGiT

}

interfaceIShape

doubleArea(>

doubleCircumference(>

///定义圆类,实现IShape接口

publicclassCircle:

IShape

//半径

privatedoubleradius。

///带参构造函数

paramname="

radius"

半径<

/param>

publicCircle(doubleradius>

this.radius=radius。

///求面积

returns>

面积<

/returns>

publicdoubleArea(>

returnMath.PI*radius*radius。

///求周长

周长<

publicdoubleCircumference(>

returnMath.PI*2*radius。

///定义长方形类,实现IShape接口

publicclassSquare:

privatedoublewidth。

//宽

privatedoubleheight。

//高

width"

宽<

height"

高<

publicSquare(doublewidth,doubleheight>

this.width=width。

this.height=height。

returnwidth*height。

return2*(width+height>

2.编写一个完整的程序。

该程序包含类Person、Student、Test,具体要求如下:

<

1)类Person

①属性

name:

String类型,表示一个人的姓名

sex:

Boolean类型,用来表示性别

id:

String类型,表示身份证号

②方法

Person(nameAsString,sexAsBoolean,idAsString>

构造函数5PCzVD7HxA

publicFunctiontoString(>

AsString:

返回个人的各项信息,包括姓名、性别等上述属性jLBHrnAILg

2)类Student

从Person类派生,增加了以下属性和方法:

sNo:

String类型,表示学生的学号

sClass:

String类型,表示学生的班级

Student(sNoAsString,nameAsString,sexAsBoolean,idAsstring,sClassAsString>

构造函数xHAQX74J0X

返回学生的各项信息,包括学号、班级、姓名等上述属性LDAYtRyKfE

3)类Test完成测试功能

publicclassPerson

protectedStringname。

protectedBooleansex。

protectedStringid。

publicPerson(>

{}

publicPerson(Stringname,Booleansex,Stringid>

this.name=name。

this.sex=sex。

this.id=id。

publicvirtualstringtoString(>

stringSex=sex?

"

男"

:

女"

return"

姓名:

"

+name+"

,性别:

+Sex+"

,身份证:

+id+"

Zzz6ZB2Ltk

publicclassStudent:

Person

{

privateStringsNo。

privateStringsClass。

publicStudent(StringsNo,Stringname,Booleansex,Stringid,StringsClass>

dvzfvkwMI1

this.sNo=sNo。

this.sClass=sClass。

publicoverridestringtoString(>

stringSex=sex?

:

学号:

+sNo+"

,姓名:

+name+"

+Sex+"

+id+"

,班级:

+sClass+"

rqyn14ZNXI

publicclassTest

PersonstuObj。

stuObj=newPerson("

ls"

true,"

010102"

Console.WriteLine(stuObj.toString(>

stuObj=newStudent("

01"

"

zs"

true,"

01010"

"

08网络"

EmxvxOtOco

Console.WriteLine(stuObj.toString(>

在Student类中构造函数写成publicStudent(StringsNo,Stringname,Booleansex,Stringid,StringsClass>

base(name,sex,id>

这样的话,就可以省去被注释掉的那部分代码<

Persion类中的无参构造函数和Student类的构造函数的部分赋值语句);

另外Student的toString(>

方法中也可以省去一些代码!

SixE2yXPq5

<

注意:

也就是说在下面的代码中绿色的部分是不需要的,比上面的程序省去了几行代码,也更能体现继承的作用,同时大家也方便我们记忆)6ewMyirQFL

#region第二题

//publicPerson(>

//{}

kavU42VRUs

publicclassStudent:

Person

publicStudent(StringsNo,Stringname,Booleansex,Stringid,StringsClass>

y6v3ALoS89

{//this.name=name。

//this.sex=sex。

//this.id=id。

this.sNo=sNo。

this.sClass=sClass。

//stringSex=sex?

returnbase.toString(>

+"

,学号:

+sNo+"

+sClass。

M2ub6vSTnP

//return"

+sClass+"

0YujCfmUCw

010101"

eUts8ZQVRd

#endregion

申明:

所有资料为本人收集整理,仅限个人学习使用,勿做商业用途。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1