1508-张晨曦总结《2016年-11月-14日》【连续24天总结】

标题:啥时候洗脑?

关键词:重载构造函数

内容

A. 一句话概括今日目标完成情况

a)复习前面学的  100%

b)学习10.2  90%

B.具体内容

 

#include<iostream> 
#include<string.h>
#include<stdlib.h>
using namespace std;
class Date
{
	private:
		int year,month,day;
	public:
		Date():year(1900),month(1),day(1){};   //无参构造函数
	        Date(int yy,int mm=1,int dd=1);     //默认参数构造函数 
		Date(Date &d):year(d.year),month(d.month),day(d.day){};
		Date(char *ps);
		void print_ymd(); 
};
Date::Date(int yy,int mm,int dd):year(1900),month(1),day(1)
{
	if(yy>=1900&&yy<=9999){          //这段还是有效性检验 
		year=yy;
	}
	else{
		return;
	}
	if(mm>=1&&mm<=12){
		month=mm;
	}
	else{
		year=1900;
		return;
	}
	if(dd>=1&&dd<=31){
		day=dd;
	}
	else{
		year=1900;
		month=1;
		return;
	}
 }
 Date::Date(char *ps):year(1900),month(1),day(1)
 {
 	char py[5],pm[3],pd[3];
 	strncpy(py,ps,4);
 	ps=ps+5;
 	strncpy(pm,ps,2);
 	ps=ps+3;
 	strncpy(pd,ps,2);
 	int yy=atoi(py),mm=atoi(pm),dd=atoi(pd);
 	if(yy>=1900&yy<9999){
 		year=yy;
	}
	else{
		return;
	} 
	if(mm>=1&&mm<=12){
		month=mm;
	}
	else{
		year=1900;
		return;
	}
	if(dd>=1&&dd<=31){
		day=dd;
	}
	else{
		year=1900;
		month=1;
		return;
	}
 }
 void Date::print_ymd()
 {
 	cout<<year<<"-"<<month<<"-"<<day<<endl;
 }
 int main()
 {
 	Date date1;
 	cout<<"date1:";
 	date1.print_ymd();
 	system("pause");
 	Date date2(2006);
 	cout<<"date2:";
 	date2.print_ymd();
 	system("pause");
 	Date date3(2006,4);
 	cout<<"date3;";
 	date3.print_ymd();
 	system("pause");
 	Date date4(2006,4,8);
 	cout<<"date4:";
	date4.print_ymd();
	system("pause");
        Date date5(2006,14,8);
	cout<<"date5:";
	date5.print_ymd();
	system("pause");
	Date date6(date4);
	cout<<"date6:";
	date6.print_ymd();
	system("pause");
	Date date7("2008-08-08");
	cout<<"date7:";
	date7.print_ymd();
	system("pause");
	cout<<endl;
	cout<<"Thanks for using!";
	return 0;	
 }
哎,课太多了,只有晚上有一点空看看10.2.

老师讲的基本理解了,就是昨天学了构造函数的定义,而今天是重载构造函数。感觉这节比较简单……也不知道要说点什么。。。啊

看了看明天学的是析构函数,明天晚上的公选课翘了吧...真没意思。。。


C.明日计划

10.3、10.4搞定

 

我的邮箱:smartisandre@yeah.net

我的博客:http://blog.csdn.net/andr3zzzz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值