📄 teachter.cpp
字号:
#include "teachter.h"
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<iomanip.h>
#include<string.h>
teachter::teachter()
:ChaoWei2("管理员.txt",ios::in),YanZi2("教师Modify.txt",ios::in)
{
name[30]=NULL;
Year=0;
Month=0;
Day=0;
Secret[30]=NULL;
ChaoWei2.close();
YanZi2.close();
}
bool teachter::Open()
{
char secret[30];
bool t=false;
cout<<endl;
cout<<"学生没有权限改动学生信息!\n";
cout<<endl;
cout<<"请教师输入密码(姓名的英文首字母大写和出生年月日即密码,\n";
cout<<"如张三,1970年4月6号 密码为:ZS19700406):";
cin>>secret;
cout<<endl;
ChaoWei2.open("管理员.txt",ios::in);
while((ChaoWei2>>name>>Year>>Month>>Day>>Secret)&&!t)
{
if(strcmp(Secret,secret)==0)
t=true;
}
ChaoWei2.close();
if(t)
cout<<"密码正确!";
else
cout<<"密码错误!";
return t;
}
void teachter::List()
{
char ttname[30];
bool as=true;
cout<<"输入姓名:";
cin>>ttname;
cout<<endl;
ChaoWei2.open("管理员.txt",ios::in);
while((ChaoWei2>>name>>Year>>Month>>Day>>Secret)&&as)
{
if(ttname==name)
{
cout<<"该教师信息已存在!"<<endl<<endl;
as=false;
}
}
ChaoWei2.close();
if(as)
{
ChaoWei2.open("管理员.txt",ios::app);
strcpy(name,ttname);
cout<<"请输入出生年月日:"<<endl<<endl;
cout<<"年:";
cin>>Year;
cout<<endl;
cout<<"月:";
cin>>Month;
cout<<endl;
cout<<"日:";
cin>>Day;
cout<<endl;
cout<<"请输入密码:";
cin>>Secret;
cout<<endl;
cout<<"信息录入成功!"<<endl<<endl;
ChaoWei2<<setiosflags(ios::left)<<setw(15)<<name
<<setw(15)<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)<<Secret<<endl;
ChaoWei2.close();
}
}
void teachter::Delete()
{
char Modifyname[30];
cout<<"请输入你要删除的教师的姓名:";
cin>>Modifyname;
cout<<endl;
bool ate=false;
ChaoWei2.open("管理员.txt",ios::in);
while((ChaoWei2>>name>>Year>>Month>>Day>>Secret)&&!ate)
{
if(strcmp(name,Modifyname)==0)
{
ate=true;
}
}
if(ate==false)
cout<<"系统中找不到这个教师"<<endl<<endl;
ChaoWei2.close();
if(ate==true)
{
cout<<"信息删除成功!"<<endl<<endl;
YanZi2.open("教师Modify.txt",ios::out);
ChaoWei2.open("管理员.txt",ios::in);
while(ChaoWei2>>name>>Year>>Month>>Day>>Secret)
{
if(strcmp(name,Modifyname)!=0)
YanZi2<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
}
ChaoWei2.close();
YanZi2.close();
YanZi2.open("教师Modify.txt",ios::in);
ChaoWei2.open("管理员.txt",ios::out);
while(YanZi2>>name>>Year>>Month>>Day>>Secret)
{
ChaoWei2<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
}
ChaoWei2.close();
YanZi2.close();
YanZi2.open("教师Modify.txt",ios::trunc);
YanZi2.close();
}
}
void teachter::Modify()
{
char Modifyname[30];
cout<<"请输入你要修改的教师的姓名:";
cin>>Modifyname;
cout<<endl;
bool ate=false;
ChaoWei2.open("管理员.txt",ios::in);
while((ChaoWei2>>name>>Year>>Month>>Day>>Secret)&&!ate)
{
if(strcmp(name,Modifyname)==0)
{
ate=true;
}
}
if(ate==false)
cout<<"系统中找不到这个教师"<<endl<<endl;
ChaoWei2.close();
if(ate==true)
{
YanZi2.open("教师Modify.txt",ios::out);
ChaoWei2.open("管理员.txt",ios::in);
while(ChaoWei2>>name>>Year>>Month>>Day>>Secret)
{
if(strcmp(name,Modifyname)!=0)
YanZi2<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
else
{
cout<<setiosflags(ios::left)<<setw(15)<<"姓名"<<setw(15)<<"年"
<<setw(15)<<"月"<<setw(15)<<"日"<<setw(15)<<"密码"<<endl;
cout<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
}
}
ChaoWei2.close();
cout<<"请再次输入姓名:";
cin>>name;
cout<<endl;
cout<<"请输入出生年月日:"<<endl<<endl;
cout<<"年:";
cin>>Year;
cout<<endl;
cout<<"月:";
cin>>Month;
cout<<endl;
cout<<"日:";
cin>>Day;
cout<<endl;
cout<<"请输入密码:";
cin>>Secret;
cout<<endl;
cout<<"信息修改成功!"<<endl<<endl;
YanZi2.close();
YanZi2.open("教师Modify.txt",ios::app);
YanZi2<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
YanZi2.close();
YanZi2.open("教师Modify.txt",ios::in);
ChaoWei2.open("管理员.txt",ios::out);
while(YanZi2>>name>>Year>>Month>>Day>>Secret)
{
ChaoWei2<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
}
ChaoWei2.close();
YanZi2.close();
YanZi2.open("教师Modify.txt",ios::trunc);
YanZi2.close();
}
}
void teachter::Search()
{
ChaoWei2.open("管理员.txt",ios::in);
char Searchname[30];
bool atee=false;
cout<<"请输入你要查询的教师的姓名:";
cin>>Searchname;
cout<<endl;
while(ChaoWei2>>name>>Year>>Month>>Day>>Secret)
{
if(strcmp(name,Searchname)==0)
{
cout<<setiosflags(ios::left)<<setw(15)<<"姓名"<<setw(15)<<"年"
<<setw(15)<<"月"<<setw(15)<<"日"<<setw(15)<<"密码"<<endl;
cout<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
atee=true;
}
}
if(atee==false)
cout<<"系统中不存在你要查询的教师!"<<endl<<endl;
ChaoWei2.close();
}
void teachter::Print()
{
ChaoWei2.open("管理员.txt",ios::in);
cout<<setiosflags(ios::left)<<setw(15)<<"姓名"<<setw(15)<<"年"
<<setw(15)<<"月"<<setw(15)<<"日"<<setw(15)<<"密码"<<endl;
while(ChaoWei2>>name>>Year>>Month>>Day>>Secret)
{
cout<<setiosflags(ios::left)<<setw(15)<<name<<setw(15)
<<Year<<setw(15)<<Month<<setw(15)<<Day<<setw(15)
<<Secret<<endl;
}
ChaoWei2.close();
int tt;
cout<<"按任意键退出界面:";
cin>>tt;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -