| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 209 人关注过本帖
标题:请大家帮忙看看!谢谢!
收藏  订阅  推荐  打印
elan1986
Rank: 3Rank: 3
等级:中级会员
帖子:181
积分:2024
威望:2
注册:2007-12-17
请大家帮忙看看!谢谢!

#include<iostream>
using namespace std;
class date
{
public:
    date(int year=1900,int month=1,int day=1) {Xyear=year; Xmonth=month; Xday=day;}
    date(date &p);
    int GetYear()  {return Xyear;}
    int Getmonth() {return Xmonth;}
    int Getday()   {return Xday;}
    void showdate();
private:
    int Xyear,Xmonth,Xday;
};

date::date(date &p)
{
    Xyear=p.Xyear;
    Xmonth=p.Xmonth;
    Xday=p.Xday;
}

inline void date::showdate()
{
    cout<<"出生日期:"<<Xyear<<"年"<<Xmonth<<"月"<<Xday<<"日"<<endl;
}

class people
{
public:
    people(int no,char sex,date birthday,int id);
    people(people &);
    ~people();
    void showpeople();

private:
    int No,Id;
    char Sex;
    date Birthday;
};

people::people(int no,char sex,date birthday,int id):Birthday(birthday)
{
    int    No=no;
    char Sex=sex;
    int Id=id;
}

people::people(people &) {}

people::~people() {}

inline void people::showpeople()
{
    cout<<"编号为:"<<No<<"性别为:"<<Sex<<"出生日期为:"<<endl;
    Birthday.showdate();
    cout<<"身份证为:"<<Id<<endl;
}

void main()
{
    date aa(1986,5,24);
    int no,id,year,month,day;
    char sex;
    people bb(no,sex,aa,id);
    cout<<"请分别输入编号,性别,出生日期和身份证号码:"<<endl;
    cout<<"请输入编号:"<<endl;
    cin>>no;
    cout<<"请输入性别:"<<endl;
    cin>>sex;
    cout<<"请输入年份:"<<endl;
    cin>>year;
        aa.GetYear();
    cout<<"请输入月份:"<<endl;
    cin>>month;
        aa.Getmonth();
    cout<<"请输入日:"<<endl;
    cin>>day;
        aa.Getday();
    cout<<"请输入ID:"<<endl;
    cin>>id;
    cout<<"我的信息是:"<<endl;
    bb.showpeople();
}

程序编译没有问题
但是在运行后会出现这个问题
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0xC74 has exited with code -858993460 (0xCCCCCCCC).
The program 'E:\C++\c++试验记录\2008-10-8\lch\Debug\lch.exe' has exited with code -858993460 (0xCCCCCCCC).
请大家帮忙看看
谢谢了!
2008-10-8 19:46
Naturelove
Rank: 1
等级:新手上路
帖子:21
积分:320
来自:浙江
注册:2008-10-1

感觉你错的好多的,例如你在main中cin>>year,然后企图用aa.GetYear()得到这个值根本是不饿可能的,所以其他的都不对,还不如定义input函数在调用清楚方便

Any difficulty is to make me strong.
2008-10-8 21:30
Naturelove
Rank: 1
等级:新手上路
帖子:21
积分:320
来自:浙江
注册:2008-10-1

我这里也能运行但是完全不是你想要做到的那种

Any difficulty is to make me strong.
2008-10-8 21:31
choco1024
Rank: 2
等级:注册会员
帖子:66
积分:804
威望:1
注册:2008-8-31

有点乱。
2008-10-12 15:25
kakaqq
Rank: 2
等级:注册会员
帖子:49
积分:600
威望:1
注册:2008-10-7

很混乱啊···2楼的说得对啊你好好看看怎么访问私有数据成员的。
2008-10-12 18:49
kakaqq
Rank: 2
等级:注册会员
帖子:49
积分:600
威望:1
注册:2008-10-7

#include<iostream>
using namespace std;
class date
{
public:
    date(int year=1900,int month=1,int day=1) {Xyear=year; Xmonth=month; Xday=day;}
    date(date &p);
    int GetYear()  {return Xyear;}
    int Getmonth() {return Xmonth;}
    int Getday()   {return Xday;}
    void showdate();
    friend class people;
private:
    int Xyear,Xmonth,Xday;
};

date::date(date &p)
{
    Xyear=p.Xyear;
    Xmonth=p.Xmonth;
    Xday=p.Xday;
}

inline void date::showdate()
{
    cout<<"出生日期:"<<Xyear<<"年"<<Xmonth<<"月"<<Xday<<"日"<<endl;
}

class people
{
public:
    people(int ,char *,int ,int,int,int );
    people(people &);
    ~people();
    void showpeople();

private:
    int No,Id;
    char Sex[10];
    date Birthday;
};

people::people(int no,char *s ,int id,int xyear,int xmonth,int day)
{
    this->No=no;
    strcpy(this->Sex,s);
    this->Id=id;
    Birthday.Xyear=xyear;Birthday.Xmonth=xmonth;Birthday.Xday=day;
}

people::people(people &) {}

people::~people() {}

inline void people::showpeople()
{
    cout<<"编号为:"<<No<<"性别为:"<<Sex<<endl;
    Birthday.showdate();
    cout<<"身份证为:"<<Id<<endl;
}

void main()
{
    int no,id,year,month,day;
     char sex[10];
    cout<<"请分别输入编号,性别,出生日期和身份证号码:"<<endl;
    cout<<"请输入编号:"<<endl;
    cin>>no;
    cout<<"请输入性别:"<<endl;
    cin>>sex;
    cout<<"请输入年份:"<<endl;
    cin>>year;
      
    cout<<"请输入月份:"<<endl;
    cin>>month;
      
    cout<<"请输入日:"<<endl;
    cin>>day;
      
    cout<<"请输入ID:"<<endl;
    cin>>id;

   
    date aa(year,month,day);
    people bb(no,sex,id,year,month,day);
    cout<<"我的信息是:"<<endl;
    bb.showpeople();
}
给你改过来了。看看行不行。你错好多地方、主要是访问权限没搞清楚。把people设成data的友元就可以直接访问了你原来的data没有赋值啊
people::people(int no,char sex,date birthday,int id):Birthday(birthday)
这句话根本不行啊。建议把书好好看。
2008-10-12 19:24
共有 208 人关注过本帖
发新话题
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.053589 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved