鱼C论坛

 找回密码
 立即注册
查看: 2905|回复: 39

[已解决]c++友元类成员变量问题

[复制链接]
发表于 2021-6-19 21:28:14 | 显示全部楼层 |阅读模式
50鱼币
QQ图片20210619212325.png QQ图片20210619212343.png QQ图片20210619212349.png
w.name是Staffoperation类的成员变量,然后在message类里面输出就为乱码,但是如第三张图片所示,在Staffoperatio类的成员函数里面输出,他的结果就是正常的,比如说内容是张三,在第一张图片里面输出就为烫烫烫,但是在第三张图片里面输出就是张三。
求求各位大佬帮帮忙
最佳答案
2021-6-19 21:28:15
147380124 发表于 2021-6-19 22:06
大佬,你就给我指点指点大概修改方向吧我自己再研究研究,就不麻烦大佬了谢谢大佬指 ...
  1. 另一个问题
  2.         strcpy_s(name_m, strlen(w.name) + 1, w.name);

  3. w 是什么?是一个数组
  4. 至少也是 w[i].name 吧?
  5. 直接 w.name 吗?
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 21:28:15 | 显示全部楼层    本楼为最佳答案   
147380124 发表于 2021-6-19 22:06
大佬,你就给我指点指点大概修改方向吧我自己再研究研究,就不麻烦大佬了谢谢大佬指 ...
  1. 另一个问题
  2.         strcpy_s(name_m, strlen(w.name) + 1, w.name);

  3. w 是什么?是一个数组
  4. 至少也是 w[i].name 吧?
  5. 直接 w.name 吗?
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 21:41:47 | 显示全部楼层
发代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 21:43:29 | 显示全部楼层

代码有点多,因为是项目出了毛病
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 21:46:23 | 显示全部楼层
147380124 发表于 2021-6-19 21:43
代码有点多,因为是项目出了毛病

你只发个代码片段,我没办法把程序运行起来调试呀
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 21:46:24 | 显示全部楼层


#include<iostream>
using namespace std;


void menu()//定义菜单函数
{
    cout << endl;
    cout << "---------------------------人事档案管理系统---------------------------" << endl << endl;
    cout << "\t\t\t 1:添加职员具体信息" << endl;
    cout << "\t\t\t 2:按姓名查找职员信息" << endl;
    cout << "\t\t\t 3:按编号查找职员信息" << endl;
    cout << "\t\t\t 4:按姓名删除职员信息" << endl;
    cout << "\t\t\t 5:按编号删除职员信息" << endl;
    cout << "\t\t\t 6:显示人事管理系统中所有职员信息" << endl;
    cout << "\t\t\t 7:清空人事管理系统中所有职员信息" << endl;
    cout << "\t\t\t 8:统计人事管理系统中的职员总数" << endl;
    cout << "\t\t\t 0:退出人事档案管理系统" << endl;
    cout << "**********************************************************************" << endl;
}

class Person {//普通人
public:
    char name[30];
    char sex[20];
    char age[20];


};

//职工职位
class PersonPosition :virtual public Person {//Person为虚基类
public:
    char position[20];//职位
    PersonPosition() {
        //Null
    }
    ~PersonPosition() {
        //Null
    }
};

//操作时间
class OperationTime :virtual public Person {//Person为虚基类
public:
    char engage_time[100];//聘用时间
    char add_time[100];//记录时间
    OperationTime() {
        //Null
    }
    ~OperationTime() {
        //Null
    }
};

//职工基本信息
class Worker :public PersonPosition, public OperationTime {//继承PersonPosition、OperationTime类,多重继承。
private:
    char num[20];//编号
    char address[500];//地址
    char tel[100];//手机号
    char nation[30];//民族
    char political_status[20];//政治面貌
    char marital_status[20];//婚姻状况
    char school[200];//毕业院校
    char identity[500];//身份证号
    char email[20];//邮箱

    friend class message;//友元类message

    Worker() {
        //Null
    }
    ~Worker() {
        //Null
    }
    friend class Staffoperation;//定义友元操作类

};

//操作函数
class Staffoperation :public PersonPosition, public OperationTime {//多重继承
private:
    Worker w[101];//100为员工最多数量
    int Num;//用于表示记录时员工的序号
    int all;//用于表示系统含有多少名员工

public:
    Staffoperation() {
        Num = 1;
        all = 0;
    }
    virtual void show() {
        //Null
        //定义虚函数show,供message类调用
    }

    void add_person();//添加员工具体信息
    void searchname();//按姓名查找
    void searchnum();//按编号查找
    void delname();//按姓名删除
    void delnum();//按编号删除
    void showall();//显示人事管理系统中所有员工信息
    void delall();//清空人事管理系统中所有员工信息
    void total();//统计人事管理系统中的员工总数

    friend ostream& operator<<(ostream& out, int a[]);

    friend class message;//定义友元类

};

//message类用于重载运算符
class message :public Staffoperation {
private:
    char name_m[32];
    char sex_m[22];
    char age_m[22];
    char num_m[22];//编号
    char address_m[502];//地址
    char tel_m[102];//手机号
    char nation_m[32];//民族
    char political_status_m[22];//政治面貌
    char marital_status_m[22];//婚姻状况
    char school_m[202];//毕业院校
    char identity_m[502];//身份证号
    char email_m[22];//邮箱
    char position_m[22];//职位
    char engage_time_m[102];//聘用时间
    char add_time_m[102];//记录时间
public:
    message(int i) {
        strcpy_s(name_m, strlen(w.name) + 1, w.name);
        strcpy_s(sex_m, strlen(w.sex) + 1, w.sex);
        strcpy_s(age_m, strlen(w.age) + 1, w.age);
        strcpy_s(num_m, strlen(w.num) + 1, w.num);
        strcpy_s(address_m, strlen(w.name) + 1, w.name);
        strcpy_s(tel_m, strlen(w.tel) + 1, w.tel);
        strcpy_s(nation_m, strlen(w.nation) + 1, w.nation);
        strcpy_s(political_status_m, strlen(w.political_status) + 1, w.political_status);
        strcpy_s(marital_status_m, strlen(w.marital_status) + 1, w.marital_status);
        strcpy_s(school_m, strlen(w.school) + 1, w.school);
        strcpy_s(identity_m, strlen(w.identity) + 1, w.identity);
        strcpy_s(email_m, strlen(w.email) + 1, w.email);
        strcpy_s(position_m, strlen(w.position) + 1, w.position);
        strcpy_s(engage_time_m, strlen(w.engage_time) + 1, w.engage_time);
        strcpy_s(add_time_m, strlen(w.add_time) + 1, w.add_time);
    }

    //拷贝构造函数
    message(const message& me) {
        strcpy_s(name_m, strlen(me.name_m) + 1, me.name_m);
        strcpy_s(sex_m, strlen(me.sex_m) + 1, me.sex_m);
        strcpy_s(age_m, strlen(me.age_m) + 1, me.age_m);
        strcpy_s(num_m, strlen(me.num_m) + 1, me.num_m);
        strcpy_s(address_m, strlen(me.name_m) + 1, me.name_m);
        strcpy_s(tel_m, strlen(me.tel_m) + 1, me.tel_m);
        strcpy_s(nation_m, strlen(me.nation_m) + 1, me.nation_m);
        strcpy_s(political_status_m, strlen(me.political_status_m) + 1, me.political_status_m);
        strcpy_s(marital_status_m, strlen(me.marital_status_m) + 1, me.marital_status_m);
        strcpy_s(school_m, strlen(me.school_m) + 1, me.school_m);
        strcpy_s(identity_m, strlen(me.identity_m) + 1, me.identity_m);
        strcpy_s(email_m, strlen(me.email_m) + 1, me.email_m);
        strcpy_s(position_m, strlen(me.position_m) + 1, me.position_m);
        strcpy_s(engage_time_m, strlen(me.engage_time_m) + 1, me.engage_time_m);
        strcpy_s(add_time_m, strlen(me.add_time_m) + 1, me.add_time_m);
    }
    friend ostream& operator<<(ostream& out, message& m);//重载运算符<<
    void show() {
        cout << *this;
    }
};

//重载运算符<<
ostream& operator<<(ostream& out, message& m) {
    out << " 编号:" << m.num_m << endl;
    out << " 姓名:" << m.name_m << endl;
    out << " 年龄:" << m.age_m << endl;
    out << " 性别:" << m.sex_m << endl;
    out << " 地址:" << m.address_m << endl;
    out << " 手机号:" << m.tel_m << endl;
    out << " 国家:" << m.nation_m << endl;
    out << " 政治面貌:" << m.political_status_m << endl;
    out << " 婚姻状况:" << m.marital_status_m << endl;
    out << " 毕业院校:" << m.school_m << endl;
    out << " 身份证号:" << m.identity_m << endl;
    out << " 邮箱:" << m.email_m << endl;
    out << " 聘用时间:" << m.engage_time_m << endl;
    out << " 记录时间:" << m.add_time_m << endl;
    return out;
}

//密码系统(如需使用管理系统,需要输入正确的密码,若连续三次密码错误,则系统推出)
void password()
{

    int password;
    int j = 1;
    cout << "欲使用本系统,请输入本系统的密码:" << endl;
    cin >> password;
    while (password != 888 && j < 3)
    {
        try {//应用异常出来来验证密码
            if (password != 888)
                throw - 1; //抛出int类型异常

        }

        catch (int e) {
            cout << "您输入的密码有误,请再次输入: " << endl;
            j++;
            cin >> password;
        }

    }
    if (password != 888 && j >= 3)
    {
        cout << "您连续三次输入密码有误,系统自动退出" << endl;
        exit(0);
    }
    else {
        cout << endl << "欢迎进入人事档案管理系统\n请根据系统功能列表选择相应的功能(请输入选项对应的数字) " << endl;
    }
}

//添加员工具体信息
void Staffoperation::add_person() {
    string choice = "Y";
    char num1[20];
    while (choice == "Y" || choice == "y")
    {
        cout << "-----新建人事档案职员信息----" << endl;
        cout << "请输入职员的的编号:(1 - 100) " << endl;
        cin >> num1;
        for (int x = 0; x <= all; x++)//判断是否有重复的编号
        {
            while (strcmp(w[x].num, num1) == 0)
            {
                cout << "此职工编号已存在,请重新输入:" << endl;
                cout << "请输入职员的的编号:(1 - 100) " << endl;
                cin >> num1;
                x = 0;
            }
        }
        strcpy_s(w[Num].num, num1);
        cout << "请输入职员姓名:" << endl;
        cin >> w[Num].name;
        //cout << "请输入性别:" << endl;
        //cin >> w[Num].sex;
        //while (strcmp(w[Num].sex,"男")!=0 && strcmp(w[Num].sex, "女") != 0)
        //{
        //    cout << "您输入的性别有误,请核对后再输入: " << endl;
        //    cin >> w[Num].sex;
        //}
        //cout << "请输入年龄:" << endl;
        //cin >> w[Num].age;
        //cout << "请输入该职员的职位:(经理,管理员,员工) " << endl;
        //cin >> w[Num].position;
        //while ((string)w[Num].position != "经理" && (string)w[Num].position != "管理员" && (string)w[Num].position != "员工")
        //{
        //    cout << "您输入的职工职位有误,请核对后再输入: " << endl;
        //    cin >> w[Num].position;
        //}
        //cout << "请输入该职员的家庭地址: " << endl;
        //cin >> w[Num].address;
        //cout << "请输入该职员的民族:" << endl;
        //cin >> w[Num].nation;
        //cout << "请输入职员的政治面貌:(群众,团员,党员)" << endl;
        //cin >> w[Num].political_status;
        //while ((string)w[Num].political_status != "群众" && (string)w[Num].political_status != "团员" && (string)w[Num].political_status != "党员")
        //{
        //    cout << "您输入的职工政治面貌有误,请核对后再输入: " << endl;
        //    cin >> w[Num].political_status;
        //}
        //cout << "请输入职员的婚姻状况(未婚,已婚)" << endl;
        //cin >> w[Num].marital_status;
        //while ((string)w[Num].marital_status != "未婚" && (string)w[Num].marital_status != "已婚")
        //{
        //    cout << "您输入的职工的婚姻状况有误,请核对后再输入: " << endl;
        //    cin >> w[Num].marital_status;
        //}
        //cout << "请输入职员的毕业学校: " << endl;
        //cin >> w[Num].school;
        //cout << "请输入职员的身份证号:" << endl;
        //cin >> w[Num].identity;
        //cout << "请输入职员的手机号:" << endl;
        //cin >> w[Num].tel;
        //cout << "请输入职员的邮箱: " << endl;
        //cin >> w[Num].email;
        //cout << "请输人职员的聘用时间:" << endl;
        //cin >> w[Num].engage_time;
        //cout << "请输入此次记录的添加时间:" << endl;
        //cin >> w[Num].add_time;
        cout << "信息添加成功!" << endl;
        cout << "您还想继续添加吗?( y/n) " << endl;
        cin >> choice;
        while (choice != "Y" && choice != "y" && choice != "N" && choice != "n")
        {
            cout << "请按要求键入(y/n) " << endl;
            cin >> choice;
        }
        if (choice == "N" || choice == "n")
        {
            Num++;
            all++;
            break;
        }
        Num++;
        all++;
    }
}

//按姓名查找
void Staffoperation::searchname() {
    if (all == 0) {
        cout << "目前还没有员工计入系统,即将返回主菜单....." << endl;
        menu();
    }
    else {
        char name1[30];
        int flag = 0;//查询成功标志
        cout << "请输入你想要查询的姓名:" << endl;
        cin >> name1;
        for (int i = 0; i < 100; i++) {
            if (strcmp(name1, w.name) == 0) {
                cout << "查询成功!该员工的信息如下: " << endl;
                int l = i;
                message A(l);
                cout << A.name << endl;
                cout << w.name << endl;

                //message B(A);//调用拷贝构造函数
                //B.show();
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
            cout << "查询失败!系统中没有此人信息!即将返回主菜单....." << endl;
        }
    }
}

//按编号查找
void Staffoperation::searchnum() {
    if (all == 0) {
        cout << "目前还没有员工计入系统,即将返回主菜单....." << endl;
        menu();
    }
    else {
        char num1[20];
        int flag = 0;//查询成功标志
        cout << "请输入你想要查询的编号:" << endl;
        cin >> num1;
        for (int i = 0; i < 100; i++) {
            if (strcmp(w.num, num1) == 0) {
                cout << "查询成功!该员工的信息如下: " << endl;
                message A(i);
                //message B(A);//调用拷贝构造函数
/*               B.show();*/
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
            cout << "查询失败!系统中没有此人信息!即将返回主菜单....." << endl;
        }
    }
}

//按姓名删除
void Staffoperation::delname() {
    if (all == 0) {
        cout << "目前还没有员工计入系统!" << endl;
    }
    char name2[30];
    cout << "请输入你想要删除的员工姓名:" << endl;
    cin >> name2;
    int flag = 0;//删除标志
    for (int i = 0; i < 100; i++) {
        if (strcmp(name2, w.name) == 0) {
            cout << "你想要删除的员工的信息如下: " << endl;
            message A(i);
            //message B(A);//调用拷贝构造函数
            //B.show();
            flag = 1;
            break;
        }
    }
    if (flag == 0) {
        cout << "系统中没有此人信息!" << endl;
    }
    cout << "确认删除请输入Y,返回主菜单请输入N " << endl;
    string p;
    int j = 0;
    cin >> p;
    while (1)
    {
        if (p == "y" || p == "Y")
        {
            for (int i = 0; i < 100; i++) {
                if (strcmp(name2, w.name) == 0) {
                    j = i;
                }
            }
            for (; j <= 99; j++) {
                w[j] = w[j + 1];
            }
            all--;
            cout << "员工信息已删除!" << endl;
            break;
        }
        else if (p == "n" || p == "N")
        {
            menu();
            break;
        }
        else
        {
            cout << "输入有误,请重新输入:";
            cin >> p;
        }
    }

}

//按编号删除
void Staffoperation::delnum() {
    if (all == 0) {
        cout << "目前还没有员工计入系统!." << endl;
    }
    char num2[20];
    cout << "请输入你想要删除的员工编号:" << endl;
    cin >> num2;
    int flag = 0;//删除标志
    for (int i = 0; i < 100; i++) {
        if (strcmp(w.num, num2) == 0) {
            cout << "你想要删除的员工的信息如下: " << endl;
            message A(i);
            //message B(A);//调用拷贝构造函数
            //B.show();
            flag = 1;
            break;
        }
    }
    if (flag == 0) {
        cout << "系统中没有此人信息!" << endl;
    }
    cout << "确认删除请输入Y,返回主菜单请输入N " << endl;
    string p;
    int j;
    cin >> p;
    while (1)
    {
        if (p == "y" || p == "Y")
        {
            for (int i = 0; i < 100; i++) {
                if (strcmp(w.num, num2) == 0) {
                    j = i;
                }
            }
            for (; j <= 99; j++) {
                w[j] = w[j + 1];
            }
            all--;
            cout << "员工信息已删除!" << endl;
            break;
        }
        else if (p == "n" || p == "N")
        {
            menu();
            break;
        }
        else
        {
            cout << "输入有误,请重新输入:";
            cin >> p;
        }
    }

}

//显示人事管理系统中所有员工信息
void Staffoperation::showall() {
    if (all == 0) {
        cout << "信息库为空,请添加职员!" << endl;
        menu();
    }
    else {
        cout << "所有员工的信息如下: " << endl;
        for (int i = 1; i <= all; i++) {
            message A(i);
            //message B(A);//调用拷贝构造函数
            //B.show();
        }
        ///////////////////////////////////////////
    }
}

//清空人事管理系统中所有员工信息
void Staffoperation::delall() {
    for (int x = 1; x <= all; x++) {
        w[x] = w[0];
    }
    all = 0;
    Num = 1;
    cout << "数据已清空!" << endl;
}

//统计人事管理系统中的员工总数
void Staffoperation::total() {
    cout << "系统中一共有:" << all << "名职工的信息。" << endl;
}

//定义控制函数
void manage()
{
    Staffoperation per;
    int choice, k = 1;
    menu();
    cout << "请根据系统功能列表选择相应的功能(请输入选项对应的数字)" << endl;
    //password();
    while (k)
    {
        cin >> choice;
        switch (choice)
        {
        case 1:
            per.add_person();//调用增加人事档案中职员信息函数
            break;
        case 2:
            per.searchname();//调用按姓名查找职工信息函数
            break;
        case 3:
            per.searchnum();//调用按编号查找职工信息函数
            break;
        case 4:
            per.delname();//调用按姓名删除职工信息函数
            break;
        case 5:
            per.delnum();//调用按编号删除职工信息函数
            break;
        case 6:
            per.showall();//调用显示人事档案管理系统中所有职员信息的函数
            break;
        case 7:
            per.delall();//调用清空人事档案管理系统中所有数据的函数
            break;
        case 8:
            per.total();//调用输出人事档案管理系统中职员数的函数
            break;
        case 0:
            cout << endl << "即将退出人事档案管理系统,再见!" << endl << endl;
            k = 0;
            break;
        default:
            cout << "您输入的选项有错,请重新选择! ";
        }
        if (k != 0)
        {
            menu();
            cout << "请根据系统功能列表选择相应的功能(请输入选项对应的数字)" << endl;
        }
    }
}

int main()
{
    manage();

    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 21:48:22 | 显示全部楼层
人造人 发表于 2021-6-19 21:46
你只发个代码片段,我没办法把程序运行起来调试呀

大佬,我知道我这个代码有些是脱了裤子放屁,但是有的像拷贝构造函数这些是老师的要求,必须要加。。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 22:02:00 | 显示全部楼层
147380124 发表于 2021-6-19 21:48
大佬,我知道我这个代码有些是脱了裤子放屁,但是有的像拷贝构造函数这些是老师的要求,必须要加。。。。 ...

不要用微软的安全函数,因为不可移植
这么多报错

  1. main.cpp: In constructor ‘message::message(int)’:
  2. main.cpp:133:35: error: request for member ‘name’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  3.   133 |         strcpy_s(name_m, strlen(w.name) + 1, w.name);
  4.       |                                   ^~~~
  5. main.cpp:133:26: error: ‘strlen’ was not declared in this scope
  6.   133 |         strcpy_s(name_m, strlen(w.name) + 1, w.name);
  7.       |                          ^~~~~~
  8. main.cpp:2:1: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  9.     1 | #include <iostream>
  10.   +++ |+#include <cstring>
  11.     2 |
  12. main.cpp:133:48: error: request for member ‘name’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  13.   133 |         strcpy_s(name_m, strlen(w.name) + 1, w.name);
  14.       |                                                ^~~~
  15. main.cpp:133:9: error: ‘strcpy_s’ was not declared in this scope
  16.   133 |         strcpy_s(name_m, strlen(w.name) + 1, w.name);
  17.       |         ^~~~~~~~
  18. main.cpp:134:34: error: request for member ‘sex’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  19.   134 |         strcpy_s(sex_m, strlen(w.sex) + 1, w.sex);
  20.       |                                  ^~~
  21. main.cpp:134:46: error: request for member ‘sex’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  22.   134 |         strcpy_s(sex_m, strlen(w.sex) + 1, w.sex);
  23.       |                                              ^~~
  24. main.cpp:135:34: error: request for member ‘age’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  25.   135 |         strcpy_s(age_m, strlen(w.age) + 1, w.age);
  26.       |                                  ^~~
  27. main.cpp:135:46: error: request for member ‘age’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  28.   135 |         strcpy_s(age_m, strlen(w.age) + 1, w.age);
  29.       |                                              ^~~
  30. main.cpp:136:34: error: request for member ‘num’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  31.   136 |         strcpy_s(num_m, strlen(w.num) + 1, w.num);
  32.       |                                  ^~~
  33. main.cpp:136:46: error: request for member ‘num’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  34.   136 |         strcpy_s(num_m, strlen(w.num) + 1, w.num);
  35.       |                                              ^~~
  36. main.cpp:137:38: error: request for member ‘name’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  37.   137 |         strcpy_s(address_m, strlen(w.name) + 1, w.name);
  38.       |                                      ^~~~
  39. main.cpp:137:51: error: request for member ‘name’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  40.   137 |         strcpy_s(address_m, strlen(w.name) + 1, w.name);
  41.       |                                                   ^~~~
  42. main.cpp:138:34: error: request for member ‘tel’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  43.   138 |         strcpy_s(tel_m, strlen(w.tel) + 1, w.tel);
  44.       |                                  ^~~
  45. main.cpp:138:46: error: request for member ‘tel’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  46.   138 |         strcpy_s(tel_m, strlen(w.tel) + 1, w.tel);
  47.       |                                              ^~~
  48. main.cpp:139:37: error: request for member ‘nation’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  49.   139 |         strcpy_s(nation_m, strlen(w.nation) + 1, w.nation);
  50.       |                                     ^~~~~~
  51. main.cpp:139:52: error: request for member ‘nation’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  52.   139 |         strcpy_s(nation_m, strlen(w.nation) + 1, w.nation);
  53.       |                                                    ^~~~~~
  54. main.cpp:140:47: error: request for member ‘political_status’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  55.   140 |         strcpy_s(political_status_m, strlen(w.political_status) + 1, w.political_status);
  56.       |                                               ^~~~~~~~~~~~~~~~
  57. main.cpp:140:72: error: request for member ‘political_status’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  58.   140 |         strcpy_s(political_status_m, strlen(w.political_status) + 1, w.political_status);
  59.       |                                                                        ^~~~~~~~~~~~~~~~
  60. main.cpp:141:45: error: request for member ‘marital_status’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  61.   141 |         strcpy_s(marital_status_m, strlen(w.marital_status) + 1, w.marital_status);
  62.       |                                             ^~~~~~~~~~~~~~
  63. main.cpp:141:68: error: request for member ‘marital_status’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  64.   141 |         strcpy_s(marital_status_m, strlen(w.marital_status) + 1, w.marital_status);
  65.       |                                                                    ^~~~~~~~~~~~~~
  66. main.cpp:142:37: error: request for member ‘school’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  67.   142 |         strcpy_s(school_m, strlen(w.school) + 1, w.school);
  68.       |                                     ^~~~~~
  69. main.cpp:142:52: error: request for member ‘school’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  70.   142 |         strcpy_s(school_m, strlen(w.school) + 1, w.school);
  71.       |                                                    ^~~~~~
  72. main.cpp:143:39: error: request for member ‘identity’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  73.   143 |         strcpy_s(identity_m, strlen(w.identity) + 1, w.identity);
  74.       |                                       ^~~~~~~~
  75. main.cpp:143:56: error: request for member ‘identity’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  76.   143 |         strcpy_s(identity_m, strlen(w.identity) + 1, w.identity);
  77.       |                                                        ^~~~~~~~
  78. main.cpp:144:36: error: request for member ‘email’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  79.   144 |         strcpy_s(email_m, strlen(w.email) + 1, w.email);
  80.       |                                    ^~~~~
  81. main.cpp:144:50: error: request for member ‘email’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  82.   144 |         strcpy_s(email_m, strlen(w.email) + 1, w.email);
  83.       |                                                  ^~~~~
  84. main.cpp:145:39: error: request for member ‘position’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  85.   145 |         strcpy_s(position_m, strlen(w.position) + 1, w.position);
  86.       |                                       ^~~~~~~~
  87. main.cpp:145:56: error: request for member ‘position’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  88.   145 |         strcpy_s(position_m, strlen(w.position) + 1, w.position);
  89.       |                                                        ^~~~~~~~
  90. main.cpp:146:42: error: request for member ‘engage_time’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  91.   146 |         strcpy_s(engage_time_m, strlen(w.engage_time) + 1, w.engage_time);
  92.       |                                          ^~~~~~~~~~~
  93. main.cpp:146:62: error: request for member ‘engage_time’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  94.   146 |         strcpy_s(engage_time_m, strlen(w.engage_time) + 1, w.engage_time);
  95.       |                                                              ^~~~~~~~~~~
  96. main.cpp:147:39: error: request for member ‘add_time’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  97.   147 |         strcpy_s(add_time_m, strlen(w.add_time) + 1, w.add_time);
  98.       |                                       ^~~~~~~~
  99. main.cpp:147:56: error: request for member ‘add_time’ in ‘((message*)this)->message::<anonymous>.Staffoperation::w’, which is of non-class type ‘Worker [101]’
  100.   147 |         strcpy_s(add_time_m, strlen(w.add_time) + 1, w.add_time);
  101.       |                                                        ^~~~~~~~
  102. main.cpp: In copy constructor ‘message::message(const message&)’:
  103. main.cpp:151:26: error: ‘strlen’ was not declared in this scope
  104.   151 |         strcpy_s(name_m, strlen(me.name_m) + 1, me.name_m);
  105.       |                          ^~~~~~
  106. main.cpp:151:26: note: ‘strlen’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  107. main.cpp:151:9: error: ‘strcpy_s’ was not declared in this scope
  108.   151 |         strcpy_s(name_m, strlen(me.name_m) + 1, me.name_m);
  109.       |         ^~~~~~~~
  110. main.cpp: In member function ‘void Staffoperation::add_person()’:
  111. main.cpp:236:20: error: ‘strcmp’ was not declared in this scope
  112.   236 |             while (strcmp(w[x].num, num1) == 0)
  113.       |                    ^~~~~~
  114. main.cpp:236:20: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  115. main.cpp:244:9: error: ‘strcpy_s’ was not declared in this scope
  116.   244 |         strcpy_s(w[Num].num, num1);
  117.       |         ^~~~~~~~
  118. main.cpp: In member function ‘void Staffoperation::searchname()’:
  119. main.cpp:324:33: error: request for member ‘name’ in ‘((Staffoperation*)this)->Staffoperation::w’, which is of non-class type ‘Worker [101]’
  120.   324 |             if (strcmp(name1, w.name) == 0) {
  121.       |                                 ^~~~
  122. main.cpp:324:17: error: ‘strcmp’ was not declared in this scope
  123.   324 |             if (strcmp(name1, w.name) == 0) {
  124.       |                 ^~~~~~
  125. main.cpp:324:17: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  126. main.cpp:329:27: error: request for member ‘name’ in ‘((Staffoperation*)this)->Staffoperation::w’, which is of non-class type ‘Worker [101]’
  127.   329 |                 cout << w.name << endl;
  128.       |                           ^~~~
  129. main.cpp: In member function ‘void Staffoperation::searchnum()’:
  130. main.cpp:354:26: error: request for member ‘num’ in ‘((Staffoperation*)this)->Staffoperation::w’, which is of non-class type ‘Worker [101]’
  131.   354 |             if (strcmp(w.num, num1) == 0) {
  132.       |                          ^~~
  133. main.cpp:354:17: error: ‘strcmp’ was not declared in this scope
  134.   354 |             if (strcmp(w.num, num1) == 0) {
  135.       |                 ^~~~~~
  136. main.cpp:354:17: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  137. main.cpp: In member function ‘void Staffoperation::delname()’:
  138. main.cpp:379:29: error: request for member ‘name’ in ‘((Staffoperation*)this)->Staffoperation::w’, which is of non-class type ‘Worker [101]’
  139.   379 |         if (strcmp(name2, w.name) == 0) {
  140.       |                             ^~~~
  141. main.cpp:379:13: error: ‘strcmp’ was not declared in this scope
  142.   379 |         if (strcmp(name2, w.name) == 0) {
  143.       |             ^~~~~~
  144. main.cpp:379:13: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  145. main.cpp:400:37: error: request for member ‘name’ in ‘((Staffoperation*)this)->Staffoperation::w’, which is of non-class type ‘Worker [101]’
  146.   400 |                 if (strcmp(name2, w.name) == 0) {
  147.       |                                     ^~~~
  148. main.cpp:400:21: error: ‘strcmp’ was not declared in this scope
  149.   400 |                 if (strcmp(name2, w.name) == 0) {
  150.       |                     ^~~~~~
  151. main.cpp:400:21: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  152. main.cpp: In member function ‘void Staffoperation::delnum()’:
  153. main.cpp:435:22: error: request for member ‘num’ in ‘((Staffoperation*)this)->Staffoperation::w’, which is of non-class type ‘Worker [101]’
  154.   435 |         if (strcmp(w.num, num2) == 0) {
  155.       |                      ^~~
  156. main.cpp:435:13: error: ‘strcmp’ was not declared in this scope
  157.   435 |         if (strcmp(w.num, num2) == 0) {
  158.       |             ^~~~~~
  159. main.cpp:435:13: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
  160. main.cpp:456:30: error: request for member ‘num’ in ‘((Staffoperation*)this)->Staffoperation::w’, which is of non-class type ‘Worker [101]’
  161.   456 |                 if (strcmp(w.num, num2) == 0) {
  162.       |                              ^~~
  163. main.cpp:456:21: error: ‘strcmp’ was not declared in this scope
  164.   456 |                 if (strcmp(w.num, num2) == 0) {
  165.       |                     ^~~~~~
  166. main.cpp:456:21: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 22:02:59 | 显示全部楼层
本帖最后由 人造人 于 2021-6-19 22:04 编辑
147380124 发表于 2021-6-19 21:48
大佬,我知道我这个代码有些是脱了裤子放屁,但是有的像拷贝构造函数这些是老师的要求,必须要加。。。。 ...

  1. 另一个问题
  2.         strcpy_s(name_m, strlen(w.name) + 1, w.name);

  3. w 是什么?是一个数组
  4. 至少也是 w[i].name 吧?
  5. 直接 w.name 吗?
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 22:03:48 | 显示全部楼层
这么多的 _s 函数,全部改一遍,实在头疼
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 22:06:08 | 显示全部楼层
人造人 发表于 2021-6-19 22:03
这么多的 _s 函数,全部改一遍,实在头疼

大佬,你就给我指点指点大概修改方向吧我自己再研究研究,就不麻烦大佬了谢谢大佬指点!!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 22:07:47 | 显示全部楼层

好的,谢谢大佬!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 22:09:57 | 显示全部楼层

大佬,我刚刚看了下,我是写的w.name,但是复制过来就没了我重新修改一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 22:11:06 | 显示全部楼层
147380124 发表于 2021-6-19 22:09
大佬,我刚刚看了下,我是写的w.name,但是复制过来就没了我重新修改一下
  1. 所以要用代码格式发代码
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 22:11:52 | 显示全部楼层
  1. #include<iostream>
  2. using namespace std;


  3. void menu()//定义菜单函数
  4. {
  5.     cout << endl;
  6.     cout << "---------------------------人事档案管理系统---------------------------" << endl << endl;
  7.     cout << "\t\t\t 1:添加职员具体信息" << endl;
  8.     cout << "\t\t\t 2:按姓名查找职员信息" << endl;
  9.     cout << "\t\t\t 3:按编号查找职员信息" << endl;
  10.     cout << "\t\t\t 4:按姓名删除职员信息" << endl;
  11.     cout << "\t\t\t 5:按编号删除职员信息" << endl;
  12.     cout << "\t\t\t 6:显示人事管理系统中所有职员信息" << endl;
  13.     cout << "\t\t\t 7:清空人事管理系统中所有职员信息" << endl;
  14.     cout << "\t\t\t 8:统计人事管理系统中的职员总数" << endl;
  15.     cout << "\t\t\t 0:退出人事档案管理系统" << endl;
  16.     cout << "**********************************************************************" << endl;
  17. }

  18. class Person {//普通人
  19. public:
  20.     char name[30];
  21.     char sex[20];
  22.     char age[20];


  23. };

  24. //职工职位
  25. class PersonPosition :virtual public Person {//Person为虚基类
  26. public:
  27.     char position[20];//职位
  28.     PersonPosition() {
  29.         //Null
  30.     }
  31.     ~PersonPosition() {
  32.         //Null
  33.     }
  34. };

  35. //操作时间
  36. class OperationTime :virtual public Person {//Person为虚基类
  37. public:
  38.     char engage_time[100];//聘用时间
  39.     char add_time[100];//记录时间
  40.     OperationTime() {
  41.         //Null
  42.     }
  43.     ~OperationTime() {
  44.         //Null
  45.     }
  46. };

  47. //职工基本信息
  48. class Worker :public PersonPosition, public OperationTime {//继承PersonPosition、OperationTime类,多重继承。
  49. private:
  50.     char num[20];//编号
  51.     char address[500];//地址
  52.     char tel[100];//手机号
  53.     char nation[30];//民族
  54.     char political_status[20];//政治面貌
  55.     char marital_status[20];//婚姻状况
  56.     char school[200];//毕业院校
  57.     char identity[500];//身份证号
  58.     char email[20];//邮箱

  59.     friend class message;//友元类message

  60.     Worker() {
  61.         //Null
  62.     }
  63.     ~Worker() {
  64.         //Null
  65.     }
  66.     friend class Staffoperation;//定义友元操作类

  67. };

  68. //操作函数
  69. class Staffoperation :public PersonPosition, public OperationTime {//多重继承
  70. private:
  71.     Worker w[101];//100为员工最多数量
  72.     int Num;//用于表示记录时员工的序号
  73.     int all;//用于表示系统含有多少名员工

  74. public:
  75.     Staffoperation() {
  76.         Num = 1;
  77.         all = 0;
  78.     }
  79.     virtual void show() {
  80.         //Null
  81.         //定义虚函数show,供message类调用
  82.     }

  83.     void add_person();//添加员工具体信息
  84.     void searchname();//按姓名查找
  85.     void searchnum();//按编号查找
  86.     void delname();//按姓名删除
  87.     void delnum();//按编号删除
  88.     void showall();//显示人事管理系统中所有员工信息
  89.     void delall();//清空人事管理系统中所有员工信息
  90.     void total();//统计人事管理系统中的员工总数

  91.     friend class message;//定义友元类

  92. };

  93. //message类用于重载运算符
  94. class message:public Staffoperation,public Worker {
  95. private:
  96.     char name_m[32];
  97.     char sex_m[22];
  98.     char age_m[22];
  99.     char num_m[22];//编号
  100.     char address_m[502];//地址
  101.     char tel_m[102];//手机号
  102.     char nation_m[32];//民族
  103.     char political_status_m[22];//政治面貌
  104.     char marital_status_m[22];//婚姻状况
  105.     char school_m[202];//毕业院校
  106.     char identity_m[502];//身份证号
  107.     char email_m[22];//邮箱
  108.     char position_m[22];//职位
  109.     char engage_time_m[102];//聘用时间
  110.     char add_time_m[102];//记录时间
  111. public:
  112.     message(int i) {
  113.         cout << w[i].name << endl;
  114.         strcpy_s(name_m, strlen(w[i].name) + 1,w[i].name);
  115.         strcpy_s(sex_m, strlen(w[i].sex) + 1, w[i].sex);
  116.         strcpy_s(age_m, strlen(w[i].age) + 1, w[i].age);
  117.         strcpy_s(num_m, strlen(w[i].num) + 1, w[i].num);
  118.         strcpy_s(address_m, strlen(w[i].name) + 1, w[i].name);
  119.         strcpy_s(tel_m, strlen(w[i].tel) + 1, w[i].tel);
  120.         strcpy_s(nation_m, strlen(w[i].nation) + 1, w[i].nation);
  121.         strcpy_s(political_status_m, strlen(w[i].political_status) + 1, w[i].political_status);
  122.         strcpy_s(marital_status_m, strlen(w[i].marital_status) + 1, w[i].marital_status);
  123.         strcpy_s(school_m, strlen(w[i].school) + 1, w[i].school);
  124.         strcpy_s(identity_m, strlen(w[i].identity) + 1, w[i].identity);
  125.         strcpy_s(email_m, strlen(w[i].email) + 1, w[i].email);
  126.         strcpy_s(position_m, strlen(w[i].position) + 1, w[i].position);
  127.         strcpy_s(engage_time_m, strlen(w[i].engage_time) + 1, w[i].engage_time);
  128.         strcpy_s(add_time_m, strlen(w[i].add_time) + 1, w[i].add_time);
  129.     }
  130.     //拷贝构造函数
  131.     message(const message& me) {
  132.         strcpy_s(name_m, strlen(me.name_m) + 1, me.name_m);
  133.         strcpy_s(sex_m, strlen(me.sex_m) + 1, me.sex_m);
  134.         strcpy_s(age_m, strlen(me.age_m) + 1, me.age_m);
  135.         strcpy_s(num_m, strlen(me.num_m) + 1, me.num_m);
  136.         strcpy_s(address_m, strlen(me.name_m) + 1, me.name_m);
  137.         strcpy_s(tel_m, strlen(me.tel_m) + 1, me.tel_m);
  138.         strcpy_s(nation_m, strlen(me.nation_m) + 1, me.nation_m);
  139.         strcpy_s(political_status_m, strlen(me.political_status_m) + 1, me.political_status_m);
  140.         strcpy_s(marital_status_m, strlen(me.marital_status_m) + 1, me.marital_status_m);
  141.         strcpy_s(school_m, strlen(me.school_m) + 1, me.school_m);
  142.         strcpy_s(identity_m, strlen(me.identity_m) + 1, me.identity_m);
  143.         strcpy_s(email_m, strlen(me.email_m) + 1, me.email_m);
  144.         strcpy_s(position_m, strlen(me.position_m) + 1, me.position_m);
  145.         strcpy_s(engage_time_m, strlen(me.engage_time_m) + 1, me.engage_time_m);
  146.         strcpy_s(add_time_m, strlen(me.add_time_m) + 1, me.add_time_m);
  147.     }
  148.     friend ostream& operator<<(ostream& out, message& m);//重载运算符<<
  149.     void show() {
  150.         cout << *this;
  151.     }
  152. };

  153. //重载运算符<<
  154. ostream& operator<<(ostream& out, message& m) {
  155.     out << " 编号:" << m.num_m << endl;
  156.     out << " 姓名:" << m.name_m << endl;
  157.     out << " 年龄:" << m.age_m << endl;
  158.     out << " 性别:" << m.sex_m << endl;
  159.     out << " 地址:" << m.address_m << endl;
  160.     out << " 手机号:" << m.tel_m << endl;
  161.     out << " 国家:" << m.nation_m << endl;
  162.     out << " 政治面貌:" << m.political_status_m << endl;
  163.     out << " 婚姻状况:" << m.marital_status_m << endl;
  164.     out << " 毕业院校:" << m.school_m << endl;
  165.     out << " 身份证号:" << m.identity_m << endl;
  166.     out << " 邮箱:" << m.email_m << endl;
  167.     out << " 聘用时间:" << m.engage_time_m << endl;
  168.     out << " 记录时间:" << m.add_time_m << endl;
  169.     return out;
  170. }

  171. //密码系统(如需使用管理系统,需要输入正确的密码,若连续三次密码错误,则系统推出)
  172. void password()
  173. {

  174.     int password;
  175.     int j = 1;
  176.     cout << "欲使用本系统,请输入本系统的密码:" << endl;
  177.     cin >> password;
  178.     while (password != 888 && j < 3)
  179.     {
  180.         try {//应用异常出来来验证密码
  181.             if (password != 888)
  182.                 throw - 1; //抛出int类型异常

  183.         }

  184.         catch (int e) {
  185.             cout << "您输入的密码有误,请再次输入: " << endl;
  186.             j++;
  187.             cin >> password;
  188.         }

  189.     }
  190.     if (password != 888 && j >= 3)
  191.     {
  192.         cout << "您连续三次输入密码有误,系统自动退出" << endl;
  193.         exit(0);
  194.     }
  195.     else {
  196.         cout << endl << "欢迎进入人事档案管理系统\n请根据系统功能列表选择相应的功能(请输入选项对应的数字) " << endl;
  197.     }
  198. }

  199. //添加员工具体信息
  200. void Staffoperation::add_person() {
  201.     string choice = "Y";
  202.     char num1[20];
  203.     while (choice == "Y" || choice == "y")
  204.     {
  205.         cout << "-----新建人事档案职员信息----" << endl;
  206.         cout << "请输入职员的的编号:(1 - 100) " << endl;
  207.         cin >> num1;
  208.         for (int x = 0; x <= all; x++)//判断是否有重复的编号
  209.         {
  210.             while (strcmp(w[x].num, num1) == 0)
  211.             {
  212.                 cout << "此职工编号已存在,请重新输入:" << endl;
  213.                 cout << "请输入职员的的编号:(1 - 100) " << endl;
  214.                 cin >> num1;
  215.                 x = 0;
  216.             }
  217.         }
  218.         strcpy_s(w[Num].num, num1);
  219.         cout << "请输入职员姓名:" << endl;
  220.         cin >> w[Num].name;
  221.         //cout << "请输入性别:" << endl;
  222.         //cin >> w[Num].sex;
  223.         //while (strcmp(w[Num].sex,"男")!=0 && strcmp(w[Num].sex, "女") != 0)
  224.         //{
  225.         //    cout << "您输入的性别有误,请核对后再输入: " << endl;
  226.         //    cin >> w[Num].sex;
  227.         //}
  228.         //cout << "请输入年龄:" << endl;
  229.         //cin >> w[Num].age;
  230.         //cout << "请输入该职员的职位:(经理,管理员,员工) " << endl;
  231.         //cin >> w[Num].position;
  232.         //while ((string)w[Num].position != "经理" && (string)w[Num].position != "管理员" && (string)w[Num].position != "员工")
  233.         //{
  234.         //    cout << "您输入的职工职位有误,请核对后再输入: " << endl;
  235.         //    cin >> w[Num].position;
  236.         //}
  237.         //cout << "请输入该职员的家庭地址: " << endl;
  238.         //cin >> w[Num].address;
  239.         //cout << "请输入该职员的民族:" << endl;
  240.         //cin >> w[Num].nation;
  241.         //cout << "请输入职员的政治面貌:(群众,团员,党员)" << endl;
  242.         //cin >> w[Num].political_status;
  243.         //while ((string)w[Num].political_status != "群众" && (string)w[Num].political_status != "团员" && (string)w[Num].political_status != "党员")
  244.         //{
  245.         //    cout << "您输入的职工政治面貌有误,请核对后再输入: " << endl;
  246.         //    cin >> w[Num].political_status;
  247.         //}
  248.         //cout << "请输入职员的婚姻状况(未婚,已婚)" << endl;
  249.         //cin >> w[Num].marital_status;
  250.         //while ((string)w[Num].marital_status != "未婚" && (string)w[Num].marital_status != "已婚")
  251.         //{
  252.         //    cout << "您输入的职工的婚姻状况有误,请核对后再输入: " << endl;
  253.         //    cin >> w[Num].marital_status;
  254.         //}
  255.         //cout << "请输入职员的毕业学校: " << endl;
  256.         //cin >> w[Num].school;
  257.         //cout << "请输入职员的身份证号:" << endl;
  258.         //cin >> w[Num].identity;
  259.         //cout << "请输入职员的手机号:" << endl;
  260.         //cin >> w[Num].tel;
  261.         //cout << "请输入职员的邮箱: " << endl;
  262.         //cin >> w[Num].email;
  263.         //cout << "请输人职员的聘用时间:" << endl;
  264.         //cin >> w[Num].engage_time;
  265.         //cout << "请输入此次记录的添加时间:" << endl;
  266.         //cin >> w[Num].add_time;
  267.         cout << "信息添加成功!" << endl;
  268.         cout << "您还想继续添加吗?( y/n) " << endl;
  269.         cin >> choice;
  270.         while (choice != "Y" && choice != "y" && choice != "N" && choice != "n")
  271.         {
  272.             cout << "请按要求键入(y/n) " << endl;
  273.             cin >> choice;
  274.         }
  275.         if (choice == "N" || choice == "n")
  276.         {
  277.             Num++;
  278.             all++;
  279.             break;
  280.         }
  281.         Num++;
  282.         all++;
  283.     }
  284. }

  285. //按姓名查找
  286. void Staffoperation::searchname() {
  287.     if (all == 0) {
  288.         cout << "目前还没有员工计入系统,即将返回主菜单....." << endl;
  289.         menu();
  290.     }
  291.     else {
  292.         char name1[30];
  293.         int flag = 0;//查询成功标志
  294.         cout << "请输入你想要查询的姓名:" << endl;
  295.         cin >> name1;
  296.         for (int i = 0; i < 100; i++) {
  297.             if (strcmp(name1, w[i].name) == 0) {
  298.                 cout << "查询成功!该员工的信息如下: " << endl;
  299.                 int l = i;
  300.                 message A(l);
  301.                 cout << A.name << endl;
  302.                 cout << w[i].name << endl;
  303.                 //message B(A);//调用拷贝构造函数
  304.                 //B.show();
  305.                 flag = 1;
  306.                 break;
  307.             }
  308.         }
  309.         if (flag == 0) {
  310.             cout << "查询失败!系统中没有此人信息!即将返回主菜单....." << endl;
  311.         }
  312.     }
  313. }

  314. //按编号查找
  315. void Staffoperation::searchnum() {
  316.     if (all == 0) {
  317.         cout << "目前还没有员工计入系统,即将返回主菜单....." << endl;
  318.         menu();
  319.     }
  320.     else {
  321.         char num1[20];
  322.         int flag = 0;//查询成功标志
  323.         cout << "请输入你想要查询的编号:" << endl;
  324.         cin >> num1;
  325.         for (int i = 0; i < 100; i++) {
  326.             if (strcmp(w[i].num, num1) == 0) {
  327.                 cout << "查询成功!该员工的信息如下: " << endl;
  328.                 message A(i);
  329.                 //message B(A);//调用拷贝构造函数
  330. /*               B.show();*/
  331.                 flag = 1;
  332.                 break;
  333.             }
  334.         }
  335.         if (flag == 0) {
  336.             cout << "查询失败!系统中没有此人信息!即将返回主菜单....." << endl;
  337.         }
  338.     }
  339. }

  340. //按姓名删除
  341. void Staffoperation::delname() {
  342.     if (all == 0) {
  343.         cout << "目前还没有员工计入系统!" << endl;
  344.     }
  345.     char name2[30];
  346.     cout << "请输入你想要删除的员工姓名:" << endl;
  347.     cin >> name2;
  348.     int flag = 0;//删除标志
  349.     for (int i = 0; i < 100; i++) {
  350.         if (strcmp(name2, w[i].name) == 0) {
  351.             cout << "你想要删除的员工的信息如下: " << endl;
  352.             message A(i);
  353.             //message B(A);//调用拷贝构造函数
  354.             //B.show();
  355.             flag = 1;
  356.             break;
  357.         }
  358.     }
  359.     if (flag == 0) {
  360.         cout << "系统中没有此人信息!" << endl;
  361.     }
  362.     cout << "确认删除请输入Y,返回主菜单请输入N " << endl;
  363.     string p;
  364.     int j = 0;
  365.     cin >> p;
  366.     while (1)
  367.     {
  368.         if (p == "y" || p == "Y")
  369.         {
  370.             for (int i = 0; i < 100; i++) {
  371.                 if (strcmp(name2, w[i].name) == 0) {
  372.                     j = i;
  373.                 }
  374.             }
  375.             for (; j <= 99; j++) {
  376.                 w[j] = w[j + 1];
  377.             }
  378.             all--;
  379.             cout << "员工信息已删除!" << endl;
  380.             break;
  381.         }
  382.         else if (p == "n" || p == "N")
  383.         {
  384.             menu();
  385.             break;
  386.         }
  387.         else
  388.         {
  389.             cout << "输入有误,请重新输入:";
  390.             cin >> p;
  391.         }
  392.     }

  393. }

  394. //按编号删除
  395. void Staffoperation::delnum() {
  396.     if (all == 0) {
  397.         cout << "目前还没有员工计入系统!." << endl;
  398.     }
  399.     char num2[20];
  400.     cout << "请输入你想要删除的员工编号:" << endl;
  401.     cin >> num2;
  402.     int flag = 0;//删除标志
  403.     for (int i = 0; i < 100; i++) {
  404.         if (strcmp(w[i].num, num2) == 0) {
  405.             cout << "你想要删除的员工的信息如下: " << endl;
  406.             message A(i);
  407.             //message B(A);//调用拷贝构造函数
  408.             //B.show();
  409.             flag = 1;
  410.             break;
  411.         }
  412.     }
  413.     if (flag == 0) {
  414.         cout << "系统中没有此人信息!" << endl;
  415.     }
  416.     cout << "确认删除请输入Y,返回主菜单请输入N " << endl;
  417.     string p;
  418.     int j;
  419.     cin >> p;
  420.     while (1)
  421.     {
  422.         if (p == "y" || p == "Y")
  423.         {
  424.             for (int i = 0; i < 100; i++) {
  425.                 if (strcmp(w[i].num, num2) == 0) {
  426.                     j = i;
  427.                 }
  428.             }
  429.             for (; j <= 99; j++) {
  430.                 w[j] = w[j + 1];
  431.             }
  432.             all--;
  433.             cout << "员工信息已删除!" << endl;
  434.             break;
  435.         }
  436.         else if (p == "n" || p == "N")
  437.         {
  438.             menu();
  439.             break;
  440.         }
  441.         else
  442.         {
  443.             cout << "输入有误,请重新输入:";
  444.             cin >> p;
  445.         }
  446.     }

  447. }

  448. //显示人事管理系统中所有员工信息
  449. void Staffoperation::showall() {
  450.     if (all == 0) {
  451.         cout << "信息库为空,请添加职员!" << endl;
  452.         menu();
  453.     }
  454.     else {
  455.         cout << "所有员工的信息如下: " << endl;
  456.         for (int i = 1; i <= all; i++) {
  457.             message A(i);
  458.             //message B(A);//调用拷贝构造函数
  459.             //B.show();
  460.         }
  461.         ///////////////////////////////////////////
  462.     }
  463. }

  464. //清空人事管理系统中所有员工信息
  465. void Staffoperation::delall() {
  466.     for (int x = 1; x <= all; x++) {
  467.         w[x] = w[0];
  468.     }
  469.     all = 0;
  470.     Num = 1;
  471.     cout << "数据已清空!" << endl;
  472. }

  473. //统计人事管理系统中的员工总数
  474. void Staffoperation::total() {
  475.     cout << "系统中一共有:" << all << "名职工的信息。" << endl;
  476. }

  477. //定义控制函数
  478. void manage()
  479. {
  480.     Staffoperation per;
  481.     int choice, k = 1;
  482.     menu();
  483.     cout << "请根据系统功能列表选择相应的功能(请输入选项对应的数字)" << endl;
  484.     //password();
  485.     while (k)
  486.     {
  487.         cin >> choice;
  488.         switch (choice)
  489.         {
  490.         case 1:
  491.             per.add_person();//调用增加人事档案中职员信息函数
  492.             break;
  493.         case 2:
  494.             per.searchname();//调用按姓名查找职工信息函数
  495.             break;
  496.         case 3:
  497.             per.searchnum();//调用按编号查找职工信息函数
  498.             break;
  499.         case 4:
  500.             per.delname();//调用按姓名删除职工信息函数
  501.             break;
  502.         case 5:
  503.             per.delnum();//调用按编号删除职工信息函数
  504.             break;
  505.         case 6:
  506.             per.showall();//调用显示人事档案管理系统中所有职员信息的函数
  507.             break;
  508.         case 7:
  509.             per.delall();//调用清空人事档案管理系统中所有数据的函数
  510.             break;
  511.         case 8:
  512.             per.total();//调用输出人事档案管理系统中职员数的函数
  513.             break;
  514.         case 0:
  515.             cout << endl << "即将退出人事档案管理系统,再见!" << endl << endl;
  516.             k = 0;
  517.             break;
  518.         default:
  519.             cout << "您输入的选项有错,请重新选择! ";
  520.         }
  521.         if (k != 0)
  522.         {
  523.             menu();
  524.             cout << "请根据系统功能列表选择相应的功能(请输入选项对应的数字)" << endl;
  525.         }
  526.     }
  527. }

  528. int main()
  529. {
  530.     manage();

  531.     return 0;
  532. }
复制代码

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 22:13:10 | 显示全部楼层

就看看按姓名查找这个功能就可以了,其他应该问题是一样的,劳烦大佬了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 22:26:18 | 显示全部楼层
147380124 发表于 2021-6-19 22:13
就看看按姓名查找这个功能就可以了,其他应该问题是一样的,劳烦大佬了

给个输入样例,输入什么会出现你图片上的错误?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 22:28:02 | 显示全部楼层
人造人 发表于 2021-6-19 22:26
给个输入样例,输入什么会出现你图片上的错误?

比如说输入张三,message内的那个就会输出乱码,是烫烫烫,而查询姓名那个成员函数里面输出就不会有乱码,就是张三
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-19 22:47:49 | 显示全部楼层
147380124 发表于 2021-6-19 22:28
比如说输入张三,message内的那个就会输出乱码,是烫烫烫,而查询姓名那个成员函数里面输出就不会有乱码 ...

先选 1 进行添加?
选了 1,然后呢?编号也选 1 ?
我要 你输入的每一步,直到出现错误
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-19 22:49:55 | 显示全部楼层
人造人 发表于 2021-6-19 22:47
先选 1 进行添加?
选了 1,然后呢?编号也选 1 ?
我要 你输入的每一步,直到出现错误

先按1添加,然后输入编号1,姓名张三,然后在输入n退出,再选择按照姓名查询,在输入张三,然后就报错了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 21:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表