学生信息管理系统c++22
发布网友
发布时间:2023-10-30 18:12
我来回答
共5个回答
热心网友
时间:2024-12-04 08:23
学生成绩管理系统
--------------------------------------------------------------------------------
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.
");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("
Please shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch==n||ch==N)
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.
");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("
xuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen
");
for(j=0,k=1;j {
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f
",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.
");
exit(0);
}
printf("
PLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s
mingzi:%s
",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("
Cannot open this file.
");
exit(0);
}
printf("
PLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s
yuwen:%f
shuxue:%f
yingyu:%f
wuli:%f
huaxue:%f
",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("
open score.txt was failed!");
getch();
exit(0);
}
printf("
Please input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("Anykey will delet it.
");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!
");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为**/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************
");
printf("*************************menu********************************
");
printf("* ========================================================= *
");
printf("* 1>shuru 2>xiugai *
");
printf("* 3>shanchu 4>chazhao *
");
printf("* 5>xianshi 6>exit *
");
printf("* *
");
printf("* --------------------------------------------------------- *
");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case 1:shuru();break;
case 2:xiugai(); break;
case 3:shanchu(); break;
case 4:chazhao(); break;
case 5:xianshi(); break;
case 6:exit(0);
default: continue;
}
}
}
热心网友
时间:2024-12-04 08:23
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<conio.h>
#include<iostream>
struct student //定义一个学生结构体
{ char name[8];
int num;
char bj[20];
int GS,YY,JSJ,SUM; };
int s=0;
class student1 //定义一个学生类
{
private:
student stu[40];
char name,bj;
int num;
int GS,YY,JSJ,SUM;
public:
void sr(char *,int,char *,int,int,int);
void print(int);
int jc(int xxh)
{ int m=0;
while(m<=s+1)
if(xxh==stu[m++].num) break;
if(m>s+1) return 0;
else
return 1; }
void cz(int);
void sc(int);
void sum(int); };
void student1::sr(char *xm,int xh,char *dz,int gs,int yy,int jsj) //输入模块
{ strcpy(stu[s].name,xm);
stu[s].num=xh; strcpy(stu[s].bj,dz); stu[s].GS=gs;
stu[s].YY=yy;
stu[s].JSJ=jsj; }
void student1::print(int s) //输出模块
{ cout<<s<<"\t";
cout<<stu[s].name<<"\t";
cout<<stu[s].num<<"\t";
cout<<stu[s].bj<<"\t";
cout<<stu[s].GS<<"\t";
cout<<stu[s].YY<<"\t";
cout<<stu[s].JSJ<<"\t"; cout<<endl; }
void student1::cz(int s) //查找模块
{ int xxh,p;
while(s==0)
{ cout<<"没有记录,请先输入记录!"<<endl;
break; }
if(s!=0)
{cout<<"请输入您要查找的学号:";
cin>>xxh;
while (xxh<100000||xxh>999999) //判断输入的学号是否正确
{ cout<<"您输入的学号不正确,请输入一个六位数的学号"<<endl;
cin>>xxh; } while(s!=0) //查找是否有符合条件的记录
{ p=1;
if (xxh==stu[s].num)
{ cout<<"姓名\t学号\t班级\t高数\t英语\t计算机"<<endl;
cout<<stu[s].name<<"\t";
cout<<stu[s].num<<"\t";
cout<<stu[s].bj<<"\t";
cout<<stu[s].GS<<"\t";
cout<<stu[s].YY<<"\t";
cout<<stu[s].JSJ<<endl;
getch(); break; }
else
p=0; s--; } if(p==0)
cout<<"很抱歉,没有找到您要查找的学号!"<<endl;}
getch(); }
void student1::sc(int n) //删除模块
{ int xxh,p;
char da;
while(s==0)
{ cout<<"没有记录,请先输入记录!"<<endl; break; }
if(s!=0)
{ cout<<"请输入您要删除的学号:";
cin>>xxh;
while (xxh<100000||xxh>999999)
{ cout<<"您输入的学号不正确,请您输入一个六位数的学号" <<endl;
cin>>xxh; }
for(int i=1;i<=n;i++)
{ if(stu[i].num!=xxh) p=0;
if(stu[i].num==xxh)
{ cout<<"姓名\t学号\t班级\t高数\t英语\t计算机"<<endl;
cout<<stu[i].name<<"\t";
cout<<stu[i].num<<"\t";
cout<<stu[i].bj<<"\t";
cout<<stu[i].GS<<"\t";
cout<<stu[i].YY<<"\t";
cout<<stu[i].JSJ<<endl;
cout<<"您确实要删除该学生的记录吗?(y/n)";
cin>>da;
if(da=='y'||da=='Y')
{ for(int j=i;j<=n-1;j++) //删除记录
{ strcpy(stu[j].name,stu[j+1].name);
stu[j].num=stu[j+1].num;
strcpy(stu[j].bj,stu[j+1].bj);
stu[j].GS=stu[j+1].GS;
stu[j].YY=stu[j+1].YY;
stu[j].JSJ=stu[j+1].JSJ; }
cout<<"该记录已删除!"<<endl; s=s-1; p=1; break; }
else
{ cout<<"该记录未删除!"<<endl;
p=1; } } }
if(p==0) cout<<"很抱歉,没有找到您要找的学号!"<<endl; }
getch(); }
void student1::sum(int s) //排序模块
{ int chang;
int b[40];
while(s==0)
{ cout<<"没有记录,请先输入记录!"<<endl; break;
} if(s!=0)
{ cout<<"姓名\t学号\t班级\t英语\t";
cout<<"高数\t计算机\t总分"<<endl;
for(int k=1;k<=s;k++)
{ b[k]=stu[k].GS+stu[k].YY+stu[k].JSJ;
stu[k].SUM=stu[k].GS+stu[k].YY+stu[k].JSJ;
} for(int i=1;i<=s;i++) //利用冒泡法对B[]进行排序
for(int j=1;j<=s-i;j++)
if(b[j]<b[j+1])
{ chang=b[j];
b[j]=b[j+1];
b[j+1]=chang; }
for(int h=1;h<=s;h++) //输出与B[]中相同总分所对应的内容
for(int e=1;e<=s;e++)
if(b[h]==stu[e].SUM)
{ cout<<stu[e].name<<"\t";
cout<<stu[e].num<<"\t";
cout<<stu[e].bj<<"\t";
cout<<stu[e].YY<<"\t";
cout<<stu[e].GS<<"\t";
cout<<stu[e].JSJ<<"\t";
cout<<stu[e].SUM<<endl; } }
getch();
} void main()
{ student1 st;
char da,a;
char *xm,*dz;
int gs,yy,jsj,xh;
time_t t;
while(1)
{ system("cls");
cout<<endl;
cout<<" 学生信息管理"<<endl;
cout<<"1.添加学生资料"<<' ';
cout<<"2.显示学生资料"<< ' ';
cout<<"3.查找"<<' ';
cout<<"4.删除"<<' ';
cout<<"5.按总分进行排序"<<endl;
cout<<"6.退出"<<endl;
cout<<"请选择操作(1-6)"<<endl;
cin>>a;
t: if(a=='6') break;
switch (a)
{ case '1':
{ cout<<"请依次输入学生的姓名,学号,班级,高数,英语,计算机:"<<endl;
xm=new char[];dz=new char[]; cin>>xm>>xh>>dz>>gs>>yy>>jsj;
while(st.jc(xh)) //调用JC模块判断学号是否重复
{ cout<<"学号重复,请重新输入!"<<endl;
cin>>xh; }
s=s+1;
st.sr(xm,xh,dz,gs,yy,jsj);
cout<<"是否继续输入?(y/n)";
cin>>da;
while (da=='y'||da=='Y') //判断是否要继续输入
{ cout<<"请依次输入学生的姓名,学号,班级,高数,英语,计算机:"<<endl;
xm=new char[];dz=new char[];
cin>>xm>>xh>>dz>>gs>>yy>>jsj;
while(st.jc(xh))
{ cout<<"学号重复,请重新输入!"<<endl;
cin>>xh; }
s=s+1;
st.sr(xm,xh,dz,gs,yy,jsj);
cout<<"是否继续输入?(y/n)";
cin>>da; }
getch();
};break;
case '2':
{ if(s==0) //判断是否有记录输入
{ cout<<"没有记录,请先输入记录!"<<endl; getch(); break; }
if(s!=0)
{ cout<<"序号"<<"\t"; cout<<"姓名"<<"\t"; cout<<"学号"<<"\t";
cout<<"班级"<<"\t";
cout<<"高数"<<"\t";
cout<<"英语"<<"\t";
cout<<"计算机"<<endl;
for(int i=1;i<=s;i++)
st.print(i);
getch(); } };
break;
case '3':st.cz(s);break;
case '4':st.sc(s);
break;
case '5':st.sum(s);break; default:
{ while(a=='0'||a>'6') //判断选项是否正确
{ cout<<"错误选项,请重新选择!"<<endl;
cin>>a; } goto t; };break; } }
cout<<"谢谢您的使用!"<<endl; }
参考资料:仅供参考,功能相似,自己改改锻炼锻炼
热心网友
时间:2024-12-04 08:24
这一言难尽啊!我还是刚做了个考试信息查询系统!即便是一个小系统也很多代码!但是步骤基本不变:
1、建立数据库
2、连接数据库
3、设计系统所需的模块
4、为模块添加事件处理程序
建议你去查阅《经典系统设计大全》
热心网友
时间:2024-12-04 08:24
给数据信息
热心网友
时间:2024-12-04 08:25
可以到百度上找源码