用C++编写一个学生信息管理系统 20
要求:有学号、姓名、年龄、性别、出生年月、家庭住址、电话、E-mail.功能:1、系统以菜单方式工作;2、学生信息录入功能;3、信息浏览功能;4、查询、排序功能;5、按学...
要求:有学号、姓名、年龄、性别、出生年月、家庭住址、电话、E-mail.
功能:1、系统以菜单方式工作;2、学生信息录入功能;3、信息浏览功能;4、查询、排序功能;5、按学号查询;、6、按姓名查询;7、学生信息的删除和修改功能。
各位大哥大姐,救命啊!帮帮我,小弟感激不尽!紧急!紧急!十万火急!!!!!!!!!!!!! 展开
功能:1、系统以菜单方式工作;2、学生信息录入功能;3、信息浏览功能;4、查询、排序功能;5、按学号查询;、6、按姓名查询;7、学生信息的删除和修改功能。
各位大哥大姐,救命啊!帮帮我,小弟感激不尽!紧急!紧急!十万火急!!!!!!!!!!!!! 展开
展开全部
刚好以前写过,捡个便宜了(就是项目是姓名、学号和各课成绩,要改的话不难)
#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;
}
#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;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |