云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > C#程序设计实验报告实验指导书-邵佳楠

C#程序设计实验报告实验指导书-邵佳楠

  • 62 次阅读
  • 3 次下载
  • 2025/5/26 11:42:30

金陵科技学院实验报告

4、设计一个Windows应用程序,在该程序中首先构造一个学生基本类,再分别构造小学生、中学生、大学生派生类,当输入相关数据,单击不用的按钮时,将分别创建不同的学生类对象,并输出当前学生的总人数,该学生的姓名,学生类型,平均成绩。

程序要求:

(1)每个学生都有的字段为姓名、年龄。

(2)小学生的字段还有语文,数学,用来表示这两科的成绩。 (3)中学生在此基础上增加英语成绩。 (4)大学生分为必修课和选修课两项成绩。

(5)学生类提供方法来统计自己的总成绩并输出。 (6)通过静态成员自动记录学生总人数。 (7)成员初始化通过构造函数完成。 using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms;

namespace WindowsFormsApplication5 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) {

int age = Convert.ToInt32(txtAge.Text);

double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text); Pupil p = new Pupil(txtName.Text, age, sub1, sub2); lblShow.Text += p.getInfo(); }

private void button2_Click(object sender, EventArgs e) {

int age = Convert.ToInt32(txtAge.Text);

double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text); double sub3 = Convert.ToDouble(txtSub3.Text);

Middle p = new Middle(txtName.Text, age, sub1, sub2, sub3); lblShow.Text += p.getInfo();

15

金陵科技学院实验报告

}

private void button3_Click(object sender, EventArgs e) {

int age = Convert.ToInt32(txtAge.Text);

double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text); double sub3 = Convert.ToDouble(txtSub3.Text);

College p = new College(txtName.Text, age, sub1, sub2, sub3); lblShow.Text += p.getInfo(); } } }

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

using System.Threading.Tasks;

namespace WindowsFormsApplication5 {

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 string getInfo() {

string result = string.Format(\总人数:{0},姓名:{1},{2},{3}岁\number, Name, type, age);

if (type == \小学生2\

16

金陵科技学院实验报告

result += string.Format(\平均成绩为{0:N2}:\\n\ else if (type == \中学生\

result += string.Format(\平均成绩为{0:N2}:\\n\ else

result += string.Format(\总学分为{0:N2}:\\n\ return result; } } }

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

using System.Threading.Tasks;

namespace WindowsFormsApplication5 {

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() {

return chinese + math; } } }

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

using System.Threading.Tasks;

17

金陵科技学院实验报告

namespace WindowsFormsApplication5 {

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 override string type {

get {

return \中学生\ } }

public override double total() {

return chinese + math + english; } } }

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

using System.Threading.Tasks;

namespace WindowsFormsApplication5 {

public class College : Student {

protected double chinese; protected double math; protected double english;

public College(string name, int age, double chinese, double math, double english) : base(name, age) {

this.chinese = chinese; this.math = math;

18

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

金陵科技学院实验报告 4、设计一个Windows应用程序,在该程序中首先构造一个学生基本类,再分别构造小学生、中学生、大学生派生类,当输入相关数据,单击不用的按钮时,将分别创建不同的学生类对象,并输出当前学生的总人数,该学生的姓名,学生类型,平均成绩。 程序要求: (1)每个学生都有的字段为姓名、年龄。 (2)小学生的字段还有语文,数学,用来表示这两科的成绩。 (3)中学生在此基础上增加英语成绩。 (4)大学生分为必修课和选修课两项成绩。 (5)学生类提供方法来统计自己的总成绩并输出。 (6)通过静态成员自动记录学生总人数。 (7)成员初始化通过构造函数完成。 using System; using System.Collections.Generic; using System.ComponentM

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com