JPC客栈 2022-04-09 17:40 采纳率: 100%
浏览 34
已结题

划红线处是怎么回事呢?求解答

划红线处怎么回事?
#include <iostream>
using namespace std;
#include <cstring>

class Date {
    private:
        int year, month, day;
    public:
        Date(int year = 0, int month = 0, int day = 0) {
            this->year = year;
            this->month = month;
            this->day = day;
        }

        void setDate() {
            cin >> year >> month >> day;
        }
        void showDate() {
            cout << year << "年" << month << "月" << day << "日";
        }

        ~Date() {}
};

class People {
    private:
        char name[11];
        char number[7];
        char sex[3];
        char id[19];
        Date birthday;
    public:
        People() {

        }
        People(char na[], char num[], char se[], int y, int m, int d, char i[]): birthday(y, m, d) {
            strcpy(name, na);
            strcpy(number, num);
            strcpy(sex, se);
            strcpy(id, i);

        }
        People(People &p) {
            strcpy(name, p.name);
            strcpy(number, p.number);
            strcpy(sex, p.sex);
            strcpy(id, p.id);
            birthday = p.birthday;
        }




        //录入人员信息
        void input() {
            cout << "姓名:";
            cin >> name;
            //cout << endl;
            cout << "编号:";
            cin >> number;
            //cout << endl;
            cout << "性别(男/女): ";
            cin >> sex;
            //cout << endl;
            cout << "出生日期(年 月 日):";

            birthday.setDate();
            //cout << endl;
            cout << "身份证号:";
            cin >> id;
            //cout << endl;


        }
        void showPeople() {
            cout << endl;
            cout << "姓名:" << name << endl;

            cout << "编号:" << number << endl;
            cout << "性别:" << sex << endl;
            cout << "出生日期: ";
            birthday.showDate();
            cout << endl;
            cout << "身份证号:" << id;
        }
        ~People() {}
};

int main() {
    int n;//员工数
    cout << "员工人数: ";
    cin >> n;
    //cout << endl;
    People *p;
    p = new People[n];
    for (int i = 0; i < n; i++) {
        p[i].input();

    }
    People p1(p[0]);
    p1.showPeople();
    for (int i = 0; i < n; i++) {
        p[i].showPeople();
    }
    return 0;
}


img

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

2条回答 默认 最新

  • A-Chin 2022-04-09 18:46
    关注

    char sex[3]; 改成 char sex[4]; 就可以了。

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月17日
  • 已采纳回答 4月9日
  • 创建了问题 4月9日

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值