可按Ctrl+D收藏 蚂蚁资源网

蚂蚁资源网

学生工作信息管理系统(学生成绩管理系统介绍)

  • 全部评论(3)
  • 亦心
  • 刚好以前写过,捡个便宜了(就是项目是姓名、学号和各课成绩,要改的话不难)#include<iostream>#include<cstring> #include<fstream>using namespace std;int num;const int MAX_NUM_OF_STUDENTS=1000;struct Student{ int no; char name [20]; int computer; int math; int english; int physics;};Student students[MAX_NUM_OF_STUDENTS];Student name_students[MAX_NUM_OF_STUDENTS];char choose;extern int Input_project();extern int Search_project();extern int Delete_project();extern int Modify_project();int Face()//主界面{ cout<<"\t\t\t~*~*~欢迎使用学生信息管理系统~*~*~"<<endl<<endl; cout<<"◇ 录入(I),"<<endl<<"◇ 查询(S),"<<endl<<"◇ 删除(D),"<<endl <<"◇ 修改(M),"<<endl<<"◇ 退出(E),"<<endl; cout<<"☆ 请输入您的选择(I,S,D,E):"; cin>>choose; switch(choose) { case 'I': case 'i': system("cls");Input_project();break; case 'S': case 's': system("cls");Search_project();break; case 'D': case 'd': system("cls");Delete_project();break; case 'M': case 'm': system("cls");Modify_project();break; case 'E': case 'e': system("cls");return -1;break; default: cout<<" 输入错误!"<<endl; } return 0;}int Input_project()//输入功能{ choose='C'; for( ;choose=='C'||choose=='c';num++) { cout<<"Ο 学号:"; cin>>students[num].no; cout<<"Ο 姓名:"; cin>>students[num].name; cout<<"Ο 数学:"; cin>>students[num].math; cout<<"Ο 英语:"; cin>>students[num].english; cout<<"Ο 物理:"; cin>>students[num].physics; cout<<"Ο 计算机:"; cin>>students[num].computer; cout<<"☆ 继续或返回主菜单(C/E):"; cin>>choose; if(choose=='E'||choose=='e') break; } num+=1;//num为总人数 int i=num;//以下是按no冒泡排序 bool exchange; while(i>1) { exchange=false; for( int k=0;k<i-1;k++) { if(students[k].no>students[k+1].no) { Student temp=students[k]; students[k]=students[k+1]; students[k+1]=temp; exchange=true; } } if (!exchange) break; i--; } for (int t=0;t<num;t++)//结构体数组各项一一复制 { name_students[t].no=students[t].no; *strcpy(name_students[t].name,students[t].name); name_students[t].math=students[t].math; name_students[t].english=students[t].english; name_students[t].computer=students[t].computer; name_students[t].physics=students[t].physics; } while(i>1)//以下是按name冒泡排序 { exchange=false; for( int k=0;k<i-1;k++) { if(strcmp(name_students[k].name,name_students[k+1].name)>0) { Student temp=name_students[k]; name_students[k]=name_students[k+1]; name_students[k+1]=temp; exchange=true; } } if (!exchange) break; i--; } FILE *fp=fopen("c:\\name.txt","a+");//存储两结构体数组 FILE *fp1=fopen("c:\\number.txt","a+"); if (fp == NULL||fp1 == NULL)//判断文件打开是否成功 { cout<<"打开文件失败!"<<endl; return -1; } for(i=0;i<num;i++) { fwrite(&students[i],sizeof(Student),1,fp); fwrite(&name_students[i],sizeof(Student),1,fp1); } fclose(fp); fclose(fp1); system("cls");return 0;}int Search_project()//查询功能{ FILE *fp=fopen("c:\\name.txt","r"); FILE *fp1=fopen("c:\\number.txt","r"); if (fp == NULL||fp1 == NULL)//判断文件打开是否成功 { cout<<"打开文件失败!"<<endl; return -1; } num=0; fread(&students[num],sizeof(Student),1,fp); fread(&name_students[num],sizeof(Student),1,fp1); while((!feof(fp))&&(!feof(fp1))) { num++;//计算已存储的资料的人数num fread(&students[num],sizeof(Student),1,fp); fread(&name_students[num],sizeof(Student),1,fp1); } fclose(fp); fclose(fp1); cout<<'\t'<<"按学号查询(A)"<<'\t'<<"按姓名查询(B)"<<'\t'<<"返回主菜单(E)"<<endl; cout<<"Ο 请选择:"; char input; cin>>input; switch(input) { case 'A': case 'a': { cout<<"Ο 输入学号:"; int number; cin>>number;//以下是折半查询: int low=0; int high=num-1; while (low<=high) { int mid=(low+high)/2; if (students[mid].no==number) { cout<<"Ο 学号:"<<students[mid].no<<endl; cout<<"Ο 姓名:"<<students[mid].name<<endl; cout<<"Ο 数学: "<<students[mid].math<<endl; cout<<"Ο 英语: "<<students[mid].english<<endl; cout<<"Ο 物理: "<<students[mid].physics<<endl; cout<<"Ο 计算机: "<<students[mid].computer<<endl; break; } else if (number>students[mid].no) low=mid+1; else high=mid-1; } if(low>high) cout<<" 无相关资料!"<<endl; }break; case 'B': case 'b': { cout<<"Ο 输入姓名:"; char name[20]; cin>>name; int low=0;int high=num-1;//以下是折半查询: while (low<=high) { int mid=(low+high)/2; if (strcmp(name_students[mid].name,name)==0) { cout<<"Ο 学号:"<<name_students[mid].no<<endl; cout<<"Ο 姓名:"<<name_students[mid].name<<endl; cout<<"Ο 数学: "<<name_students[mid].math<<endl; cout<<"Ο 英语: "<<name_students[mid].english<<endl; cout<<"Ο 物理: "<<name_students[mid].physics<<endl; cout<<"Ο 计算机: "<<name_students[mid].computer<<endl; break; } else if (strcmp(name_students[mid].name,name)<0) low=mid+1; else high=mid-1; } if(low>high) cout<<" 无相关资料!"<<endl; }break; case 'E': case 'e':system("cls");return -1;break; } cout<<"☆ 继续或返回主菜单(C/E):"; cin>>choose; if(choose=='C'||choose=='c') {system("cls");Search_project();} else {system("cls");return -1;} return 0;}int Delete_project(){ cout<<"Ο 需删除的学生的学号是:"; int number; cin>>number; for(int i=0;i<num;i++) { if( students[i].no==number) break; } for(;i<num;i++)//将要删除的学生调至数组最后一位,前num-1位仍按no排列 { Student temp =students[i]; students[i]=students[i+1]; students[i+1]=temp; } for(int t=0;t<num;t++) { if( name_students[t].no==number) break; } for(;t<num;t++)//将要删除的学生调至数组最后一位,前num-1位仍按name排列 { Student temp =name_students[t]; name_students[t]=name_students[t+1]; name_students[t+1]=temp; } num-=1;//总人数减一,即删除最后一位 FILE *fp=fopen("c:\\name.txt","w"); FILE *fp1=fopen("c:\\number.txt","w"); if (fp == NULL||fp1 == NULL)//判断文件打开是否成功 { cout<<"打开文件失败!"<<endl; return -1; } for(i=0;i<num;i++) { fwrite(&students[i],sizeof(Student),1,fp); fwrite(&name_students[i],sizeof(Student),1,fp1); } fclose(fp); fclose(fp1); bool p=true;//以下查找并判断删除是否成功 int low=0; int high=num-1; while (low<=high) { int mid=(low+high)/2; if (students[mid].no==number||name_students[mid].no==number) { cout<<" 删除失败!"<<endl; p=false; break; } else if (number>students[mid].no) low=mid+1; else high=mid-1; } if(p) cout<<" 删除成功!"<<endl; cout<<"☆ 继续或返回主菜单(C/E):"; cin>>choose; if(choose=='C'||choose=='c') {system("cls");Delete_project();} else {system("cls");return -1;} return 0;}int Modify_project(){ FILE *fp=fopen("c:\\name.txt","r"); FILE *fp1=fopen("c:\\number.txt","r"); if (fp == NULL||fp1 == NULL)//判断文件打开是否成功 { cout<<"打开文件失败!"<<endl; return -1; } num=0; fread(&students[num],sizeof(Student),1,fp); fread(&name_students[num],sizeof(Student),1,fp1); while((!feof(fp))&&(!feof(fp1))) { num++;//计算已存储的资料的人数num fread(&students[num],sizeof(Student),1,fp); fread(&name_students[num],sizeof(Student),1,fp1); } fclose(fp); fclose(fp1); cout<<"Ο 需修改的学生的学号是:"; int number; cin>>number; int t,math,english,physics,computer; cout<<"Ο 输入修改结果:"<<endl; cout<<"Ο 数学:"; cin>>math; cout<<"Ο 英语:"; cin>>english; cout<<"Ο 物理:"; cin>>physics; cout<<"Ο 计算机:"; cin>>computer; for(int i=0;i<num;i++) { if( students[i].no==number) break; } students[i].math=math; students[i].english=english; students[i].physics=physics; students[i].computer=computer; i=num;//以下是按no冒泡排序 bool exchange; while(i>1) { exchange=false; for( int k=0;k<i-1;k++) { if(students[k].no>students[k+1].no) { Student temp=students[k]; students[k]=students[k+1]; students[k+1]=temp; exchange=true; } } if (!exchange) break; i--; } for (t=0;t<num;t++)//结构体数组各项一一复制 { name_students[t].no=students[t].no; *strcpy(name_students[t].name,students[t].name); name_students[t].math=students[t].math; name_students[t].english=students[t].english; name_students[t].computer=students[t].computer; name_students[t].physics=students[t].physics; } while(i>1)//以下是按name冒泡排序 { exchange=false; for( int k=0;k<i-1;k++) { if(strcmp(name_students[k].name,name_students[k+1].name)>0) { Student temp=name_students[k]; name_students[k]=name_students[k+1]; name_students[k+1]=temp; exchange=true; } } if (!exchange) break; i--; }fp=fopen("c:\\name.txt","w+");//存储两结构体数组,w+表示清空已有文件的内容 fp1=fopen("c:\\number.txt","w+"); if (fp == NULL||fp1 == NULL)//判断文件打开是否成功 { cout<<"打开文件失败!"<<endl; return -1; } for(i=0;i<num;i++) { fwrite(&students[i],sizeof(Student),1,fp); fwrite(&name_students[i],sizeof(Student),1,fp1); } fclose(fp); fclose(fp1); cout<<"☆ 继续或返回主菜单(C/E):"; cin>>choose; if(choose=='C'||choose=='c') {system("cls");Delete_project();} else {system("cls");return -1;} return 0;}int main(){ system("cls"); do {Face();} while (choose=='e'||choose=='E'); return 0;}
  • 2022-01-04 02:39:40
  • nij
  • 2022-01-04 02:38:18
  • 电竞比分源码专营
  • 学生信息管理系统C语言编程,#include<stdio.h> /*I/O函数*/#include<stdlib.h> /*其它说明*/#include<string.h> /*字符串函数*/#define BUFLEN 100 /* 缓冲区最大字符数 */#define LEN 15 /* 学号和姓名最大字符数,实际请更改 */#define N 100 /* 最大学生人数,实际请更改*/struct record /*结构体*/{char code[LEN+1]; /* 学号 */char name[LEN+1]; /* 姓名 */int age; /* 年龄 */char sex[3]; /* 性别 */char time[LEN+1]; /* 出生年月 */char add[30]; /* 家庭地址 */char tel[LEN+1]; /* 电话号码 */char mail[30]; /* 电子邮件地址 */}stu[N];int k=1,n,m; /* 定义全局变量 */ void readfile();/* 函数声明 */void seek();void modify();void insert();void del();void display();void save();void menu(); int main(){ while(k)menu();system("pause");return 0;} void help(){ printf("\n0.欢迎使用系统帮助!\n");printf("\n1.进入系统后,先刷新学生信息,再查询;\n");printf("\n2.按照菜单提示键入数字代号;\n");printf("\n3.增加学生信息后,切记保存按7;\n");printf("\n4.谢谢您的使用!\n");} void readfile()/* 建立信息 */{char *p="student.txt";FILE *fp;int i=0;if ((fp=fopen("student.txt","r"))==NULL){ printf("Open file %s error! Strike any key to exit!",p);system("pause");exit(0);}while(fscanf(fp,"%s %s%d%s %s %s %s %s",stu[i].code,stu[i].name,&stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail)==8){i++;i=i;}fclose(fp);n=i;printf("录入完毕!\n");} void seek() /*查找*/{int i,item,flag;char s1[21]; /* 以姓名和学号最长长度+1为准 */printf("------------------\n");printf("-----1.按学号查询-----\n");printf("-----2.按姓名查询-----\n");printf("-----3.退出本菜单-----\n");printf("------------------\n");while(1){printf("请选择子菜单编号:");scanf("%d",&item);flag=0;switch(item){case 1:printf("请输入要查询的学生的学号:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].code,s1)==0){flag=1;printf("学生学号 学生姓名 年龄 性别 出生年月 地址 电话 E-mail\n");printf("--------------------------------------------------------------------\n");printf("%6s %7s %6d %5s %9s %8s %10s %14s\n",stu[i].code,stu[i].name,stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}if(flag==0)printf("该学号不存在!\n"); break;case 2:printf("请输入要查询的学生的姓名:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].name,s1)==0){flag=1;printf("学生学号 学生姓名 年龄 性别 出生年月 地址 电话 E-mail\n");printf("--------------------------------------------------------------------\n");printf("%6s %7s %6d %5s %9s %8s %10s %14s\n",stu[i].code,stu[i].name,stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}if(flag==0)printf("该姓名不存在!\n"); break;case 3:return;default:printf("请在1-3之间选择\n");}}} void modify() /*修改信息*/{int i,item,num;char sex1[3],s1[LEN+1],s2[LEN+1]; /* 以姓名和学号最长长度+1为准 */printf("请输入要要修改的学生的学号:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].code,s1)==0) /*比较字符串是否相等*/num=i;printf("------------------\n");printf("1.修改姓名\n");printf("2.修改年龄\n");printf("3.修改性别\n");printf("4.修改出生年月\n");printf("5.修改地址\n");printf("6.修改电话号码\n");printf("7.修改E-mail地址\n");printf("8.退出本菜单\n");printf("------------------\n");while(1){printf("请选择子菜单编号:");scanf("%d",&item);switch(item){case 1:printf("请输入新的姓名:\n");scanf("%s",s2);strcpy(stu[num].name,s2); break;case 2:printf("请输入新的年龄:\n");scanf("%d",&stu[num].age);break;case 3:printf("请输入新的性别:\n");scanf("%s",sex1);strcpy(stu[num].sex,sex1); break;case 4:printf("请输入新的出生年月:\n");scanf("%s",s2);strcpy(stu[num].time,s2); break;case 5:printf("请输入新的地址:\n");scanf("%s",s2);strcpy(stu[num].add,s2); break;case 6:printf("请输入新的电话号码:\n");scanf("%s",s2);strcpy(stu[num].tel,s2); break;case 7:printf("请输入新的E-mail地址:\n");scanf("%s",s2);strcpy(stu[num].mail,s2); break;case 8:return;default:printf("请在1-8之间选择\n");}}} void sort()/*按学号排序*/{int i,j,*p,*q,s; char temp[10];for(i=0;i<n-1;i++){for(j=n-1;j>i;j--)if(strcmp(stu[j-1].code,stu[j].code)>0){strcpy(temp,stu[j-1].code);strcpy(stu[j-1].code,stu[j].code);strcpy(stu[j].code,temp);strcpy(temp,stu[j-1].name);strcpy(stu[j-1].name,stu[j].name);strcpy(stu[j].name,temp);strcpy(temp,stu[j-1].sex);strcpy(stu[j-1].sex,stu[j].sex);strcpy(stu[j].sex,temp);strcpy(temp,stu[j-1].time);strcpy(stu[j-1].time,stu[j].time);strcpy(stu[j].time,temp);strcpy(temp,stu[j-1].add);strcpy(stu[j-1].add,stu[j].add);strcpy(stu[j].add,temp);strcpy(temp,stu[j-1].tel);strcpy(stu[j-1].tel,stu[j].tel);strcpy(stu[j].tel,temp);strcpy(temp,stu[j-1].mail);strcpy(stu[j-1].mail,stu[j].mail);strcpy(stu[j].mail,temp); p=&stu[j-1].age; q=&stu[j].age; s=*q; *q=*p; *p=s;}}} void insert() /*插入函数*/{ int i=n,j,flag;printf("请输入待增加的学生数:\n");scanf("%d",&m);do{ flag=1;while(flag){flag=0;printf("请输入第 %d 个学生的学号:\n",i+1);scanf("%s",stu[i].code);for(j=0;j<i;j++)if(strcmp(stu[i].code,stu[j].code)==0){printf("已有该学号,请检查后重新录入!\n");flag=1;break; /*如有重复立即退出该层循环,提高判断速度*/}}printf("请输入第 %d 个学生的姓名:\n",i+1);scanf("%s",stu[i].name);printf("请输入第 %d 个学生的年龄:\n",i+1);scanf("%d",&stu[i].age);printf("请输入第 %d 个学生的性别:\n",i+1);scanf("%s",stu[i].sex);printf("请输入第 %d 个学生的出生年月:(格式:年.月)\n",i+1);scanf("%s",stu[i].time);printf("请输入第 %d 个学生的地址:\n",i+1);scanf("%s",stu[i].add);printf("请输入第 %d 个学生的电话:\n",i+1);scanf("%s",stu[i].tel);printf("请输入第 %d 个学生的E-mail:\n",i+1);scanf("%s",stu[i].mail);if(flag==0){ i=i;i++;}}while(i<n+m);n+=m;printf("录入完毕!\n\n");sort();} void del(){int i,j,flag=0;char s1[LEN+1];printf("请输入要删除学生的学号:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].code,s1)==0){ flag=1;for(j=i;j<n-1;j++)stu[j]=stu[j+1];}if(flag==0)printf("该学号不存在!\n");if(flag==1){printf("删除成功,显示结果请选择菜单6\n");n--;}} void display(){ int i;printf("所有学生的信息为:\n");printf("学生学号 学生姓名 年龄 性别 出生年月 地址 电话 E-mail\n");printf("--------------------------------------------------------------------\n");for(i=0;i<n;i++){ printf("%6s %7s %5d %5s %9s %8s %10s %14s\n",stu[i].code,stu[i].name,stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}} void save(){int i;FILE *fp;fp=fopen("student.txt","w"); /*写入*/for(i=0;i<n;i++){fprintf(fp,"%s %s %d %s %s %s %s %s\n",stu[i].code,stu[i].name,stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}fclose(fp);} void menu()/* 界面 */{int num;printf("*********************系统功能菜单************************ \n");printf("友情提醒:查询前请先刷新系统! \n");printf(" ---------------------- ---------------------- \n");printf(" ********************************************* \n");printf(" * 0.系统帮助及说明 * * 1.刷新学生信息 * \n");printf(" ********************************************* \n"); printf(" * 2.查询学生信息 * * 3.修改学生信息 * \n");printf(" ********************************************* \n");printf(" * 4.增加学生信息 * * 5.按学号删除信息 * \n");printf(" ********************************************* \n");printf(" * 6.显示当前信息 * * 7.保存当前学生信息* \n");printf(" ********************** ********************** \n");printf(" * 8.退出系统 * \n");printf(" ********************** \n");printf(" ---------------------- ---------------------- \n");printf("请选择菜单编号:");scanf("%d",&num);switch(num){ case 0:help();break;case 1:readfile();break;case 2:seek();break;case 3:modify();break;case 4:insert();break;case 5:del();break;case 6:display();break;case 7:save();break;case 8:k=0;break;default:printf("请在0-8之间选择\n");}
  • 2022-01-04 02:38:18
  • 商品推荐