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

这个人员类有什么问题 怎么解决

不会游的鱼 发布于 2008-11-20 11:51, 771 次点击
这个人员类有什么问题,该怎么解决
#include<iostream>
using namespace std;
class Birthday
{
private:
        int Year;
        int Month;
        int Day;

public:
        Birthday(){};
        Birthday(int y,int m,int d)
  {Year=y;Month=m;Day=d;}
  void Set(int y,int m,int d){Year=y;Month=m;Day=d;}
  void Show(){Cout<<Year<<"-"<<Month<<"-"<<"Day;
  };
 
Birthday::Birthday(Birthday &b)
 {Year=b.Year;
Month=b.Month;
Day=b.Day;
}

class Person
{
private:
       char number;
    char sex;
    charID[19];
    int birthday;
public:
 Person(){};
 Person::Person(int n,int y,int m,int d,char s='m',char id[19]):birthday(y,m,d)
 {number=n;
 sex=m;
 strpcy(ID,id);
 }
 ~Person(){};


 
 
   
 

 Person(Person &p)
 {
number=p.number;
 sex=p.sex;
 birthday=p.birthday;
 strpcy(ID,p.id);
 }
 void input();
 void output();
};
void Person::input()
{cout<<"录入数据"<<endl;
cout<<"编号"<<endl;
cin>>number;
cout<<"性别"<<endl;
cin>>(m||f);
cout<<"生日"<<endl;
cout<<"身份证号"<<endl;
cin>>ID;
ID[18]='0';
}
void Person::output();
cout<<"编号"<<number;
cout<<"性别"<<sex;
cout<<"生日"<<birthday;
cout<<"身份证号"<<ID<<endl;
}
void main()
{ Person p1
p1.input();
p1.output();
return(0);

}
5 回复
#2
sunkaidong2008-11-20 11:52
你要好好看看书了
#3
shmilytong2008-11-20 14:17
赞成楼上的观点,改到一半实在改不下去了……
#4
asd67918682008-11-20 20:47
public:
        Birthday(){};
        Birthday(int y,int m,int d)
  {Year=y;Month=m;Day=d;}
  void Set(int y,int m,int d){Year=y;Month=m;Day=d;}
  void Show(){Cout<<Year<<"-"<<Month<<"-"<<"Day;
  };

Birthday::Birthday(Birthday &b)
{Year=b.Year;
Month=b.Month;
Day=b.Day;
}

单是这里就够乱的了。。。。。
有些更能重复了
#5
hitcolder2008-11-20 20:55
我也是新手,不过确实有好多问题啊,尝试着改了下,互相学习吧:( 问题可真的不少,建议楼主先编点简单的,还有可以考虑好好看看构造函数是怎么用的,还有构造函数的重载问题。)

#include<iostream>
using namespace std;

// define class of Birthday
class Birthday
{
        int Year;   //C++默认私有变量,不需要private
        int Month;
        int Day;

public:
        //Birthday(Birthday &b);//函数声明不需要加{},还有声明的形式要跟下面定义的相一致
        Birthday(int y,int m,int d)
        {Year=y;
        Month=m;
        Day=d;}

  void Set(int y,int m,int d)
  {Year=y;
  Month=m;
  Day=d;}

  void Show()
  {
   cout<<Year<<" . "<<Month<<" . "<<Day;
  }
};

//Birthday::Birthday(Birthday &b)   
//{Year=b.Year;
//Month=b.Month;
//Day=b.Day;   
//}

//define class of Person
class Person
{
    int number;
    char sex;
    long int ID;
    int birthday;
public:
    Person(Person &p)
    {
      number=p.number;
      sex=p.sex;
      birthday=p.birthday;
      ID=p.ID;
    }

Person(int n,char m,long int id,long int bir)
{number=n;
sex=m;
ID=id;
birthday=bir;
}

void in_put()
{
cout<<"录入数据"<<endl;
cout<<"编号:";
cin>>number;
cout<<endl;
cout<<"性别:";
cin>>sex;
cout<<endl;
cout<<"生日:";
cin>>birthday;
cout<<endl;
cout<<"身份证号:";
cin>>ID;
cout<<endl;
}
void out_put()
{
cout<<"编号"<<number<<endl;
cout<<"性别"<<sex<<endl;
cout<<"生日"<<birthday<<endl;
cout<<"身份证号"<<ID<<endl<<endl;
}
};

//the main function
int  main()
{
    Person p(12,'f',123,56);                     
    Birthday birth(1984,10,30);
cout<<"the birthday is:  ";
birth.Show();
cout<<endl;

p.out_put();

return 0;
}
#6
不会游的鱼2008-11-21 19:40
谢谢啦!!!
1