1、小学生有语文、数学成绩。中学生有语文、数学和英语成绩。大学生有必修课学分总数和选修课学分总数,不包含单科成绩。学生类提供向外输出信息的方法。学生类提供统计个人总成绩或总学分的方法。通过静态成员自动记录学生的总人数。能通过构造函数完成各字段成员初始化。(2)设计一个Windows应用程序,在该程序中定义平面图形抽象类和其派生类圆、矩形和三角形。该程序实现的功能包括:输入相应的图形的参数,如矩形的长和宽,单击相应的按钮,根据输入参数创建图形类并输出该图形的面积。(3)声明一个播放器接口IPlayer,包含5个接口方法:播放、停止、暂停、上一首和下一首。设计一个Windows应用程序,在该程序中定义
2、一个MP3播放器类和一个AVI播放器类,以实现该接口,最后创建相应类的实例测试程序。以下内容填写请利用截屏图片和文字对实验原理和实验效果进行说明任务1( )完成情况:实际效果如下:代码:using System;using ;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;namespace S5_1 public partial class Form1 : Form public Form1() InitializeComponent(
3、); public abstract class Student protected string name; protected int age; public static int number; public Student(string name, int age) this.name = name; this.age = age; number+; public string Name get return name; public virtual string type get return 学生; public abstract double total(); public st
4、ring getInfo() string result = string.Format(总人数:0,姓名:1,2,3岁, number, Name, type, age); if (type = 小学生) result += string.Format(,平均成绩为0:N2:n, total() / 2); else if (type = 中学生, total() / 3); else,总学分为0:, total(); return result; public class Pupil : Student protected double chinese; protected double
5、math; public Pupil(string name, int age, double chinese, double math) : base(name, age) this.chinese = chinese; this.math = math; public override string type public override double total() return chinese + math; public class Middle : protected double english; public Middle(string name, int age, doub
6、le chinese, double math, double english) this.english = english; return chinese + math + english; public class University : protected double majors; protected double elective; public University(string name, int age, double majors, double elective) this.majors = majors; this.elective = elective; retu
7、rn majors + elective; private void button1_Click(object sender, EventArgs e) int age = Convert.ToInt32(textBox2.Text); double sub1 = Convert.ToDouble(textBox3.Text); double sub2 = Convert.ToDouble(textBox4.Text); Pupil p = new Pupil(textBox1.Text, age, sub1, sub2); label6.Text += p.getInfo(); privat
8、e void button2_Click(object sender, EventArgs e) double sub3 = Convert.ToDouble(textBox5.Text); Middle m = new Middle (textBox1.Text, age, sub1, sub2,sub3); label6.Text += m.getInfo(); private void button3_Click(object sender, EventArgs e) University u = new University(textBox1.Text, age, sub1, sub2
9、); label6.Text += u.getInfo();运行结果:自我评价:达到了实验预计的效果 任务2( )完成情况:namespace S5_2 public abstract class Figure public abstract double Area(); public class Circle : Figure double radius; public Circle(double r) radius = r; public override double Area() return radius * radius * 3.14; public class Rectangle
10、 : double length; double width; public Rectangle(double l ,double w) length = l; width = w; return length * width; public class Triangle : double bottom; double high; public Triangle(double b, double h) bottom = b; high = h; return bottom * high / 2; double r = Convert.ToDouble(textBox1.Text); Circl
11、e a = new Circle(r); label6.Text = 圆的面积为:+ a.Area(); double l = Convert.ToDouble(textBox1.Text); double w = Convert.ToDouble(textBox2.Text); Rectangle a = new Rectangle(l,w);矩形面积为: + a.Area(); double b = Convert.ToDouble(textBox1.Text); double h = Convert.ToDouble(textBox2.Text); Triangle a = new Tr
12、iangle(b,h);三角形面积为:任务3( )完成情况:namespace S5_3 interface IPlayer string Play(); string Stop(); string Pause(); string Pre(); string Next(); public class MP3 : IPlayer public string Play() return 正在播放MP3歌曲! public string Stop()停止播放MP3歌曲! public string Pause()暂停播放MP3歌曲! public string Pre()播放上一首MP3歌曲! pu
13、blic string Next()播放下一首MP3歌曲! public class AVI :正在播放AVI视频!停止播放AVI视频!暂停播放AVI视频!播放上一部AVI视频!播放下一部AVI视频! IPlayer ip; MP3 m; AVI a; m = new MP3(); ip = (IPlayer)m; a = new AVI(); ip = (IPlayer)a; label1.Text = ip.Pre(); private void button4_Click(object sender, EventArgs e) label1.Text = ip.Stop(); priva
14、te void button5_Click(object sender, EventArgs e) label1.Text = ip.Play(); private void button6_Click(object sender, EventArgs e) label1.Text = ip.Pause(); private void button7_Click(object sender, EventArgs e) label1.Text = ip.Next();总结你在完成任务1-3的过程中遇到的问题及解决的方法:完成的比较顺利,基本没有遇到问题总结本次实验涉及到的基本原理:C#窗体设计,
15、面向对象的高级程序设计本次实验小结:通过这次试验,对抽象类和派生类有了更深的理解要求:1. 报告格式和内容要求: a. 内容和格式整齐。大标题采用黑体四号字加粗,小标题采用小四号字加粗。正文采用五号宋体,单倍行距。 b. 贴图时请剪裁到适当大小,要保证打印时可以看清,但也不要太大以免“越界”。 c. 不要在报告中写与实验无关的话,内容要有条理、完整、并能突出重点,要将遇到的主要问题说明。2. 文件格式要求: a. 将实验成果放入一个文件夹中,文件夹的内容包括:本实验报告、项目。 b. 文件夹以“学号姓名_S1”为文件名。其中,S1表示这是实验1的报告,S大写,以后的实验报告以类似方法编号顺延,注意:你的学号放在姓名前。 c. 注意:所有文件保存后关闭,然后再打包成RAR文件,以免提交的内容丢失或打不开。3. 提交方式和时间:一周内完成。可以将文件包发到我邮箱zcwang4. 主动查阅资料,坚持自己亲手完成实验,弄清每个步骤和相关原理。5.
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2