c++课程设计,职工管理系统

来源:互联网 发布:php iconv utf 16le 编辑:程序博客网 时间:2024/04/27 23:42
#include <iostream>#include <string>#include <set>#include <windows.h>#include <cstdio>#include <conio.h>#include <cmath>#include <fstream>#define I 12 //爱心的上半部分两个小半圆的半径#define R 240 //爱心的下半部分圆弧曲线半径using namespace std;class zhigong//职工类,表示单个职工{    string nam;//姓名    string gh;//工号    bool sex;//性别    string sr;//生日    string xl;//学历    string zw;//职务    int gz;//工资    string zhu;//住址    string tel;//电话public:    bool operator < (const  zhigong &b) const;//为set提供排序方式    zhigong(string _nam,string _gh,bool _sex,string _sr,string _xl,string _zw,int _gz,string _zhu,string _tel);    zhigong();    zhigong(string x);//为工号查找提供简易构造函数    void prin();//屏幕输出    friend ostream& operator << (ostream &out,const zhigong& b);//为文件对象提供输出    void change();//修改    string na();//为姓名模糊查找提供nam};class zgxt:public set<zhigong>//继承STL_set作为程序主题类表示职工系统类,作为平衡红黑二叉树树存储{public:    void sdin();//手动插入    void shuc();//输出    zgxt::iterator mhfind(string _na);//模糊查找姓名} acm;//定义一个对象acm表示职工的集合void gotoxy(int x,int y){    COORD loc;    loc.X  =  y;    loc.Y  =  x;    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), loc);}//坐标定位函数void xinxing()//欢迎界面{    int i,j,e,a;    for(i=1,a=I; i<I/2; i++,a--)//爱心的上半部分 为两个实心半圆    {        for(j=(int) ( I-sqrt((double)(I*I-(a-i)*(a-i))) ); j>0; j--)            printf(" ");        for(e=1; e<=2*sqrt((double)(I*I-(a-i)*(a-i))); e++)            printf("\3");        for(j=(int) ( 2*( I-sqrt((double)(I*I-(a-i)*(a-i))) ) ); j>0; j--)            printf(" ");        for(e=1; e<=2*sqrt( (double) (I*I-(a-i)*(a-i)) ); e++)            printf("\3");        printf("\n");    }    for(i=1; i<56; i++)//爱心的中间一行 可以打印一些标记    {        if(i==14)        {            printf("\3\3\3\3\3 ~Welcome~ \3\3\3\3\3\3");            i+=30;        }        printf("\3");    }    printf("\n");    for(i=1; i<=R/2; i++)//爱心的下半部分 以R为半径的左右两条圆弧曲线 R设置为比较大    {        if(i%2||i%3)continue;//因为R很大 两条曲线应该删去中间的一些点 这样就会更像爱心        for(j=(int) ( R-sqrt( (double) (R*R-i*i) ) ); j>0; j--)            printf(" ");        for(e=1; e<=2*( sqrt( (double)(R*R-i*i) ) - (R-2*I) ); e++)            printf("\3");        printf("\n");    }    gotoxy(0,79);//以下是控制变色    system("color a");    if(kbhit())        return;    Sleep(500);    system("color b");    if(kbhit())        return;    Sleep(500);    system("color c");    if(kbhit())        return;    Sleep(500);    system("color d");    system("color e");    if(kbhit())        return;    Sleep(500);    system("color f");    if(kbhit())        return;    Sleep(500);    system("color 0");    if(kbhit())        return;    Sleep(500);    system("color 1");    if(kbhit())        return;    Sleep(500);    system("color 2");    system("color 3");    if(kbhit())        return;    Sleep(500);    system("color 4");    if(kbhit())        return;    Sleep(500);    system("color 5");    if(kbhit())        return;    Sleep(500);    system("color 6");    if(kbhit())        return;    Sleep(500);    system("color 7");    system("color 8");    if(kbhit())        return;    Sleep(500);    system("color 9");    system("color ab");    if(kbhit())        return;    Sleep(500);    system("color ac");    if(kbhit())        return;    Sleep(500);    system("color ad");    if(kbhit())        return;    Sleep(500);    system("color ae");    if(kbhit())        return;    Sleep(500);    system("color 1f");    system("cls");}void caidan()//显示菜单{    system("cls");    gotoxy(2,28);    puts("职工信息管理系统");    puts("");    puts("                                 1.插入");    puts("                                 2.删除");    puts("                                 3.显示");    puts("                                 4.修改");    puts("                                 5.查询");    puts("                                 6.结束");}int main(){    acm.clear();    fstream in("1.txt",ios::in);//打开文件    if(!in)//如果1.txt不存在    {        in.open("1.txt",ios::out);//就用out建立一个        in.close();        in.open("1.txt",ios::in);//让输入流等于1.txt    }    string nam_;//姓名    string gh_;//工号    bool sex_;//性别    string sr_;//生日    string xl_;//学历    string zw_;//职务    int gz_;//工资    string zhu_;//住址    string tel_;//电话    while(in>>nam_)    {        in>>gh_;        int ac;        in>>ac;        sex_=ac;        in>> sr_>>xl_ >>zw_ >>gz_ >>zhu_ >>tel_;        zhigong qwe(nam_,gh_,sex_,sr_,xl_,zw_,gz_,zhu_,tel_);//文件读入        acm.insert(qwe);//存入集合中    }    in.close();//关闭文件    xinxing();//心形界面    system("color 1e");    caidan();    string k;    while(cin>>k)    {        if(k.size()==1)        {            switch(k[0])            {                case '1':                    acm.sdin();//手动插入                    break;                case '2':                {                    cout<<"请输入要删除的工号,输入out退出"<<endl;                    string _gh;                    while(cin>>_gh)                    {                        if(_gh=="out")                            break;                        zhigong x(_gh);                        zgxt::iterator p=acm.find(x);//set提供了一个find()返回的是符合条件的迭代器                        if(p==acm.end())                        {                            cout<<"输入有误请重新输入"<<endl;                            Sleep(500);                            cout<<"请输入要删除的工号"<<endl;                            continue;                        }                        zhigong ak=*p;                        ak.prin();                        string w;                        cout<<"该职工是否是您需要的?(y/n):";                        bool adc=true;                        while(cin>>w)                        {                            if(w=="Y"||w=="y")                            {                                acm.erase(*p);                                cout<<"删除成功"<<endl;                                system("pause");                                break;                            }                            if(w=="N"||w=="n")                            {                                cout<<"那么你想干啥?\n1:重新输入\n2:退出"<<endl;                                int apc;                                while(cin>>apc)                                {                                    if(apc==1)                                    {                                        adc=false;                                        break;                                    }                                    if(apc==2)                                        break;                                    cout<<"输入有误"<<endl;                                }                                break;                            }                            cout<<"输入有误"<<endl;                        }                        if(!adc)                        {                            cout<<"请输入要删除的工号,输入out退出"<<endl;                            continue;                        }                        else                            break;                    }                    break;                }                case '3':                    acm.shuc();//输出集合                    break;                case '4':                {                    cout<<"请输入要修改的工号,输入out退出"<<endl;                    string _gh;                    while(cin>>_gh)                    {                        if(_gh=="out")                            break;                        zhigong x(_gh);                        zgxt::iterator p=acm.find(x);                        if(p==acm.end())                        {                            cout<<"输入有误请重新输入"<<endl;                            Sleep(500);                            cout<<"请输入要删除的工号"<<endl;                            continue;                        }                        x=*p;                        acm.erase(*p);                        x.change();                        acm.insert(x);                        break;                    }                    break;                }                case '5':                {                    zgxt::iterator p;                    cout<<"请输入姓名关键字"<<endl;//姓名查找                    string s;                    cin>>s;                    p=acm.mhfind(s);                    if(p==acm.end())                    {                        cout<<"不存在"<<endl;                        system("pause");                    }                    else                    {                        cout<<"您想干什么?"<<endl;                        cout<<"1: 删除\n2: 修改\n3: 只是看一下"<<endl;                        int ss;                        while(cin>>ss)                        {                            if(ss==1)                            {                                zhigong x=*p;                                acm.erase(x);                                cout<<"删除成功"<<endl;                                system("pause");                                break;                            }                            if(ss==2)                            {                                zhigong x=*p;                                acm.erase(x);                                x.change();                                acm.insert(x);                                break;                            }                            if(ss==3)                                break;                            cout<<"输入有误请重新输入"<<endl;                        }                    }                    break;                }                case '6':                {                    fstream out("1.txt",ios::out);//打开文件                    zgxt::iterator p=acm.begin();                    while(p!=acm.end())//把zgxt里面的所有元素都存入文件中                    {                        zhigong lx=*p;                        out<<lx;                        p++;                    }                    out.close();//关闭文件                    return 0;                }                default :                {                    cout<<"输入有误,请重新输入"<<endl;                    Sleep(500);                    break;                }            }            caidan();            continue;        }        cout<<"输入有误,请重新输入"<<endl;        Sleep(500);        caidan();    }    return 0;}void zhigong::change()//修改{    prin();    cout<<"您需要修改几处?";    int n;    cin>>n;    while(n--)    {        cout<<"您需要修改的是:"<<"\n"            <<"1:姓名"<<"\n"            <<"2:工号"<<"\n"            <<"3:性别"<<"\n"            <<"4:生日"<<"\n"            <<"5:学历"<<"\n"            <<"6:职务"<<"\n"            <<"7:工资"<<"\n"            <<"8:住址"<<"\n"            <<"9:电话"<<endl;        string k;        while(cin>>k)        {            if(k.size()==1&&k[0]>='1'&&k[0]<='9')                break;            cout<<"输入有误请重新输入"<<endl;        }        switch(k[0]-'0')        {            case 1:            {                cout<<"姓名: ";                cin>>nam;                break;            }            case 2:            {                cout<<"工号: ";                string _gh;                while(cin>>_gh)                {                    if(gh==_gh)                        break;                    zhigong x(_gh);                    if(!acm.count(x))//判断当前工号是否存在                        break;                    cout<<"该工号重复,请重新输入"<<endl;                    cout<<"工号: ";                }                gh=_gh;                break;            }            case 3:            {                cout<<"请选择性别:(男:1/女 0) : ";                string kt;                while(cin>>kt)                {                    if(kt=="0")                    {                        sex=false;                        break;                    }                    if(kt=="1")                    {                        sex=true;                        break;                    }                    cout<<"输入有误,请重新输入"<<endl;                    cout<<"请选择性别:(男:1/女 0) : ";                }                break;            }            case 4:            {                cout<<"生日: ";                cin>>sr;                break;            }            case 5:            {                cout<<"学历: ";                cin>>xl;                break;            }            case 6:            {                cout<<"职务: ";                cin>>zw;                break;            }            case 7:            {                cout<<"工资: ";                cin>>gz;                break;            }            case 8:            {                cout<<"住址: ";                cin>>zhu;                break;            }            case 9:            {                cout<<"电话: ";                cin>>tel;                break;            }        }    }    cout<<"修改成功"<<endl;    system("pause");}void zgxt::sdin(){    int n,cont=0;    cout<<"请输入要插入的职工个数 :";    cin>>n;    while(n--)    {        cout<<"第"<<++cont<<"个职工"<<endl;        cout<<"姓名: ";        string _nam;        cin>>_nam;        cout<<"工号: ";        string _gh;        while(cin>>_gh)        {            zhigong x(_gh);            if(!this->count(x))//判重                break;            cout<<"该工号重复,请重新输入"<<endl;            cout<<"工号: ";        }        cout<<"请选择性别:(男:1/女 0) : ";        string k;        bool _sex=false;        while(cin>>k)        {            if(k=="0")            {                _sex=false;                break;            }            if(k=="1")            {                _sex=true;                break;            }            cout<<"输入有误,请重新输入"<<endl;            cout<<"请选择性别:(男:1/女 0) : ";        }        cout<<"生日: ";        string _sr;        cin>>_sr;        cout<<"学历: ";        string _xl;        cin>>_xl;        cout<<"职务: ";        string _zw;        cin>>_zw;        cout<<"工资: ";        int _gz;        cin>>_gz;        cout<<"住址: ";        string _zhu;        cin>>_zhu;        cout<<"电话: ";        string _tel;        cin>>_tel;        cout<<endl;        zhigong x(_nam,_gh,_sex,_sr,_xl,_zw,_gz,_zhu,_tel);        this->insert(x);//插入    }}bool zhigong::operator < (const  zhigong &b)const//为set提供排序方式{    return gh<b.gh;}zhigong::zhigong(string _nam,string _gh,bool _sex,string _sr,string _xl,string _zw,int _gz,string _zhu,string _tel)    :nam(_nam),gh(_gh),sex(_sex),sr(_sr),xl(_xl),zw(_zw),gz(_gz),zhu(_zhu),tel(_tel) {}//构造函数zhigong::zhigong() {}zhigong::zhigong(string x)//为工号查找提供简易构造函数{    nam="",gh=x,sex=false,sr="",xl="",zw="",gz=0,zhu="",tel="";}void zhigong::prin()//屏幕输出{    cout<<"姓名: "<<nam<<endl;    cout<<"工号: "<<gh<<endl;    cout<<"性别: ";    if(sex)        cout<<"男"<<endl;    else        cout<<"女"<<endl;    cout<<"生日: "<<sr<<endl;    cout<<"学历: "<<xl<<endl;    cout<<"职务: "<<zw<<endl;    cout<<"工资: "<<gz<<endl;    cout<<"住址: "<<zhu<<endl;    cout<<"电话: "<<tel<<"\n"<<endl;}ostream& operator << (ostream &out,const zhigong& b)//为文件对象提供输出{    out<<b.nam<<endl<<b.gh<<endl<<b.sex<<endl<<b.sr<<endl<<b.xl<<endl<<b.zw<<endl<<b.gz<<endl<<b.zhu<<endl<<b.tel<<endl;    return out;}string zhigong::na()//为姓名模糊查找提供nam{    return nam;}void zgxt::shuc()//输出{    system("cls");    zgxt::iterator p = this->begin();//迭代器    cout<<"共"<<this->size()<<"个成员"<<endl;    while(p!=this->end())    {        zhigong x;        x=*p;        p++;        x.prin();    }    system("pause");}zgxt::iterator zgxt::mhfind(string _na)//模糊查找姓名{    zgxt::iterator p=this->begin();    while(p!=this->end())    {        zhigong x=*p;        if(x.na().find(_na)!=0xffffffff)//string 提供了find()函数,如果未找到就返回一个0xffffffff        {            cout<<"找到目标"<<endl;            x.prin();            cout<<"该目标是否是您需要的?(y/n) ";            string s;            while(cin>>s)            {                if(s=="y"||s=="Y")                    return p;                if(s=="N"||s=="n")                    break;                cout<<"输入有误"<<endl;            }        }        p++;    }    return this->end();}

0 0
原创粉丝点击