求助:C++如何使用已创建的类

来源:百度知道 编辑:UC知道 时间:2024/07/07 03:57:40
首先我建了一个日期类Date
#include<iostream.h>
class Date
{
int year,mon,day;
public:
Date() { }
Date(int y,int m,int d)
{
year=y;
mon=m;
day=d;
}
Date(Date &d)
{
year=d.year;
mon=d.mon;
day=d.day;
}
void SetDate(int y,int m,int d)
{
year=y;
mon=m;
day=d;
}
void GetDate()
{
cout<<year<<"year"<<mon<<"mon"<<day<<"day"<<endl;
}
int GetYear() { return year; }
int GetMonth() { return mon; }
int GetDay() { return day; }
};
void main()
{
Date d1(2005,5,8);
Date d2;
Date d3(d1);
d2.SetDate(2005,10,1);
d1.GetDate();
d2.GetDate();
d3.GetDate();
}

然后建一个雇员类employee
要求说使用上个程序设计的日期类作为成员对象
#include<iostream.h>
#include<string.h><

主要错误:
1.头文件中不能包含main()主函数,应将头文件中主函数的内容挪动到.cpp文件的main()函数中
2.if (jane.IsBirthday(today))与函数体中的函数名IsBirtheday不一样
按照我说的改一下:
1.新建date头文件date.h
内容包括:
#include<iostream.h>
class Date
{
int year,mon,day;
public:
Date() { }
Date(int y,int m,int d)
{
year=y;
mon=m;
day=d;
}
Date(Date &d)
{
year=d.year;
mon=d.mon;
day=d.day;
}
void SetDate(int y,int m,int d)
{
year=y;
mon=m;
day=d;
}
void GetDate()
{
cout<<year<<"year"<<mon<<"mon"<<day<<"day"<<endl;
}
int GetYear()
{
return year;
}
int GetMonth()
{
return mon;
}
int GetDay()
{
return day;
}
};
2.建立cpp文件,内容包括:
#include<iostream.h>
#in