📄 schoolmanagesystem.cpp
字号:
#include <iomanip>
#include <conio.h>
#include <iostream.h>
using namespace std;
#define SIZE 50
int sum=0;
static char *str[]={"软件工程","计算机","现代密码学","数据库","网络网络设计"};
struct student
{
int n;
char num[10];//学号
char name[10];//姓名
int score[5];
float avr;
}
stu[SIZE];
/* 1--输入 */
void fin()
{
int i,j,s;
char f;
char flag;
FILE *fp;
cout<<" 提示! 你确定输入吗? ( y/n ) : ";
cin>>f;
if(f!='y')
return;
fp=fopen("fstu","wb");
for(i=0;i<SIZE;i++)
{
cout<<"按任意键继续,退出请按 a :";
cin>>flag;
if (flag=='a')
{
fclose(fp);
return;
}
else
{
stu[i].n=i+1;
cout<<" 请输入学生的学号:" ;
cin>>stu[i].num;
cout<<" 请输入学生的姓名:" ;
cin>>stu[i].name;
stu[i].n=i+1;
s=0;
cout<<"编号"<<i+1<<" 请输入学生的成绩 : "<<endl;
for(j=0;j<5;j++)
{
cout<<str[j] ;
cin>>stu[i].score[j];
if(stu[i].score[j]>100 || stu[i].score[j]<0 )
{
cout<<"输入错误,请重新输入!"<<endl;
j--;
}
s+=stu[i].score[j];
}
fwrite(&stu[i],sizeof(struct student),1,fp);
}
}
fclose(fp);
getch();
}
/*查询最高成绩*/
void searchmax()
{
int a;
cout<<"1.软件工程,2.计算机网络,3.现代密码学,4.数据库原理,5.网络程序设计"<<endl;
cout<<"请输入您要查询的课程代码:";
cin>>a;
loop:if((a>5)||(a<1))
{
cout<<"输入不正确,请重新输入:";
cin>>a;
goto loop;
}
FILE *fp;
fp=fopen("fstu","rb");
float maxch=0;
for(int j=0;fread(&stu[j],sizeof(struct student),1,fp)!=0;j++)
{
rewind(fp);
fseek(fp,(j)*sizeof(struct student),0);
if(stu[j].score[a-1]>maxch)
{
maxch=stu[j].score[a-1];
}
}
fclose(fp);
cout<<str[a-1]<<"最高成绩为:"<<maxch<<endl;
cout<<" -+-+★-+-+☆-+-+-按任意键返回主菜单-+-+-☆+-+-★+-+-"<<endl;
getch();
}
/*查询最低成绩*/
void searchmin()
{
int a;
cout<<"1.软件工程,2.计算机网络,3.现代密码学,4.数据库原理,5.网络程序设计"<<endl;
cout<<"请输入您要查询的课程代码:";
cin>>a;
loop:if((a>5)||(a<1))
{
cout<<"输入不正确,请重新输入:";
cin>>a;
goto loop;
}
FILE *fp;
fp=fopen("fstu","rb");
float minch=100;
for(int j=0;fread(&stu[j],sizeof(struct student),1,fp)!=0;j++)
{
rewind(fp);
fseek(fp,(j)*sizeof(struct student),0);
if(stu[j].score[a-1]<minch)
{
minch=stu[j].score[a-1];
}
}
fclose(fp);
cout<<str[a-1]<<"最低成绩为:"<<minch<<endl;
cout<<" -+-+★-+-+☆-+-+-按任意键返回主菜单-+-+-☆+-+-★+-+-"<<endl;
getch();
}
/*查询平均成绩*/
void searchavg()
{
int a;
cout<<"1.软件工程,2.计算机网络,3.现代密码学,4.数据库原理,5.网络程序设计"<<endl;
cout<<"请输入您要查询的课程代码:";
cin>>a;
loop:if((a>5)||(a<1))
{
cout<<"输入不正确,请重新输入:";
cin>>a;
goto loop;
}
FILE *fp;
fp=fopen("fstu","rb");
float sum=0;
float average;
for(int j=0;fread(&stu[j],sizeof(struct student),1,fp)!=0;j++)
{
rewind(fp);
fseek(fp,(j)*sizeof(struct student),0);
sum=sum+stu[j].score[a-1];
}
average=sum/(j+1);
fclose(fp);
cout<<str[a-1]<<"平均成绩为:"<<average<<endl;
cout<<" -+-+★-+-+☆-+-+-按任意键返回主菜单-+-+-☆+-+-★+-+-"<<endl;
getch();
}
/*查询学生成绩*/
void searchstu()
{
char number[11];
cout<<"请输入学号:";
cin>>number;
for(int j=0;j<SIZE;j++)
{
if(!strcmp(number,stu[j].num))//学号进行比较
{
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*你查询的结果为*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;//显示查询结果
cout<<"\t\n\t\n";
//cout<<"学号:"<<stu[j].stuno<<endl;
cout<<"学生姓名:"<<stu[j].name<<endl;
cout<<"学号:"<<stu[j].num<<endl;
cout<<str[0]<<":"<<stu[j].score[0]<<endl;
cout<<str[1]<<":"<<stu[j].score[1]<<endl;
cout<<str[2]<<":"<<stu[j].score[2]<<endl;
cout<<str[3]<<":"<<stu[j].score[3]<<endl;
cout<<str[4]<<":"<<stu[j].score[4]<<endl;
getch();
return ;
}
}
cout<<"该学生不在系统中"<<endl;
}
//修改学生信息
void fchan()
{
char number[11];
cout<<"请输入学号:";
cin>>number;
char s;
for(int j=0;j<SIZE;j++)
{
if(!strcmp(number,stu[j].num))//学号进行比较
{
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*你查询的结果为*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;//显示查询结果
cout<<"\t\n\t\n";
cout<<"学生姓名:"<<stu[j].name<<endl;
cout<<"学号:"<<stu[j].num<<endl;
cout<<str[0]<<":"<<stu[j].score[0]<<endl;
cout<<str[1]<<":"<<stu[j].score[1]<<endl;
cout<<str[2]<<":"<<stu[j].score[2]<<endl;
cout<<str[3]<<":"<<stu[j].score[3]<<endl;
cout<<str[4]<<":"<<stu[j].score[4]<<endl;
cout<<"你是否要修改这个学生的信息? y/n"<<endl;
cin>>s;
if(s=='y')
{
cout<<" 请输入学生的学号:" ;
cin>>stu[j].num;
cout<<" 请输入学生的姓名:" ;
cin>>stu[j].name;
s=0;
cout<<"编号"<<j+1<<" 请输入学生的成绩 : "<<endl;
for(int k=0;k<5;k++)
{
cout<<str[k] ;
cin>>stu[j].score[k];
if(stu[j].score[k]>100 || stu[j].score[k]<0 )
{
cout<<"输入错误,请重新输入!"<<endl;
k--;
}
s+=stu[j].score[k];
}
cout<<"修改成功,按任意键返回"<<endl;
getch();
return;
}
else
return;
}
}
cout<<"该学生不在系统中"<<endl;
}
/* 2--查找 */
void ffind()
{
cout<<" +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" <<endl;
cout<<" *※ 1. 查 询 最 高 成 绩 ※*"<<endl;
cout<<" *※ 2. 查 询 最 低 成 绩 ※*"<<endl;
cout<<" *※ 3. 查 询 平 均 成 绩 ※*"<<endl;
cout<<" *※ 4. 查 询 学 生 成 绩 ※*"<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<" Please Enter ( 1 -- 4 ) : ";
int a;
cin>>a;
switch(a)
{
case 1:
searchmax();
break;
case 2:
searchmin();
break;
case 3:
searchavg();
break;
case 4:
searchstu();
break;
}
}
/*删除学生信息*/
void fdel()
{
char number[11];
cout<<"输入您要删除的学生的学号:";
cin>>number;
int j=0;
while(strcmp(number,stu[j].num)&&(j<SIZE))//学号进行比较
{
j++;
}
if(!strcmp(number,stu[j].num))//查到要删除的信息
{
for(;j<(SIZE-1);j++)
{
strcpy(stu[j].name,stu[j+1].name);
strcpy(stu[j].num,stu[j+1].num);
for(int i=0;i<5;i++)
{
stu[j].score[i]=stu[j+1].score[i];
}
}
cout<<endl;
cout<<" -+-+★-+-+☆-+-+-删除成功-+-+-☆+-+-★+-+-"<<endl;
return ;
}
else
{
cout<<"此学生不在系统中"<<endl;
return ;
}
}
void main()
{
system("color f0"); //设置颜色
int n;
for(;;)
{
cout<<"\n\n\n\n\n"<<endl;
cout<<" ★-*-*-*-*-☆-*-*-*-*-★-*-*-*-*-☆-*-*-*-*-★-*-*-*-*-☆"<<endl;
cout<<"\t\n"<<endl;
cout<<" 欢--迎--进--入--学--生--成--绩--管--理--系--统 ";
cout<<"\t\n"<<endl;
cout<<" +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" <<endl;
cout<<" *※ 1. 输 入 学 生 数 据 ※*"<<endl;
cout<<" *※ 2. 查 询 学 生 数 据 ※*"<<endl;
cout<<" *※ 3. 修 改 学 生 数 据 ※*"<<endl;
cout<<" *※ 4. 删 除 学 生 数 据 ※*"<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<" *※ 0. 退 出 系 统 ※*"<<endl;
cout<<" +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n"<<endl;
cout<<" Please Enter ( 0 -- 4 ) : ";
cin>>n;
cout<<"\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n"<<endl;
switch(n)
{
case 1 : fin();
break;
case 2 : ffind();
break;
case 3 : fchan();
break;
case 4 : fdel();
break;
case 0 : cout<<" *-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*"<<endl;
cout<<" * *"<<endl;
cout<<" * Finish ! *"<<endl;
cout<<" * *"<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*"<<endl;
cout<<" * *"<<endl;
cout<<" * Good Bye ! *"<<endl;
cout<<" * *"<<endl;
cout<<" * o(∩_∩)o... *"<<endl;
cout<<" *-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*"<<endl;
cout<< "\t\n\t\n\t\n\t\n\t\n\t\n"<<endl;
getch();
exit(0);
default: cout<<" * * * Error ! Press any key continue. * * *"<<endl;
getch();
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -