第十二周项目三日期时间类

01./*                        
02.*Copyright (c) 2014,烟台大学计算机学院                        
03.*All gight reserved.                        
04.*文件名称:temp.cpp                        
05.*作者:张震刚                       
06.*完成时间:2015年5月26日                        
07.*版本号:v1.0                        
08.*问题描述:分别定义Date和Time类,采用多重继承方式派生出新类DateTime,完成要求。                      
09.*输入描述:无。                       
10.*输出描述:无。                         
11.*/      
#include <iostream>

using namespace std;
class Date
{
protected:
    int year;
    int month;
    int day;
public:
    Date():year(0),month(0),day(0){}
    Date(int y,int m,int d);
    int SetDate(int y,int m,int d);
    void PrintDate();
};
Date::Date(int y,int m,int d):
    year(y),month(m),day(d){}
int Date::SetDate(int y,int m,int d)
{
    year=y;
    month=m;
    day=d;
}
void Date::PrintDate()
{
    cout<<year<<"/"<<month<<"/"<<day<<endl;
}
class Time
{
protected:
    int hour;
    int minuter;
    int second;
public:
    Time():hour(0),minuter(0),second(0){}
    Time(int h,int m,int s);
    int SetTime(int h,int m,int s);
    void PrintTime();
};
Time::Time(int h,int m,int s):
    hour(h),minuter(m),second(s){}
int Time::SetTime(int h,int m,int s)
{
    hour=h;
    minuter=m;
    second=s;
}
void Time::PrintTime()
{
    cout<<hour<<":"<<minuter<<":"<<second<<endl;
}
class TimeDate:public Date,public Time
{
public:
    TimeDate():Date(),Time(){};
    TimeDate(int y,int mo,int d,int h,int mi,int s):
        Date(y,mo,d),Time(h,mi,s){}
    void PrintDate_Time();
};
void TimeDate::PrintDate_Time()
{
    PrintDate();
    cout<<" ";
    PrintTime();
}
int main()
{
    TimeDate dt_a,dt_b(2010,4,16,9,30,0);
    cout<<"dt_a: ";
    dt_a.PrintDate_Time();
    cout<<endl;
    cout<<"dt_b: ";
    dt_b.PrintDate_Time();
    dt_a.SetTime(20,00,00);
    dt_a.SetDate(2008,8,7);
    cout<<endl;
    cout<<"dt_after uptate: ";
    dt_a.PrintDate_Time();
    return 0;
}

总结:多继承一般用法觉得已经熟练了,关于这个程序最后输出效果不懂为什么执行了换行。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JS实现年月日第几下拉框选择时间: ```html <label for="year">年份:</label> <select id="year"></select> <label for="month">月份:</label> <select id="month"></select> <label for="week">第几:</label> <select id="week"></select> <script> // 获取当前年份 var currentYear = new Date().getFullYear(); // 填充年份下拉框 for (var i = currentYear; i >= 2015; i--) { var option = document.createElement("option"); option.value = i; option.text = i; document.getElementById("year").add(option); } // 填充月份下拉框 for (var i = 1; i <= 12; i++) { var option = document.createElement("option"); option.value = i; option.text = i; document.getElementById("month").add(option); } // 填充第几下拉框 for (var i = 1; i <= 53; i++) { var option = document.createElement("option"); option.value = i; option.text = i; document.getElementById("week").add(option); } </script> ``` JSP实现年月日第几下拉框选择时间: ```html <label for="year">年份:</label> <select id="year"> <option value="${currentYear}">${currentYear}</option> <c:forEach begin="2015" end="${currentYear-1}" var="year"> <option value="${year}">${year}</option> </c:forEach> </select> <label for="month">月份:</label> <select id="month"> <c:forEach begin="1" end="12" var="month"> <option value="${month}">${month}</option> </c:forEach> </select> <label for="week">第几:</label> <select id="week"> <c:forEach begin="1" end="53" var="week"> <option value="${week}">${week}</option> </c:forEach> </select> ``` 其中,`${currentYear}`是JSP中的EL表达式,表示获取当前年份。`<c:forEach>`是JSTL标签库中的循环标签,可以用来生成下拉框的选项。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值