实验5-面向对象的高级程序设计

上传人:枫** 文档编号:487112867 上传时间:2023-02-24 格式:DOC 页数:14 大小:340.50KB
返回 下载 相关 举报
实验5-面向对象的高级程序设计_第1页
第1页 / 共14页
实验5-面向对象的高级程序设计_第2页
第2页 / 共14页
实验5-面向对象的高级程序设计_第3页
第3页 / 共14页
实验5-面向对象的高级程序设计_第4页
第4页 / 共14页
实验5-面向对象的高级程序设计_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《实验5-面向对象的高级程序设计》由会员分享,可在线阅读,更多相关《实验5-面向对象的高级程序设计(14页珍藏版)》请在金锄头文库上搜索。

1、实验5面向对象的高级程序设计实验日期和时间:实验室:班级: 学号:姓名: 实验环境:1. 硬件:主频:2.20 GHz内存:海力士 DDR3 1600 MHz 2GB硬盘空间:500GB 5400转/分操作系统版本:win72. 软件:Microsoft Visual Studio 2010实验主要任务:(1) 设计一个Windows应用程序,在该程序中首先构造一个学生基本类,再分别构造小学生、中学生、大学生等派生类,当输入相关数据,单击不同的按钮(小学生、中学生、大学生)将分别创建不同的学生对象,并输入当前的学生人数、该学生的姓名、学生类型和平均成绩。要求如下:每个学生都有姓名和年龄。小学生

2、有语文、数学成绩。中学生有语文、数学和英语成绩。大学生有必修课学分总数和选修课学分总数,不包含单科成绩。学生类提供向外输出信息的方法。学生类提供统计个人总成绩或总学分的方法。通过静态成员自动记录学生的总人数。能通过构造函数完成各字段成员初始化。(2) 设计一个Windows应用程序,在该程序中定义平面图形抽象类和其派生类圆、矩形和三角形。该程序实现的功能包括:输入相应的图形的参数,如矩形的长和宽,单击相应的按钮,根据输入参数创建图形类并输出该图形的面积。(3) 声明一个播放器接口IPlayer,包含5个接口方法:播放、停止、暂停、上一首和下一首。设计一个Windows应用程序,在该程序中定义一

3、个MP3播放器类和一个AVI播放器类,以实现该接口,最后创建相应类的实例测试程序。以下内容填写请利用截屏图片和文字对实验原理和实验效果进行说明任务1( )完成情况:实际效果如下:代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace S5_1 public partial cl

4、ass Form1 : Form public Form1() InitializeComponent(); 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

5、return 学生; public abstract double total(); public string 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 = 中学生) result += string.Format(,平均成绩为0:N2:n, total() / 3); else result += stri

6、ng.Format(,总学分为0:N2:n, total(); return result; public class Pupil : Student protected double chinese; protected double math; public Pupil(string name, int age, double chinese, double math) : base(name, age) this.chinese = chinese; this.math = math; public override string type get return 小学生; public

7、override double total() return chinese + math; public class Middle : Student protected double chinese; protected double math; protected double english; public Middle(string name, int age, double chinese, double math, double english) : base(name, age) this.chinese = chinese; this.math = math; this.en

8、glish = english; public override string type get return 中学生; public override double total() return chinese + math + english; public class University : Student protected double majors; protected double elective; public University(string name, int age, double majors, double elective) : base(name, age)

9、 this.majors = majors; this.elective = elective; public override string type get return 小学生; public override double total() return majors + elective; private void button1_Click(object sender, EventArgs e) int age = Convert.ToInt32(textBox2.Text); double sub1 = Convert.ToDouble(textBox3.Text); double

10、 sub2 = Convert.ToDouble(textBox4.Text); Pupil p = new Pupil(textBox1.Text, age, sub1, sub2); label6.Text += p.getInfo(); private void button2_Click(object sender, EventArgs e) int age = Convert.ToInt32(textBox2.Text); double sub1 = Convert.ToDouble(textBox3.Text); double sub2 = Convert.ToDouble(textBox4.Text); 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)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号