用C#编写一个学生成绩管理系统,定义以下几个类
classCourse{stringname;intgrade;publicCourse(){}publicCourse(stringname){this.name=na...
class Course
{
stringname;
int grade;
public Course()
{
}
public Course(string name)
{
this.name=name;
this.grade=-1;
}
public Course(string name, int grade)
{
}
}
classStudent
{
stringname;
Course[] myCourse;
publicStudent() //构造函数
{
}
publicStudent(string name, Course[] courses)
{
}
public int CourseGradeSum( )
{
}
public bool IsBetterThan(Student s1)
{
}
public static Student WhoIsBest(Student s1, Student s2)
{
}
public static Student WhoIsBest(Student[] ss)
{
}
public stringGetInfo()
{
}
添加只读属性EveGrade
}
class Test
{
public static void Main() {
Course[] a=new Course[3];
a[0]=new Course("数据结构",80);
a[1]=new Course("数据库",90);
a[2]=new Course("软件工程",70);
StudentJohn=new Student("John",a);
Course[] b=new Course[3];
b[0]=new Course("数据结构",70);
b[1]=new Course("数据库",80);
b[2]=new Course("软件工程",60);
Student Mike=new Student("Mike",b);
Course[] c=new Course[3];
c[0]=new Course("数据结构",90);
c[1]=new Course("数据库",80);
c[2]=new Course("软件工程",90);
Student Rose=new Student("Rose",c); 展开
{
stringname;
int grade;
public Course()
{
}
public Course(string name)
{
this.name=name;
this.grade=-1;
}
public Course(string name, int grade)
{
}
}
classStudent
{
stringname;
Course[] myCourse;
publicStudent() //构造函数
{
}
publicStudent(string name, Course[] courses)
{
}
public int CourseGradeSum( )
{
}
public bool IsBetterThan(Student s1)
{
}
public static Student WhoIsBest(Student s1, Student s2)
{
}
public static Student WhoIsBest(Student[] ss)
{
}
public stringGetInfo()
{
}
添加只读属性EveGrade
}
class Test
{
public static void Main() {
Course[] a=new Course[3];
a[0]=new Course("数据结构",80);
a[1]=new Course("数据库",90);
a[2]=new Course("软件工程",70);
StudentJohn=new Student("John",a);
Course[] b=new Course[3];
b[0]=new Course("数据结构",70);
b[1]=new Course("数据库",80);
b[2]=new Course("软件工程",60);
Student Mike=new Student("Mike",b);
Course[] c=new Course[3];
c[0]=new Course("数据结构",90);
c[1]=new Course("数据库",80);
c[2]=new Course("软件工程",90);
Student Rose=new Student("Rose",c); 展开
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Course
{
private string name;
private int grade;
public Course(string name)
{
this.name = name;
this.grade = -1;
}
public Course(string name, int grade)
{
this.name = name;
this.grade = grade;
}
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public int Grade
{
get { return this.grade; }
set { this.grade = value; }
}
}
class Student
{
string name;
Course[] myCourse;
public Student(string name, Course[] courses)
{
this.name = name;
myCourse = courses;
}
public int CourseGradeSum()
{
int sum = 0;
for (int i = 0; i < myCourse.Length; i++)
{
sum += myCourse[i].Grade;
}
return sum;
}
public bool IsBetterThan(Student s1)
{
if (this.CourseGradeSum() > s1.CourseGradeSum()) return true;
else return false;
}
public static Student WhoIsBest(Student s1, Student s2)
{
if (s1.IsBetterThan(s2)) return s1;
else return s2;
}
public static Student WhoIsBest(Student[] ss)
{
int index = -1;
int maxGradeSum = 0;
for (int i = 0; i < ss.Length; i++)
{
if (ss[i].CourseGradeSum() > maxGradeSum)
{
maxGradeSum = ss[i].CourseGradeSum();
index = i;
}
}
return ss[index];
}
public string GetInfo()
{
return "姓名:" + name + ";总分:" + this.CourseGradeSum().ToString();
}
}
//控制类
class Test
{
static void Main(string[] args)
{
Course[] a = new Course[3];
a[0] = new Course("数据结构", 80);
a[1] = new Course("数据库", 90);
a[2] = new Course("软件工程", 70);
Student John = new Student("John", a);
Course[] b = new Course[3];
b[0] = new Course("数据结构", 70);
b[1] = new Course("数据库", 80);
b[2] = new Course("软件工程", 60);
Student Mike = new Student("Mike", b);
Course[] c = new Course[3];
c[0] = new Course("数据结构", 90);
c[1] = new Course("数据库", 80);
c[2] = new Course("软件工程", 90);
Student Rose = new Student("Rose", c);
Student[] ss = { John, Mike, Rose };
Console.WriteLine("最佳学生:{0}",
Student.WhoIsBest(ss).GetInfo());
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询