C++大作业系统管理 – Zechel

设计方案:

主要利用类与类之间的关系来进行模块分类,使用静态成员来储存信息,比如vector数组,map映射等。用于可利用的信息较多,为了使程序更具有灵活性,使用了重载函数,对同一功能,比如查找某病人或医生,可以使用多种信息来作为查找的依据。通过模块化的设计,每一项功能对应的实现方法被集中起来,方便整合。

在各模块整合过程中,使用了while(1)这样无限循环,可以使同一功能可以多次进行,在没有特定的退出命令时不会结束执行功能,不必要返回上一级,提高了效率。同时,在输出方面采用了system(“cls”),这样的语句,可以使界面更加整洁。

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
//病人信息存储:
class Patient
{
    public:
        Patient(string name,char condition,long long number);     //构造函数
        static void addPatient(Patient one);    //添加一个病人
        static Patient findPatient(string name);   //查找病人信息
        static Patient findPatient(long long number);
        //..... 重载函数 findPatient() 使可以通过其他病人信息查找病人
        static void deletePatient(string name);     //删除某个病人信息
        static void deletePatient(long long number);
        //..... 重载函数 deletePatient() 使可以通过其他病人信息删除病人
        static void changePatientInformation(string name,char condition);
        static void changePatientInformation(string name,long long number);
        static void changePatientInformation(long long number,string name);
        static void changePatientInformation(long long number,char condition);
                                    //第一个参数为正确信息,作为查找依据,第二个参数为需要修改的错误信息
        //..... 重载函数 changePatientInformation() 使用其他信息来删改另外的信息
        static pair<int,int> show();     //预测未来医院出院和入院人数
        void showInformation();       //展示病人信息
    private:
        string PatientName;   //病人名字
        char HealthCondition;       //病人健康状况,分为'A','B','C'等级,代表重、中、轻
        long long PatientNumber;    //病人号码
        static vector<Patient>PatientInformation;    //病人信息存储的数组
        static int RecoverNumber;         //总计康复人数
};
//账号密码信息储存:
class LoginSystem
{
    public:
        LoginSystem(long long account,string password);  //构造函数
        static void addAccount(long long account,string password);  //新增用户
        static bool checkAccount(long long account,string password);  //检查账号密码的正确性
        static string findPassword(long long account,string name,int number);      //确认对应医生信息,找回密码
    private:
        long long Account;   //账号
        string Password;     //密码
        static map<long long,string>AccountInformation;     //账户信息储存
};
//医护人员信息存储:
class Doctor
{
    public:
        Doctor(string name,int number,long long account);       //构造函数
        static void addDoctor(Doctor one);     //添加一个医生
        static Doctor findDoctor(string name);   //查找医生信息
        static Doctor findDoctor(int number);
        static Doctor findDoctor(long long account);
        //..... 重载函数 findDoctor() 使可以通过其他病人信息查找医生
        static void changeDoctorInformation(string name,int number);
        static void changeDoctorInformation(string name,long long account);
        static void changeDoctorInformation(int number,string name);
        static void changeDoctorInformation(int number,long long account);
        static void changeDoctorInformation(long long account,string name);
        static void changeDoctorInformation(long long account,int number);
                    //第一个参数为正确信息,作为查找依据,第二个参数为需要修改的错误信息
        //..... 重载函数 changeDoctorInformation() 使用其他信息来删改另外的信息
        friend string LoginSystem::findPassword(long long account,string name,int number);      //友元函数
        void showInformation();       //展示医生信息
    private:
        string DoctorName;     //医生名字
        int DoctorNumber;        //医生编号
        long long DoctorAccount;    //医生的管理系统账户
        static vector<Doctor>DoctorInformation;     //医生信息存储数组
};
vector<Patient> Patient::PatientInformation;    //初始化vector数组,病人信息
int Patient::RecoverNumber=0;        //初始化静态成员,康复人数
vector<Doctor>Doctor::DoctorInformation;        //初始化map,医生信息
map<long long,string>LoginSystem::AccountInformation;       //初始化map,登录系统信息储存
//病人类的构造函数
Patient::Patient(string name,char condition,long long number)
{
    PatientName=name;
    HealthCondition=condition;
    PatientNumber=number;
}
//添加病人实现:可以添加一个Patient对象到vector信息储存数组PatientInformation里;
//如果已存在该对象,则不重复添加
void Patient::addPatient(Patient one)
{
    Patient tmp=findPatient(one.PatientName);
    if(tmp.PatientName=="NoExist")PatientInformation.push_back(one);
}
//查找病人函数实现:可以通过病人名字和代号进行查找
//如果返回的对象的成员PatientName值是"NoExist",则说明这个人不存在,否则,返回的即目标对象
Patient Patient::findPatient(string name)
{
    Patient AimPatient("NoExist",'A',0);
    for(int i=0;i<PatientInformation.size();i++)
    {
        Patient tmp=PatientInformation[i];
        if(tmp.PatientName==name)
        {
            AimPatient=tmp;
            break;
        } 
    }
    return AimPatient;
}
Patient Patient::findPatient(long long number)
{
    Patient AimPatient("NoExist",'A',0);
    for(int i=0;i<PatientInformation.size();i++)
    {
        Patient tmp=PatientInformation[i];
        if(tmp.PatientNumber==number)
        {
            AimPatient=tmp;
            break;
        } 
    }
    return AimPatient;
}
//删除病人信息函数实现:可以通过病人名字和代号进行查找
//如果该病人存在则删除该病人,否则不做处理
void Patient::deletePatient(string name)
{
    vector<Patient>::iterator it;
    for(it=PatientInformation.begin();it!=PatientInformation.end();it++)
    {
        if((*it).PatientName==name)
        {
            PatientInformation.erase(it);
            RecoverNumber++;
            break;
        }
    }
}
void Patient::deletePatient(long long number)
{
    vector<Patient>::iterator it;
    for(it=PatientInformation.begin();it!=PatientInformation.end();it++)
    {
        if((*it).PatientNumber==number)
        {
            PatientInformation.erase(it);
            RecoverNumber++;
            break;
        }
    }
}
//修改病人信息函数实现:可以利用病人名字和号码这两项之一的正确信息,来修改病人的其他信息
//如果查找时依据的信息是错误的,或者不存在,则不作修改
void Patient::changePatientInformation(string name,char condition)
{
    vector<Patient>::iterator it;
    for(it=PatientInformation.begin();it!=PatientInformation.end();it++)
    {
        if((*it).PatientName==name)
        {
            (*it).HealthCondition=condition;
            break;
        }
    }
}
//通过姓名查找病人,修改号码
void Patient::changePatientInformation(string name,long long number)
{
    vector<Patient>::iterator it;
    for(it=PatientInformation.begin();it!=PatientInformation.end();it++)
    {
        if((*it).PatientName==name)
        {
            (*it).PatientNumber=number;
            break;
        }
    }
}
//通过号码查找病人,修改名字
void Patient::changePatientInformation(long long number,string name)
{
    vector<Patient>::iterator it;
    for(it=PatientInformation.begin();it!=PatientInformation.end();it++)
    {
        if((*it).PatientNumber==number)
        {
            (*it).PatientName=name;
            break;
        }
    }
}
//通过号码查找病人,修改健康条件
void Patient::changePatientInformation(long long number,char condition)
{
    vector<Patient>::iterator it;
    for(it=PatientInformation.begin();it!=PatientInformation.end();it++)
    {
        if((*it).PatientNumber==number)
        {
            (*it).HealthCondition=condition;
            break;
        }
    }
}
//病人数量模型预测:
//建模:1.出院人数=(中度患病+轻度患病)*平均出院率
//      2.入院人数=(重度患病+中度患病)*平均入院率;
pair<int,int> Patient::show()
{
    int first=0,second=0,third=0,sum=0;
    vector<Patient>::iterator it;
    for(it=PatientInformation.begin();it!=PatientInformation.end();it++)
    {
        sum++;
        if((*it).HealthCondition=='A')first++;
        if((*it).HealthCondition=='B')second++;
        if((*it).HealthCondition=='C')third++;
    }
    double RecoverPercent=RecoverNumber*1.0/(RecoverNumber+sum);
    int ForecastRecover=(second+third)*RecoverPercent;
    int ForecastInfect=(first+second)*(1-RecoverPercent);
    return make_pair(ForecastInfect,ForecastRecover);
}
void Patient::showInformation()       //展示病人信息
{
    cout<<"The patient' name is: "<<(*this).PatientName<<endl;
    cout<<"The patient' number is: "<<(*this).PatientNumber<<endl;
    cout<<"The patient' condition is: "<<(*this).HealthCondition<<endl;
}
//医生类的构造函数
Doctor::Doctor(string name,int number,long long account)
{       
    DoctorName=name;
    DoctorNumber=number;
    DoctorAccount=account;
}
//添加医生实现:可以添加一个Doctor对象到vector信息储存数组DoctorInformation里;
//如果已存在该对象,则不重复添加
void Doctor::addDoctor(Doctor one)     
{
    Doctor tmp=findDoctor(one.DoctorName);
    if(tmp.DoctorName=="NoExist")DoctorInformation.push_back(one);
}
//查找医生函数实现:可以通过医生名字,编号,账户名进行查找
//如果返回的对象的成员DoctorName值是"NoExist",则说明这个人不存在,否则,返回的即目标对象
Doctor Doctor::findDoctor(string name)
{
    Doctor AimDoctor("NoExist",0,0);
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorName==name)AimDoctor=(*it);
    }
    return AimDoctor;
}
Doctor Doctor::findDoctor(int number)
{
    Doctor AimDoctor("NoExist",0,0);
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorNumber==number)AimDoctor=(*it);
    }
    return AimDoctor;
}
Doctor Doctor::findDoctor(long long account)
{
    Doctor AimDoctor("NoExist",0,0);
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorAccount==account)AimDoctor=(*it);
    }
    return AimDoctor;
}
//修改医生信息函数实现:可以利用医生名字,编号,账户这三项之一的正确信息,来修改医生的其他信息
//如果查找时依据的信息是错误的,或者不存在,则不作修改
void Doctor::changeDoctorInformation(string name,int number)
{
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorName==name)(*it).DoctorNumber=number;
    }
}
//通过姓名查找医生,修改账户
void Doctor::changeDoctorInformation(string name,long long account)
{
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorName==name)(*it).DoctorAccount=account;
    }
}
//通过编号查找医生,修改姓名
void Doctor::changeDoctorInformation(int number,string name)
{
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorNumber==number)(*it).DoctorName=name;
    }
}
//通过编号查找医生,修改账户
void Doctor::changeDoctorInformation(int number,long long account)
{
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorNumber==number)(*it).DoctorAccount=account;
    }
}
//通过账户查找医生,修改姓名
void Doctor::changeDoctorInformation(long long account,string name)
{
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorAccount==account)(*it).DoctorName=name;
    }
}
//通过账户查找医生,修改编号
void Doctor::changeDoctorInformation(long long account,int number)
{
    vector<Doctor>::iterator it;
    for(it=DoctorInformation.begin();it!=DoctorInformation.end();it++)
    {
        if((*it).DoctorAccount==account)(*it).DoctorNumber=number;
    }
}
//登录系统类的构造函数
LoginSystem::LoginSystem(long long account,string password)
{
    Account=account;
    Password=password;
}
void LoginSystem::addAccount(long long account,string password)  //新增用户
{
    AccountInformation[account]=password;
}
bool LoginSystem::checkAccount(long long account,string password)  //检查账号密码的正确性
{
    return AccountInformation[account]==password;
}
string LoginSystem::findPassword(long long account,string name,int number)      //确认对应医生信息,找回密码
{
    Doctor AimDoctor=Doctor::findDoctor(account);
    if(AimDoctor.DoctorName==name&&AimDoctor.DoctorNumber==number)
    {
        return AccountInformation[account];
    }
    return "Wrong";
}
void Doctor::showInformation()       //展示医生信息
{
    cout<<"The doctor' name is: "<<(*this).DoctorName<<endl;
    cout<<"The doctor' number is: "<<(*this).DoctorNumber<<endl;
    cout<<"The doctor' account is: "<<(*this).DoctorAccount<<endl;
}
int main()
{
    while(1)
    {
        system("cls");
        cout<<"Please enter the instruction"<<endl;
        cout<<"Login in: 1 "<<endl;
        cout<<"Register: 2 "<<endl;
        cout<<"Quit: 3 "<<endl;
        int opt;
        scanf("%d",&opt);
        if(opt==1)
        {
            bool check;
            long long account;
            string password;
            while(1)
            {
                system("cls");
                cout<<"Please enter your account number:"<<endl;
                scanf("%lld",&account);
                cout<<"Please enter your password:"<<endl;
                cin>>password;
                check=LoginSystem::checkAccount(account,password);
                if(check)break;
                else
                {
                    system("cls");
                    string c;
                    cout<<"The password is wrong,Looking for the password?(Y/N); Quit: 3"<<endl;
                    cin>>c;
                    if(c=="3")break;
                    else if(c=="N")continue;
                    else
                    {
                        system("cls");
                        string name;
                        int number;
                        cout<<"Please enter your name and number:"<<endl;
                        cin>>name>>number;
                        string u=LoginSystem::findPassword(account,name,number);
                        system("cls");
                        if(u=="Wrong")
                        {
                            cout<<"Failure,the information is wrong"<<endl;
                            cout<<"waiting continue...(enter Y if continue)"<<endl;
                            string r;
                            cin>>r;
                            continue;
                        }
                        else
                        {
                            cout<<"Your password is: "<<u<<endl;
                            cout<<"waiting continue...(enter Y if continue)"<<endl;
                            string r;
                            cin>>r;
                            continue;   
                        }
                    }
                }
            }
            system("cls");
            if(check){break;}
            else continue;
        }
        else if(opt==2)
        {
            system("cls");
            long long account;
            string password,name;
            int number;
            cout<<"Please enter your account number:"<<endl;
            cin>>account;
            cout<<"Please enter your password:"<<endl;
            cin>>password;
            cout<<"Please enter your name:"<<endl;
            cin>>name;
            cout<<"Please enter your number:"<<endl;
            cin>>number;
            Doctor exm_1(name,number,account);
            Doctor::addDoctor(exm_1);
            LoginSystem::addAccount(account,password);
            continue;
        }
        return 0;
    }
    while(1)
    {
        system("cls");
        cout<<"Please enter the instruction"<<endl;
        cout<<"Management of Doctor: 1"<<endl;
        cout<<"Management of Patient: 2"<<endl;
        cout<<"Quit: 3"<<endl;
        int opt;
        scanf("%d",&opt);
        if(opt==1)
        {
           while(1)
           {
               system("cls");
               cout<<"Modify a doctor's information: 1"<<endl;
               cout<<"Add a doctor: 2"<<endl;
               cout<<"Find a doctor: 3"<<endl;
               cout<<"Quit :4"<<endl;
               int c;
               scanf("%d",&c);
               if(c==1)
               {
                    while(1)
                    {
                        system("cls");
                        cout<<"Select the type of correct information and enter the correct information: "<<endl;
                        cout<<"name : 1   number : 2  account : 3 "<<endl;
                        int a,b;
                        string c,d;
                        int e,f;
                        long long g,h;
                        scanf("%d",&a);
                        if(a==1)cin>>c;
                        if(a==2)cin>>e;
                        if(a==3)cin>>g;
                        cout<<"Select the type of wrong information and enter the correct information: "<<endl;
                        cout<<"name : 1   number : 2  account : 3 "<<endl;
                        scanf("%d",&b);
                        if(b==1)cin>>d;
                        if(b==2)cin>>f;
                        if(b==3)cin>>h;
                        if(a==1)
                        {
                            if(b==2)Doctor::changeDoctorInformation(c,f);
                            if(b==3)Doctor::changeDoctorInformation(c,h);
                        }
                        if(a==2)
                        {
                            if(b==1)Doctor::changeDoctorInformation(e,d);
                            if(b==3)Doctor::changeDoctorInformation(e,h);
                        }
                        if(a==3)
                        {
                            if(b==1)Doctor::changeDoctorInformation(g,d);
                            if(b==2)Doctor::changeDoctorInformation(g,f);
                        }
                        system("cls");
                        cout<<"succeed! Quit?(Y/N)"<<endl;
                        string r;
                        cin>>r;
                        if(r=="Y")break;
                    }
                }
                else if(c==2)
                {
                   while(1)
                   {
                       system("cls");
                       cout<<"Please enter the doctor's name, number and account: "<<endl;
                       string name;
                       int number;
                       long long account;
                       cin>>name>>number>>account;
                       Doctor exm_2(name,number,account);
                       Doctor::addDoctor(exm_2);
                       system("cls");
                       cout<<"succeed! Quit?(Y/N)"<<endl;
                       string r;
                       cin>>r;
                       if(r=="Y")break;
                   }
                }
                else if(c==3)
                {
                    while(1)
                    {
                        system("cls");
                        cout<<"Select the type of correct information and enter the correct information: "<<endl;
                        cout<<"name : 1   number : 2  account : 3 "<<endl;
                        string a;
                        int b,k;
                        long long c;
                        scanf("%d",&k);
                        Doctor AimDoctor("NoExist",0,0);
                        if(k==1){cin>>a;AimDoctor=Doctor::findDoctor(a);}
                        else if(k==2){cin>>b;AimDoctor=Doctor::findDoctor(b);}
                        else {cin>>c;AimDoctor=Doctor::findDoctor(a);}
                        AimDoctor.showInformation();
                        cout<<"Quit?(Y/N)"<<endl;
                        string r;
                        cin>>r;
                        if(r=="Y")break;
                    }
                }
                else break;
           } 
        }
        else if(opt==2)
        {
            while(1)
            {
                system("cls");
                cout<<"Add a patient: 1"<<endl;
                cout<<"Delete a patient: 2"<<endl;
                cout<<"Modify a patient's information: 3"<<endl;
                cout<<"Predict the future: 4"<<endl;
                cout<<"Find a patient: 5"<<endl;
                cout<<"Quit: 6"<<endl;
                int c;
                scanf("%d",&c);
                if(c==1)
                {
                    while(1)
                    {
                        system("cls");
                        cout<<"Please enter the patient's name, condition of health, and number:"<<endl;
                        string name;
                        char condition;
                        long long number;
                        cin>>name>>condition>>number;
                        Patient exm_3(name,condition,number);
                        Patient::addPatient(exm_3);
                        system("cls");
                        cout<<"succeed! Quit?(Y/N)"<<endl;
                        string r;
                        cin>>r;
                        if(r=="Y")break;
                    }
                }
                else if(c==2)
                {
                    while(1)
                    {
                        system("cls");
                        cout<<"Please select the type of patient'information to enter, as well as the information"<<endl;
                        cout<<"name : 1   number : 2"<<endl;
                        int k;
                        string name;
                        long long number;
                        scanf("%d",&k);
                        if(k==1){cin>>name;Patient::deletePatient(name);}
                        if(k==2){cin>>number;Patient::deletePatient(number);}
                        system("cls");
                        cout<<"succeed! Quit?(Y/N)"<<endl;
                        string r;
                        cin>>r;
                        if(r=="Y")break;
                    }
                }
                else if(c==3)
                {
                    while(1)
                    {
                        system("cls");
                        cout<<"Select the type of correct information and enter the correct information: "<<endl;
                        cout<<"name : 1   number : 2 "<<endl;
                        int a,b;
                        string c,d;
                        long long e,f;
                        char g;
                        scanf("%d",&a);
                        if(a==1)cin>>c;
                        else cin>>e;
                        cout<<"Select the type of wrong information and enter the correct information: "<<endl;
                        cout<<"name : 1   number : 2  condition : 3 "<<endl;
                        scanf("%d",&b);
                        if(b==1)cin>>d;
                        else if(b==2)cin>>f;
                        else cin>>g;
                        if(a==1)
                        {
                            if(b==2)Patient::changePatientInformation(c,f);
                            else if(b==3)Patient::changePatientInformation(c,g);
                        }
                        else if(a==2)
                        {
                            if(b==1)Patient::changePatientInformation(e,d);
                            else if(b==3)Patient::changePatientInformation(e,g);
                        }
                        system("cls");
                        cout<<"succeed! Quit?(Y/N)"<<endl;
                        string r;
                        cin>>r;
                        if(r=="Y")break;
                    }   
                }
                if(c==4)
                {
                    system("cls");
                    pair<int,int> P=Patient::show();
                    cout<<"The number of infect: "<<P.first<<endl;
                    cout<<"The number of recover: "<<P.second<<endl;
                    cout<<endl;
                    cout<<"waiting continue...(enter Y if continue)"<<endl;
                    string r;
                    cin>>r;
                }
                if(c==5)
                {
                    while(1)
                    {
                        system("cls");
                        cout<<"Select the type of correct information and enter the correct information: "<<endl;
                        cout<<"name : 1   number : 2 "<<endl;
                        string a;
                        long long b;
                        int k;
                        scanf("%d",&k);
                        Patient AimPatient("NoExist",'A',0);
                        if(k==1){cin>>a;AimPatient=Patient::findPatient(a);}
                        else if(k==2){cin>>b;AimPatient=Patient::findPatient(b);}
                        else {cin>>c;AimPatient=Patient::findPatient(a);}
                        AimPatient.showInformation();
                        cout<<"Quit?(Y/N)"<<endl;
                        string r;
                        cin>>r;
                        if(r=="Y")break;
                    }
                }
                if(c==6)break;
            }
        }
        if(opt==3)break;
    }
}

 

总结:

数据测试后的结果符合预期,但是有一些不尽人意的错误,比如输入的命令的容错性比较低,如果输入一些未知指令将导致死循环。在数据输出方面,由于终端输出的处理,所以为了输出能够被看见,在数据输出后都必须要手动确认一次,较为繁琐。在运行上,如果严格按照要求输出和输入数据,那么程序的运行正常。根据预测,该程序大约可进行百万级数的数据输入和整合,在时间和空间上都是可以满足的,但是运行速度会稍稍减慢。

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

川公网安备 51130202000337号