学生信息管理系统C++语言程序代码Word格式文档下载.docx
《学生信息管理系统C++语言程序代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《学生信息管理系统C++语言程序代码Word格式文档下载.docx(20页珍藏版)》请在冰豆网上搜索。
student*creat();
//建立链表函数。
voidoutput(student*head);
intcount(student*head);
//定义函数count()统计考生总数
student*insert(student*head);
//指针函数*insert()用来添加考生信息.
student*cancel(student*head,longintnum);
//指针函数*cancel()用来删除考生信息.
student*find(student*head,longintnum);
//指针函数*find()用来查找考生信息。
voidinorder(student*head);
//定义inorder()函数将考生的总分从大到小排列并输出
voidaverage(student*head);
//求学生成绩的平均分的函数
voidsave(student*head);
//保存函数
student*Read();
//读取函数
private:
student*p1,*p2,*p3,*head,st;
};
Information:
:
Information()//构造函数
{
cout<
<
”******************************************************************************\n”;
cout〈<
"
—-—-———--—-—-—--——-——-——〈<
欢迎您使用学生信息管理系统>
〉----—-——--—--——————————-\n"
;
cout〈〈”******************************************************************************\n\n”;
}
Information:
~Information()//构造函数
{
”******************************************************************************\n"
〈"
----—-—-------—--—--—-——〈〈谢谢您使用学生信息管理系统〉>
———--—————-—-——----————-\n"
;
cout〈〈”******************************************************************************\n"
}
student*Information:
:
creat(void)//定义一个指向structstudent的结构体指针函数*creat()用来增加学生信息。
charch[20];
n=0;
p1=p2=(student*)malloc(LEN);
//调用malloc()函数用来开辟一个新的存储单元
cout〈〈”——-————-----—<
请建立学生考试信息表,在姓名处输入!
结束输入。
〉〉—-—-—--—-—-—-—"
〈<
endl;
姓名:
cin〉〉ch;
head=NULL;
//给指针head赋初值
while(strcmp(ch,”!
)!
=0)//调用字符比较函数strcmp()用来判断是否继续输入
{
charstr[10];
intflag=0;
p1=(student*)malloc(LEN);
strcpy(p1->
name,ch);
//将循环结构前面输入的姓名复制到结构体名为p1的数组name中
性别:
”;
cin〉〉p1—>
sex;
”院系:
;
cin〉〉str;
学号(9位):
do{
cin>
〉str;
if(atol(str)>
999999999||atol(str)〈1)
cout〈〈”对不起,请正确输入!
\n"
else
p1—〉id=atol(str);
flag=1;
}
}while(flag==0);
flag=0;
”语文成绩:
”;
do{
cin〉>
str;
if(atoi(str)>
100||atoi(str)〈1)
对不起,请输入1-100之间的数字!
!
p1—>
score[0]=atoi(str);
flag=1;
外语成绩:
do{
>
str;
if(atoi(str)〉100||atoi(str)〈1)
cout〈〈"
对不起,请输入1—100之间的数字!
\n”;
{p1-〉score[1]=atoi(str);
}
}while(flag==0);
cout〈〈”数学成绩:
100||atoi(str)<
1)
cout〈〈”对不起,请输入1-100之间的数字!
!
{p1-〉score[2]=atoi(str);
flag=0;
C++成绩:
if(atoi(str)〉100||atoi(str)<
cout〈〈”对不起,请输入1-100之间的数字!
{p1—>
score[3]=atoi(str);
}while(flag==0);
p1—〉total=p1—〉score[0]+p1->
score[1]+p1->
score[2]+p1->
score[3];
//计算总分
if(n==0)head=p1;
//如果是输入第一组学生考试信息就将指针p1赋给指针head
elsep2—〉next=p1;
//否则将p1赋给p2所指结构体的next指针
p2=p1;
//将指针p1赋给指针p2
n++;
//将n的值加1
姓名:
ch;
//将输入的姓名存放到字符数组ch中
p2—>
next=NULL;
//将p2所指结构体的next指针重新赋空值
return(head);
//将输入的第一组学生考试信息返回
voidInformation:
output(student*head)//定义output()函数将学生的信息从头指针所指内容开始输出
if(head==NULL)cout<
这是一个空表,请先输入考生成绩。
else{
cout<
〈”-—--—--—-—--———-——-—-—-———-———-—-———---————--—-----—--———-—-———--——---—-—---—-—\n”;
*学生成绩信息表*\n"
---——-—-—-——--—------------—----——---—-—--—---————--—-—--——-—----————-----——-—-\n"
学号姓名性别院系语文英语数学C++平均成绩总分\n”;
--——-————————-—--—--------—————---——---—--———----———--—---——---———--————-——---—\n"
p1=head;
//将头指针赋给p
do
setw(8)<
〈p1->
id
<
setw(9)〈〈p1—〉name
〈setw(8)〈<
sex
〈〈setw(13)〈<
score[0]
setw(16)〈<
p1—〉score[1]
〈〈setw(10)<
〈p1-〉score[2]
setw(9)<
〈p1—〉score[3]
setw(6)〈〈p1-〉total/4.0
〈setw(11)<
p1-〉total<
endl;
cout〈〈”-—————----——-——---—----—-———-—--——-—--———-———-——-—-—-—-———-——-—--—---——----——--\n"
p1=p1—>
next;
//将下一组学生信息的next指针赋给p
}while(p1!
=NULL);
//若指针p非空则继续,目的是把所有的学生信息都传给指针p然后输出。
//统计学生人数的函数
intInformation:
count(structstudent*head)//定义函数count()统计考生总数
if(head==NULL)//若指针head为空返回值为0
return(0);
elsereturn(1+count(head—〉next));
//函数的递归调用
//插入学生的成绩信息的函数
student*Information:
insert(student*head)//插入新结点定义一个指向structstudent的结构体指针函数*insert()用来添加考生信息.
charstr[10];
〈”\t—-——---———--—--—<
请输入新增学生成绩信息〉>
——--—-———----——-\n"
p1=(student*)malloc(LEN);
//使p1指向插入的新结点
name;
//将输入的姓名存放到结构体名为p1的数组name中
”性别:
p1—〉sex;
cout〈〈”学号(9位):
if(atol(str)〉99999999||atol(str)<
”对不起,请请正确输入!
\n”;
{p1—>
id=atol(str);
cout〈〈”语文成绩:
100||atoi(str)<
cout〈〈”对不起,请输入1—100之间的数字!
{p1->
score[0]=atoi(str);
{p1—〉score[1]=atoi(str);
数学成绩:
if(atoi(str)〉100||atoi(str)<
cout〈〈”对不起,请输入1—100之间的数字!
score[2]=atoi(str);
”C++成绩:
cin〉〉str;
对不起,请输入1-100之间的数字!
score[3]=atoi(str);
p1-〉total=p1—〉score[0]+p1-〉score[1]+p1—〉score[2]+p1—〉score[3];
p2=head;
//将头指针赋给p2
if(head==NULL)//若没调用次函数以前的头指针head为空
head=p1;
p1->
//则将p1赋给头指针head并将p1所指结构体成员指针next赋空值
while((p1-〉id〉p2->
id)&
&
(p2—>
next!
=NULL))
p3=p2;
//p3指向原p2指向的结点
p2=p2—〉next;
}//p2后移一个结点
if(p1—〉id〈=p2->
id)
if(head==p2)
p1—〉next=head;
head=p1;
}//插入到第一个结点之前
p3->
next=p1;
p1—〉next=p2;
}//插入到p3所指结点之后
p2—>
p1—>
}//插入到尾结点之后
n++;
//将学生人数加1
”\t你输入的学生信息已经成功插入”〈<
return(head);
//删除学生信息函数
cancel(student*head,longintnum)//定义一个指向structstudent的结构体指针函数*delete()用来删除考生信息。
if(head==NULL)//若调用次函数以前的头指针head为空
return(head);
else
p1=head;
//否则将头指针赋给p1
while(num!
=p1->
id&
next!
=NULL)//寻找要删除的结点当p1所指的学号不是输入的学号并且p1所指的next指针不为空
p1=p1—〉next;
//p2指向原p1指向的结点p1后移一个结点
}
if(num==p1->
id)//如果输入的学生准考证号是p1所指的学号结点找到后删除
if(p1==head)head=p1->
//如果head指针和p1指针相等则将下一个结点赋给指针head
p2-〉next=p1—>
next;
//否则将p1所指结点赋给p2所指结点将要删除的学生信息跳过去
删除学号为"
〈num<
〈”的学生\n"
n—-;
//将学生人数减1
return(head);
//将头指针返回
//查找学生信息函数
find(student*head,longintnum)//定义一个指向structstudent的结构体指针函数*find()用来查找学生信息.
if(head==NULL)//若调用次函数以前的头指针head为空
”这是一个空表,请先输入考生成绩。
while(num!
=p1—〉id&&p1—>
=NULL)
//寻找结点当p1所指的学号不是输入的学生学号并且p1所指的next指针不为空
p1=p1-〉next;
//p1后移一个结点
id)//如果要查找的学号是p1所指的学号
”—----—-———--———----—-—---—-——————-——---——--—-—----—-—-——--—-—--—————-———————-—\n”;
〈”学号姓名性别院系语文英语数学C++平均分总分\n”;
〈”—-———--———---————------————---———-----—-——-——-——--————-——-——-————————-------——\n”;
〈setw(8)〈〈p1—>
〈setw(9)<
p1—〉name
〈setw(8)<
〈〈setw(13)<
〈p1—>
〈<
setw(16)<
〈p1-〉score[1]
〈〈setw(10)〈<
p1—〉score[2]
〈p1-〉score[3]
setw(6)<
total/4.0
setw(11)〈<
total<
〈”-—--—-—------———————--———-————————-—-——----———-----—---------——-—————-—-—-———-\n"
没找到学号为"
〈〈num〈<
”的学生。
//结点没找到
voidInformation:
inorder(student*head)//定义inorder()函数将考生的总分从大到小排列并输出
inti,k,m=0,j;
student*p[20];
//定义一个指向structstudent的结构体指针数组p
if(head!
=NULL)//如果头指针是空则继续
{m=count(head);
cout〈〈”—--—--——————--—---—————-———--—-—--—---———--—----——--—-—--————---——-—---—--——--\n”;
学生成绩统计表\n”;
〈”-——-—————---————-—-—-——---———-——---—-—-——-—---——----——-—-----————----——-——-———\n"
学号姓名性别院系语文英语数学C++平均分总分名次\n"
-————-—-—--——--———-—————----—----————————--——---—--—-——----—--—--—--—-——-—---—\n"
for(k=0;
k〈m;
k++)
p[k]=p1;
k〈m—1;
k++)//选择排序法
for(j=k+1;
j〈m;
j++)
if(p[k]—>
total〈p[j]->
total)
p2=p[k];
p[k]=p[j];
p[j]=p2;
for(i=0;
i〈m;
i++)
setw(8)〈<
p1—〉id
〈setw(9)〈<
p1-〉name
〈〈setw(8)〈〈p1—〉sex
setw(13)〈<
p1—〉score[0]
〈〈setw(16)〈〈p1->
score[1]
setw(10)<
p1-〉score[2]
score[3]
setw(6)〈<
total/4。
0
〈〈setw(11)〈<
p1—〉total<
〈endl;
————--——--—-—————-—-—----——-—————----—--———-—-—--——-—--—-------——--——-—--—-—--\n”;
voidInformation:
average(student*head)//求各科平均成绩的函数
intk,m;
floatarg1=0,arg2=0,arg3=0,arg4=0;
if(head==NULL)//如果头指针是空则继续
这是一个空表,请先输入学生成绩.\n"
m=count(head);
k〈m;
arg1+=p1->
score[0];
arg2+=p1—〉score[1];
arg3+=p1->
score[2];
arg4+=p1-〉score[3];
arg1/=m;
arg2/=m;
arg3/=m;
arg4/=m;
〈”全班单科成绩平均分\n”;
—--—--—-———--—-—-——-——-——-—-—————-——-——---—---—-—-—--—-——-—--———————————-———-—\n”;
co