金陵科技学院实验报告
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