按照网友要求,我做了一个学生管理系统
?花了好几天(主要是因为构思和做其他事情花了一些时间)
#undef UNICODE
#undef _UNICODE
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<windows.h>
#include<conio.h>
#include<fstream>
#include<algorithm>
using namespace std;
namespace b_game
{
//常量
const long long ESC=27,
Enter=13,
Tab=9,
Shang=38,
Xia=40,
Zuo=37,
You=39,
Kong=' ',
z_sb=VK_LBUTTON,
y_sb=VK_RBUTTON,
Shift=VK_SHIFT,
z_Shift=VK_LSHIFT,
y_Shift=VK_RSHIFT,
Ctrl=VK_CONTROL,
z_Ctrl=VK_LCONTROL,
y_Ctrl=VK_RCONTROL,
Alt=VK_MENU,
z_Alt=VK_LMENU,
y_Alt=VK_RMENU,
A='A',
B='B',
C='C',
D='D',
E='E',
F='F',
G='G',
H='H',
I='I',
J='J',
K='K',
L='L',
M='M',
N='N',
O='O',
P='P',
Q='Q',
R='R',
S='S',
T='T',
U='U',
V='V',
W='W',
X='X',
Y='Y',
Z='Z';
//结构体
struct hl//行列
{
long long h,l;
};
//函数
bool axj(long long key)
{
return (GetKeyState(key)<0);
}
void bout(string n, long long s=50,bool f=0,char key=13)//输出
{
for (long long i = 0; i < n.size(); i++)
{
if (f&&GetKeyState(key)<0)
{
cout<<n.substr(i,n.size());
return ;
}
cout << n[i];
Sleep(s);
}
return;
}
void gs(long long h, long long l, string z)//格式
{
for (long long i = 1; i <= h; i++)
cout << "\n";
for (long long i = 1; i <= l; i++)
cout << " ";
cout << z;
return;
}
void yanse(int n)//颜色
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), n);
return;
}
void ycbj()//移除快速编辑模式
{
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin, &mode);
mode&=~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
return ;
}
void ycgb()//隐藏光标
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = FALSE;
cursor.dwSize = sizeof(cursor);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
return;
}
void ydgb(long long h, long long l)//移动光标
{
COORD pos = { l-1,h-1 };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
return;
}
}
using namespace b_game;
long long rens;
bool cx_flag=1;
struct _st
{
string mz,js;
long long nj,xh;
bool xb,f;
}st[10000000],csst={"","",0,0,1,1},ls;
bool cmp(_st _1,_st _2)
{
if(_1.f&&_2.f)
{
return _1.xh<_2.xh;
}
else
{
if(_1.f)
{
return 1;
}
else
{
return 0;
}
}
}
namespace cd
{
void out()
{
long long tot=0;
ofstream cd1("信息.txt");
for(long long i=1;i<=rens;i++)
{
if(st[i].f)
{
cd1<<st[i].mz<<"\n";
cd1<<st[i].xh<<"\n";
cd1<<st[i].xb<<"\n";
cd1<<st[i].nj<<"\n";
cd1<<st[i].js<<"\n";
cd1<<"\n";
}
else
{
tot++;
}
}
rens-=tot;
cd1.close();
ofstream cd2("人数.txt");
cd2<<rens<<"\n";
cd2.close();
return ;
}
void in()
{
ifstream cd1("人数.txt");
cd1>>rens;
cd1.close();
ifstream cd2("信息.txt");
for(long long i=1;i<=rens;i++)
{
cd2>>st[i].mz;
cd2>>st[i].xh;
cd2>>st[i].xb;
cd2>>st[i].nj;
cd2>>st[i].js;
st[i].f=1;
}
cd2.close();
return ;
}
};
void zy();
void zc();
void sc();
void ck();
int main()
{
yanse(240);
system("cls");
system("mode con cols=80 lines=20");
system("title 学生管理系统");
ycbj();
cout<<"正在加载...";
cd::in();
ls=csst;
system("cls");
while(cx_flag)
{
system("cls");
zy();
}
system("cls");
cout<<"正在储存数据...";
cd::out();
return 0;
}
void zy()
{
system("cls");
char s;
gs(3,30,"学生管理系统");
gs(3,30,"0.退出");
gs(2,30,"1.注册");
gs(2,30,"2.删除");
gs(2,30,"3.查看\n\n\n\n\n\n\n ");
s=_getch();
while(s!='0'&&s!='1'&&s!='2'&&s!='3')s=_getch();
switch(s)
{
case '0':
cx_flag=0;
system("cls");
return ;
case '1':
zc();
break;
case '2':
sc();
break;
case '3':
ck();
break;
}
return ;
}
void zc()
{
ls=csst;
string t;
system("cls");
gs(1,1,"姓名:");
cin>>ls.mz;
gs(1,1,"学号:");
cin>>ls.xh;
for(long long i=1;i<=rens;i++)
{
if(st[i].xh==ls.xh&&st[i].f)
{
cout<<"\n该学号已存在";
ls=csst;
Sleep(1000);
system("cls");
return ;
}
}
gs(1,1,"年龄:");
cin>>ls.nj;
gs(1,1,"性别(男/女或1/0或b/g):");
cin>>t;
if(t!="男"&&t!="女"&&t!="1"&&t!="0"&&t!="b"&&t!="g")
{
cout<<"\n请按要求输入";
ls=csst;
Sleep(1000);
system("cls");
return ;
}
if(t=="男"||t=="1"||t=="b")
{
ls.xb=1;
}
else
{
ls.xb=0;
}
gs(1,1,"请输入该学生介绍(下划线(_)表示换行&下一行继续写):\n");
ls.js="";
string s;
do
{
cin>>s;
ls.js+=s;
}
while(s[s.size()-1]=='_');
system("cls");
cout<<"注册成功!";
rens++;
st[rens]=ls;
sort(st+1,st+rens+1,cmp);
Sleep(1000);
return ;
}
void sc()
{
long long t;
system("cls");
gs(1,1,"请输入要删除的学生的学号:");
cin>>t;
for(long long i=1;i<=rens;i++)
{
if(t==st[i].xh&&st[i].f)
{
st[i].f=0;
cout<<"删除成功";
Sleep(1000);
system("cls");
return ;
}
}
cout<<"无此学生";
Sleep(1000);
system("cls");
return ;
}
void ck()
{
system("cls");
long long t;
char s;
for(long long i=1;i<=rens;i++)
{
if(st[i].f)
{
cout<<st[i].xh<<" ";
}
}
cout<<"\n请输入你要查看的学生的学号:";
cin>>t;
for(long long i=1;i<=rens;i++)
{
if(st[i].xh==t&&st[i].f)
{
system("cls");
cout<<"名字:"<<st[i].mz<<"\n";
cout<<"学号:"<<st[i].xh<<"\n";
cout<<"年龄:"<<st[i].nj<<"\n";
cout<<"性别:"<<((st[i].xb==1)?("男"):("女"))<<"\n";
cout<<"介绍:\n";
for(long long j=0;j<st[i].js.size();j++)
{
if(st[i].js[j]=='_')
{
cout<<"\n";
}
else
{
cout<<st[i].js[j];
}
}
cout<<"\n--------------------------------------------------------------------------------\n按空格继续";
s=_getch();
while(s!=' ')s=_getch();
system("cls");
return ;
}
}
cout<<"没有这个学生!\n";
Sleep(1000);
system("cls");
return ;
}
|