实验5面向对象高级程序设计Word文档下载推荐.docx

上传人:b****2 文档编号:440544 上传时间:2023-04-28 格式:DOCX 页数:15 大小:17.79KB
下载 相关 举报
实验5面向对象高级程序设计Word文档下载推荐.docx_第1页
第1页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第2页
第2页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第3页
第3页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第4页
第4页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第5页
第5页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第6页
第6页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第7页
第7页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第8页
第8页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第9页
第9页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第10页
第10页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第11页
第11页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第12页
第12页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第13页
第13页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第14页
第14页 / 共15页
实验5面向对象高级程序设计Word文档下载推荐.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验5面向对象高级程序设计Word文档下载推荐.docx

《实验5面向对象高级程序设计Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《实验5面向对象高级程序设计Word文档下载推荐.docx(15页珍藏版)》请在冰点文库上搜索。

实验5面向对象高级程序设计Word文档下载推荐.docx

②小学生有语文、数学成绩。

③中学生有语文、数学和英语成绩。

④大学生有必修课学分总数和选修课学分总数,不包含单科成绩。

⑤学生类提供向外输出信息的方法。

⑥学生类提供统计个人总成绩或总学分的方法。

⑦通过静态成员自动记录学生的总人数。

⑧能通过构造函数完成各字段成员初始化。

(2)设计一个Windows应用程序,在该程序中定义平面图形抽象类和其派生类圆、矩形和三角形。

该程序实现的功能包括:

输入相应的图形的参数,如矩形的长和宽,单击相应的按钮,根据输入参数创建图形类并输出该图形的面积。

(3)声明一个播放器接口IPlayer,包含5个接口方法:

播放、停止、暂停、上一首和下一首。

设计一个Windows应用程序,在该程序中定义一个MP3播放器类和一个AVI播放器类,以实现该接口,最后创建相应类的实例测试程序。

以下内容填写请利用截屏图片和文字对实验原理和实验效果进行说明

任务1()完成情况:

实际效果如下:

代码:

usingSystem;

using;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

namespaceS5_1

{

publicpartialclassForm1:

Form

{

publicForm1()

InitializeComponent();

}

publicabstractclassStudent

protectedstringname;

protectedintage;

publicstaticintnumber;

publicStudent(stringname,intage)

this.name=name;

this.age=age;

number++;

publicstringName

get{returnname;

publicvirtualstringtype

get{return"

学生"

;

publicabstractdoubletotal();

publicstringgetInfo()

stringresult=string.Format("

总人数:

{0},姓名:

{1},{2},{3}岁"

number,Name,type,age);

if(type=="

小学生"

result+=string.Format("

平均成绩为{0:

N2}:

\n"

total()/2);

elseif(type=="

中学生"

total()/3);

else

总学分为{0:

total());

returnresult;

publicclassPupil:

Student

protecteddoublechinese;

protecteddoublemath;

publicPupil(stringname,intage,doublechinese,doublemath)

:

base(name,age)

this.chinese=chinese;

this.math=math;

publicoverridestringtype

publicoverridedoubletotal()

returnchinese+math;

publicclassMiddle:

protecteddoubleenglish;

publicMiddle(stringname,intage,doublechinese,doublemath,doubleenglish)

this.english=english;

returnchinese+math+english;

publicclassUniversity:

protecteddoublemajors;

protecteddoubleelective;

publicUniversity(stringname,intage,doublemajors,doubleelective)

this.majors=majors;

this.elective=elective;

returnmajors+elective;

privatevoidbutton1_Click(objectsender,EventArgse)

intage=Convert.ToInt32(textBox2.Text);

doublesub1=Convert.ToDouble(textBox3.Text);

doublesub2=Convert.ToDouble(textBox4.Text);

Pupilp=newPupil(textBox1.Text,age,sub1,sub2);

label6.Text+=p.getInfo();

privatevoidbutton2_Click(objectsender,EventArgse)

doublesub3=Convert.ToDouble(textBox5.Text);

Middlem=newMiddle(textBox1.Text,age,sub1,sub2,sub3);

label6.Text+=m.getInfo();

privatevoidbutton3_Click(objectsender,EventArgse)

Universityu=newUniversity(textBox1.Text,age,sub1,sub2);

label6.Text+=u.getInfo();

}

运行结果:

自我评价:

达到了实验预计的效果

任务2()完成情况:

namespaceS5_2

publicabstractclassFigure

publicabstractdoubleArea();

publicclassCircle:

Figure

doubleradius;

publicCircle(doubler)

radius=r;

publicoverridedoubleArea()

returnradius*radius*3.14;

publicclassRectangle:

doublelength;

doublewidth;

publicRectangle(doublel,doublew)

length=l;

width=w;

returnlength*width;

publicclassTriangle:

doublebottom;

doublehigh;

publicTriangle(doubleb,doubleh)

bottom=b;

high=h;

returnbottom*high/2;

doubler=Convert.ToDouble(textBox1.Text);

Circlea=newCircle(r);

label6.Text="

圆的面积为:

"

+a.Area();

doublel=Convert.ToDouble(textBox1.Text);

doublew=Convert.ToDouble(textBox2.Text);

Rectanglea=newRectangle(l,w);

矩形面积为:

+a.Area();

doubleb=Convert.ToDouble(textBox1.Text);

doubleh=Convert.ToDouble(textBox2.Text);

Trianglea=newTriangle(b,h);

三角形面积为:

任务3()完成情况:

namespaceS5_3

interfaceIPlayer

stringPlay();

stringStop();

stringPause();

stringPre();

stringNext();

publicclassMP3:

IPlayer

publicstringPlay()

return"

正在播放MP3歌曲!

publicstringStop()

停止播放MP3歌曲!

publicstringPause()

暂停播放MP3歌曲!

publicstringPre()

播放上一首MP3歌曲!

publicstringNext()

播放下一首MP3歌曲!

publicclassAVI:

正在播放AVI视频!

停止播放AVI视频!

暂停播放AVI视频!

播放上一部AVI视频!

播放下一部AVI视频!

IPlayerip;

MP3m;

AVIa;

m=newMP3();

ip=(IPlayer)m;

a=newAVI();

ip=(IPlayer)a;

label1.Text=ip.Pre();

privatevoidbutton4_Click(objectsender,EventArgse)

label1.Text=ip.Stop();

privatevoidbutton5_Click(objectsender,EventArgse)

label1.Text=ip.Play();

privatevoidbutton6_Click(objectsender,EventArgse)

label1.Text=ip.Pause();

privatevoidbutton7_Click(objectsender,EventArgse)

label1.Text=ip.Next();

总结你在完成任务1-3的过程中遇到的问题及解决的方法:

完成的比较顺利,基本没有遇到问题

总结本次实验涉及到的基本原理:

C#窗体设计,面向对象的高级程序设计

本次实验小结:

通过这次试验,对抽象类和派生类有了更深的理解

要求:

1.报告格式和内容要求:

a.内容和格式整齐。

大标题采用黑体四号字加粗,小标题采用小四号字加粗。

正文采用五号宋体,单倍行距。

b.贴图时请剪裁到适当大小,要保证打印时可以看清,但也不要太大以免“越界”。

c.不要在报告中写与实验无关的话,内容要有条理、完整、并能突出重点,要将遇到的主要问题说明。

2.文件格式要求:

a.将实验成果放入一个文件夹中,文件夹的内容包括:

本实验报告、项目。

b.文件夹以“学号姓名_S1”为文件名。

其中,S1表示这是实验1的报告,S大写,以后的实验报告以类似方法编号顺延,注意:

你的学号放在姓名前。

c.注意:

所有文件保存后关闭,然后再打包成RAR文件,以免提交的内容丢失或打不开。

3.提交方式和时间:

一周内完成。

可以将文件包发到我邮箱zcwang@

4.主动查阅资料,坚持自己亲手完成实验,弄清每个步骤和相关原理。

5.

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

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2