首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

小弟我初学着,这也程序有什么东东啊能帮小弟我看下吗,最好指出来下~

2012-03-01 
我初学着,这也程序有什么错误啊,能帮我看下吗,最好指出来下~~我初学着,这也程序有什么错误啊,能帮我看下吗

我初学着,这也程序有什么错误啊,能帮我看下吗,最好指出来下~~
我初学着,这也程序有什么错误啊,能帮我看下吗,最好指出来下~~
#include <iostream.h>
class   Tdate
{public:
Tdate(int   m=1,int   d=0,int   y=1995)
{
month=m;day=d;year=y;}
        int   &getm(){return   month;}
        int   &gety(){return   year;}
        protected:
int   month;
int   day;
        int   year;
};
class   People
{
        private:
        int   number;
        char   sex;
        int   id;
        Tdate   birthday;
public:
People(int   n=0,char   s= 'm ',int   i=32000000,int   m=1,int   d=0,int   y=1995):bithday(m,d,y)
{
number=n;
        sex=s;
        id=i;
}
People(People&p)
{
number=p.number;
        sex=p.sex;
        id=p.id;
        birthday.gety()=p.birthday.gety();
        birthday.getm()=p.birthday.getm();
        birthday.getd()=p.birthday.getd();
        cout < < "copy " < <endl;
}
};
        void   main()
{
People   p1;
        p1.output();
        p1.input();
        p1.output();
        People   p2(p1);
        cout < < "another   people... " < <endl;
        p2.output();
}
void   input()
        {
cout < < "number: ";
cin> > number;
cout < < "sex: ";
cin> > sex;
cout < < "id: "
                cin> > id;
cout < < "the   year   of   birthday ";
cin> > birthday.gety;
cout < < "the   monthy   of   birthday ";
cin> > birthday.getm;
cout < < "the   day   of   birthday: ";
                cin> > birthday.getd;
}
void   output()
{
cout < < "number: " < <number < <endl;
cout < < "sex " < <sex < <endl;
cout < < "birthday " < <birthday.gety() < < "-- " < <birthday.getm() < < "-- " < <birthday.getd() < <endl;
        }
People(People&p);
~People()
{
cout < < "xigou... " < <endl;
}
}


[解决办法]
#include <iostream.h>
class Tdate
{
public:
Tdate(int m=1,int d=0,int y=1995)
{
month=m;day=d;year=y;}
int &getm(){return month;}
int &gety(){return year;}
int &getd(){return day;}
protected:
int month;
int day;
int year;
};
class People
{
int number;
char sex;
int id;
Tdate birthday;
public:


People(int n=0,char s= 'm ',int i=32000000,int m=1,int d=0,int y=1995):birthday(m,d,y)
{
number=n;
sex=s;
id=i;
}
People(People& p)
{
number=p.number;
sex=p.sex;
id=p.id;
birthday.gety()=p.birthday.gety();
birthday.getm()=p.birthday.getm();
birthday.getd()=p.birthday.getd();
cout < < "copy " < <endl;
}
void input()
{
cout < < "number: ";
cin> > number;
cout < < "sex: ";
cin> > sex;
cout < < "id: ";
cin> > id;
cout < < "the year of birthday: ";
cin> > birthday.gety();
cout < < "the monthy of birthday: ";
cin> > birthday.getm();
cout < < "the day of birthday: ";
cin> > birthday.getd();
}
void output()
{
cout < < "number: " < <number < <endl;
cout < < "sex " < <sex < <endl;
cout < < "birthday: " < <birthday.gety() < < "-- " < <birthday.getm() < < "-- " < <birthday.getd() < <endl;
}
~People()
{
cout < < "xigou... " < <endl;
}
};
void main()
{
People p1;
p1.input();
p1.output();
People p2(p1);
cout < < "another people... " < <endl;
p2.output();
}

[解决办法]
#include <iostream.h>
class Tdate
{
public:
Tdate(int m=1,int d=0,int y=1995)
{
month=m;day=d;year=y;
}
int &getm(){return month;}
int &gety(){return year;}
int &getd(){return day;}
public:
int month;
int day;
int year;
};

class People
{
public:
int number;
char sex;
int id;
Tdate birthday;
public:
People(int n=0,char s= 'm ',int i=32000000,int m=1,int d=0,int y=1995)
{
number=n;
sex=s;
id=i;
this-> birthday =Tdate(m,d,y);
}
People(People&p)
{
number=p.number;
sex=p.sex;
id=p.id;
birthday.gety()=p.birthday.gety();
birthday.getm()=p.birthday.getm();
birthday.getd()=p.birthday.getd();
cout < < "copy " < <endl;
}
virtual ~People();
void output();
void input();
};
int main()
{
People p1;
p1.output();
p1.input();
p1.output();
People p2(p1);
cout < < "another people... " < <endl;
p2.output();
return 0 ;
}
void People::input()
{
cout < < "number: ";
cin> > number;
cout < < "sex: ";
cin> > sex;
cout < < "id: ";
cin> > id;
cout < < "the year of birthday ";
cin> > birthday.year;
cout < < "the monthy of birthday ";
cin> > birthday.month;
cout < < "the day of birthday: ";
cin> > birthday.day;
}
void People::output()
{
cout < < "number: " < <number < <endl;
cout < < "sex " < <sex < <endl;
cout < < "birthday " < <birthday.gety() < < "-- " < <birthday.getm() < < "-- " < <birthday.getd() < <endl;


return;
}
People::People(People&p);
People::~People()
{
cout < < "xigou... " < <endl;
}

热点排行