学生管理系统C++课设
类
#include
#include
#include<string.h>
#include
#include
using namespace std;
#define MAX 100
int numb;
class Student
{
private:
public:
int num;
string name;
int sex;
double subject[3];
double total;
void input(Student s[], int );//输入
void sort(Student s[], int );//排序
void print(Student s[], int );
void save(Student s[],int );//输出
void find(Student s[], int );//查询
void order(Student s[], int );
void binary(Student s[], int );
void change(Student s[], int );//更新
void modi(Student s[],int );
void add(Student s[],int );
void del(Student s[],int );
void stat(Student s[],int );//统计
}stu[MAX];
//1.输入模块
void Student::input(Student s[], int n)
{
system(“cls”); //清屏函数
for (int i=0; i<n; i++)
{
cout<<endl<<endl<<endl;
cout<<"\t\t\t\t\t输入第" <<i+1<<“个学生的学号:”;
cin>>s[i].num;
cout<<"\t\t\t\t\t输入第"<<i+1<<“个学生的姓名:”;
cin>>s[i].name;
cout<<"\t\t\t\t\t输入学生的性别:男输入1,女输入0 输入为:";
cin>>s[i].sex;
s[i].total=0;
cout<<"\t\t\t\t\t按高数,英语,计算机的顺序输入各科成绩"<<endl;
for(int j=0;j<3;j++)
{
cout <<"\t\t\t\t\t输入第"<<j+1<<"门课的成绩:";
cin >> s[i].subject[j];
s[i].total+=s[i].subject[j];
}
cout<<endl;
}
}
//2.查询模块
void Student::find(Student s[], int )
{
a1: system(“cls”); //清屏函数
while(true)
{
int n;
cout<<"\t\t成绩查找\n";
cout<<"\t\t 1. 按学号查找\n";
cout<<"\t\t 2. 按姓名查找\n";
cout<<"\t\t 3. 输出成绩单\n";
cout<<"\t\t 4. 返回主菜单\n";
cout<<"请选择(1-4):";
cin>>n;
switch(n)
{
case 1: s->order(stu, numb);goto a1;break;
case 2: s->binary(stu, numb);goto a1;break;
case 3: s->print(stu,numb);goto a1;break;
case 4: return;
}
}
}
//(1).学号查找
void Student::order(Student s[], int )
{
int i,m;
double x;
cout<<"\t\t\t 按学号查找 \n";
cout<<"请输入要查找的学号:";
cin>>m;
for(i=0;i<100;i++)
{
if(m==num)
{
cout<<"学号:"<<s[i].num<<endl
<<"姓名:"<<s[i].name<<endl
<<"高数成绩:"<<s[i].subject[0]<<endl
<<"英语成绩:"<<s[i].subject[1]<<endl
<<"计算机成绩:"<<s[i].subject[2]<<endl;
break;
}
}
if(i>=100)
cout<<" 抱歉 找不到该学号! \n";
cout<<" 输入1返回上一级菜单:\n";
cin>>x;
}
//(2).姓名查找
void Student::binary(Student s[], int )
{
system(“cls”); //清屏函数
int i;
string ch;
double x;
cout<<"\t\t\t 按姓名查找 \n";
cout<<"请输入要查找的姓名:";
cin>>ch;
for(i=0;i<100;i++)
{
if(ch==s[i].name)
{
cout<<"学号:"<<s[i].num<<endl
<<"姓名:"<<s[i].name<<endl
<<"高数成绩:"<<s[i].subject[0]<<endl
<<"英语成绩:"<<s[i].subject[1]<<endl
<<"计算机成绩:"<<s[i].subject[2]<<endl;
}
else
cout<<" ";
}
if(i>=100)
cout<<" 抱歉 找不到该姓名! \n";
cout<<"输入1返回上一级菜单:\n";
cin>>x;
}
//(3).输出成绩单
void Student::print(Student s[], int n)
{
system(“cls”); //清屏函数
double x;
for (int i=0; i<n;i++)
{
cout<<" 学号:"<<s[i].num<<endl;
cout<<" 姓名:"<<s[i].name<<endl;
cout<<" 性别:";
if(s[i].sex=1)
cout<<"男"<<endl;
else
cout<<"女"<<endl;
cout<<" 高数成绩:"<<s[i].subject[0]<<endl;
cout<<" 英语成绩:"<<s[i].subject[1]<<endl;
cout<<" 计算机成绩:"<<s[i].subject[2]<<endl;
cout<<" 平均成绩:"<<s[i].total/3<<endl;
cout<<endl;
}
cout<<endl<<endl<<" 输入1返回上一级菜单:";
cin>>x;
}
//3.更新模块
void Student::change(Student s[], int )
{
a2: system(“cls”); //清屏函数
while(true)
{
int n;
cout<<"\t\t更新学生数据\n";
cout<<"\t\t 1. 修改学生数据\n";
cout<<"\t\t 2. 添加学生数据\n";
cout<<"\t\t 3. 删除学生数据\n";
cout<<"\t\t 4. 返回主菜单\n";
cout<<"请选择(1-4):";
cin>>n;
switch(n)
{
case 1: s->modi(stu, numb);goto a2;break;
case 2: s->add(stu, numb);goto a2;break;
case 3: s->del(stu,numb);goto a2;break;
case 4: return;
}
}
}
//(1).修改学生数据
void Student::modi(Student s[],int )
{
system(“cls”); //清屏函数
int i,m,j,score;
char ch,y=‘Y’,n=‘N’;
double x;
cout<<"\t\t\t修改成绩\n";
cout<<"请输入要修改学生的学号:";
cin>>m;
int N=100;
for(i=0;i<N;i++)
if(m==num)
{
cout<<"找到该学生,信息如下:\n";
cout<<"学号:"<<num<<endl
<<"姓名:"<<name<<endl
<<"高数成绩:"<<subject[0]<<endl
<<"英语成绩:"<<subject[1]<<endl
<<"计算机成绩:"<<subject[2]<<endl;
cout<<"修改高数输入0,英语输入1,计算机输入2:";
cin>>j;
cout<<"要修改为:";
cin>>score;
cout<<"请确认是否修改?Y/N";
cin>>ch;
if(ch==y)
cout<<"修改成功!\n";
if(ch==n)
{
cout<<"取消修改!";
goto end;
}
switch(j)
{
case 0: subject[0]=score;break;
case 1: subject[1]=score;break;
case 2: subject[2]=score;break;
}
cout<<"修改后该学生,信息如下:\n";
cout<<"学号:"<<num<<endl
<<"姓名:"<<name<<endl
<<"高数成绩:"<<subject[0]<<endl
<<"英语成绩:"<<subject[1]<<endl
<<"计算机成绩:"<<subject[2]<<endl;
break;
}
if(i>=N)
cout<<"找不到该学生信息!\n";
end:cout<<"输入1返回上一级菜单:\n";
cin>>x;
}
//(2).添加学生数据
void Student::add(Student s[],int )
{
system(“cls”); //清屏函数
int i,j,m;
double x;
cout<<"添加学生数据:";
cout<<"请输入添加学生人数(30以内):\n";
a3:cin>>m;
if(m>30)
{
cout<<“人数超过30,请重新输入:”;
goto a3;
}
for(i=0;i<m;i++)
{
cout<<“请输入第”<<numb+i+1<<“个学生的学号:\n”;
cin>>num;
cout<<“请输入第”<<numb+i+1<<“个学生的姓名:\n”;
cin>>name;
cout<<“请输入第”<<numb+i+1<<“个学生的3门课程成绩:\n”;
for(j=0;j<3;j++)
cin>>s[i].subject[j];
}
numb+=m;
cout<<“添加成功!\n”;
cout<<“输入1返回上一级菜单:\n”;
cin>>x;
}
//(3).删除学生数据
void Student::del(Student s[],int )
{
system(“cls”); //清屏函数
int i,a,n;
int flag=0;
char ch;
double x;
cout<<"\t\t\t删除学生数据\n";
cout<<"请输入要删除学生数据的学号:";
cin>>a;
for(i=0;i<n;i++)
{
if(a==num)
{
flag=1;
cout<<"学号:"<<num<<endl
<<"姓名:"<<name<<endl
<<"高数成绩:"<<subject[0]<<endl
<<"英语成绩:"<<subject[1]<<endl
<<"计算机成绩:"<<subject[2]<<endl;
cout<<"确认是否删除?Y/N\n";
cin>>ch;
if(ch=='N')
{
break;
}
if(ch=='Y')
{
for(i;i<n;i++)
{
s[i].num=s[i+1].num;
s[i].name=stu[i+1].name;
s[i].subject[0]=s[i+1].subject[0];
s[i].subject[1]=s[i+1].subject[1];
s[i].subject[2]=s[i+1].subject[2];
}
cout<<"删除成功!\n";
}
}
if(flag==0)
cout<<"找不到该学号!\n";
}
numb--;
cout<<"输入1返回上一级菜单:\n";
cin>>x;
}
//4.排序模块
void Student::sort(Student s[], int n)
{
system(“cls”); //清屏函数
int ch=0;
int i;
int j;
cout<<" ******************请输入 1.升序, 2.降序******************"<<endl;
cout<<" 输入为:";
cin>>ch;
if(ch=1)
{
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(s[i].total>=s[j].total)
{
Student tmp=s[i];
s[i]=s[j];
s[j]=tmp;
}
}
}
cout<<" 排序成功!"<<endl;
}
else
{
for( i=0;i<n-1;i++)
{
for( j=i+1;j<n;j++)
{
if (s[i].total>=s[j].total)
{
Student tmp=s[i];
s[i]=s[j];
s[j]=tmp;
}
}
}
cout<<" 排序成功!"<<endl;
}
}
//5.统计模块
void Student::stat(Student s[],int )
{
system(“cls”);
int score;
int x;
int a=0,b=0,c=0,d=0,e=0,f=0;
double y;
cout<<" *********************** 请输入: 1.统计高数成绩 2.统计英语成绩 3.统计计算机成绩 *************"<<endl;
cout<<" 输入为:";
cin>>x;
x=x-1;
cout<<endl<<endl<<endl;
for(int i=0;i<numb;i++)
{
score=s[i].subject[x]/10;
switch(score)
{
case 10:
a=a+1;break;
case 9:
b=b+1;break;
case 8:
c=c+1;break;
case 7:
d=d+1;break;
case 6:
e=e+1;break;
default:
f=f+1;break;
}
}
cout<<"90~100分数段有"<<b+a<<"个"<<endl;
cout<<"80~89分数段有"<<c<<"个"<<endl;
cout<<"70~79分数段有"<<d<<"个"<<endl;
cout<<"60~69分数段有"<<e<<"个"<<endl;
cout<<"及格人数为:"<<a+b+c+d+e<<"个"<<endl;
cout<<"不及格人数为:"<<f<<"个"<<endl;
cout<<endl<<endl<<endl;
cout<<"输入1返回主菜单";
cin>>y;
}
//6.输出模块 文件保存
void Student::save(Student s[],int )
{
ofstream fcout(“myFile.txt”,ios::binary);
if(fcout.fail())
{
cerr<<“error opening file\n”;
}
for(int i=0;i<numb;i++)
{
fcout<<"学号: "<<s[i].num<<" ";
fcout<<"姓名:"<<s[i].name<<" ";
fcout<<"性别:";
if(s[i].sex=1)
fcout<<"男 ";
else
fcout<<"女 ";
fcout<<"高数: "<<s[i].subject[0]<<" ";
fcout<<"英语: "<<s[i].subject[1]<<" ";
fcout<<"计算机: "<<s[i].subject[2]<<" ";
fcout<<"平均分: "<<s[i].total/3<<" "<<endl;
}
fcout.close;
//输入:从文件读数据
}
//主菜单
int main()
{
loop: int n;
Student s;
ofstream outfile;
ifstream infile;
system("cls"); //清屏函数
cout<<" -----------------------------------------------------------"<<endl;
cout<<" (* ̄︶ ̄)** ** (* ̄︶ ̄)** 欢迎进入学生成绩管理系统! (* ̄︶ ̄)** **(* ̄︶ ̄)**"<<endl;
cout<<" ***************请输入选择:************ "<<endl
<<endl;
cout<<" (* ̄︶ ̄) *********1.输入模块*********"<<endl
<<" (* ̄︶ ̄) *********2.查询模块*********"<<endl
<<" (* ̄︶ ̄) *********3.更新模块*********"<<endl
<<" (* ̄︶ ̄) *********4.排序模块*********"<<endl
<<" (* ̄︶ ̄) *********5.统计模块*********"<<endl
<<" (* ̄︶ ̄) *********6.输出模块*********"<<endl;
cout<<"-------------------------------------------------------------------------------------------------"<<endl;
cout<<" ****输入其他任意键退出****"<<endl;
cout<<" \n 您输入的选择为:";
cin>>n;
switch(n)
{
case 1:
{
system("CLS");
cout<<endl<<endl<<endl;
cout<<" *(* ̄︶ ̄) 请输入学生个数: ";
cin>>numb;
s.input(stu, numb);
system("cls"); //清屏函数
cout<<endl<<endl<<endl;
cout<<" ******** 耶! 输入完毕 ! *(* ̄︶ ̄) *********** "<<endl;
}
goto loop;
break;
case 2:
s.find(stu, numb);
goto loop;
break;
case 3:
s.change(stu, numb);
goto loop;
break;
case 4:
system("cls"); //清屏函数
s.sort(stu, numb);
cout<<" 排序后的学生数据为:"<<endl;
s.print(stu, numb);
goto loop;
break;
case 5:
s.stat(stu, numb);
goto loop;
break;
case 6:
system("cls"); //清屏函数
s.save(stu, numb);
cout<<endl<<endl;
cout<<" ***** 欧耶! 保存成功! ****** "<<endl<<endl;
goto loop;
break;
default:
cout<<" *************** 噢!... 退出成功....... ************** \n";
break;
};
return 0;
}
转载:https://blog.csdn.net/weixin_44861979/article/details/90896890