编制一个C语言成绩记录簿,要求每个学生信息包括:学号、姓名、C语言成绩。具体功能: (1)创建信息

编制一个C语言成绩记录簿,要求每个学生信息包括:学号、姓名、C语言成绩。具体功能:
(1)创建信息链表并以磁盘文件保存;
(2)读取磁盘文件并显示输出所有学生的成绩;
(3)按学号或姓名查询成绩;
(4)添加成绩记录;
(5)修改指定姓名或学号的学生的成绩并可存盘;
(6)显示输出60分以下、60~79、80~89、90分以上各分数段的学生信息(可选项)

#include<iostream> #include<cstdlib> #include<cstddef> #include<string> #include<iomanip> #include<fstream> using namespace std; struct xueshengguanli { string name; string xibie; string banbie; string sex; int num; float zongheCJ; xueshengguanli *next; }; typedef xueshengguanli* xueshengGL; xueshengGL Input(xueshengGL head) { char SEL='y'; int m=0; xueshengGL p1,p2,top; ofstream out_stream; out_stream.open("student.txt",ios::app); //以追加数据信息打开文件 if(out_stream.fail()) { cout<<"打开文件失败.\n"; exit(1); } while(SEL=='y'||SEL=='Y') { p1=new xueshengguanli; p1->next=NULL; cout<<"\n请输入你的姓名:"; cin>>p1->name; cout<<"\n请输入你的学号:"; cin>>p1->num; cout<<"\n请输入你的性别(男/女):"; cin>>p1->sex; cout<<"\n请输入你的系别:"; cin>>p1->xibie; cout<<"\n请输入你的班别:"; cin>>p1->banbie; cout<<"\n请输入你的综合成绩:"; cin>>p1->zongheCJ; if(m==0) { head=p1; p2=head; m=1; } else { p2->next=p1; p2=p1; } cout<<"\n是否继续输入?(y/n)\n"; //判断是否继续输入 cin>>SEL; } top=head; //写入文件 while(head!=NULL) { out_stream<<head->name<<" "<<head->num<<"\t"<<head->sex<<"\t"<<head->xibie <<"\t"<<head->banbie<<"\t"<<head->zongheCJ; head=head->next; } out_stream.close(); //关闭文件 if(SEL=='n'||SEL=='N') cout<<"输入完毕.\n"; return top; //返回链表头结点地址 } //从文件里读取数据 xueshengGL WenJian(xueshengGL top) { int n=0; xueshengGL p,h; ifstream in_stream; in_stream.open("student.txt"); if(in_stream.fail()) { cout<<"打开文件失败.\n"; return 0; } while(1) { if(in_stream.eof()) break; else {p=new xueshengguanli; p->next=NULL; in_stream>>p->name>>p->num>>p->sex>>p->xibie>>p->banbie>>p->zongheCJ; if(n==0) { top=p; h=top; n=1; } else { h->next=p; h=p; } } } in_stream.close(); return top; } void xuanzhe(xueshengGL top) { int h; while(h<1||h>3) { cout<<"\n请输入你要修改的项:"; cin>>h; if(h==1) { cout<<"\n请输入新的系别:"; cin>>top->xibie; break; } else if(h==2) { cout<<"\n请输入新的班别:"; cin>>top->banbie; break; } else if(h==3) { cout<<"\n请输入新的综合成绩:"; cin>>top->zongheCJ; break; } else cout<<"\n输入错误!请重输!\n"; } } //修改 xueshengGL Change(xueshengGL top) { string NAME; int NUM,l=0; char SEL='y'; xueshengGL q,head; cout<<"\n请输入修改人的姓名:"; cin>>NAME; cout<<"\n请输入修改人的学号:"; cin>>NUM; top=WenJian(top); q=top; while(top!=NULL) { if(top->name==NAME&&top->num==NUM) { l=1; while(SEL=='y'||SEL=='Y') { cout<<"\n1系别 2班别 3综合成绩\n"; xuanzhe(top); cout<<"\n这是修改后的学生信息:\n"; cout<<"\n姓名"<<"\t"<<"学号"<<"\t"<<"性别"<<"\t"<<"系别"<<"\t"<<"班别"<<"\t"<<"综合成绩\n"; cout<<top->name<<"\t"<<top->num<<"\t"<<top->sex<<"\t"<<top->xibie<<"\t" <<top->banbie<<"\t"<<top->zongheCJ<<endl; cout<<"\n是否继续修改?(y/n)\n"; cin>>SEL; } if(SEL=='n'||SEL=='N') cout<<"输入完毕,任意键返回\n"; break; } else top=top->next; } //修改后学生信息写入文件 if(l==1) { head=q; ofstream out_stream; out_stream.open("student.txt",ios::trunc); //以覆盖文件原数据方式打开文件 if(out_stream.fail()) { cout<<"打开文件失败.\n"; exit(1); } while(head!=NULL) { out_stream<<head->name<<" "<<head->num<<"\t"<<head->sex<<"\t"<<head->xibie <<"\t"<<head->banbie<<"\t"<<head->zongheCJ; head=head->next; } out_stream.close(); } else cout<<"\n对不起,没有你要修改的人.\n\n"; return q; } //删除 xueshengGL Del(xueshengGL top) { string NAME; int NUM,l=0,n=0; xueshengGL p,h,q,back,head; cout<<"\n请输入修改人的姓名:"; cin>>NAME; cout<<"\n请输入修改人的学号:"; cin>>NUM; ofstream out_stream; ifstream in_stream; in_stream.open("student.txt"); if(in_stream.fail()) { cout<<"打开文件失败.\n"; cout<<"还没有学生信息\n\n"; return 0; } while(1) { if(in_stream.eof()) break; else {p=new xueshengguanli; p->next=NULL; in_stream>>p->name>>p->num>>p->sex>>p->xibie>>p->banbie>>p->zongheCJ; if(n==0) { top=p; h=top; n=1; } else { h->next=p; h=p; } } } in_stream.close(); q=top; while(1) { if(NAME==top->name&&NUM==top->num&&top->next==NULL) { l=2; top=q->next; out_stream.open("student.txt",ios::trunc);//删除文件 break; } if(NAME==top->name&&NUM==top->num&&top->next!=NULL) { l=1; top=q->next; cout<<"\n删除成功.\n"; break; } if(q->next==NULL) { printf("\nNot Found!\n"); break; } back=q; q=q->next; if(NAME==q->name&&NUM==q->num) { l=1; back->next=q->next; cout<<"\n删除成功.\n"; break; } } //删除学生信息后重新写入文件 if(l==1) { head=top; out_stream.open("student.txt",ios::trunc); if(out_stream.fail()) { cout<<"打开文件失败.\n"; exit(1); } while(head!=NULL) { out_stream<<head->name<<" "<<head->num<<"\t"<<head->sex<<"\t"<<head->xibie <<"\t"<<head->banbie<<"\t"<<head->zongheCJ; head=head->next; } out_stream.close(); } else if(l==2) cout<<"\n删除成功.\n"; else cout<<"\n找不到此人信息!\n"; return top; } //查询 xueshengGL LookUp(xueshengGL top) { string XM; int number,l=0; cout<<"\n请输入你查询的姓名:"; cin>>XM; cout<<"\n请输入你查询的工号:"; cin>>number; top=WenJian(top); while(top!=NULL) { if(XM==top->name&&number==top->num) { l=1; cout<<endl; cout<<"\n这是你要查询人的信息.\n"; cout<<"\n姓名"<<"\t"<<"学号"<<"\t"<<"性别"<<"\t"<<"系别"<<"\t"<<"班别"<<"\t"<<"综合成绩\n"; cout<<top->name<<"\t"<<top->num<<"\t"<<top->sex<<"\t"<<top->xibie<<"\t" <<top->banbie<<"\t"<<top->zongheCJ<<endl; break; } else top=top->next; } if(l==1) cout<<"\n谢谢你的查询.\n"; else cout<<"\n对不起,没有你要查询人的信息.\n"; cout<<endl; return top; } xueshengGL sort(xueshengGL top) { string name1,xibie1,banbie1,sex1; int num1; float zongheCJ1; int n=0,l=0; xueshengGL p1,p2,p3,p,h,head; ifstream in_stream; in_stream.open("student.txt"); if(in_stream.fail()) { cout<<"打开文件失败.\n"; cout<<"还没有学生信息保存\n\n"; return 0; } while(1) { if(in_stream.eof()) break; else {p=new xueshengguanli; p->next=NULL; in_stream>>p->name>>p->num>>p->sex>>p->xibie>>p->banbie>>p->zongheCJ; l=1; if(n==0) { top=p; h=top; n=1; } else { h->next=p; h=p; } } } in_stream.close(); for(p1=top;p1->next!=NULL;p1=p1->next) { l=1; for(p2=p1->next;p2!=NULL;p2=p2->next) { if(p1->zongheCJ<p2->zongheCJ) { name1=p1->name; p1->name=p2->name; p2->name=name1; num1=p1->num; p1->num=p2->num; p2->num=num1; sex1=p1->sex; p1->sex=p2->sex; p2->sex=sex1; xibie1=p1->xibie; p1->xibie=p2->xibie; p2->xibie=xibie1; banbie1=p1->banbie; p1->banbie=p2->banbie; p2->banbie=banbie1; zongheCJ1=p1->zongheCJ; p1->zongheCJ=p2->zongheCJ; p2->zongheCJ=zongheCJ1; } } } p3=top; cout<<"\n以下是全部学生的综合成绩由高到低的排序:\n"; cout<<"\n姓名"<<"\t"<<"学号"<<"\t"<<"性别"<<"\t"<<"系别"<<"\t"<<"班别"<<"\t"<<"综合成绩\n"; while(p3!=NULL) { cout<<p3->name<<"\t"<<p3->num<<"\t"<<p3->sex<<"\t"<<p3->xibie<<"\t" <<p3->banbie<<"\t"<<p3->zongheCJ<<endl; p3=p3->next; } if(l==1) { head=top; ofstream out_stream; out_stream.open("student.txt",ios::trunc); //以覆盖文件原数据方式打开文件 if(out_stream.fail()) { cout<<"打开文件失败.\n"; exit(1); } while(head!=NULL) { out_stream<<head->name<<" "<<head->num<<"\t"<<head->sex<<"\t"<<head->xibie <<"\t"<<head->banbie<<"\t"<<head->zongheCJ; head=head->next; } out_stream.close(); } else cout<<"\n谢谢.\n"; cout<<endl; return top; } void display(xueshengGL top) { int l=0,n=0; xueshengGL p,h; ifstream in_stream; in_stream.open("student.txt"); if(in_stream.fail()) { cout<<"打开文件失败.\n"; cout<<"还没有学生信息\n\n"; return; } while(1) { if(in_stream.eof()) break; else {p=new xueshengguanli; p->next=NULL; in_stream>>p->name>>p->num>>p->sex>>p->xibie>>p->banbie>>p->zongheCJ; l=1; if(n==0) { top=p; h=top; n=1; } else { h->next=p; h=p; } } } in_stream.close(); if(l==1) { cout<<"\n以下是全部学生信息:\n"; cout<<"\n姓名"<<"\t"<<"学号"<<"\t"<<"性别"<<"\t"<<"系别"<<"\t"<<"班别"<<"\t"<<"综合成绩\n"; while(top!=NULL) { cout<<top->name<<"\t"<<top->num<<"\t"<<top->sex<<"\t"<<top->xibie<<"\t" <<top->banbie<<"\t"<<top->zongheCJ<<endl; top=top->next; } cout<<endl<<endl; } return; } int main() { xueshengGL head; int sel; cout<<"\n\n ---------------------------------------------\n"; cout<<"\t\t* 设计者 *\n" <<"\t\t* *\n" <<"\t\t* 学号: *\n"; cout<<" ---------------------------------------------\n\n"; while(1) { cout<<"\t\t-------------------------------\n" <<"\t\t欢迎使用学生信息管理系统\n" <<"\t\t 1输入学生信息\n" <<"\t\t 2修改学生信息\n" <<"\t\t 3删除学生信息\n" <<"\t\t 4查找学生信息\n" <<"\t\t 5学生综合成绩排序信息\n" <<"\t\t 6显示学生信息\n" <<"\t\t 0返回\n" <<"\t\t-------------------------------\n\n\n"; cout<<"请你选择操作类型:"; cin>>sel; cout<<"\n"; switch(sel) { case 1:head=Input(head); break; case 2:head=Change(head); break; case 3:head=Del(head); break; case 4:head=LookUp(head); break; case 5:head=sort(head); break; case 6:display(head); break; case 0:{ cout<<"谢谢使用再见\n\n"; exit(0); } default : cout<<"输入有错误请重新输入!\n\n"; } } return 0; }追问

怎么感觉不对

可以根据我的题目 帮我编一个程序吗

拜托拜托

急

温馨提示:答案为网友推荐,仅供参考