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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答