#include
#include
#include
// 循环列表结构 head->[,->next]...[data0,->next][data1,->next]...[datan,->head]
struct SCORE
{
int courseId;
int score;
SCORE *pnext;
};
struct STU_SCORE
{
char name[16];
int stuId;
SCORE *scoreHead;//学生课程成绩列表
struct STU_SCORE *pnext;
STU_SCORE(int ID,char names[])
{
int len=strlen(names);
for(int i=0;i
name[len]='\0';
stuId=ID;
}
};
int mainMenu();
int stuReg(STU_SCORE *pHead);
int selCourse(STU_SCORE *pHead);
int inputData(STU_SCORE *pHead);
int scoreSort(STU_SCORE *pHead);
int scoreQuery(STU_SCORE *pHead);
int modify(STU_SCORE *pHead);
enum MAIN_CMD{REG,SEL=1,INPUT,QUERY,MODI,EXIT};
int main(int argc, char* argv[])
{
STU_SCORE *head=( STU_SCORE *)malloc(sizeof(STU_SCORE));
head->stuId=-1;
head->pnext=head;
while(1)
{
int cmd=mainMenu();
switch(cmd)
{
case REG:
stuReg(head);
break;
case SEL:
selCourse(head);
break;
case INPUT:
inputData(head);
break;
case QUERY:
scoreQuery(head);
break;
case MODI:
modify(head);
break;
case EXIT:
return 0;
}
}
return 0;
}
int mainMenu()
{
system("cls");
cout<<"\t\t《学生成绩管理系统》\n";
cout<<" \t\t[0]新生注册\n";
cout<<" \t\t[1]选课登记\n";
cout<<" \t\t[2]学生成绩输入\n";
cout<<" \t\t[3]成绩查询\n";
cout<<" \t\t[4]修改成绩\n";
cout<<" \t\t[5]退出\n";
cout<<"命令? ";
int cmd;
cin>>cmd;
return cmd;
}
//新生注册:建立学生信息链表,从键盘输入学生姓名学号,插入到链表中。
int stuReg(STU_SCORE *pHead)
{
cout<<"注意:新生注册学号不能重复!\n";
start:
cout<<"学号\t\t姓名\n";
int ID;
char StudentName[20];
cin>>ID;
while(ID>0)
{
cin>>StudentName;
STU_SCORE *newStu=new STU_SCORE(ID,StudentName);
newStu->scoreHead=new SCORE();
newStu->scoreHead->pnext=newStu->scoreHead;
STU_SCORE*q=pHead->pnext,*p=pHead;
while(q!=pHead)
{
p=q;
if(q->stuId
q=q->pnext;
else
break;
}
p->pnext=newStu;
newStu->pnext=q;
cin>>ID;
}
int cnt=0;
STU_SCORE*q=pHead->pnext;
while(q!=pHead)
{
q=q->pnext;
cnt++;
}
cout<<"学生数据库共有"<
char c;
cin>>c;
if(c=='y'||c=='Y')goto start;
return 0;
}
//学生选课
int selCourse(STU_SCORE *pHead)
{
start:
int cid;
cout<<"课程号:";
cin>>cid;
cout<<"输入选择该课程的学生学号:\n";
int stuId;
cin>>stuId;
while(stuId>0)
{
STU_SCORE *pStu=pHead->pnext;
while(pStu!=pHead)//链表已有记录
{
if(pStu->stuId==stuId)//有该学号
{
bool be=false;
SCORE *pcourse=pStu->scoreHead->pnext;
while(pcourse!=pStu->scoreHead)//已有选课
{
if(pcourse->courseId==cid)
{
be=true;////已有该选课
break;
}
pcourse=pcourse->pnext;
}
if(!be)
{ //还没有选此课程
SCORE *pNewcourse=(SCORE *)malloc(sizeof(SCORE));
pNewcourse->courseId=cid;
SCORE*q=pStu->scoreHead->pnext;
pStu->scoreHead->pnext=pNewcourse;
pNewcourse->pnext=q;
}
}
pStu=pStu->pnext;
}
cin>>stuId;
}
int count=0;
STU_SCORE *pStu=pHead->pnext;
while(pStu!=pHead)//链表已有记录
{
SCORE *pcourse=pStu->scoreHead->pnext;
while(pcourse!=pStu->scoreHead)
{
if(pcourse->courseId==cid)
{
count++;
}
pcourse=pcourse->pnext;
}
pStu=pStu->pnext;
}
cout<<"共有"<
char c;
cin>>c;
if(c=='y'||c=='Y')goto start;
return 0;
}
//学生成绩输入
int inputData(STU_SCORE *pStuHead)
{
int count;
start:
count=0;
cout<<"课程号:";
int cid;
cin>>cid;
STU_SCORE *pStu=pStuHead->pnext;
while(pStu!=pStuHead)//if链表已有学生记录
{
SCORE *pcourse=pStu->scoreHead->pnext;
while(pcourse!=pStu->scoreHead)
{
if(pcourse->courseId==cid)
{
cout<<"学号:"<
cout<<" 成绩:";
if(pcourse->score>=0)
cout<<"已输入";
else
{
cin>>pcourse->score;
count++;
}
break;
}
pcourse=pcourse->pnext;
}
pStu=pStu->pnext;
}
if(count==0)
cout<<"该课程无学生选!\n";
else
cout<
char c;
cin>>c;
if(c=='y'||c=='Y')goto start;
return 0;
}
//课程成绩查询
int scoreQuery(STU_SCORE *pStuHead)
{
start:
int ID;
cout<<"学号:"<
STU_SCORE*pStu=pStuHead->pnext;
while(pStu!=pStuHead)
{
if(pStu->stuId==ID)
{
cout<<"姓名:"<
while(pcourse!=pStu->scoreHead)
{
cout<<"课程号:"<
}
break;
}
pStu=pStu->pnext;
}
if(pStu==pStuHead)
{
cout<<"查无此人"<
cout<<"继续查询?";
char c;
cin>>c;
if(c=='y'||c=='Y')
goto start;
return 0;
}
//课程成绩修改
int modify(STU_SCORE *pStuHead)
{
start:
int ID;
cout<<"学号:";
cin>>ID;
STU_SCORE*pStu=pStuHead->pnext;
while(pStu!=pStuHead)
{
if(pStu->stuId==ID)
{
int cid;
cout<<"课程号:";
cin>>cid;
SCORE*pcourse=pStu->scoreHead->pnext;
while(pcourse!=pStu->scoreHead)
{
if(pcourse->courseId==cid)
{
int rescore;
cout<<"原成绩:"<
cin>>rescore;
pcourse->score=rescore;
goto ask;
}
pcourse=pcourse->pnext;
}
if(pcourse==pStu->scoreHead)
{
cout<<"此人没有选择该课程。"<
}
}
pStu=pStu->pnext;
}
if(pStu==pStuHead)
{
cout<<"查无此人"<
ask:
cout<<"继续修改?";
char c;
cin>>c;
if(c=='y'||c=='Y')
goto start;
return 0;
}