
一个TURBO C的C语言编程,求高手
程序名称:学生成绩处理要求程序可接收10个学生的学号、某门课程平时、期末考试的成绩,按平时40%、期末60%计算总评成绩并输出,可对成绩按高分到低分排序,可对学生总评成绩...
程序名称:学生成绩处理
要求程序可接收10个学生的学号、某门课程平时、期末考试的成绩,按平时40%、期末60%计算总评成绩并输出,可对成绩按高分到低分排序,可对学生总评成绩按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)和不及格(0-59)进行统计,可按学号进行成绩查询等。
程序设计方案:
进入程序首先给出功能选择,用户通过功能选择,完成相应操作;
主函数给出功能选择界面,各具体功能分别设计成独立函数;
设计模拟数据进行测试
-------------------------------
我知道编出来程序会比较长,所以麻烦各位在旁边适当的加注释说明下啊,万分感激,详细和清晰的我采纳为答案同时加分!
要求程序可接收3个学生的学号、某门课程平时、期末考试的成绩,按平时40%、期末60%计算总评成绩并输出,可对成绩按高分到低分排序,可对学生总评成绩按优秀(60-100)、和不及格(0-59)进行统计,可按学号进行成绩查询等。
----------------------
嗯我也觉得很多所以大家只要做个这样简单一些的就可以了
让我了解一下结构就可以了 展开
要求程序可接收10个学生的学号、某门课程平时、期末考试的成绩,按平时40%、期末60%计算总评成绩并输出,可对成绩按高分到低分排序,可对学生总评成绩按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)和不及格(0-59)进行统计,可按学号进行成绩查询等。
程序设计方案:
进入程序首先给出功能选择,用户通过功能选择,完成相应操作;
主函数给出功能选择界面,各具体功能分别设计成独立函数;
设计模拟数据进行测试
-------------------------------
我知道编出来程序会比较长,所以麻烦各位在旁边适当的加注释说明下啊,万分感激,详细和清晰的我采纳为答案同时加分!
要求程序可接收3个学生的学号、某门课程平时、期末考试的成绩,按平时40%、期末60%计算总评成绩并输出,可对成绩按高分到低分排序,可对学生总评成绩按优秀(60-100)、和不及格(0-59)进行统计,可按学号进行成绩查询等。
----------------------
嗯我也觉得很多所以大家只要做个这样简单一些的就可以了
让我了解一下结构就可以了 展开
8个回答
展开全部
拿去改改吧 程序是没有问题的 调试通过
我前几天刚做的 有问题可以随时问我
这个是用链表做的
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#define LEN sizeof(struct student)
struct student
{
char xh[12]; //学号 主键
char xm[12]; //姓名
int sxcj; //数学成绩
int cxsj; //程序设计成绩
int zf; //总分
struct student *next; //指向下条记录
struct student *prev; //指向上条记录
};
struct student *head=NULL; //链表头指针,定义为全局变量
struct student *tail=NULL; //链表尾指针,定义为全局变量
struct student *current=NULL; //链表结点指针,定义为全局变量
int nodes; //接点数
void orderprint()
{
struct student *p;
p=head;
if(head==NULL)
{
printf("\n没有记录!");
}
else
{
printf("\n");
do
{
printf("%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
p=p->next;
}
while(p!=NULL);
}
}
void order(int tag)
{ void save(int); //save函数申明
int i,min,nodes1=0;
struct student *head1,*tail1,*p;
if(head==NULL)
{
printf("\n没有找到记录!\n");
}
else
{
for(i=0;i<nodes;i++)
{
p=head;
current=NULL;
if(tag==1)
{
min=p->sxcj;
do
{
if(p->sxcj<=min)
{
min=p->sxcj;
current=p;
}
p=p->next;
}
while(p!=NULL);
}
if(tag==2)
{
min=p->cxsj;
do
{
if(p->cxsj<=min)
{
min=p->cxsj;
current=p;
}
p=p->next;
}
while(p!=NULL);
}
if(tag==3)
{
min=p->zf;
do
{
if(p->zf<=min)
{
min=p->zf;
current=p;
}
p=p->next;
}
while(p!=NULL);
}
if(current==head) //老链表中去掉该节点
{
head=head->next;
if(head!=NULL)
{
head->prev=NULL;
}
}
else if(current==tail)
{
tail=tail->prev;
tail->next=NULL;
}
else
{
(current->prev)->next=current->next;
(current->next)->prev=current->prev;
}
if(nodes1==0) //插入新的链表
{
head1=current;
tail1=current;
current->prev=NULL;
current->next=NULL;
nodes1+=1;
}
else
{
current->prev=tail1;
tail1->next=current;
tail1=current;
tail1->next=NULL;
nodes1+=1;
}
}
}
head=head1;
tail=tail1;
nodes=nodes1;
head1=NULL;
tail1=NULL;
current=NULL;
orderprint();
}
void save(int tag) //记录存入数据库
{
int i;
struct student *p;
FILE *fp;
if(tag==1)
{
fp=fopen("sxcj.txt","w");
}
if(tag==2)
{
fp=fopen("cxsj.txt","w");
}
if(tag==3)
{
fp=fopen("zf.txt","w");
}
if(tag==7)
{
fp=fopen("students.txt","w");
}
p=head;
if(fp==NULL)
{
printf("\n\n保存失败!\n");
}
else
{
do
{
if(fwrite(p,LEN,1,fp)!=1)
{
printf("file write error\n");
}
p=p->next;
}
while(p!=NULL);
}
fclose(fp);
fp=fopen("nodes.txt","w");
if(fp==NULL)
{
printf("\n\n节点数保存失败!\n");
}
else
{
fprintf(fp,"%d",nodes);
}
fclose(fp);
current=NULL;
}
int select(struct student *p1) //查询
{
struct student *p;
p=head;
current=NULL;
if(p==NULL)
{
return 1;
}
else
{
do
{
if(strcmp(p->xh,p1->xh)==0)
{
current=p; //记录符合记录的位置
return 0;
}
p=p->next;
}
while(p!=NULL);
return 1;
}
}
void selectbyxh() //学号查询
{
struct student *p;
p=(struct student * )malloc(LEN);
printf("\n请输入需要查找的学生的学号:");
scanf("%s",p->xh);
if(select(p))
{
printf("\n未找到该学生的信息!");
}
else
{
printf("\n%12s%12s%4d%4d%4d\n",current->xh,current->xm,current->sxcj,current->cxsj,current->zf);
}
}
void selectbyxm() //姓名查询
{
struct student *p,*p1;
p1=(struct student * )malloc(LEN);
printf("\n请输入需要查找的学生的姓名:");
scanf("%s",p1->xm);
p=head;
current=NULL;
if(p==NULL)
{
printf("\n未找到记录!\n");
}
else
{
do
{
if(strcmp(p->xm,p1->xm)==0)
{
current=p; //记录查找到的位置
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
}
p=p->next;
}
while(p!=NULL);
}
}
void selectbysxcj() //数学成绩查询
{
struct student *p,*p1;
p1=(struct student * )malloc(LEN);
printf("\n请输入数学成绩:");
scanf("%d",&p1->sxcj);
p=head;
if(p==NULL)
{
printf("\n未找到成绩大于%d的同学!\n",p1->sxcj);
}
else
{
do
{
if(p->sxcj>=p1->sxcj)
{
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
}
p=p->next;
}
while(p!=NULL);
}
}
void selectbycxsj() //程序设计成绩查询
{
struct student *p;
struct student *p1;
p1=(struct student *)malloc(LEN);
printf("\n请输入程序设计成绩:\n");
scanf("%d",&(p1->cxsj));
p=head;
if(p==NULL)
{
printf("\n未找到成绩大于%d的同学!\n",p1->cxsj);
}
else
{
do
{
if(p->cxsj>=p1->cxsj)
{
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
}
p=p->next;
}
while(p!=NULL);
}
}
void selectbyzf() //总分查询
{
struct student *p;
struct student *p1;
int tag=0; //标记
p1=(struct student * )malloc(LEN);
printf("\n请输入总分:");
scanf("%d",&p1->zf);
p=head;
if(p==NULL)
{
printf("\n未找到总分大于等于%d的同学!\n",p1->zf);
}
else
{
do
{
if(p->zf>=p1->zf)
{
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
tag=1; //修改标记
}
p=p->next;
}
while(p!=NULL);
if(tag==0)
{
printf("\n未找到总分大于等于%d的同学!\n",p1->zf);
}
}
}
void addstudent() //添加学生
{
struct student *p;
printf("\n请按照:学号 姓名 数学成绩 程序设计成绩 结束请输入0!\n");
p=(struct student * )malloc(LEN);
scanf("%s%s%d%d",p->xh,p->xm,&(p->sxcj),&(p->cxsj));
(p->zf)=(p->sxcj)+(p->cxsj);
if(nodes==0)
{
head=p;
tail=p;
p->prev=NULL;
p->next=NULL;
nodes+=1;
}
else
{
if(select(p))
{
p->prev=tail;
tail->next=p;
tail=p;
tail->next=NULL;
nodes+=1;
}
else
{
printf("\n请不重复录入学号为");
puts(p->xh);
printf("学生的成绩!\n");
}
}
}
void delstudent() //删除记录
{
struct student *p;
current=NULL;
p=(struct student * )malloc(LEN);
printf("\n请输入需要删除的学生的学号:");
scanf("%s",p->xh);
if(select(p))
{
printf("\n\n数据库中未找到该学生资料!\n");
}
else
{
if(current==head) //在链表表头找到学生
{
head=current->next;
if(head!=NULL)
{
head->prev=NULL;
}
free(current);
printf("\n删除成功!\n");
orderprint();
}
else if(current==tail) //在链表表尾找到学生
{
tail=current->prev;
tail->next=NULL;
free(current);
printf("\n删除成功!\n");
orderprint();
}
else
{
(current->prev)->next=current->next;
(current->next)->prev=current->prev;
free(current);
printf("\n删除成功!\n");
orderprint();
}
nodes-=1;
}
current=NULL;
}
void creatnewlist()
{
int goon=1;
nodes=0;
while(1)
{
if(goon)
{
addstudent();
printf("\n继续输入请按1、输入完成请按0:\n");
scanf("%d",&goon);
}
else
{
break;
}
}
}
void main()
{
int menu; //1级菜单
int menu1; //2级菜单
int menu2; //2级菜单
while(1)
{
printf("\n1.新建数据 2.添加数据 3.删除数据 4.查看记录 5.排序 6查询 7.退出\n");
printf("\n请选择:");
scanf("%d",&menu);
if(menu==1)
{
creatnewlist();
}
else if(menu==2)
{
addstudent();
}
else if(menu==3)
{
delstudent();
}
else if(menu==4)
{
orderprint();
}
else if(menu==5)
{
while(1)
{
printf("\n1.数学成绩排序 2.程序设计成绩排序 3.总分排序。4.返回主菜单\n");
printf("\n请选择:\n");
scanf("%d",&menu1);
if(menu1==1)
{
order(menu1);
}
else if(menu1==2)
{
order(menu1);
}
else if(menu1==3)
{
order(menu1);
}
else if(menu1==4)
{
break;
}
}
}
else if(menu==6)
{
while(1)
{
printf("\n1.按学号查询 2.按姓名查询 3.按数学成绩查询。4.按程序设计成绩查询 5.按总分查询 6.返回主菜单\n");
printf("\n请选择查询方式:\n");
scanf("%d",&menu2);
if(menu2==1)
{
selectbyxh();
}
else if(menu2==2)
{
selectbyxm();
}
else if(menu2==3)
{
selectbysxcj();
}
else if(menu2==4)
{
selectbycxsj();
}
else if(menu2==5)
{
selectbyzf();
}
else if(menu2==6)
{
break;
}
}
}
else if(menu==7)
{
exit(0);
}
else
{
printf("\n请重新选择:\n");
}
}
}
我前几天刚做的 有问题可以随时问我
这个是用链表做的
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#define LEN sizeof(struct student)
struct student
{
char xh[12]; //学号 主键
char xm[12]; //姓名
int sxcj; //数学成绩
int cxsj; //程序设计成绩
int zf; //总分
struct student *next; //指向下条记录
struct student *prev; //指向上条记录
};
struct student *head=NULL; //链表头指针,定义为全局变量
struct student *tail=NULL; //链表尾指针,定义为全局变量
struct student *current=NULL; //链表结点指针,定义为全局变量
int nodes; //接点数
void orderprint()
{
struct student *p;
p=head;
if(head==NULL)
{
printf("\n没有记录!");
}
else
{
printf("\n");
do
{
printf("%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
p=p->next;
}
while(p!=NULL);
}
}
void order(int tag)
{ void save(int); //save函数申明
int i,min,nodes1=0;
struct student *head1,*tail1,*p;
if(head==NULL)
{
printf("\n没有找到记录!\n");
}
else
{
for(i=0;i<nodes;i++)
{
p=head;
current=NULL;
if(tag==1)
{
min=p->sxcj;
do
{
if(p->sxcj<=min)
{
min=p->sxcj;
current=p;
}
p=p->next;
}
while(p!=NULL);
}
if(tag==2)
{
min=p->cxsj;
do
{
if(p->cxsj<=min)
{
min=p->cxsj;
current=p;
}
p=p->next;
}
while(p!=NULL);
}
if(tag==3)
{
min=p->zf;
do
{
if(p->zf<=min)
{
min=p->zf;
current=p;
}
p=p->next;
}
while(p!=NULL);
}
if(current==head) //老链表中去掉该节点
{
head=head->next;
if(head!=NULL)
{
head->prev=NULL;
}
}
else if(current==tail)
{
tail=tail->prev;
tail->next=NULL;
}
else
{
(current->prev)->next=current->next;
(current->next)->prev=current->prev;
}
if(nodes1==0) //插入新的链表
{
head1=current;
tail1=current;
current->prev=NULL;
current->next=NULL;
nodes1+=1;
}
else
{
current->prev=tail1;
tail1->next=current;
tail1=current;
tail1->next=NULL;
nodes1+=1;
}
}
}
head=head1;
tail=tail1;
nodes=nodes1;
head1=NULL;
tail1=NULL;
current=NULL;
orderprint();
}
void save(int tag) //记录存入数据库
{
int i;
struct student *p;
FILE *fp;
if(tag==1)
{
fp=fopen("sxcj.txt","w");
}
if(tag==2)
{
fp=fopen("cxsj.txt","w");
}
if(tag==3)
{
fp=fopen("zf.txt","w");
}
if(tag==7)
{
fp=fopen("students.txt","w");
}
p=head;
if(fp==NULL)
{
printf("\n\n保存失败!\n");
}
else
{
do
{
if(fwrite(p,LEN,1,fp)!=1)
{
printf("file write error\n");
}
p=p->next;
}
while(p!=NULL);
}
fclose(fp);
fp=fopen("nodes.txt","w");
if(fp==NULL)
{
printf("\n\n节点数保存失败!\n");
}
else
{
fprintf(fp,"%d",nodes);
}
fclose(fp);
current=NULL;
}
int select(struct student *p1) //查询
{
struct student *p;
p=head;
current=NULL;
if(p==NULL)
{
return 1;
}
else
{
do
{
if(strcmp(p->xh,p1->xh)==0)
{
current=p; //记录符合记录的位置
return 0;
}
p=p->next;
}
while(p!=NULL);
return 1;
}
}
void selectbyxh() //学号查询
{
struct student *p;
p=(struct student * )malloc(LEN);
printf("\n请输入需要查找的学生的学号:");
scanf("%s",p->xh);
if(select(p))
{
printf("\n未找到该学生的信息!");
}
else
{
printf("\n%12s%12s%4d%4d%4d\n",current->xh,current->xm,current->sxcj,current->cxsj,current->zf);
}
}
void selectbyxm() //姓名查询
{
struct student *p,*p1;
p1=(struct student * )malloc(LEN);
printf("\n请输入需要查找的学生的姓名:");
scanf("%s",p1->xm);
p=head;
current=NULL;
if(p==NULL)
{
printf("\n未找到记录!\n");
}
else
{
do
{
if(strcmp(p->xm,p1->xm)==0)
{
current=p; //记录查找到的位置
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
}
p=p->next;
}
while(p!=NULL);
}
}
void selectbysxcj() //数学成绩查询
{
struct student *p,*p1;
p1=(struct student * )malloc(LEN);
printf("\n请输入数学成绩:");
scanf("%d",&p1->sxcj);
p=head;
if(p==NULL)
{
printf("\n未找到成绩大于%d的同学!\n",p1->sxcj);
}
else
{
do
{
if(p->sxcj>=p1->sxcj)
{
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
}
p=p->next;
}
while(p!=NULL);
}
}
void selectbycxsj() //程序设计成绩查询
{
struct student *p;
struct student *p1;
p1=(struct student *)malloc(LEN);
printf("\n请输入程序设计成绩:\n");
scanf("%d",&(p1->cxsj));
p=head;
if(p==NULL)
{
printf("\n未找到成绩大于%d的同学!\n",p1->cxsj);
}
else
{
do
{
if(p->cxsj>=p1->cxsj)
{
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
}
p=p->next;
}
while(p!=NULL);
}
}
void selectbyzf() //总分查询
{
struct student *p;
struct student *p1;
int tag=0; //标记
p1=(struct student * )malloc(LEN);
printf("\n请输入总分:");
scanf("%d",&p1->zf);
p=head;
if(p==NULL)
{
printf("\n未找到总分大于等于%d的同学!\n",p1->zf);
}
else
{
do
{
if(p->zf>=p1->zf)
{
printf("\n%12s%12s%4d%4d%4d\n",p->xh,p->xm,p->sxcj,p->cxsj,p->zf);
tag=1; //修改标记
}
p=p->next;
}
while(p!=NULL);
if(tag==0)
{
printf("\n未找到总分大于等于%d的同学!\n",p1->zf);
}
}
}
void addstudent() //添加学生
{
struct student *p;
printf("\n请按照:学号 姓名 数学成绩 程序设计成绩 结束请输入0!\n");
p=(struct student * )malloc(LEN);
scanf("%s%s%d%d",p->xh,p->xm,&(p->sxcj),&(p->cxsj));
(p->zf)=(p->sxcj)+(p->cxsj);
if(nodes==0)
{
head=p;
tail=p;
p->prev=NULL;
p->next=NULL;
nodes+=1;
}
else
{
if(select(p))
{
p->prev=tail;
tail->next=p;
tail=p;
tail->next=NULL;
nodes+=1;
}
else
{
printf("\n请不重复录入学号为");
puts(p->xh);
printf("学生的成绩!\n");
}
}
}
void delstudent() //删除记录
{
struct student *p;
current=NULL;
p=(struct student * )malloc(LEN);
printf("\n请输入需要删除的学生的学号:");
scanf("%s",p->xh);
if(select(p))
{
printf("\n\n数据库中未找到该学生资料!\n");
}
else
{
if(current==head) //在链表表头找到学生
{
head=current->next;
if(head!=NULL)
{
head->prev=NULL;
}
free(current);
printf("\n删除成功!\n");
orderprint();
}
else if(current==tail) //在链表表尾找到学生
{
tail=current->prev;
tail->next=NULL;
free(current);
printf("\n删除成功!\n");
orderprint();
}
else
{
(current->prev)->next=current->next;
(current->next)->prev=current->prev;
free(current);
printf("\n删除成功!\n");
orderprint();
}
nodes-=1;
}
current=NULL;
}
void creatnewlist()
{
int goon=1;
nodes=0;
while(1)
{
if(goon)
{
addstudent();
printf("\n继续输入请按1、输入完成请按0:\n");
scanf("%d",&goon);
}
else
{
break;
}
}
}
void main()
{
int menu; //1级菜单
int menu1; //2级菜单
int menu2; //2级菜单
while(1)
{
printf("\n1.新建数据 2.添加数据 3.删除数据 4.查看记录 5.排序 6查询 7.退出\n");
printf("\n请选择:");
scanf("%d",&menu);
if(menu==1)
{
creatnewlist();
}
else if(menu==2)
{
addstudent();
}
else if(menu==3)
{
delstudent();
}
else if(menu==4)
{
orderprint();
}
else if(menu==5)
{
while(1)
{
printf("\n1.数学成绩排序 2.程序设计成绩排序 3.总分排序。4.返回主菜单\n");
printf("\n请选择:\n");
scanf("%d",&menu1);
if(menu1==1)
{
order(menu1);
}
else if(menu1==2)
{
order(menu1);
}
else if(menu1==3)
{
order(menu1);
}
else if(menu1==4)
{
break;
}
}
}
else if(menu==6)
{
while(1)
{
printf("\n1.按学号查询 2.按姓名查询 3.按数学成绩查询。4.按程序设计成绩查询 5.按总分查询 6.返回主菜单\n");
printf("\n请选择查询方式:\n");
scanf("%d",&menu2);
if(menu2==1)
{
selectbyxh();
}
else if(menu2==2)
{
selectbyxm();
}
else if(menu2==3)
{
selectbysxcj();
}
else if(menu2==4)
{
selectbycxsj();
}
else if(menu2==5)
{
selectbyzf();
}
else if(menu2==6)
{
break;
}
}
}
else if(menu==7)
{
exit(0);
}
else
{
printf("\n请重新选择:\n");
}
}
}
展开全部
这个程序思路很清晰
我给你说说算法:
1.结构体来存放学生信息(包括学号 课程的平时,期末,以及总成绩)
2.编写输入输出函数 以及排序函数 还有查询函数
我给你说说算法:
1.结构体来存放学生信息(包括学号 课程的平时,期末,以及总成绩)
2.编写输入输出函数 以及排序函数 还有查询函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
同意一楼的说法,不是为了分来的,
给你提供个参考列子,自己慢慢的看懂并修改
// 学生成绩管理系统.cpp : Defines the entry point for the console application.
//
//#include <stdafx.h>
#include <stdio.h>
#include <malloc.h>
#include <iostream>
#include <string>
#define NULL 0
#define LEN sizeof(struct student)
using namespace std;
struct student
{
int num;
char name[256];
int china;
int english;
int math;
struct student*next;
};
int n;
struct student *creat_list()
{
struct student*p1,*p2,*head;
n=0;
p1=p2=(struct student*)malloc(LEN);
cout<<"please input number:"<<endl;
cin>>p1->num;
cout<<"please input name,china,english and math:"<<endl;
cin>>p1->name>>p1->china>>p1->english>>p1->math;
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
cout<<"please input number:"<<endl;
cin>>p1->num;
if(p1->num==0)break;
cout<<"please input name,china,english and math:"<<endl;
cin>>p1->name>>p1->china>>p1->english>>p1->math;
}
p2->next=NULL;
return(head);
}
void print_list(struct student*head)
{
struct student*p;
p=head;
if(head!=NULL)
do
{
cout<<p->num<<" "<<p->name<<" "<<p->china<<" "<<p->english<<" "<<p->math<<endl;
p=p->next;
}
while(p!=NULL);
}
void search_list(int key1,struct student*head)
{
struct student*p;
p=head;
while(p!=NULL)
{
if(p->num==key1)
{
cout<<p->num<<" "<<p->name<<" "<<p->china<<" "<<p->english<<" "<<p->math<<endl;
}
p=p->next;
}
}
struct student* delete_list(int key2,struct student*head)
{
struct student*p1,*p2;
//if(head==NULL) break;
p1=head;
while(key2!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(key2==p1->num)
{
if(p1==head)
{
head=p1->next;
}
else
{
p2->next=p1->next;
}
cout<<"delete:"<<key2<<endl;
n=n-1;
}
else cout<<key2<<"not be found!"<<endl;
return(head);
}
struct student* modefy_list(int key3,struct student*head)
{
struct student*p1,*p2;
p1=head;
while(key3!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
int choose;
cout<<"enter 0 exit modify."<<endl;
cout<<"enter 1 modefy name."<<endl;
cout<<"enter 2 modefy china."<<endl;
cout<<"enter 3 modefy english."<<endl;
cout<<"enter 4 modefy math."<<endl;
cout<<"enter 5 modefy number."<<endl;
cin>>choose;
switch(choose)
{
case 1:
cout<<"please input name:"<<endl;
cin>>p1->name;break;
case 2:
cout<<"please input china:"<<endl;
cin>>p1->china;break;
case 3:
cout<<"please input english:"<<endl;
cin>>p1->english;break;
case 4:
cout<<"please input math:"<<endl;
cin>>p1->math;break;
case 5:
cout<<"please input number:"<<endl;
cin>>p1->num;break;
}
return(head);
}
struct student*insert_list(int key4,struct student*head,struct student*New)
{
struct student*p;
p=head;
while(1)
{
if(p==NULL)
{
New->next=head;
head=New;
break;
}
if(p->num==key4)
{
New->next=p->next;
p->next=New;
break;
}
p=p->next;
}
return(head);
}
void average_score(struct student*head)
{
struct student*p;
int pchina=0,ppchina;
int penglish=0,ppenglish;
int pmath=0,ppmath;
int count=0;
p=head;
while(1)
{
pchina=pchina+p->china;
penglish=penglish+p->english;
pmath=pmath+p->math;
count=++count;
if(p->next==NULL)break;
p=p->next;
}
ppchina=pchina/count;
ppenglish=penglish/count;
ppmath=pmath/count;
cout<<"The average of china:"<<ppchina<<endl;
cout<<"The average of english:"<<ppenglish<<endl;
cout<<"The average of math:"<<ppmath<<endl;
}
void main()
{
for(;;)
{
struct student*head;
struct student*New;
int key;
int keynum;
cout<<"0>exit the programm."<<endl;
cout<<"1>creat list."<<endl;
cout<<"2>search list."<<endl;
cout<<"3>delete list."<<endl;
cout<<"4>modefy list."<<endl;
cout<<"5>insert list."<<endl;
cout<<"6>average score."<<endl;
cout<<"7>print chengji."<<endl;
cin>>key;
switch(key)
{
case 0:
exit(0);break;
case 1:
head=creat_list();break;
case 2:
cout<<"please input 0 Exit."<<endl;
cout<<"please input number for search."<<endl;
cin>>keynum;
if(keynum==0)break;
search_list(keynum,head);break;
case 3:
cout<<"please input 0 exit"<<endl;
cout<<"please input number for delete:"<<endl;
cin>>keynum;
if(keynum==0)break;
head=delete_list(keynum,head);break;
case 4:
cout<<"please input 0 exit."<<endl;
cout<<"please input number for modefy:"<<endl;
cin>>keynum;
if(keynum==0)break;
head=modefy_list(keynum,head);
print_list(head);break;
case 5:
if(head!=NULL)
{
New=(struct student*)malloc(LEN);
cout<<"please input number:"<<endl;
cin>>New->num;
if(New->num==0)break;
cout<<"please input name:"<<endl;
cin>>New->name;
cout<<"please input china:"<<endl;
cin>>New->china;
cout<<"please input english:"<<endl;
cin>>New->english;
cout<<"please input math:"<<endl;
cin>>New->math;
cout<<"please input the data number for insert:"<<endl;
cin>>keynum;
head=insert_list(keynum,head,New);
if(head!=NULL) print_list(head);
}break;
case 6:
average_score(head);break;
case 7:
print_list(head);break;
}
}
}
给你提供个参考列子,自己慢慢的看懂并修改
// 学生成绩管理系统.cpp : Defines the entry point for the console application.
//
//#include <stdafx.h>
#include <stdio.h>
#include <malloc.h>
#include <iostream>
#include <string>
#define NULL 0
#define LEN sizeof(struct student)
using namespace std;
struct student
{
int num;
char name[256];
int china;
int english;
int math;
struct student*next;
};
int n;
struct student *creat_list()
{
struct student*p1,*p2,*head;
n=0;
p1=p2=(struct student*)malloc(LEN);
cout<<"please input number:"<<endl;
cin>>p1->num;
cout<<"please input name,china,english and math:"<<endl;
cin>>p1->name>>p1->china>>p1->english>>p1->math;
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
cout<<"please input number:"<<endl;
cin>>p1->num;
if(p1->num==0)break;
cout<<"please input name,china,english and math:"<<endl;
cin>>p1->name>>p1->china>>p1->english>>p1->math;
}
p2->next=NULL;
return(head);
}
void print_list(struct student*head)
{
struct student*p;
p=head;
if(head!=NULL)
do
{
cout<<p->num<<" "<<p->name<<" "<<p->china<<" "<<p->english<<" "<<p->math<<endl;
p=p->next;
}
while(p!=NULL);
}
void search_list(int key1,struct student*head)
{
struct student*p;
p=head;
while(p!=NULL)
{
if(p->num==key1)
{
cout<<p->num<<" "<<p->name<<" "<<p->china<<" "<<p->english<<" "<<p->math<<endl;
}
p=p->next;
}
}
struct student* delete_list(int key2,struct student*head)
{
struct student*p1,*p2;
//if(head==NULL) break;
p1=head;
while(key2!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(key2==p1->num)
{
if(p1==head)
{
head=p1->next;
}
else
{
p2->next=p1->next;
}
cout<<"delete:"<<key2<<endl;
n=n-1;
}
else cout<<key2<<"not be found!"<<endl;
return(head);
}
struct student* modefy_list(int key3,struct student*head)
{
struct student*p1,*p2;
p1=head;
while(key3!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
int choose;
cout<<"enter 0 exit modify."<<endl;
cout<<"enter 1 modefy name."<<endl;
cout<<"enter 2 modefy china."<<endl;
cout<<"enter 3 modefy english."<<endl;
cout<<"enter 4 modefy math."<<endl;
cout<<"enter 5 modefy number."<<endl;
cin>>choose;
switch(choose)
{
case 1:
cout<<"please input name:"<<endl;
cin>>p1->name;break;
case 2:
cout<<"please input china:"<<endl;
cin>>p1->china;break;
case 3:
cout<<"please input english:"<<endl;
cin>>p1->english;break;
case 4:
cout<<"please input math:"<<endl;
cin>>p1->math;break;
case 5:
cout<<"please input number:"<<endl;
cin>>p1->num;break;
}
return(head);
}
struct student*insert_list(int key4,struct student*head,struct student*New)
{
struct student*p;
p=head;
while(1)
{
if(p==NULL)
{
New->next=head;
head=New;
break;
}
if(p->num==key4)
{
New->next=p->next;
p->next=New;
break;
}
p=p->next;
}
return(head);
}
void average_score(struct student*head)
{
struct student*p;
int pchina=0,ppchina;
int penglish=0,ppenglish;
int pmath=0,ppmath;
int count=0;
p=head;
while(1)
{
pchina=pchina+p->china;
penglish=penglish+p->english;
pmath=pmath+p->math;
count=++count;
if(p->next==NULL)break;
p=p->next;
}
ppchina=pchina/count;
ppenglish=penglish/count;
ppmath=pmath/count;
cout<<"The average of china:"<<ppchina<<endl;
cout<<"The average of english:"<<ppenglish<<endl;
cout<<"The average of math:"<<ppmath<<endl;
}
void main()
{
for(;;)
{
struct student*head;
struct student*New;
int key;
int keynum;
cout<<"0>exit the programm."<<endl;
cout<<"1>creat list."<<endl;
cout<<"2>search list."<<endl;
cout<<"3>delete list."<<endl;
cout<<"4>modefy list."<<endl;
cout<<"5>insert list."<<endl;
cout<<"6>average score."<<endl;
cout<<"7>print chengji."<<endl;
cin>>key;
switch(key)
{
case 0:
exit(0);break;
case 1:
head=creat_list();break;
case 2:
cout<<"please input 0 Exit."<<endl;
cout<<"please input number for search."<<endl;
cin>>keynum;
if(keynum==0)break;
search_list(keynum,head);break;
case 3:
cout<<"please input 0 exit"<<endl;
cout<<"please input number for delete:"<<endl;
cin>>keynum;
if(keynum==0)break;
head=delete_list(keynum,head);break;
case 4:
cout<<"please input 0 exit."<<endl;
cout<<"please input number for modefy:"<<endl;
cin>>keynum;
if(keynum==0)break;
head=modefy_list(keynum,head);
print_list(head);break;
case 5:
if(head!=NULL)
{
New=(struct student*)malloc(LEN);
cout<<"please input number:"<<endl;
cin>>New->num;
if(New->num==0)break;
cout<<"please input name:"<<endl;
cin>>New->name;
cout<<"please input china:"<<endl;
cin>>New->china;
cout<<"please input english:"<<endl;
cin>>New->english;
cout<<"please input math:"<<endl;
cin>>New->math;
cout<<"please input the data number for insert:"<<endl;
cin>>keynum;
head=insert_list(keynum,head,New);
if(head!=NULL) print_list(head);
}break;
case 6:
average_score(head);break;
case 7:
print_list(head);break;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分好多啊。我还是不做了。估计够我搞半天的了。呵呵。。好象书上有这个题目啊。你仔细看看应该可以会的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哈哈,跟我们学C语言的时候题目一样啊 ,能不能再具体点儿,几门课程呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
大家不是为分来的,
希望你能自己努力学好编程。
希望你能自己努力学好编程。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询