推荐-实验报告三

上传人:鲁** 文档编号:477816931 上传时间:2023-01-10 格式:DOC 页数:14 大小:145KB
返回 下载 相关 举报
推荐-实验报告三_第1页
第1页 / 共14页
推荐-实验报告三_第2页
第2页 / 共14页
推荐-实验报告三_第3页
第3页 / 共14页
推荐-实验报告三_第4页
第4页 / 共14页
推荐-实验报告三_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《推荐-实验报告三》由会员分享,可在线阅读,更多相关《推荐-实验报告三(14页珍藏版)》请在金锄头文库上搜索。

1、攀 枝 花 学 院 实 验 报 告实验课程:Visual C#.NET程序设计教程 实验项目:上机实验5 实验日期:2015.05.05系:数计学院 成绩: 一、 实验目的1、 区分静态类与非静态类,掌握静态字段、静态方法和静态构造函数的定义方法。2、 理解类的继承性与多态性,掌握其应用方法。3、 理解抽象类、接口的概念,掌握抽象类与接口的定义及使用方法。4、 理解分部类和命名空间的概念,掌握分部类和命名空间的使用方法。二、 实验要求1. 熟悉Visual Studio.Net2010的基本操作方法。2. 认真阅读本章相关内容,尤其是案例。3. 实验前进行程序设计,完成源程序的编写任务。4.

2、反复操作,直到不需要参考教材、能熟练操作为止。 三、 实验步骤1、 设计一个Windows应用程序,在该程序中首先构造一个学生基本类,再分别构造小学生、中学生、大学生等派生类,当输入相关数据,单击不同的按钮(小学生、中学生、大学生)将分别创建不同的学生对象,并输入当前的学生总人数、该学生的姓名、学生类型和平均成绩。具体要求如下:(1) 每个学生都有的字段为:姓名、年龄。(2) 小学生的字段还有语文、数学,用来表示这两科的成绩。(3) 中学生在此基础上多了英语成绩。(4) 大学生只有必修课和选修课两项成绩。(5) 学生类具有方法来统计自己的总成绩,并输出。(6) 通过静态成员自动记录学生总人数。

3、(7) 成员初始化能通过构造函数完成。源程序如下: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 Test3_1 public partial class Form1 : Form推荐精选 public Form1() InitializeComponent(); publi

4、c abstract class Student protected string name; protected int age; protected 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 abstrac

5、t double Average(); public string getInto() 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 += string.Format(,总学分为0:N2:n, tot

6、al(); 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 override double total(

7、) 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.english = english; public

8、 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)推荐精选 this.majors = majors

9、 ; this.elective = elective; public override string type get return 大学生; public override double total() return majors+elective; private void btpupil_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtage.Text); double chinese = Convert.ToDouble(txtChinese.Text); double math = Convert.ToD

10、ouble(txtMath.Text); Pupil p = new Pupil(txtname.Text, age, chinese, math); txtshow.Text += p.getInto(); private void btMiddle_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtage.Text); double chinese = Convert.ToDouble(txtChinese.Text); double math = Convert.ToDouble(txtMath.Text); double english = Conver

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

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