课程设计模拟选课系统.docx
《课程设计模拟选课系统.docx》由会员分享,可在线阅读,更多相关《课程设计模拟选课系统.docx(15页珍藏版)》请在冰豆网上搜索。
![课程设计模拟选课系统.docx](https://file1.bdocx.com/fileroot1/2022-10/9/5450742f-56d2-4668-ae71-597f39810c24/5450742f-56d2-4668-ae71-597f39810c241.gif)
课程设计模拟选课系统
模拟选课系统
1:
选课系统是为学校提供课程管理的信息系统。
能实现学生选课,查询。
老师班级管理的部分功能。
通过简要的分析,可知本系统的基本功能需求包括以下几个方面。
(1)一个学生可以选择多门课程。
(2)学生选课不能重复。
(3)一个班级有很多学生组成。
(4)班级学生信息不能重复。
(5)满足班级人数限制要求。
(6)能够支持学生查询课表,和所有可选课程。
(7)能够支持老师查看班级选课情况。
在上述分析的基础上,可以找到一系列可能的对象,并将其抽象到不同的类。
1)学生类:
学生名称、学号、专业等可作为类的属性;可选入课程。
2)教师类:
教师称呼、教师号、所教课程等作为类的属性。
3)班级类:
班级课程、任课教师、教学班号、上课时间、地点等属性。
可加入学生。
学生类中的主要代码:
publicclassStudent
{
privatestringname;//姓名
publicstringName
{
get{returnname;}
set{name=value;}
}
privatestringnum;//学号
publicstringNum
{
get{returnnum;}
set{num=value;}
}
privatestringsubject;//专业
publicstringSubject
{
get{returnsubject;}
set{subject=value;}
}
privateClass[]choiceCla;//学生的课表
privateintcount;//选课的门数
publicintCount
{
get{returncount;}
set{count=value;}
}
publicStudent(stringname,stringnum)
{
this.name=name;
this.num=num;
this.choiceCla=newClass[100];
count=0;
}
publicStudent(stringname,stringnum,stringsubject)
{
this.name=name;
this.num=num;
this.subject=subject;
this.choiceCla=newClass[100];
count=0;
}
//将学生信息转换为字符串
publicoverridestringToString()
{
return"学生姓名:
"+this.name+"学号:
"+this.num;
}
publicboolIsAddClass(Classc)
{
if(count==0)
returntrue;
//课程总数不能超过100门
if(count==100)
returnfalse;
foreach(Classc1inchoiceCla)
{
//该课程c该学生已经选修了
if(c1==c)
returnfalse;
}
returntrue;
}
//增加一名课程
publicvoidAddClass(Classc)
{
choiceCla[count]=c;
count=count+1;
}
//显示所有选修的课程
publicvoidShowClass()
{
stringstr="";
if(count==0)
{
Console.WriteLine("该学生还没有选修任何课程!
");
return;
}
for(inti=0;i{
str=str+choiceCla[i].Num+"";
}
Console.WriteLine("该学生选修了以下课程:
"+str);
}
//显示所有选修的课程的具体信息
publicvoidShowClassInfo()
{
if(count==0)
{
Console.WriteLine("该学生还没有选修任何课程!
");
return;
}
Console.WriteLine("该学生选修了以下课程:
");
for(inti=0;i{
Console.Write("第{0}门课程——",i+1);
choiceCla[i].ShowInfo();
}
}
}
教师类中的代码:
publicclassTeacher
{
privatestringname;//姓名
publicstringName
{
get{returnname;}
set{name=value;}
}
privatestringsubject;//所教课程的名称
publicstringSubject
{
get{returnsubject;}
set{subject=value;}
}
privatestringteacher_num;//教师号
publicstringTeacher_num
{
get{returnteacher_num;}
set{teacher_num=value;}
}
publicTeacher(stringname,stringteacher_num)
{
this.name=name;
this.teacher_num=teacher_num;
}
publicTeacher(stringname,stringsubject,stringteacher_num)
{
this.name=name;
this.subject=subject;
this.teacher_num=teacher_num;
}
publicoverridestringToString()
{
return"老师姓名:
"+this.name+"职工号:
"+this.teacher_num;
}
}
班级类中的代码:
publicclassClass
{
privatestringname;//课程名
publicstringName
{
get{returnname;}
set{name=value;}
}
publicTeachert;//任课教师
privatestringnum;//教学班号
publicstringNum
{
get{returnnum;}
set{num=value;}
}
privatestringstart;//上课时间
publicstringStart
{
get{returnstart;}
set{start=value;}
}
privatestringadress;//上课地点
publicstringAdress
{
get{returnadress;}
set{adress=value;}
}
publicStudent[]students;//所有选择这门课的同学
privateintcount;//选课的人数
publicintCount
{
get{returncount;}
set{count=value;}
}
publicClass(stringnum)
{
this.num=num;
this.students=newStudent[150];
count=0;
}
publicClass(stringname,stringnum)
{
this.name=name;
this.num=num;
this.students=newStudent[150];
count=0;
}
publicoverridestringToString()
{
return"课程名:
"+this.name+"编号:
"+this.num;
}
publicvoidShowInfo()
{
Console.WriteLine("课程名:
"+this.name+"编号:
"+this.num);
Console.WriteLine("时间:
"+this.start);
Console.WriteLine("地点:
"+this.adress);
}
//判断是否能选修该门课程
publicboolIsAddStu(Students)
{
if(count==0)
returntrue;
//选课人数不能超过150
if(count==150)
returnfalse;
foreach(Students1instudents)
{
//该课程c该学生已经选修了
if(s1==s)
returnfalse;
}
returntrue;
}
//增加一名课程
publicvoidAddStu(Students)
{
students[count]=s;
count=count+1;
}
//显示所有选修该门课程的学生
publicvoidShowStu()
{
stringstr="";
if(count==0)
{
Console.WriteLine("还没有任何学生选修该课程!
");
return;
}
for(inti=0;i{
str=str+students[i].Name+"";
}
Console.WriteLine("以下学生选修了该课程:
"+str);
}
}
主函数中的代码及运行截图:
Console.Write("请选择您要以什么身份进入该系统(A老师;B学生;Q退出系统):
");
stringa=Console.ReadLine();
while(a!
="Q")
{
switch(a)
{
case"B":
Console.Write("请输入您的学号:
(已设定0001-0003)");
stringc=Console.ReadLine();
inti=0;
for(;i{
if(STU[i]!
=null)
if(STU[i].Num=