#include<iostream>
#include<fstream>
#include <string.h>
/*zjm 主界面
xz 选择
cw 错误
sr 输入
tj 添加功能
xs 显示功能
cz 查找功能
xg 修改功能
sc 删除功能
cc 存储功能
xh 学号
mz 名字
xb 性别
nl 年龄
cj 成绩
zh 账号
mm 密码
px 排序
*/
using namespace std;
void zjm();
void cw();
void xz();
void sr();
void tj();
void xs();
void cz();
void xg();
void sc();
void cc();
void px();
int N;
struct student
{
char xh[20];
char mz[20];
char xb[20];
char nl[20];
char cj[20];
}stu[100];
int main()
{
zjm();
return 0;
}
void zjm()
{
system("color F0");
cout<<endl;
cout<<" ╔════════════════════════╗"<<endl;
cout<<" ║ ║"<<endl;
cout<<" ║ 欢迎登陆本系统 ║"<<endl;
cout<<" ║ ║"<<endl;
cout<<" ║ ║"<<endl;
cout<<" ╚════════════════════════╝"<<endl;
cout<<" ◤━━━━━━━━━━━━━━━━━━━━━━━◥"<<endl;
cout<<" "<<endl;
cout<<" ≡≡≡学生成绩管理系统 ≡≡≡ "<<endl;
cout<<" ◣━━━━━━━━━━━━━━━━━━━━━━━◢"<<endl;
cout<<" ╔════════════════════════╗"<<endl;
cout<<" ║ 组长: ║"<<endl;
cout<<" ║ 组员: ║"<<endl;
cout<<" ║ 组员: ║"<<endl;
cout<<" ║ 指导教授: ║"<<endl;
cout<<" ╚════════════════════════╝"<<endl;
char zh[10];
char mm[10];
cout<<" 请输入用户密码"<<endl;
cout<<" 用户:";
cin>>zh;
cout<<" 密码:";
cin>>mm;
if(0== strcmp( "yx21",zh) && 0== strcmp( "123",mm))
{
xz();
}
else
{
cw();
}
}
void cw()
{
system("cls");
cout<<" ╔════════════════════════╗"<<endl;
cout<<" ║ ≡≡≡学生成绩管理系统 ≡≡≡ ║"<<endl;
cout<<" ╚════════════════════════╝"<<endl;
cout<<" 用户名或密码错误! "<<endl;
cout<<" 请重新输入用户密码"<<endl;
cout<<" 用户:";
char zh[10];
char mm[10];
cin>>zh;
cout<<" 密码:";
cin>>mm;
if( 0== strcmp( "yx21",zh) && 0== strcmp( "123",mm))
{
xz();
}
else
{
cw();
}
}
void xz()
{
system("cls");
cout<<" ╔════════════════════════╗"<<endl;
cout<<" ║ 欢迎进入学生信息管理系统 ║"<<endl;
cout<<" ╚════════════════════════╝"<<endl;
cout<<" ◤━━━━━━━━━━━━━━━━━━━━━━━◥"<<endl;
cout<<" ┃ <1>. 输入学生信息 ┃"<<endl;
cout<<" ┃ <2>. 添加学生信息 ┃"<<endl;
cout<<" ┃ <3>. 显示学生信息 ┃"<<endl;
cout<<" ┃ <4>. 查找学生信息 ┃"<<endl;
cout<<" ┃ <5>. 修改学生信息 ┃"<<endl;
cout<<" ┃ <6>. 删除学生信息 ┃"<<endl;
cout<<" ┃ <7>. 保存学生信息 ┃"<<endl;
cout<<" ┃ <8>. 成绩排序 ┃"<<endl;
cout<<" ┃ <0>. 退出系统 ┃"<<endl;
cout<<" ◣━━━━━━━━━━━━━━━━━━━━━━━◢"<<endl;
char a;
cout<<" 请输入您要进行的操作选项:";
cin>>a;
switch(a)
{
case '1': sr();xz();break;
case '2': tj();xz();break;
case '3': xs();xz();break;
case '4': cz();xz();break;
case '5': xg();xz();break;
case '6': sc();xz();break;
case '7': cc();xz();break;
case '8': px();xz();break;
case '0': break;
}
}
void sr()
{
system("cls");
cout<<"请输入学生的人数:";
cin>>N;
cout<<"现在开始输入: "<<endl;
cout<<"━━━━━━━━━━━━━━━━"<<endl;
cout<<"学号 姓名 性别 年龄 成绩"<<endl;
cout<<"━━━━━━━━━━━━━━━━"<<endl;
for(int i=0;i<N;i++)
{
cin>>stu[i].xh>>stu[i].mz>>stu[i].xb>>stu[i].nl>>stu[i].cj;
}
}
void tj()
{
system("cls");
cout<<"请输入您要添加的学生的信息:"<<endl;
cout<<"━━━━━━━━━━━━━━"<<endl;
cout<<"学号 姓名 性别 年龄 成绩"<<endl;
cout<<"━━━━━━━━━━━━━━"<<endl;
cin>>stu[N].xh>>stu[N].mz>>stu[N].xb>>stu[N].nl>>stu[N].cj;
N++; //学生人数N+1
system("pause");
}
void xs()
{
system("cls");
cout<<"━━━━━━━━━━━━━━"<<endl;
cout<<"学号 姓名 性别 年龄 成绩"<<endl;
cout<<"━━━━━━━━━━━━━━"<<endl;
for(int i=0;i<N;i++)
{
cout<<stu[i].xh<<" "<<stu[i].mz<<" "<<stu[i].xb<<" "<<stu[i].nl<<" "<<stu[i].cj;
cout<<endl;
}
system("pause");
}
void cz()
{
system("cls");
char number[20];
cout<<"请输入您要查询的学生的学号:";
cin>>number;
cout<<"━━━━━━━━━━━━━━"<<endl;
cout<<"学号 姓名 性别 年龄 成绩"<<endl;
cout<<"━━━━━━━━━━━━━━"<<endl;
for(int i=0;i<N;i++)
{
if(strcmp(stu[i].xh,number)==0)
{
cout<<stu[i].xh<<" "<<stu[i].mz<<" "<<stu[i].xb<<" "<<stu[i].nl<<" "<<stu[i].cj;
}
}
cout<<endl;
system("pause");
}
void xg()
{
system("cls");
char number[20];
cout<<"请输入您要修改的学生的学号:";
cin>>number;
cout<<"请输入新的信息:"<<endl;
cout<<"━━━━━━━━━━━━━━"<<endl;
cout<<"学号 姓名 性别 年龄 成绩"<<endl;
cout<<"━━━━━━━━━━━━━━"<<endl;
for(int i=0;i<N;i++)
{
if(strcmp(stu[i].xh,number)==0)
cin>>stu[i].xh>>stu[i].mz>>stu[i].xb>>stu[i].nl>>stu[i].cj;
}
system("pause");
}
void sc()
{
system("cls");
char number[20];
cout<<"请输入要删除的学生的学号:";
cin>>number;
for(int i=0;i<N;i++)
{
if(strcmp(stu[i].xh,number)==0)
{
for(i;i<N;i++)
{
stu[i]=stu[i+1];
}
}
}
cout<<"删除学生信息执行完毕,已删除该学生信息"<<endl;
N--;
system("pause");
}
void cc()
{
system("cls");
ofstream outfile("student.txt",ios::out);
for(int i=0;i<N;i++)
{
outfile<<stu[i].xh<<" "<<stu[i].mz<<" "<<stu[i].xb<<" "<<stu[i].nl<<" "<<stu[i].cj<<endl;
}
outfile.close();
cout<<"已成功保存信息。"<<endl;
system("pause");
}
void px()
{
system("cls");
cout<<"━━━━━━━━━━━━━━"<<endl;
cout<<"成绩"<<endl;
cout<<"━━━━━━━━━━━━━━"<<endl;
int i,j;
if(stu[i].cj[j]>stu[i].cj[j+1])
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
cout<<stu[i].cj[j];
}
}
else
{
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
cout<<stu[i].cj[j+1];
}
}
}
system("pause");
}
用冒泡或者选择等排序算法都可以的。
希望对题主有所帮助,可以的话,帮忙点个采纳!