c++函数重载题目

来源:百度知道 编辑:UC知道 时间:2024/05/21 10:31:45
3.设计完成Date类,要求满足以下条件:
a)可以用重载的构造函数生成Date对象:
(1) 默认构造函数,将Date对象设置为当前系统日期。可以利用ctime头文件(或者time.h)的标准库函数读取系统日期。
(2) 以 DDD YYYY 类型构造Date对象,例如:
Date d2(86, 1999);// 1999年第86天。
(3) 以 MM DD YY 类型构造对象,例如:
Date d3(3, 3, 1999);// 1999年3月3日。
(4) 以 MM(字符串型) DD YY 类型构造对象,例如:
Date d4("September", 1, 1998); // 1998年9月1日
b)用多种格式输出日期,例如:
DDD YYYY
MM/DD/YY
June 14,1922
c)在main函数中创建多个Date对象,分别运用以上构造函数和输出函数。
哪位大哥给我做一下啊 万分感谢 急用啊
大哥 拜托 编完吧 小弟菜鸟 不会哈 作业急着交那。。。

#include "iostream.h"
#include"string.h"
class Date
{
private:
int m;int d;int y;
char str[20];
public:

Date(int a,int b)
{d=a;
y=b;
}
Date(int a,int b,int c)
{d=a;
m=b;
y=c;}
Date(char *s,int a,int b)
{strcpy(str,s);
d=a;
y=b;
}
void shuchu1()
{
cout<<m<<"/"<<d<<"/"<<y<<endl;
}
void shuchu2()
{
cout<<str<<" "<<d<<","<<y<<endl;
}
};
void main()
{
Date d3(3,3,1999);
d3.shuchu1();
Date d4("september",1,1998);
d4.shuchu2();
}
可累死我了,这个程序可以直接运行,没有什么错误.不过第一个功能没有实现,输出的类型你可以再做几个函数.我就写了两个输出的方式.