C#程序设计实验报告(4)

2018-12-29 20:14

金陵科技学院实验报告

square s = new square(a,b);

Console.WriteLine(\求矩形面积,长为a={0},宽为b={1},面积area={2}\

square i = new square(a);

Console.WriteLine(\求圆形面积,半径a={0},面积area={1}\a, i.area);

square j = new square(a, b, h);

Console.WriteLine(\求梯形面积,上底为a={0},下底为b={1},高为h={2}面积area={3}\

} } }

6、设计一个windows应用程序,在该程序中定义一个学生类和班级类,以处理每个学生的学号,姓名,语文,数学和英语成绩,要求:

1)能查询每个学生的总成绩。 2)能显示全班前三名的名单。

3)能显示单科成绩最高分和不及格的学生名单。 4)能统计全班学生的平均成绩。

5)能显示各科成绩不同分数段的学生人数的百分比。

Student类: using System;

using System.Collections.Generic; using System.Text; namespace Test2_6 {

public class Student {

public string stuNo; public string name; public double chinese; public double math; public double english; public double sumScore {

14

金陵科技学院实验报告

get { return chinese + math + english; } } } }

StudentList类: using System;

using System.Collections.Generic; using System.Text; namespace Test2_6 {

public class StudentList:Student {

int snums;

public Student[] stu=new Student[50]; public StudentList() {

snums = 0; }

public void addstu(Student s) {

stu[snums] = s; snums++; }

public int searchstu(string name) { int i;

for (i = 0; i < snums; i++) {

if (stu[i].name == name) break; }

if (i == snums) return -1; else return i; }

//给所有成绩排序,用后面实现前三名的排名

15

金陵科技学院实验报告

public void ProThree() {

for (int i = 0; i < snums; i++) {

int k = i;

for (int j = i + 1; j < snums; j++)

if (stu[j].sumScore > stu[k].sumScore) k = j; if (k != i) {

Student temp; temp = stu[k]; stu[k] = stu[i]; stu[i] = temp; } } }

//显示单科成绩的最高分 public int HighScore(int k) {

int p = 0; if (k == 0) {

for (int i = 1; i < snums; i++)

if (stu[i].math > stu[p].math) p = i; }

else if (k == 1) {

for (int i = 1; i < snums; i++)

if (stu[i].chinese > stu[p].chinese) p = i; } else {

for (int i = 1; i < snums; i++)

if (stu[i].chinese > stu[p].chinese) p = i;

16

金陵科技学院实验报告

} return p; }

//显示不及格名单

public string BuhgName(int k) {

string name=\ if (k == 0) {

for (int i = 0; i < snums; i++)

if (stu[i].math < 60) name +=stu[i].name+\ }

else if (k == 1) {

for (int i = 0; i < snums; i++)

if (stu[i].chinese < 60) name += stu[i].name + \ } else {

for (int i = 0; i < snums; i++)

if (stu[i].english < 60) name += stu[i].name + \ }

return name; }

public string getHL() {

string Maxer = \

Maxer += \单科数学最高:\ Maxer += \单科语文最高:\ Maxer += \单科英语最高:\ Loser += \单科数学挂科名单:\ Loser += \单科语文挂科名单:\ Loser += \单科英语挂科名单:\

17

金陵科技学院实验报告

return Maxer + \ }

//全班的平均成绩 public string SumScore() {

double sum = 0; double avg=0;

for (int i = 0; i < snums; i++) {

sum = sum + stu[i].sumScore; }

avg = sum / snums;

return \班级总分平均分:\ }

//各科成绩不同分数段的学生百分比

//英语成绩各分数段百分比 public string PerC() {

double per1, per2, per3, per4, per5;

double sumC1 = 0, sumC2 = 0, sumC3 = 0, sumC4 = 0, sumC5 = 0;

for (int i = 0; i < snums; i++) {

if ((stu[i].chinese > 90) && (stu[i].chinese <= 100)) {

sumC1++; }

else if ((80 <= stu[i].chinese) && (stu[i].chinese < 90)) {

sumC2++; }

18


C#程序设计实验报告(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017电大开放英语3unit6形考测试(2)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: