马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<windows.h>
#include<fstream>
#include<iomanip>
#include<string>
#include<conio.h>
//常量定义
#define userNameLen 10
#define LEN 20
#define passwordLen 10
const int M=16;
//函数声明
using namespace std;
bool Login(); //登陆
void inputPSW(char *password); //输入口令
void Start();
void sysQuit();
void print1();
int main();
//定义信息类
class Hospital
{
private:
string name; //姓名
string grades; //班级
string id; //学号
string gender; //性别
string address; //宿舍号
string phone; //电话号码
string card; //通知书号
string vaccine; //疫苗型号
public:
Hospital(){}
Hospital(string name,string grades,string id,string gender,string address,string phone,string card,string vaccine)
{
this->name=name; this->grades=grades; this->id=id;
this->gender=gender; this->address=address;
this->phone=phone; this->card=card;
this->vaccine=vaccine;
}
string getName() { return this->name; }
string getgrades() { return this->grades; }
string getId() { return this->id; }
string getgender() { return this->gender; }
string getaddress() { return this->address; }
string getphone() { return this->phone; }
string getcard() { return this->card; }
string getvaccine() { return this->vaccine; }
void print()
{
cout<<setw(14)<<name<<setw(10)<<grades<<setw(10)<<id<<setw(5)<<gender<<setw(7)
<<address<<setw(12)<<phone<<setw(10)<<card<<setw(7)<<vaccine<<endl;
}
friend class Hospital;
};
//定义信息管理类
class HospitalManage
{
Hospital Arb[M];
public:
void input(int N); //录入信息方法,n为实际录入人数
void show(); //显示信息方法
int seek(); //查找信息方法
void sorting(); //排序信息方法
void del(); //删除信息方法
void del(int S);
void save(int N); //保存到文件方法,n为实际写入人数
int read(); // 从文件读出数据方法,返回值为读出的记录数
void add(); //添加信息的方法
void compile(); //编辑信息方法
void amend(); //修改信息方法
};
//函数定义
void print1()
{
cout<<setw(14)<<"姓名"<<setw(10)<<"班级"<<setw(10)<<"学号"<<setw(5)<<"性别"<<setw(7)
<<"宿舍号"<<setw(12)<<"电话号码"<<setw(10)<<"录取通知书号"<<setw(7)<<"疫苗编号"<<endl;
}
void HospitalManage::input(int N)
{
HospitalManage ip; system("cls");
string name,grades,id,gender,address,phone,card,vaccine;
for(int i=0;i<N;i++)
{
cout<<"\n\t\t 输入第"<<i+1<<"个系统信息: \n";
cout<<"\t\t 姓名: "; cin>>name;
cout<<"\t\t 班级: "; cin>>grades;
cout<<"\t\t 学号: "; cin>>id;
cout<<"\t\t 性别(F/M): "; cin>>gender;
cout<<"\t\t 宿舍号(X-XXX): "; cin>>address;
cout<<"\t\t 电话号码: "; cin>>phone;
cout<<"\t\t 录取通知书号: "; cin>>card;
cout<<"\t\t11.出血热第一针; 12.出血热第二针; 13.出血热第三针; \n2.麻腮风疫苗; 3.乙肝疫苗;"<<"\n\t\t 疫苗编号: "; cin>>vaccine;
Arb[i]=Hospital(name,grades,id,gender,address,phone,card,vaccine);
}
}
void HospitalManage::add()
{
system("cls");
int N=read(); int k=0; HospitalManage ad;
cout<<"\n\t\t\t\t 信息系统人数: "<<N<<"\n\t\t 输入第 "<<N+1<<"个系统信息: \n";
string name,grades,id,gender,address,phone,card,vaccine;
cout<<"\t\t 姓名: "; cin>>name;
cout<<"\t\t 班级: "; cin>>grades;
cout<<"\t\t 学号: "; cin>>id;
cout<<"\t\t 性别(F/M): "; cin>>gender;
cout<<"\t\t 宿舍号(X-XXX): " ; cin>>address;
cout<<"\t\t 电话号码: "; cin>>phone;
cout<<"\t\t 录取通知书号: "; cin>>card;
cout<<"\t\t11.出血热第一针; 12.出血热第二针; 13.出血热第三针; \n 2.疫苗; 3.乙肝疫苗;"<<"\n\t\t 疫苗编号: "; cin>>vaccine;
if(N>1)
{
for(int j=0;j<N;j++)
{
if((Arb[j].getId()==id)&&(Arb[j].getvaccine()==vaccine)&&(Arb[j].getcard()==card))
{
print1(); Arb[j].print();
cout<<"\t\t 该同学已接种过该疫苗! ";
k++; break;
}
}
}
if(!k)
{
Arb[N]=Hospital(name,grades,id,gender,address,phone,card,vaccine);
N++; ad.save(N);
}
}
int HospitalManage::read()
{
string name,grades,id,gender,address,phone,card,vaccine;
const char *file="Hospital.txt";
ifstream fin(file,ios_base::in);
if(!fin.is_open()) {cerr<<"\n\\n\t 无法打开 "<<file<<endl; exit(EXIT_FAILURE); }
int i=0;
while(!fin.eof())
{
fin>>name>>grades>>id>>gender>>address>>phone>>card>>vaccine;
Arb[i]=Hospital(name,grades,id,gender,address,phone,card,vaccine); i++;
}fin.close(); return i-1;
}
void HospitalManage::save(int N)
{
const char *file="Hospital.txt";
ofstream fout(file,ios_base::out);
if(!fout.is_open()) {cerr<<"\\n\n\t 无法打开 "<<file<<endl; exit(EXIT_FAILURE); }
for(int i=0;i<N;i++)
fout<<setw(16)<<Arb[i].getName()<<setw(9)<<Arb[i].getgrades()
<<setw(12)<<Arb[i].getId()<<setw(9)<<Arb[i].getgender()<<setw(11)
<<Arb[i].getaddress()<<setw(15)<<Arb[i].getphone()<<setw(12)<<
Arb[i].getcard()<<setw(9)<<Arb[i].getvaccine()<<endl;
cout<<"\t\t 保存数据成功 "; fout.flush(); fout.close();
}
|