学生选课管理系统.docx
《学生选课管理系统.docx》由会员分享,可在线阅读,更多相关《学生选课管理系统.docx(29页珍藏版)》请在冰豆网上搜索。
学生选课管理系统
#include
#include
#include
#include
#include
//定义学生对象类型
typedefstructnode
{
charSno[10];//学号
charSname[10];//姓名
charSsex[3];//性别
charSage[3];//年龄
charSdept[4];//所在系
structnode*next;
}Student;
//定义课程对象类型
typedefstructnode2
{
charCno[10];//课程号
charCname[10];//课程名
charCpno[5];//先行课
charCcredit[3];//学分
structnode2*next;
}Course;
//定义选课对象类型
typedefstructnode3
{
charSno[10];
charCno[10];
intGrade;
structnode3*next;
}SC;
//初始化学生信息表
voidInitlistA(Student*stu)
{
stu->next=NULL;
}
//初始化课程信息表
voidInitlistB(Course*C)
{
C->next=NULL;
}
//初始化选课信息表
voidInitlistC(SC*S)
{
S->next=NULL;
}
//求选课表的深度
intGetlength(SC*S)
{
inti=0;
SC*p;
p=S->next;
while(p!
=NULL)
{
p=p->next;
i;
}
return(i);
}
//用户输入数据建立学生信息表(尾插法)
voidCreatelistA(Student*stu)
{
Student*s,*r;
intm,i;
r=stu;
cout<<"现在输入学生信息"<cout<<"请输入学生个数:
";
cin>>m;
cout<<"|学号|姓名|性别|年龄|所在系|"<for(i=0;i{
s=(Student*)malloc(sizeof(Student));
cin>>s->Sno;
cin>>s->Sname;
cin>>s->Ssex;
cin>>s->Sage;
cin>>s->Sdept;
r->next=s;
r=s;
}
r->next=NULL;
}
//由用户输入数据建立课程信息列表
voidCreatelistB(Course*C)
{
Course*s,*r;
r=C;
intm,i;
cout<<"现在输入课程信息"<cout<<"请输入课程数量:
";
cin>>m;
cout<<"|课程号|课程名|先行课|学分|"<for(i=0;i{
s=(Course*)malloc(sizeof(Course));
cin>>s->Cno;
cin>>s->Cname;
cin>>s->Cpno;
cin>>s->Ccredit;
r->next=s;
r=s;
}
r->next=NULL;
}
//由用户输入数据建立选课信息列表
voidCreatelistC(SC*S)
{
SC*q,*r;
r=S;
intm,i;
cout<<"现在输入选课信息"<cout<<"请输入选课信息条数:
";
cin>>m;
cout<<"|学号|课程号|成绩|"<for(i=0;i{
q=(SC*)malloc(sizeof(SC));
cin>>q->Sno;
cin>>q->Cno;
cin>>q->Grade;
r->next=q;
r=q;
}
r->next=NULL;
}
//输出学生信息表
voidDisplistA(Student*stu)
{
Student*p=stu->next;
cout<<"学生信息表"<cout<<"___________________________________________________"<cout<<"|学号|姓名|性别|年龄|所在系|"<cout<<"|Sno|Sname|Ssex|Sage|Sdept|"<cout<<"___________________________________________________"<while(p!
=NULL)
{
printf("|s|%9s|%8s|%8s|s|\n",p->Sno,p->Sname,p->Ssex,p->Sage,p->Sdept);
cout<<"___________________________________________________"<p=p->next;
}
}
//输出课程信息表
voidDisplistB(Course*C)
{
Course*p=C->next;
cout<<"课程信息表"<cout<<"_______________________________________________"<cout<<"|课程号|课程名|先行课|学分|"<cout<<"|Cno|Cname|Cpno|Ccredit|"<cout<<"_______________________________________________"<while(p!
=NULL)
{
printf("|%8s|s|s|s|\n",p->Cno,p->Cname,p->Cpno,p->Ccredit);
cout<<"_______________________________________________"<p=p->next;
}
}
//输出选课信息表
voidDisplistC(SC*S)
{
if(Getlength(S)==0)
{
cout<<"对不起!
选课信息表已为空!
"<}
else
{
SC*p=S->next;
cout<<"选课信息表"<cout<<"_______________________________________________"<cout<<"|学号|课程号|成绩|"<cout<<"|Sno|Cno|Grade|"<cout<<"_______________________________________________"<while(p!
=NULL)
{
printf("|s|s|d|\n",p->Sno,p->Cno,p->Grade);
cout<<"_______________________________________________"<p=p->next;
}
}
}
//查询学生个人基本信息,以姓名或学号为参数
voidQueryStudent(Student*stu)
{
inti=0;
charsn[20];
Student*p;
p=stu->next;
cout<<"请输入所要查询的学生的学号或姓名"<cout<<"请输入:
";
cin>>sn;
do
{
if(strcmp(p->Sname,sn)==0||strcmp(p->Sno,sn)==0)
{
cout<<"___________________________________________________"<cout<<"|学号|姓名|性别|年龄|所在系|"<cout<<"|Sno|Sname|Ssex|Sage|Sdept|"<cout<<"___________________________________________________"<printf("|s|%9s|%8s|%8s|s|\n",p->Sno,p->Sname,p->Ssex,p->Sage,p->Sdept);
cout<<"___________________________________________________"<break;
}
p=p->next;//注意指针要往后走
}while(p!
=NULL);
if(p==NULL)
cout<<"对不起!
无此学生的信息!
"<}
//查询学生单科目的成绩
voidQuerySC(Student*stu,Course*C,SC*S)
{
charsn[20];
charcn[20];
Student*p;
Course*q;
SC*r;
p=stu->next;
cout<<"请输入所要查询的学生的学号和课程号"<cout<<"学号或姓名:
";
cin>>sn;
p=stu->next;//将姓名计算转化成为学号
do
{
if(strcmp(p->Sname,sn)==0||strcmp(p->Sno,sn)==0)
{
strcpy(sn,p->Sno);
break;
}
p=p->next;
}while(p!
=NULL);
if(p==NULL)
{
cout<<"对不起!
无该名学生的信息!
"<return;
}
cout<<"课程号或课程名:
";
cin>>cn;
q=C->next;//将课程名计算转化成为课程号
do
{
if(strcmp(q->Cno,cn)==0||strcmp(q->Cname,cn)==0)
{
strcpy(cn,q->Cno);
break;
}
q=q->next;
}while(q!
=NULL);
if(q==NULL)
{
cout<<"对不起!
您输入的课程信息有误!
"<return;
}
r=S->next;
do
{
if(strcmp(r->Sno,sn)==0&&str