c++疫情防控系统
#include<iostream>
#include<fstream>
#include<sstream>
using namespace std;
class tonggao {
private:
string neirong;
int year;
int month;
int day;
int hour;
int min;
int sec;
time_t guoqu;
public:
tonggao()
{
time_t now = time(0);
tm* ltm = localtime(&now);
this->year = 1900 + ltm->tm_year;
this->month = 1 + ltm->tm_mon;
this->day = ltm->tm_mday;
this->hour = ltm->tm_hour;
this->min = ltm->tm_min;
this->sec = ltm->tm_sec;
this->guoqu = now;
}
void Setneirong()
{
time_t now = time(0);
tm* ltm = localtime(&now);
cout << "请输入通告内容:";
cin >> this->neirong;
this->year = 1900 + ltm->tm_year;
this->month = 1 + ltm->tm_mon;
this->day = ltm->tm_mday;
this->hour = ltm->tm_hour;
this->min = ltm->tm_min;
this->sec = ltm->tm_sec;
this->guoqu = now;
}
string printneirong()
{
return this->neirong;
}
void printall()
{
if (this->neirong == "")
{
cout << endl << "无" << endl;
return;
}
cout <<endl<< " 最新通知 "<< endl;
cout << " " << this->neirong << endl;
cout << "发布时间:" << this->year << "年" << this->month << "月" << this->day << "日" << this->hour << "时" << this->min << "分" << this->sec << "秒"<<endl;
}
void read();
void save();
};
class person {
private:
float tiwen;
int jiezhong;
bool hesuan;
int quanxian;
string phone;
string password;
string name;
string number;
public:
void Setnumber(string a)
{
this->number = a;
}
void Setname(string a)
{
this->name = a;
}
void Setpassword(string a)
{
this->password = a;
}
void Setphone(string a)
{
this->phone = a;
}
void Setquanxian(int a)
{
this->quanxian = a;
}
person()
{
this->tiwen = 0;
this->jiezhong = 0;
this->hesuan = false;
this->quanxian = 0;
}
void Sethesuan(bool a)
{
this->hesuan = a;
}
void Setjiezhong(int a)
{
this->jiezhong = a;
}
void Settiwen(float a)
{
this->tiwen = a;
}
int printquanxian()
{
return this->quanxian;
}
void printall(int m)//打印个人信息
{
cout << endl << "姓名:" << this->name << endl;
if (m == 2)
cout << " 学号:" << this->number << endl;
cout << "体温:" << this->tiwen << "°C" << endl;
cout << "接种疫苗次数:" << this->jiezhong << endl;
if (this->hesuan)
cout << "核酸情况:已做" << endl;
else
cout << "核酸情况:未做" << endl << endl;
}
void Setall()
{
cout << "请输入体温值:";
cin >> this->tiwen;
cout << "请输入是否做完核酸(请输入0/1):";
cin >> this->hesuan;
cout << "请输入接种疫苗次数:";
cin >> this->jiezhong;
}
void Settiwen()
{
cout << "请输入体温值:";
cin >> this->tiwen;
}
void Setnumber()
{
cout << "请输入学号:";
cin >> this->number;
}
void Setname()
{
cout << "请输入姓名:";
cin >> this->name;
}
void Setpassword()
{
cout << "请输入新密码:";
cin >> this->password;
cout << "请输入电话号码:";
cin >> this->phone;
}
void Sethesuan()
{
cout << "请输入是否做完核酸(请输入0/1):";
cin >> this->hesuan;
}
void Setjiezhong()
{
cout << "请输入接种疫苗次数:";
cin >> this->jiezhong;
}
void Setphone()
{
cout << "请输入电话号码:";
cin >> this->phone;
}
float printtiwen()
{
return this->tiwen;
}
bool printhesuan()
{
return this->hesuan;
}
int printjiezhong()
{
return this->jiezhong;
}
string printphone()
{
return this->phone;
}
string printname()
{
return this->name;
}
string printnumber()
{
return this->number;
}
string printpassword()
{
return this->password;
}
};
//构建一个节点类
class NodeStudent
{
public:
person person; //数据域
NodeStudent* next; //指针域
};
//构建一个单链表类
class LinkList
{
public:
LinkList(); //构建一个单链表;//
~LinkList(); //销毁一个单链表;//
void CreateLinkList(); //创建一个单链表//
void TravalLinkList(); //遍历线性表//
int GetLength(); //获取线性表长度//
bool IsEmpty(); //判断单链表是否为空//
NodeStudent* Find(string password); //查找节点//
void InsertElemAtEnd(int m); //在尾部插入指定的元素//
void DeleteElemAtPoint(string password); //删除指定的数据//
void DeleteElemAtHead(); //在头部删除节点//
void save(LinkList S);
void read(LinkList S);
private:
NodeStudent* head; //头结点
};
void LinkList::save(LinkList S)
{
int length=S.GetLength();
float tiwen;
int jiezhong;
bool hesuan;
int quanxian;
string phone;
string password;
string name;
string number;
ofstream ofile;
ofile.open("Person.txt", ios::out);
NodeStudent* p = head; //另指针指向头结点
p = p->next;
ofile <<length << endl;
for (int i = 0; i < S.GetLength(); i++)
{
tiwen = p->person.printtiwen();
number = p->person.printnumber();
name = p->person.printname();
password = p->person.printpassword();
phone = p->person.printphone();
quanxian = p->person.printquanxian();
hesuan = p->person.printhesuan();
jiezhong = p->person.printjiezhong();
ofile << number << " " << name << " " << password << " "<< phone << " " << quanxian << " "<< hesuan << " " << tiwen << " " << jiezhong << " " << endl;
p = p->next; //p指向p的下一个地址
}
ofile.close();
}
void LinkList::read(LinkList S)
{
int length;
float tiwen;
int jiezhong;
bool hesuan;
int quanxian;
string phone;
string password;
string name;
string number;
ifstream ifile;
ifile.open("Person.txt", ios::in);
if (!ifile.is_open())
{
cout << endl << "文件打开失败!" << endl;
return;
}
NodeStudent* p = head,* pnew; //另指针指向头结点
ifile >> length;
for (int i = 0; i < length; i++) { //将值一个一个插入单链表中
pnew = new NodeStudent;
ifile >> number>>name>>password>>phone>>quanxian>>hesuan>>tiwen>>jiezhong;
pnew->person.Setnumber(number);
pnew->person.Setname(name);
pnew->person.Setpassword(password);
pnew->person.Setphone(phone);
pnew->person.Setquanxian(quanxian);
pnew->person.Sethesuan(hesuan);
pnew->person.Settiwen(tiwen);
pnew->person.Setjiezhong(jiezhong);
pnew->next = NULL; //新节点的下一个地址为NULL
p->next = pnew; //当前结点的下一个地址设为新节点
p = pnew; //将当前结点设为新节点
}
ifile.close();
}//读取
void tonggao::save()
{
ofstream ofile;
ofile.open("Tonggao.txt", ios::out);
ofile <<" "<<this->year << " " << this->month << " " << this->day << " " << this->hour << " " << this->min << " " << this->sec << " " << this->guoqu << " " << this->neirong<<" "<< endl;
ofile.close();
}
void tonggao::read()
{
ifstream ifile;
ifile.open("Tonggao.txt", ios::in);
if (!ifile.is_open())
{
cout << endl << "文件打开失败!" << endl;
return;
}
ifile >> this->year>> this->month>> this->day>> this->hour>> this->min>> this->sec>> this->guoqu >> this->neirong;
ifile.close();
}//读取
//初始化单链表
LinkList::LinkList()
{
head = new NodeStudent;
head->next = NULL; //头结点的下一个定义为NULL
}
//销毁单链表
LinkList::~LinkList()
{
//delete head; //删除头结点
}
//遍历单链表
void LinkList::TravalLinkList()
{
if (head == NULL || head->next == NULL) {
cout << "链表为空表" << endl;
}
NodeStudent* p = head; //另指针指向头结点
p = p->next;
while (p!= NULL) //当指针的下一个地址不为空时,循环输出p的数据域
{
if (p->person.printquanxian()==0)
p->person.printall(2);
p = p->next; //p指向p的下一个地址
}
}
//获取单链表的长度
int LinkList::GetLength()
{
int count = 0; //定义count计数
NodeStudent* p = head->next; //定义p指向头结点
while (p != NULL) //当指针的下一个地址不为空时,count+1
{
count++;
p = p->next; //p指向p的下一个地址
}
return count; //返回count的数据
}
//判断单链表是否为空
bool LinkList::IsEmpty()
{
if (head->next == NULL) {
return true;
}
return false;
}
//通过密码查找节点
NodeStudent* LinkList::Find(string password)
{
NodeStudent* p = head;
if (p == NULL) { //当为空表时,报异常
cout << "无教师信息" << endl;
return NULL;
}
else
{
while (p != NULL) //循环每一个节点
{
if (p->person.printpassword() == password) {
return p; //返回指针域
}
p = p->next;
}
return NULL; //未查询到结果
}
}
//插入新节点
void LinkList::InsertElemAtEnd(int m)
{
NodeStudent* newNodeStudent = new NodeStudent; //定义一个NodeTeacher结点指针newNodeTeacher
newNodeStudent->next = NULL; //定义newNodeTeacher的数据域和指针域
newNodeStudent->person.Setname();
if (m == 2)
newNodeStudent->person.Setnumber();
else
newNodeStudent->person.Setnumber("teacher");
newNodeStudent->person.Sethesuan();
newNodeStudent->person.Setjiezhong();
newNodeStudent->person.Setphone();
newNodeStudent->person.Settiwen();
newNodeStudent->person.Setpassword(newNodeStudent->person.printphone());
if (m == 1)
{
newNodeStudent->person.Setquanxian(1);
}
NodeStudent* p = head; //定义指针p指向头结点
if (head == NULL) { //当头结点为空时,设置newNodeTeacher为头结点
head = newNodeStudent;
}
else //循环知道最后一个节点,将newNodeTeacher放置在最后
{
while (p->next != NULL)
{
p = p->next;
}
newNodeStudent->next = NULL;
p->next = newNodeStudent;
}
cout << "注册成功" << endl << endl;
}
//在头部删除节点
void LinkList::DeleteElemAtHead()
{
NodeStudent* p = head;
if (p == NULL || p->next == NULL) { //判断是否为空表,报异常
cout << "无教师信息" << endl;
}
else
{
NodeStudent* ptemp = NULL; //创建一个占位节点
p = p->next;
ptemp = p->next; //将头结点的下下个节点指向占位节点
delete p; //删除头结点的下一个节点
p = NULL;
head->next = ptemp; //头结点的指针更换
}
}
void menu1(int m)//登录注册界面
{
if (m == 2)
cout << endl << "学生登录注册" << endl;
else
cout << endl << "教师登录注册" << endl;
cout << endl << "1.注册" << endl;
cout << "2.登录" << endl;
cout << "0.退出" << endl << endl;
}
void Smenu2()//学生主界面
{
cout << endl << "1.查看账户信息" << endl;
cout << "2.查看最新通知" << endl;
cout << "3.修改个人信息" << endl;
cout << "4.修改登录密码" << endl;
cout << "0.退出" << endl << endl;
}
void Smain(LinkList S, string password, tonggao T)//学生主界面
{
int i;
do
{
T.read();
Smenu2();
cout << "请输入要执行的操作: ";
cin >> i;
switch (i)
{
case 0:
S.save(S);
return;
case 1:
S.Find(password)->person.printall(2);
break;
case 2:
T.printall();
break;
case 3:
S.Find(password)->person.Setall();
break;
case 4:
S.Find(password)->person.Setpassword();
break;
default:
cout << "输入不合法,请重新输入" << endl;
break;
}
} while (i != 0);
}
void Tmenu1()//教师主界面
{
cout << endl << "1.最新通知发布" << endl;
cout << "2.添加学生信息" << endl;
cout << "3.修改学生信息" << endl;
cout << "4.查看所有学生信息" << endl;
cout << "5.查看账户信息" << endl;
cout << "6.修改个人信息" << endl;
cout << "7.修改登录密码" << endl;
cout << "0.退出" << endl << endl;
}
void Tmain(LinkList S, string password, tonggao T)//教师主界面
{
string Snumber;
int i;
do
{
T.read();
Tmenu1();
cout << "请输入要执行的操作: ";
cin >> i;
switch (i)
{
case 0:
S.save(S);
T.save();
return;
case 1:
T.Setneirong();
break;
case 2:
S.InsertElemAtEnd(2);
break;
case 3:
cout << endl << "请输入需要修改的学生学号:";
cin >> Snumber;
S.Find(Snumber)->person.Setpassword();
break;
case 4:
S.TravalLinkList();
break;
case 5:
S.Find(password)->person.printall(1);
break;
case 6:
S.Find(password)->person.Setall();
break;
case 7:
S.Find(password)->person.Setpassword();
break;
default:
cout << "输入不合法,请重新输入" << endl;
break;
}
} while (i != 0);
}
void login(LinkList S, int m, tonggao T)//登录,m=1时表示教师,m=2时表示学生
{
string data1, data2;
if (m == 2)
cout << "请输入学号:";
else
cout << "请输入用户名:";
cin >> data1;
cout << "请输入密码:";
cin >> data2;
if(S.Find(data2)==NULL)
{
cout << endl << "密码错误" << endl << endl;
return;
}
if (m == 2)
{
if (S.Find(data2)->person.printquanxian() == 0)
{
cout << endl << "登录成功" << endl << endl;
Smain(S, data1, T);
}
else
cout << "您不是学生" << endl;
}
else
{
if (S.Find(data2)->person.printquanxian() == 1)
{
cout << endl << "登录成功" << endl << endl;
Tmain(S, data1, T);
}
else
cout << "您不是教师" << endl;
}
}
void menu()//主菜单
{
cout << endl << "1.教师登录" << endl;
cout << "2.学生登录" << endl;
cout << "0.退出" << endl << endl;
}
void Smain(LinkList S, tonggao T)//学生主界面
{
int i;
do
{
T.read();
menu1(2);
cout << "请输入要执行的操作: ";
cin >> i;
switch (i)
{
case 0:
S.save(S);
T.save();
break;
case 1:
S.InsertElemAtEnd(2);
break;
case 2:
login(S, 2, T);
break;
default:
cout << "输入不合法,请重新输入" << endl;
break;
}
} while (i != 0);
}
void Tmain(LinkList S, tonggao T)//教师主界面
{
int i;
do
{
T.read();
menu1(1);
cout << "请输入要执行的操作: ";
cin >> i;
switch (i)
{
case 0:
S.save(S);
T.save();
return;
case 1:
S.InsertElemAtEnd(1);
break;
case 2:
login(S, 1, T);
break;
default:
cout << "输入不合法,请重新输入" << endl;
break;
}
} while (i != 0);
}
int main()//主界面
{
LinkList S;
tonggao T;
int i;
do
{
S.read(S);
T.read();
menu();
cout << "请输入要执行的操作: ";
cin >> i;
switch (i)
{
case 0:
S.save(S);
T.save();
exit(0);
case 1:
Tmain(S, T);
break;
case 2:
Smain(S, T);
break;
default:
cout << "输入不合法,请重新输入" << endl;
break;
}
} while (i != 0);
return 0;
}