定 义 一 个 名 为 Date 的 类 ,用 于 输 入 并 验 证 日 期 ,类 中 的 数 据 成 员 和
成员函数应满足下面的规则;在主函数中编写相应代码验证这些规
则 是 否 正 确 地 实 现 了 ; 并 用 Debug 功 能 仔 细 体 会 程 序 的 运 行 过 程 。
1 ) 日 期 包 括 年 ( y e a r ) 、 月 ( mo n t h ) 、 日 ( d a y ) , 均 为 整 型 数 据 , 以 及 一
个 布 尔 数 据 成 员 pa ss 用 来 判 断 输 入 日 期 是 否 正 确 。
2 ) 布 尔 类 型 p r i v a t e 成 员 函 数 c h e c k F o r ma t ( ) , 有 一 个 字 符 串 引 用 形
参 , 验 证 读 入 的 日 期 格 式 是 否 正 确 ( yyyy: mm:dd 格 式 ) ?
3) void 类 型 private 成 员 函 数 validate(), 没 有 形 参 。 判 断 输 入 的 日
期是否合法。
4) 默 认 构 造 函 数 , 没 有 形 参 , 将 year , mont h, da y 分 别 初 始 化 为
2006, 1, 1; 在 构 造 函 数 中 要 调 用 va lida te( )。
5) 定 义 拷 贝 构 造 函 数
6) 定 义 类 型 转 换 构 造 函 数 , 能 从 字 符 串 转 换 成 Date 对 象 。
7 ) 使 用 带 默 认 参 数 的 构 造 函 数 , 三 个 整 形 形 参 i n t y , i n t m= 2 , i n t
d=29, 分 别 对 yea r, mont h, da y 赋 值 ; 注 意 要 调 用 va lida te( )
验证。
8) void 类 型 public 成 员 函 数 setDate(), 有 一 个 字 符 串 引 用 形 参 , 负
责 设 置 新 日 期 , 先 调 用 c h e c k F o r ma t ( ) 判 断 日 期 数 据 格 式 是 否 正首
确 , 如 正 确 , 继 续 调 用 va lida te( )验 证 输 入 日 期
9) void 类 型 public 成 员 函 数 pr intD a ta( ), 没 有 形 参 , 根 据 pa ss 值
决 定 是 否 打 印 设 置 的 日 期 , 如 果 打 印 , 要 按 照 ” yyyy 年 mm 月 dd
日 ”的 格 式 。
求代码,各位高手请帮忙,还要有注释....我可以加分