stuInfos[i]=stuInfos[i+1];
}
total--;
flag=true;
break;} } return flag;
public
void 删除页面(){ System.out.print(“删除页面”);//请输入要删除的学号
try{
int choice;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“1:学生信息修改”);
System.out.println(“2:学生信息删除”);
System.out.println(“请输入您的选择(1--2)”);
//...choice = Integer.parseInt(buf.readLine());
switch(choice){
case 1:
System.out.println(“请输入要修改的学号:”);choice = Integer.parseInt(buf.readLine());
修改学生(choice);
break;case 2:
System.out.println(“请输入要删除的学号:”);choice = Integer.parseInt(buf.readLine());
删除学生(choice);break;//补充
} /*if(删除学生(choice)){
System.out.print(“删除成功!”);//删除成功
}else{
System.out.print(“删除失败!”);//删除失败
}*/ }catch(Exception e){ out.print(e);} } public void showMenu(){ try{
int choice;
do{
System.out.println(“学生管理系统主菜单界面”);
System.out.println(“1:学生信息录入”);
System.out.println(“2:学生信息浏览”);
System.out.println(“3:学生信息查询”);
System.out.println(“4:学生修改与删除”);
System.out.println(“5:学生信息保存”);
System.out.println(“6:学生信息读取”);
System.out.println(“0:退出系统”);
System.out.println(“请输入您的选择(0--6)”);
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
choice = Integer.parseInt(buf.readLine());
switch(choice){
case 1:
信息录入();//
break;
case 2:
//补全方法调用
显示学生(stuInfos, total);
break;
case 3:
查找菜单();
break;
case 4:
删除页面();
break;
case 5:
保存数据();
break;
case 6:
读取数据();
break;
default:
System.out.print(“出现异常!”);
}
}while(choice!=0);
}catch(Exception e){
System.out.println(e);
}
// TODO 自动生成的方法存根
}
public static void main(String[] args){
Student student = new Student();
student.showMenu();
} }
//异常:7
第二篇:VB学生信息管理系统及源代码
VB学生信息管理系统及源代码
Option Explicit
'标识是否能关闭
Dim mbClose As Boolean
'标识当前要显示的照片的文件 Dim mstrFileName As String Private Sub Form_Load()
On Error Resume Next
If frmMain.mnUserType = 1 Then
'学生用户
fraSeek.Enabled = False
fraBrowse.Enabled = False
cmdAdd.Enabled = False
cmdDelete.Enabled = False
txtSerial.Enabled = False
dcbClass.Enabled = False
grdScan.Enabled = False
If Not(DataEnv.rsStudent.EOF And DataEnv.rsStudent.BOF)Then
Dim Temp As String
Temp = “name = ” & “'” & frmMain.msUserName & “'”
DataEnv.rsStudent.MoveFirst
DataEnv.rsStudent.Find Temp
'刷新所绑定的控件
Call RefreshBinding
End If
Exit Sub
Else
fraSeek.Enabled = True
fraBrowse.Enabled = True
cmdAdd.Enabled = True
cmdDelete.Enabled = True
txtSerial.Enabled = True
dcbClass.Enabled = True
grdScan.Enabled = True
End If
Dim rsDep As New ADODB.Recordset, rsClass As New ADODB.Recordset
Set rsDep = DataEnv.rsDepartment
Set rsClass = DataEnv.rsClass
rsDep.Open
'从Department表中读取数据,填充cboDep组合框到中
cboDep.Clear
cboDep.AddItem “全部”
'将各个系的id号作为ItemData附加到组合框中
cboDep.ItemData(0)= 0
While Not rsDep.EOF
cboDep.AddItem rsDep(“Name”)
cboDep.ItemData(cboDep.ListCount1)
ChunkAry = blobColumn.GetChunk(Fragment)
Put FileNumber, , ChunkAry
'写入文件
End If
ReDim ChunkAry(ChunkSize-1)
'为数据块重新开辟空间
For lngI = 1 To Chunks
'循环读出所有块
ChunkAry = blobColumn.GetChunk(ChunkSize)
'在数据库中连续读数据块
Put FileNumber, , ChunkAry()
'将数据块写入文件中
Next lngI
Close FileNumber
ReadImage = strFileName
Exit Function
errHander:
ReadImage = “" End Function
Private Sub imgPhoto_Click()End
'关闭文件 Sub
Option Explicit '表示当前的用户类型:0---管理员类型的用户;1---学生类型的用户 Public mnUserType As Integer '表示当前登录的用户名 Public msUserName As String
Private Sub MDIForm_Load()
'根据不同的用户类型,使相应的菜单项可见
Select Case mnUserType
Case 0:
'以管理员身份登录
mnuFind.Visible = True
tlbMain.Buttons.Item(3).Visible = True
tlbMain.Buttons.Item(4).Visible = True
Exit Sub
Case 1:
'以学生身份登录,只能查询自己的信息
mnuFind.Visible = False
'“信息查询”菜单不可见
tlbMain.Buttons.Item(3).Visible = False
'“信息查询”按钮不可见
tlbMain.Buttons.Item(4).Visible = False
'第二个分隔条不可见
Exit Sub
End Select End Sub
Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox(”真的要对出本系统吗?“, vbQuestion + vbYesNo + vbDefaultButton2, ”退出“)= vbNo Then
Cancel = 1
End If End Sub Private Sub mnuAbout_Click()
Load frmSplash
frmSplash.mbAbout = True
frmSplash.Show vbModal End Sub
Private Sub mnuArr_Click()
frmMain.Arrange(3)
'设置主窗体中所有最小化MDI子窗体图标重排 End Sub
Private Sub mnuCas_Click()
frmMain.Arrange(0)
'设置主窗体中所有非最小化MDI子窗体层叠显示 End Sub
Private Sub mnuExit_Click()
Unload Me End Sub
Private Sub mnuFind_Click()
frmFind.Show End Sub
Private Sub mnuHori_Click()
frmMain.Arrange(1)
'设置主窗体中所有非最小化MDI子窗体水平平铺 End Sub
Private Sub mnuLog_Click()
If MsgBox(”若重新登录,所有窗体都将关闭!“ & vbCrLf & ”
是否重新登录?“, _
vbQuestion + vbYesNo + vbDefaultButton2, ”重新登录“)= vbYes Then
Unload Me
frmLogin.Show
End If End Sub
Private Sub mnuStudent_Click()
Load frmStudent
frmStudent.Show End Sub Private Sub mnuVer_Click()
frmMain.Arrange(2)
'设置主窗体中所有非最小化MDI子窗体垂直平铺 End Sub
Private Sub tlbMain_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case ”Student“
mnuStudent_Click
Exit Sub
Case ”Find“
mnuFind_Click
Exit Sub
Case ”Login“
mnuLog_Click
Exit Sub
Case ”Exit“
mnuExit_Click
Exit Sub
End Select End SubOption Explicit
'表示当前用户登录所选择的身份,即用户类型, 0-表示教务管理人员;1-表示学生 Dim mnUserType As Integer Private Sub cmdCancel_Click()
Unload Me End Sub
Private Sub cmdOK_Click()
'取得用户输入的用户名和密码
Dim user As String, pwd As String
user = Trim(txtUser)
pwd = Trim(txtPwd)
'根据不同的身份,选择不同的表用以查询
Dim r As New ADODB.Recordset
Set r = DataEnv.rssqlSeek
Dim strSQL As String
Select Case mnUserType
Case 0: '若身份为管理员
strSQL = ”select * from 系统人员表 where name='“ & user & ”' and pwd='“ & pwd & ”'“
Case 1: '若身份为学生
strSQL = ”select * from 学生信息表 where name='“ & user & ”' and serial='“ & pwd & ”'“
End Select
On Error Resume Next
'查询DataEnv.rssqlSeek的状态,如果已经打开,则先关闭
If r.State = adStateOpen Then r.Close
r.Open strSQL
'根据strSQL的内容刷新DataEnv.rssqlSeek
'用户密码错误的次数,如果错误次数超过3次,则退出系统
Static nTryCount As Integer
If r.EOF Then
'登录失败
MsgBox ”对不起,无此用户或者密码不正确!请重新输入!“, vbCritical, ”错误“
txtUser.SetFocus
txtUser.SelStart = 0
txtUser.SelLength = Len(txtUser)
nTryCount = nTryCount + 1
If nTryCount >= 3 Then
MsgBox ”您无权操作本系统!“, vbCritical, ”错误“
Unload Me
End If
Else
'登陆成功
'显示MDI窗体, 并将用户类型和用户名传到MDI窗体中的mnUserType, msUserName中
With frmMain
.mnUserType = mnUserType
.msUserName = user
End With
Load frmMain
frmMain.Show
Unload Me
End If End Sub Private Sub Form_Load()
optUserType(0).Value = True End Sub
Private Sub optUserType_Click(Index As Integer)
mnUserType = Index End Sub Explicit
Private Sub Command1_Click()
Dim strCon1 As String
Dim strCon2 As String
On Error GoTo myerr
If Trim(Text1.Text)= ”“ Or Trim(Text2.Text)= ”“ Then
If MsgBox(”请输入查询条件!“, vbInformation, ”提示“)Then GoTo myerr
End If
Select Case Trim(Combo1.Text)
Case ”学号“
strCon1 = ”Serial“
Case ”姓名“
strCon1 = ”Name“
Case ”班级“
strCon1 = ”Class“
Option
Case ”生日“
strCon1 = ”Birthday“
Case ”性别“
strCon1 = ”Sex“
Case ”家庭地址“
strCon1 = ”Address“
Case ”电话“
strCon1 = ”Tel“
End Select
Select Case Trim(Combo4.Text)
Case ”学号“
strCon2 = ”Serial“
Case ”姓名“
strCon2 = ”Name“
Case ”班级“
strCon2 = ”Class“
Case ”生日“
strCon2 = ”Birthday“
Case ”性别“
strCon2 = ”Sex“
Case ”家庭地址“
strCon1 = ”Address“
Case ”电话“
strCon2 = ”Tel“
End Select
DataEnv.rsStudent.Close
DataEnv.rsStudent.Open ”select * from 学生信息表
where “ & _
strCon1 & Trim(Combo2.Text)& ” '“ & Trim(Text1.Text)_
& ”'“ & ” “ & Trim(Combo3.Text)& ” “ & strCon2 & _
Trim(Combo5.Text)& ”'“ & Trim(Text2.Text)& ”'“
dgdCX.DataMember = ”“
dgdCX.Refresh
DataEnv.rsStudent.Requery
dgdCX.DataMember = ”Student“
dgdCX.Refresh myerr: End Sub
Private Sub Command3_Click()
Unload Me End Sub
Private Sub dgdCX_Click()
End Sub
Private Sub Form_Load()
'添加Combo1的子项作为查询标准
Combo1.AddItem(”学号“)
Combo1.AddItem(”姓名“)
Combo1.AddItem(”班级“)
Combo1.AddItem(”生日“)
Combo1.AddItem(”性别“)
Combo1.AddItem(”家庭地址“)
Combo1.AddItem(”电话“)
Combo1.ListIndex = 0
'添加Combo2的子项作为关系符
Combo2.AddItem(”=“)
Combo2.AddItem(”>“)
Combo2.AddItem(”>=“)
Combo2.AddItem(”<“)
Combo2.AddItem(”<=“)
Combo2.AddItem(”<>“)
Combo2.ListIndex = 0
'添加Combo3的子项作为逻辑连接符
Combo3.AddItem(”And“)
Combo3.AddItem(”Or“)
Combo3.ListIndex = 0
'添加Combo4的子项作为第二种查询标准
Combo4.AddItem(”学号“)
Combo4.AddItem(”姓名“)
Combo4.AddItem(”班级“)
Combo4.AddItem(”生日“)
Combo4.AddItem(”性别“)
Combo4.AddItem(”家庭地址“)
Combo4.AddItem(”电话“)
Combo4.ListIndex = 0
'添加Combo5的子项作为第二种关系符
Combo5.AddItem(”=“)
Combo5.AddItem(”>“)
Combo5.AddItem(”>=“)
Combo5.AddItem(”<“)
Combo5.AddItem(”<=“)
Combo5.AddItem(”<>")
Combo5.ListIndex = 0 End Sub
Private Sub Form_Unload(Cancel As Integer)
frmMain.Enabled = True
frmMain.Show End Sub
第三篇:职工信息管理系统源代码
#include #include #include int N=2;struct worker/*定义一个职工信息的结构体*/ {
intnum;
/*定义一个职工信息的结构体*/ char name[20];
/*定义一个职工信息的结构体*/
char sex[10];
//用字符串存放职工的性别数据
char birth[20];//用字符串存放职工的出生年月数据
char deta[20];//用字符串存放职工的工作年月数据
char education[20];//用字符串存放职工的学历数据
double salary;
//用字符串存放职工的性别数据
char work[30];//用字符串存放职工的职务数据
char addr[20];//用字符串存放职工的地址数据
char tel[20];//用字符串存放职工的电话数据 }worker[100];//用结构体数组存放职工的所有信息 void menu();
void input();
void save();
void read();
void display();
void add();
void search();
voidsearch_education();
voidsearch_num();
void del();
void modify();
void main()
{ char s;
system(“color 3f”);
printf(“nn”);
printf(“ t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓n”);
printf(“ t┃**********************************************************┃n”);
printf(“ t┃***┏━━━━━━━━━━━━━━━━━━━━━━━━┓***┃n”);
printf(“ t┃***┃************************************************┃***┃n”);
printf(“ t┃***┃***
****┃***┃n”);
printf(“ t┃***┃***
欢迎使用职工信息管理系统
****┃***┃n”);
printf(“ t┃***┃***
****┃***┃n”);
printf(“ t┃***┃***
****┃***┃n”);
printf(“ t┃***┃***
制作人吴青伶
****┃***┃n”);
printf(“ t┃***┃***
****┃***┃n”);
printf(“ t┃***┃***
2013.12.28
****┃***┃n”);
printf(“ t┃***┃***
****┃***┃n”);
printf(“ t┃***┃************************************************┃***┃n”);
printf(“ t┃***┗━━━━━━━━━━━━━━━━━━━━━━━━┛***┃n”);
printf(“ t┃**********************************************************┃n”);printf(“ t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛n”);do { menu();printf(“Do you want to continue?(y/n)”);
s=getchar();}while(s=='Y'||s=='y');} void menu()/*菜单函数*/ { int b;printf(“t
n”);printf(“t
n”);printf(“t
n”);printf(“t
n”);printf(“t
n”);printf(“t
请选择
n”);printf(“t
------------------------------n”);printf(“t
||
||
n”);printf(“t
||
1.职工信息录入
||
n”);printf(“t
||
2.职工信息浏览
||
n”);printf(“t
||
3.职工信息添加
||
n”);printf(“t
||
4.职工信息查询
||
n”);printf(“t
||
5.职工信息删除
||
n”);printf(“t
||
6.职工信息修改
||
n”);printf(“t
||
0.退出
||
n”);printf(“tn”);printf(“n 输入你的选择项(0~6):n”);
scanf(“%d”,&b);
switch(b)
{
case 1 : //职工信息录入、保存
input();
save();
getchar();
break;
case 2 ://读入职工信息并显示
read();
display();
getchar();break;
case 3 : //添加职工信息
add();getchar();break;
case 4 : //查询职工信息
search();getchar();break;
case 5 : //读入职工信息并实现职工信息删除功能
read();
del();
getchar();
break;
case 6 : //读入职工信息并修改职工信息
read();modify();getchar();break;
case 0 : exit(0);//退出
default:break;} } void input()
//录入职工信息 {
inti,flag,j;printf(“输入职工个数(默认个数为2):”);scanf(“%d”,&N);fflush(stdin);//清除缓存 for(i=0;i{ loop: printf(“职工号:”);scanf(“%d”,&worker[i].num);fflush(stdin);flag=1;if(worker[N].num<0)
printf(“请输入正整数:n”);else for(j=0;j
{
if(worker[i].num==worker[j].num)
{
flag=0;
printf(“ 工号重复,请重新输入!n”);
goto loop;
}
} printf(“姓名:”);scanf(“%s”,worker[i].name);fflush(stdin);printf(“性别:”);scanf(“ %s”,worker[i].sex);fflush(stdin);printf(“出生年月:”);scanf(“%d”,&worker[i].birth);fflush(stdin);printf(“工作年月:”);scanf(“%lf”,&worker[i].deta);fflush(stdin);printf(“请输入学历(中专=zz,大专=dz,本科=bk,研究生=yjs):n”);scanf(“%s”,worker[i].education);fflush(stdin);printf(“工资:”);scanf(“%lf”,worker[i].salary);fflush(stdin);printf(“职务:”);scanf(“%s”,worker[i].work);fflush(stdin);printf(“住址:”);scanf(“%s”,worker[i].addr);fflush(stdin);printf(“电话:”);scanf(“%s”,worker[i].tel);fflush(stdin);
} printf(“n创建完毕!n”);}
void save()
//保存函数 {
FILE *fp;int i;
if((fp=fopen(“worker.txt”,“wb”))==NULL)//以只写方式打开一个二进制文件
{
printf(“ncannot open filen”);
exit(0);} for(i=0;ivoid read()
//读入函数 {
FILE *fp;int i=0;
if((fp=fopen(“worker.txt”,“rb”))==NULL)//以只读方式为输出打开磁盘文件中的一个二进制文件
{
printf(“ncannot open filen”);
exit(0);} do{ fread(&worker[i],sizeof(struct worker),1,fp);//从worker.txt文件向内存读入数据(二进制)
i++;}while(!feof(fp));fclose(fp);
N=i-1;}
void display()
//信息浏览函数 {
int i;for(i=0;i{ printf(“职工号:%dn”,worker[i].num);printf(“姓名:%sn”,worker[i].name);printf(“性别:%sn”,worker[i].sex);printf(“出生年月:%dn”,worker[i].birth);printf(“工作年月:%dn”,worker[i].deta);printf(“学历:%sn”,worker[i].education);printf(“工资:%lfn”,worker[i].salary);printf(“职务:%dn”,worker[i].work);printf(“住址:%sn”,worker[i].addr);printf(“电话:%sn”,worker[i].tel);
} } void add()
//添加函数 { FILE *fp;int i;struct worker p;double t;printf(“n请输入新增加职工的信息:n”);
printf(“请输入职工号:n”);
scanf(“%d”,&p.num);
for(i=0;i{
while(worker[i].num==p.num)
{
printf(“ 工号重复,请重新输入!n”);
scanf(“%d”,&p.num);
}
} printf(“请输入姓名:n”);scanf(“%s”,p.name);printf(“请输入性别:n”);scanf(“%s”,p.sex);printf(“请输入出生年月:n”);scanf(“%d”,&p.birth);printf(“请输入工作年月:n”);scanf(“%d”,&p.deta);printf(“请输入学历(中专=zz,大专=dz,本科=bk,=yjs:):n”);scanf(“%s”,p.education);printf(“请输入工资:n”);scanf(“%lf”,&t);p.salary=t;printf(“请输入职务:n”);scanf(“%s”,p.work);printf(“请输入住址:n”);scanf(“%s”,p.addr);printf(“请输入电话:n”);scanf(“%s”,p.tel);printf(“n添加完毕!n”);
if((fp=fopen(“worker.txt”,“ab”))==NULL)//以追加方式打开一个二进制文件尾部
{ printf(“ncannot open filen”);exit(0);
} fwrite(&p,sizeof(struct worker),1,fp);fclose(fp);} void search()
//查询函数 {
int c;do {
puts(“nsearch by=>n1.学历2.职工号3.取消并返回”);printf(“Which you needed?:n”);scanf(“%d”,&c);
研究生if(c>3||c<1)
{
puts(“nchoiceerror!please again!”);getchar();//此语句用于接受在执行上一句时最后输出的回车符
}
} while(c>3||c<1);
{ switch(c)
{ case 1:search_education();break;case 2:search_num();break;case 3:menu();break;
}
} } void search_education()
//按学历查询函数 { inti,flag=0;char s[10];printf(“n请输入你要查询的学历:n”);scanf(“%s”,s);for(i=0;i{ if(strcmp(s,worker[i].education)==0)
{
printf(“职工号:%dn”,worker[i].num);
printf(“姓名:%sn”,worker[i].name);
printf(“性别:%sn”,worker[i].sex);
printf(“出生年月:%dn”,worker[i].birth);
printf(“工作年月:%dn”,worker[i].deta);
printf(“学历(中专=zz,大专=dz,yjs):%sn”,worker[i].education);printf(“工资:%lfn”,worker[i].salary);printf(“职务:%lfn”,worker[i].work);
printf(“住址:%sn”,worker[i].addr);
printf(“电话:%sn”,worker[i].tel);flag++;
}
} if(flag==0)
printf(“n对不起没有找到!n”);getchar();} void search_num()
//按工号查询函数 { inti,s,flag=0;printf(“n输入要查询的职工号!:n”);scanf(“%d”,&s);
本科=bk,研究生=for(i=0;i{
if(s==worker[i].num)
{
printf(“职工号:%dn”,worker[i].num);
printf(“姓名:%sn”,worker[i].name);
printf(“性别:%sn”,worker[i].sex);
printf(“出生年月:%dn”,worker[i].birth);
printf(“工作年月:%dn”,worker[i].deta);
printf(“学历(中专=zz,大专=dz,本科=bk,研究生=yjs):%sn”,worker[i].education);
printf(“工资:%lfn”,worker[i].salary);printf(“职务:%lfn”,worker[i].work);
printf(“住址:%sn”,worker[i].addr);
printf(“电话:%sn”,worker[i].tel);
flag++;
}
}
if(flag==0)printf(“n对不起没有找到!please”);
getchar();}
void del()
//删除函数 { inti,j;FILE *fp;char name[20];char c;if((fp=fopen(“worker.txt”,“wb”))==NULL)//以只写方式打开一个二进制文件
{
printf(“ncannot open filen”);exit(0);
} printf(“请输入要删除的职工的姓名:”);scanf(“%s”,name);for(i=0;iif(strcmp(name,worker[i].name)==0)//判断输入的姓名和原来的姓名是否相同
{
printf(“找到该职工,是否删除?(y/n)”);
fflush(stdin);
scanf(“%c”,&c);
if(c =='Y'||c=='y')
{
for(j=i;jworker[j]=worker[j+1];
printf(“删除成功!n”);
//break;
}
} } if(i>=N){ printf(“没有找到该职工!n ”);
return;}
else {
N=N-1;
for(i=0;iif(fwrite(&worker[i],sizeof(struct worker),1,fp)!=1)
{
printf(“ncannot save filen”);getchar();
}
fclose(fp);}
}
void modify()
//修改函数 { struct worker p;FILE *fp;inti,n;double t;printf(“n输入要修改的职工号:n”);scanf(“%d”,&n);
for(i=0;iif(n==worker[i].num)
{
printf(“找到该职工的信息(任意键继续)!”);
printf(“n请输入职工的信息!n”);
printf(“请输入姓名:n”);scanf(“%s”,p.name);
printf(“请输入性别:n”);scanf(“%s”,p.sex);
printf(“请输入出身年月:n”);scanf(“%d”,&p.birth);printf(“请输入工作年月:n”);scanf(“%lf”,&p.deta);
printf(“请输入学历(中专=zz,大专=dz,yjs):n”);scanf(“%s”,p.education);printf(“请输入工资:n”);scanf(“%lf”,&t);
p.salary=t;printf(“请输入职务:n”);scanf(“%s”,p.work);
printf(“请输入住址:n”);scanf(“%s”,p.addr);
本科=bk,研究生=
}
printf(“请输入电话:n”);scanf(“%s”,p.tel);p.num=n;
if((fp=fopen(“worker.txt”,“r+”))==NULL)//以读写的方式将修改的信息写入磁盘文件
{
printf(“ncannot open filen”);
exit(0);
}
fseek(fp,i*sizeof(struct worker),0);//将位置指针移到i*sizeof(struct worker)个字节处
fwrite(&p,sizeof(struct worker),1,fp);
fclose(fp);
printf(“修改成功!n”);
break;} } if(i>=N)printf(“n未找到该职工!n”);
第四篇:C++课程设计 教职工信息管理系统源代码
教职工信息管理系统源码
#include #include #include #include
#define maxsize 100 fstream iofile;//文件指针
class Time //时间类 {
public:
int year;
int month;
int day;};
class Telem //个人信息 {
public:
char name[20];
char sex[10];
Time birthtime;//组合Time类
char num[20];
char wage[20];
Time worktime;
int year;
char department[20];
friend istream& operator>>(istream& input,Telem& T);
friend ostream& operator<<(ostream& output,Telem& T);
friend int operator-(Time & t1,Time & t2);};
class People:virtual public Telem //雇员类 {
public:
People();
virtual void AddF()=0;//添加
virtual void Addall()=0;
virtual void Add()=0;
virtual void Display();//输出数组的内容
virtual void Displaypart(char p[]);
virtual void Findname(char n[]);
virtual void Findyear(int);
virtual void Del(char n[])=0;
virtual void Del(int);protected:
Telem data[maxsize];
Time now;
int length;};
class Teacher:virtual public People //派生虚基类 {
public:
virtual void AddF();
virtual void Addall();
virtual void Add();
virtual void Display();
virtual void Del(int i);
virtual void Del(char n[]);};
class worker:virtual public People //派生虚基类 {
public:
virtual void AddF();
virtual void Addall();
virtual void Add();
virtual void Display();
virtual void Del(int i);
virtual void Del(char n[]);};
People::People()//系统自动生成的构造函数 {
length=0;
now.year=2010;
now.month=7;
now.day=6;}
void People::Display()//引用 {
int i;
for(i=0;icout<void People::Displaypart(char p[])//引用数组
{
int i,c;
for(i=0;iif(strcmp(data[i].wage,p)==0)
{
cout<<“输出选择姓名1 性别2 编号3 工资4 出生日期5 工作时间6 年龄7 系别8 退出选择9”<while(cin>>c)
{
switch(c)
{
case 1: cout<<“姓名:”<case 2: cout<<“性别:”<case 3: cout<<“编号:”<case 4: cout<<“工资:”<case 5: cout<<“出生日期:”<case 6: cout<<“工作时间:”<case 7: cout<<“年龄:”<case 8: cout<<“系别:”<case 9: goto loop;
default:cout<<“操作错误......”<}
}
loop:;
} }
void People::Findname(char n[])//引用 {
int i;
for(i=0;iif(strcmp(data[i].name,n)==0)//对象引用
cout<void People::Findyear(int y){
int i;
for(i=0;iif(data[i].year==y)
cout<void People::Del(int i){
int j;
if(i<1||i>length)
cout<<“不存在第”<
for(j=i;jdata[j-1]=data[j];
length--;}
void worker::AddF(){
int flag=0;
iofile.open(“worker_information.txt”,ios::in|ios::binary);//文件的打开与关闭
while(iofile.seekg(ios::cur))
{
iofile.seekg(length*sizeof(data[length]),ios::beg);
iofile.read((char*)&data[length],sizeof(data[length]));//文件的随机访问
length++;
if(length==maxsize)
{
flag=1;
goto loop;
}
}
People::Del(length);
cout<<“添加人员信息成功......”<loop:
if(1==flag)
cout<<“人员信息储存空间已满......”<iofile.close();}
void worker::Addall(){
char ans;
int flag=0;
iofile.open(“worker_information.txt”,ios::out|ios::binary);
do
{
cin>>data[length];
data[length].year=now-data[length].birthtime;
iofile.write((char*)&data[length],sizeof(data[length]));
cout<<“添加人员信息成功......”<length++;
if(length==maxsize)
{
flag=1;
goto loop;
}
cout<<“contine(Y|N)?”;
cin>>ans;
}while('y'==ans||'Y'==ans);loop:
if(1==flag)
cout<<“人员信息储存空间已满......”<iofile.close();}
void worker::Add(){
int flag=0;
iofile.open(“worker_information.txt”,ios::app|ios::out|ios::binary);
if(length==maxsize)
{
flag=1;
goto loop;
}
cin>>data[length];
data[length].year=now-data[length].birthtime;
iofile.write((char*)&data[length],sizeof(data[length]));
cout<<“添加人员信息成功......”<length++;
loop:
if(1==flag)
cout<<“人员信息储存空间已满......”<iofile.close();}
void worker::Display(){
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆工人信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<if(0==length)
cout<<“无......”<int i;
for(i=0;icout<int i,j,k;
for(i=0;iif(strcmp(data[i].name,n)==0){
k=i+1;break;}
if(k<1)
cout<<“不存在姓名”<for(j=k;jdata[j-1]=data[j];
length--;
cout<<“删除人员信息成功......”<void worker::Del(int i){
int j;
if(i<1||i>length)
cout<<“不存在第”<
for(j=i;jdata[j-1]=data[j];
length--;
cout<<“删除成功......”<}
void Teacher::AddF(){
int flag=0;
iofile.open(“Teacher_information.txt”,ios::in|ios::binary);
while(iofile.seekg(sizeof(data[length]),ios::cur))
{
if(iofile.seekg(length*sizeof(data[length]),ios::beg))
iofile.read((char*)&data[length],sizeof(data[length]));
else
break;
length++;
if(length==maxsize)
{
flag=1;
goto loop;
}
}
People::Del(length);
cout<<“添加人员信息成功......”<if(1==flag)
cout<<“人员信息储存空间已满......”<iofile.close();}
void Teacher::Addall(){
char ans;
int flag=0;
iofile.open(“Teacher_information.txt”,ios::in|ios::out|ios::binary);
do
{
cin>>data[length];
data[length].year=now-data[length].birthtime;
iofile.write((char*)&data[length],sizeof(data[length]));
cout<<“添加人员信息成功......”<length++;
if(length==maxsize)
{
flag=1;
goto loop;
}
cout<<“contine(Y|N)?”;
cin>>ans;
}while('y'==ans||'Y'==ans);loop:
if(1==flag)
cout<<“人员信息储存空间已满......”<iofile.close();}
void Teacher::Add(){
int flag=0;
iofile.open(“Teacher_information.txt”,ios::app|ios::out|ios::binary);
if(length==maxsize)
{
flag=1;
goto loop;
}
cin>>data[length];
data[length].year=now-data[length].birthtime;
iofile.write((char*)&data[length],sizeof(data[length]));
cout<<“添加人员信息成功......”<length++;loop:
if(1==flag)
cout<<“人员信息储存空间已满......”<iofile.close();}
void Teacher::Display(){
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆教师信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<if(0==length)
cout<<“无......”<int i;
for(i=0;icout<void Teacher::Del(char n[]){
int i,j,k;
for(i=0;iif(strcmp(data[i].name,n)==0)
{
k=i+1;break;
}
if(k<1)cout<<“不存在姓名”<for(j=k;jdata[j-1]=data[j];
length--;
cout<<“删除人员信息成功......”<void Teacher::Del(int i){
int j;
if(i<1||i>length)
cout<<“不存在第”<
for(j=i;jdata[j-1]=data[j];
length--;
cout<<“删除成功......”<istream& operator>>(istream& input,Telem& T){
int y,m,d;
cout<<“请输入姓名(以*结尾):”<input.getline(T.name,20,'*');
cout<<“请输入性别(以*结尾 男或女):”<input.getline(T.sex,10,'*');
cout<<“编号(以*结尾):”<input.getline(T.num,20,'*');
cout<<“工资(以*结尾):”<input.getline(T.wage,20,'*');
cout<<“请输入出生日期:”<input>>y>>m>>d;
T.birthtime.year=(y>=1900&&y<=2100)?y:1900;
T.birthtime.month=(m>=1&&m<=12)?m:1;
T.birthtime.day=(d>=1&&d<=31)?d:1;
cout<<“请输入系别(以*结尾):”<input.getline(T.department,20,'*');
cout<<“参加工作时间:”<input>>y>>m>>d;
T.worktime.year=(y>=1900&&y<=2100)?y:1900;
T.worktime.month=(m>=1&&m<=12)?m:1;
T.worktime.day=(d>=1&&d<=31)?d:1;
return input;}
ostream& operator<<(ostream& output,Telem& T){
cout<<“姓名:”;
output<cout<<“性别:”;
output<cout<<“编号:”;
output<cout<<“工资:”;
output<cout<<“出生日期:”;
output<cout<<“系别:”;
output<cout<<“参加工作时间:”;
output<cout<<“年龄:”;
output<return output;}
int operator-(Time & t1,Time & t2){
return t1.year-t2.year;}
void Showmenu(){
cout<cout<<“
欢 迎 进 入 教 职 工 信 息 管 理 系 统”<cout<<“
2010 年7月7日发布”<<“
版权所有: swa”<cout<<“
★ ☆ ★ ☆ ★ ☆ ★ ☆ ★人员信息管理系统★ ☆ ★ ☆ ★ ☆ ★ ☆ ★”<cout<<“
★
1-从键盘录入全部人员记录
☆ ”<cout<<“
☆ 2-增加一位人员记录
★”<cout<<“
★
3-显示全部人员记录
☆”<cout<<“
☆ 4-按系别输出人员信息(可选)★ ”<cout<<“
★
5-按姓名或年龄检索所有信息☆ ”<cout<<“
☆ 6-显示菜单目录
★ ”<cout<<“
★
7-结束程序运行
☆ ”<cout<<“
★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<int main(){
Teacher tea;
worker stu;
People *pt=&tea;
People *ps=&stu;
int c=0,k=0,l=0,i=0;
char nam[20],part[20];Showmenu();
for(;;)
{
cout<<“请根据菜单执行相应操作: ”;
cin>>c;
switch(c)
{
case 1:
{
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★录入全部人员记录 ★ ☆ ★ ☆ ★ ☆ ★”<cout<<“ ★ ☆ ★ ☆ ★从键盘输入教师信息 ☆ ★ ☆ ★ ☆”<pt->Addall();
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆从键盘输入工人信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<ps->Addall();
break;
}
case 2:
{
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆从键盘增加一位人员记录 ★ ☆ ★ ☆ ★ ☆ ★ ☆”<cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆教师操作请按1 工人操作请按2 ★ ☆ ★ ☆ ★ ☆ ★ ☆”<cin>>k;
if(1==k)
pt->Add();
else if(2==k)
ps->Add();
else
cout<<“操作错误...”<break;
}
case 3:
{
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆显示全部人员记录 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<pt->Display();
ps->Display();
break;
}
case 4:
{
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆按部门输出人员信息(可选)★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<cout<<“ ★ ☆ ★ ☆ ★ ☆教师操作请按1 工人操作请按2 ★ ☆ ★ ☆ ★ ☆”<cin>>k;
if(1==k)
{
cout<<“请输入要输出人员的系别(以*结尾):”<pt->Displaypart(part);
}
else if(2==k)
{
cout<<“请输入要输出人员的系别(以*结尾):”<ps->Displaypart(part);
}
else
cout<<“操作错误......”<break;
}
case 5:
{
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★按姓名或年龄检索所有信息 ★ ☆ ★ ☆ ★ ☆ ★”<cout<<“ ★ ☆ ★ ☆ ★ ☆ ★按姓名查找1 按年龄查找2 ★ ☆ ★ ☆ ★ ☆ ★”<cin>>k;
if(1==k)
{
cout<<“按姓名查找1 按年龄查找2”<>l;
if(1==l)
{
cout<<“请输入要查找人员的姓名(以*结尾):”<pt->Findname(nam);
}
else if(2==l)
{
cout<<“请输入要查找人的年龄:”<>i;
pt->Findyear(i);
}
else
cout<<“操作错误......”<}
else if(2==k)
{
cout<<“按姓名查找1 按年龄查找2”<>l;
if(1==l)
{
cout<<“请输入要查找人员的姓名(以*结尾):”<ps->Findname(nam);
}
else if(2==l)
{
cout<<“请输入要查找人的年龄:”<>i;
ps->Findyear(i);
}
else
cout<<“操作错误......”<}
else
cout<<“操作错误......”<break;
}
case 6:
{
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆显示菜单目录 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<Showmenu();
break;
}
case 7:
{
cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆结束程序运行 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<exit(0);
}
default:cout<<“操作错误......”<}
}
return 0;}
第五篇:C++大作业_职工信息管理系统源代码
#include #include #include using namespace std;
const N=5000;// 定义系统可录入的职工最大数值
string Ename[N];long Enum[N];char Esex[N];int Eage[N];
char Emarriage[N];int Edepart[N];int Eposition[N];int Edegree[N];int Eworktime[N];float Epay[N];
class Employee {
public:
string Employeename;
long Employeenum;
char Employeesex;
int Employeeage;
char Employeemarriage;
int Employeedepart;
int Employeeposition;
int Employeedegree;
int Employeeworktime;
float Employeepay;
static long EmployeeMaxNum;
static float EmployeeBasePay;
void NewInfo();
void ShowInfo();
void showall();
void showdepart(int depart);
void showdegree(int degree);
void showage(int min,int max);
void shownum(long number);
void RefreshInfo();
void DeleteInfo();
float Pay(int Employeegrade);
static int MaxNum();};
class DBOperate {
public:
string Employeename;
long Employeenum;
char Employeesex;
int Employeeage;
char Employeemarriage;
int Employeedepart;
int Employeeposition;
int Employeedegree;
int Employeeworktime;
float Employeepay;
static long EmployeeMaxNum;
static float EmployeeBasePay;
void WriteIn(int iflag);
void ReadOut();
void RefreshMaxNum(int iflag);//iflg=1 or-1 or 0 };
long Employee::EmployeeMaxNum = 1000;float Employee::EmployeeBasePay = 1500;
int Employee::MaxNum()//返回系统已经存储的人数
{
int MN = 0;
ifstream myf;
myf.open(“EmployeeMaxNum.txt”);
myf>>MN;
cout<myf.close();
return MN;}
void Employee::NewInfo()//添加新职工函数
{
cout<<“新职工姓名: ”;
cin>>Employee::Employeename;
Employee::Employeenum = EmployeeMaxNum + Employee::MaxNum()+1;
cout<<“新职工性别(F为女性,M为男性): ”;
cin>>Employee::Employeesex;
cout<<“新职工年龄: ”;
cin>>Employee::Employeeage;
cout<<“新职工婚姻状况(Y为已婚,N为未婚): ”;
cin>>Employee::Employeemarriage;
cout<<“新职工学历,请输入相应学历的序号: ”<cout<<“ [1:小学 2:初中 3:高中 4:本科 5:硕士 6:博士] ”;
cin>>Employee::Employeedegree;
while(Employee::Employeedegree!=1&&Employee::Employeedegree!=2&&Employee::Employeedegree!=3&&Employee::Employeedegree!=4&&Employee::Employeedegree!=5&&Employee::Employeedegree!=6)
{
cout<<“输入有误,请重新输入:”<cout<<“ [1:小学 2:初中 3:高中 4:本科 5:硕士 6:博士] ”;
cin>>Employee::Employeedegree;
}
cout<<“新职工所在部门,请输入相应部门的序号:”<cout<<“ [1:董事会 2:销售部 3:人事部 4:客服中心 5:财务部 6:技术研发部 7:安全监察部] ”;
cin>>Employee::Employeedepart;
while(Employee::Employeedepart!=1&&Employee::Employeedepart!=2&&Employee::Employeedepart!=3&&Employee::Employeedepart!=4&&Employee::Employeedepart!=5&&Employee::Employeedepart!=6&&Employee::Employeedepart!=7)
{
cout<<“输入有误,请重新输入:”<cout<<“ [1:董事会 2:销售部 3:人事部 4:客服中心 5:财务部 6:技术研发部 7:安全监察部] ”;
cin>>Employee::Employeedepart;
}
cout<<“新职工职位, 请输入相应职位的序号: ”<