学生信息管理系统代码

时间:2015-12-25 17:07:56
【文件属性】:

文件名称:学生信息管理系统代码

文件大小:22KB

文件格式:TXT

更新时间:2015-12-25 17:07:56

Student1 Student2

学生信息管理系统# include # include # include #include #include using namespace std; struct Student1 { char *num;//学号 char *subnum;//课程编号 char *subname;//课程编号 char *grade;//学分 char *score1;//平时成绩 char *score2;//实验成绩 char *score3;//卷面成绩 float m;//综合成绩 float n;//实得学分 Student1 *next; };//学号 姓名 性别 宿舍号码 电话号码 struct Student2 { char *num;//学号 char *name;//姓名 char *sex;//性别 char *roomnum;//宿舍号码 char *tel;//电话号码 Student2 * next; }; struct InfList { Student2* head; int size; }; struct CourseList { Student1 * head; int size; }; InfList create2()//创建一个空链表 { InfList list; list.head=0; list.size=0; return list; } CourseList create1()//创建一个空链表 { CourseList list; list.head = 0; list.size = 0; return list; } void deleteAll1(Student1 * p)//cc { delete []p->num; delete []p->grade; delete []p->subnum; delete []p->subname; } void deleteAll(Student2* p1)//in { delete []p1->name; delete []p1->num; delete []p1->roomnum; delete []p1->sex; delete []p1->tel; } void removeAll1 (CourseList & list) { Student1 *p1; while(list.head != NULL) { p1 = list.head; list.head = list.head->next; delete p1; } list.size = 0; } void removeAll (InfList & list) { Student2 *p1; while(list.head != NULL) { p1 = list.head; list.head = list.head->next; delete p1; } list.size = 0; } double getM(char* a,char *b,char *c)//计算综合成绩 { double m; double a1=atof(a); double b1=atof(b); double c1=atof(c); if(!strcmp(b,"-1")) { m=a1*(0.3)+c1*(0.7); return m; } else { m=a1*(0.15)+b1*(0.15)+c1*(0.7); return m; } } double getN(char *a,double b)//计算实得学分 { double n; double a1=atof(a); switch(int(b)/10) { case 10: case 9:n=a1*1;return n;break; case 8:n=a1*(0.8);return n;break; case 7:n=a1*(0.75);return n;break; case 6:n=a1*(0.6);return n;break; default:n=0;return n; } } CourseList LoadData1 (CourseList & list) //将成绩数据读入数组中,动态变量管理 { list=create1(); ::ifstream infile("b.txt",ios::in|ios::nocreate);//打开成绩文件 if(!infile) { cout<<"不能打开文件:b.txt"<<'\n'; return list; } int n=0; Student1 *p1,*p2; char buff[300]; infile.getline(buff,300); while (!infile.eof()) //当读到文件尾时,函数返回1;否则返回0 { p1=new Student1; infile>>buff; if(infile.eof()) break; p1->num=new char[strlen(buff)+1]; strcpy(p1->num,buff); infile>>buff; p1->subnum=new char[strlen(buff)+1]; strcpy(p1->subnum,buff); infile>>buff; p1->subname=new char[strlen(buff)+1]; strcpy(p1->subname,buff); infile>>buff; p1->grade=new char[strlen(buff)+1]; strcpy(p1->grade,buff); infile>>buff; p1->score1=new char[strlen(buff)+1]; strcpy(p1->score1,buff); infile>>buff; p1->score2=new char[strlen(buff)+1]; strcpy(p1->score2,buff); infile>>buff; p1->score3=new char[strlen(buff)+1]; strcpy(p1->score3,buff); p1->m=getM(p1->score1,p1->score2,p1->score3); p1->n=getN(p1->grade,p1->m); p1->next=NULL; if (list.head==0) list.head=p1; else p2->next=p1; p2=p1; n++; } list.size=n; infile.close(); return list; } InfList LoadData (InfList & list) //将基本信息数据读入数组中,动态变量管理 { list=create2(); ::ifstream infile("a.txt",ios::in|ios::nocreate);//打开信息文件 if(!infile) { cout<<"不能打开文件:a.txt"<<'\n'; return list; } int n=0; Student2 *p1,*p2; char buff[300]; infile.getline(buff,300); while (!infile.eof())//开始读数据 { p1=new Student2; infile>>buff; if(infile.eof()) break; p1->num=new char[strlen(buff)+1]; strcpy(p1->num,buff); infile>>buff; p1->name=new char[strlen(buff)+1]; strcpy(p1->name,buff); infile>>buff; p1->sex=new char[strlen(buff)+1]; strcpy(p1->sex,buff); infile>>buff; p1->roomnum=new char[strlen(buff)+1]; strcpy(p1->roomnum,buff); infile>>buff; p1->tel=new char[strlen(buff)+1]; strcpy(p1->tel,buff); p1->next=NULL; if (list.head==0) list.head=p1; else p2->next=p1; p2=p1; n++; } list.size=n; return list; infile.close(); } char * getChar(const char * sen) { cout<>c; while(!cin.good()) { cin.clear(); cin.getline(buffer, 80); cout<<"输入错误,请重新输入:"; cin>>c; } return c; } int getInt( const char * msg) { cout<>n; while(!cin.good()) { cin.clear(); cin.getline(buffer, 80); cout<<"输入整数错误,请重新输入:"; cin>>n; } return n; } void print(CourseList &list;)//输出所有数据 { system("cls");//清屏 LoadData1(list); cout<num<subnum<subname<grade; cout<score1<score2<score3; cout<m<n<next; } cout<<"size(学生个数)="<next; deleteAll1(p1); } removeAll1(list); } void Numprint(InfList & list) { LoadData(list); char num[20]; int m=0; strcpy(num,getChar("请输入学号:")); cout<num,num)) { cout<<"学号"<num<roomnum<name<sex<tel<next; } if(m==0) { cout<<"未找到学生学号"<next; deleteAll(p1); } removeAll(list); } void Nameprint(InfList & list) { LoadData (list); char name [20]; int m=0; strcpy(name,getChar("输入姓名:")); Student2 * p = list.head; for(int i = 0; p != NULL; i++) { if (!strcmp(p->name,name)) { cout<<"学号"<num<roomnum<name<sex<tel<next; } if(m==0) { cout<<"未找到学生"<next; deleteAll(p1); } removeAll(list); } void Rnumprint(InfList & list) { LoadData (list); char rnum [20]; int m=0; strcpy(rnum,getChar("输入宿舍号:")); Student2 * p = list.head; for(int i = 0; p != NULL; i++) { if (!strcmp(p->roomnum,rnum)) { cout<<"学号"<num<roomnum<name<sex<tel<next; } if(m==0) { cout<<"未找到宿舍号"<next; deleteAll(p1); } removeAll(list); } void NumPrint(CourseList & list) { LoadData1(list); char num[20]; int s=0; double sum=0; strcpy(num,getChar("请输入学号:")); cout<num,num)) { if(s==0) { cout<<' '<<"学号"<num<subnum<subname<m<n<n; } p=p->next; } cout<<"共修:"<next; deleteAll1(p1); } removeAll1(list); } int Gochoice () { system("cls"); cout<<" <**************************************************>\n\n"; cout<<" 学 生 基 本 信 息 查 询"; cout<<"\n\n <**************************************************>\n\n"; cout<< "输入命令编号:\n\n"; cout<<" 1. 学号查询\n"< list.size) return ; if (index == 0) { list.size--; Student2 *p = list.head; list.head = list.head->next; cout<<"删除文件a.txt中:"<num<name<sex<roomnum<tel<next; } list.size--; p1->next = p2->next; cout<<"删除文件a.txt中:"<num<name<sex<roomnum<tel<= list2.size) return ; if (index == 0) { list2.size--; Student1 *p = list2.head; list2.head = list2.head->next; cout<<"删除文件b.txt中:"<num<subnum<subname<m<n<next; } list2.size--; p1->next = p2->next; cout<<"删除文件b.txt中:"<num<subnum<subname<m<n<num,num)==0) return i; p=p->next; } return -1; } int SearchList( CourseList & list, char * num) { Student1 *p = list.head; for(int i = 0; p != NULL; i++) { if (strcmp(p->num,num)==0) return i; p = p -> next; } return -1; } void DeleteOne()//删除函数 { cout<num<<'\t'<name<<'\t'<sex<<'\t'<roomnum<<'\t'<<'\t'<tel<<'\n'; p1=p1->next; } outfile.close(); ::ofstream outfile2("b.txt",ios::out); if (!outfile2 ) { cout << "不能打开目的文件:"<<"b.txt"<<'\n'; return; } if((list1.size)!=0) { outfile2<<"学号"<<' '<<"课程编号"<<' '<<"课程名称"<<' '<<"学分"<<' '<<"平时成绩"<<' '<<"实验成绩"; outfile2<<' '<<"卷面成绩"<<' '<<"综合成绩"<<' '<<"实得学分"<<'\n'; } else cout<<"文件已空"<subname,"VC++")==0) { if(pp1->next==NULL) { outfile2<num<subnum; outfile2<subname<grade<score1; outfile2<score2<score3; } else { outfile2<num<subnum; outfile2<subname<grade<score1; outfile2<score2<score3<<'\n';} } else { outfile2<num<subnum; outfile2<subname<<' '<grade<score1; outfile2<score2<score3<<'\n'; } pp1=pp1->next; } outfile2.close(); cout<next; deleteAll1(p1); } removeAll1(list1); while(list.head!=NULL) { Student2*p1; p1=list.head; list.head=list.head->next; deleteAll(p1); } removeAll(list); } CourseList sortM(CourseList & list)//综合成绩降序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->mm) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } return list; } CourseList sortN(CourseList & list)//实得学分降序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(p1=list.head;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->nn) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } /*while(list.head!=NULL) { Student1*p1; p1=list.head; list.head=list.head->next; deleteAll1(p1); } removeAll1(list);*/ return list; } CourseList sortMM(CourseList & list)//综合成绩升序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(p1=list.head;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->m>p2->m) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } return list; } CourseList sortNN(CourseList & list)//实得学分升序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(p1=list.head;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->n>p2->n) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } /*while(list.head!=NULL) { Student1*p1; p1=list.head; list.head=list.head->next; deleteAll1(p1); } removeAll1(list);*/ return list; } void sortPrint (char * c,CourseList & list,char *cc)//输出实得学分排名 { system("cls"); Student1 * p = list.head; if (p==0) { cout<<"数据为空"<subname,c)&&!strcmp(cc,"实得学分")) { cout<<"第"<num<<'\t'<<"课程名称:"<subname<<'\t'<<"实得学分:"<n<subname,c)&&!strcmp(cc,"综合成绩")) { cout<<"第"<num<<'\t'<<"课程名称:"<subname<<'\t'<<"综合成绩:"<m<next; } if (n==0) cout<<"未找到"<next; deleteAll1(p1); } removeAll1(list1); } void Arrange2()//综合成绩 { char str[3][10]={"大学物理","高等数学","VC++"}; char zh[]={"综合成绩"}; int j=0; CourseList list1; char c[256]; strcpy(c,getChar("输入学科:")); for(int i=0;i<3;i++) { if (!strcmp(str[i],c)) j++; } if(j==0) cout<<"查无此学科"<next; deleteAll1(p1); } removeAll1(list1); } int enterChoice() { cout<<"<***************************************************>\n\n"; cout<<" 学 生 信 息 管 理 系 统"; cout<<"\n\n<***************************************************>\n\n"; cout<<"请输入命令编号:\n\n"; cout<<" 1. 学生成绩录入\n"; cout<<" 2. 学生信息查询\n"; cout<<" 3. 学生成绩查询\n"; cout<<" 4. 学生信息删除\n"; cout<<" 5. 实得学分排名\n"; cout<<" 6. 综合成绩排名\n"; cout<<" 0. 退出\n"; return getInt("选择命令:"); } void main() { int choice; while((choice = enterChoice()) != 0) { switch(choice) { case 1: GetAll();break; //学生成绩录入 case 2: LookInf(); system("cls"); break;//学生基本信息查询 case 3: LookGrade(); system("cls");break;//学生成绩查询 case 4: DeleteOne(); system("cls");break;//学生信息删除 case 5: Arrange1(); system("cls");break;//实得学分排名 case 6: Arrange2(); system("cls");break;//综合成绩排名 default:cout<<"输入命令不存在\n"; cout<<"请重输:\n"<


网友评论