注册 登录
编程论坛 C++教室

一个错误 求高手指教

糊涂无罪 发布于 2012-05-31 21:40, 367 次点击
#include <iostream>
#include <string>
using namespace std;

class Date
{
private:
    int year;
    int month;
    int day;
public:
    Date(){}  
    Date(int y,int m,int d)
    {
        year=y;
        month=m;
        day=d;
    }
    void set()
    {
        cin>>year>>month>>day;
    }
    void display()
    {
        cout<<year<<"年"<<month<<"月"<<day<<"日";
    }
};

class people
{
private:
    char num[7];
    char sex[3];
    Date birthday;
    char ID[16];
public:
    people(){}
    people(char n[7],int y,int m,int d,char id[16],char s[3]):birthday(y,m,d)
    {
        strcpy(num,n);  
        strcpy(sex,s);
        strcpy(ID,id);
    }
    people(people& p)
    {
        strcpy(num,p.num);
        strcpy(sex,p.sex);
        
        birthday=p.birthday;
        strcpy(ID,p.ID);
    }
    void input()
    {
        cout<<"录入数据:"<<endl;
        cout<<"编号:";
        num[7]='\0';
        cout<<endl;
        cin>>num;
        cout<<"性别(m/f):";
        cin>>sex;
        sex[3]='\0';
        cout<<endl;
        cout<<"生日:";
        birthday.set();
        cout<<"身份证号:";
        cin>>ID;
        ID[16]='\0';
        cout<<endl;
    }
    void output()
    {
        cout<<"编号:"<<num<<endl;
        cout<<"性别:"<<sex<<endl;
        cout<<"生日:";
        birthday.display();
        cout<<endl;
        cout<<"身份证号:"<<ID<<endl;
    }
    ~people()
    {
        cout<<" "<<num<<"号人员已经录入"<<endl;
    }
};

class student:virtual public people{
private :
    char classNO[7];
public:
    student(char n[7],int y,int m,int d,char id[16],char s[3],char no[7]):
      people( n[7], y, m, d, id[16], s[3]) {
          strcpy(classNO,no);
          cout<<"the constructing of student is called"<<endl;}
};
1 回复
#2
hellovfp2012-06-03 11:38
#include <cstring>

class student:virtual public people
{
private :
    char classNO[7];
public:
    student(char n[7],int y,int m,int d,char id[16],char s[3],char no[7]):
        people( n, y, m, d, id, s)
    {
        strcpy(classNO,no);
        cout<<"the constructing of student is called"<<endl;
    }
};
1