C++程序题、 补充构造一个日期时间类 在线等!!!急啊!!!
数据成员包括年、月、日和时、分、秒,函数成员包括设置日期时间和输出时间,其中年、月请用整型,并完成测试。注意,自己写的代码中不能有cout#include<iostrea...
数据成员包括年、月、日和时、分、秒,函数成员包括设置日期时间和输出时间,其中年、月请用整型,并完成测试。注意,自己写的代码中不能有cout
#include <iostream>
#include <iomanip>
using namespace std;
/**********Program**********/
/********** End **********/
void Timedate::list(){
cout<<"year/month/date :";
switch(year){
case 2000:cout<<"2000";break;
case 2001:cout<<"2001";break;
case 2002:cout<<"2002";break;
case 2003:cout<<"2003";break;
case 2004:cout<<"2004";break;
case 2005:cout<<"2005";break;
}
switch(month){
case 1:cout<<'/'<<"Jan";break;
case 2:cout<<'/'<<"Feb";break;
case 3:cout<<'/'<<"Mar";break;
case 4:cout<<'/'<<"Apr";break;
case 5:cout<<'/'<<"May";break;
case 6:cout<<'/'<<"Jun";break;
case 7:cout<<'/'<<"Jul";break;
case 8:cout<<'/'<<"Aug";break;
case 9:cout<<'/'<<"Sep";break;
case 10:cout<<'/'<<"Oct";break;
case 11:cout<<'/'<<"Nov";break;
case 12:cout<<'/'<<"Dec";break;
}
cout<<'/'<<date<<endl;
cout<<"hour:minite:second :";
cout<<hh<<':'<<mm<<':'<<ss<<endl;
}
int main(){
Timedate A(2004,3,3),B;
A.list();
B.list();
B.putdate(2005,10,18);
B.puttime(17,30,00);
B.list();
return 0;
} 展开
#include <iostream>
#include <iomanip>
using namespace std;
/**********Program**********/
/********** End **********/
void Timedate::list(){
cout<<"year/month/date :";
switch(year){
case 2000:cout<<"2000";break;
case 2001:cout<<"2001";break;
case 2002:cout<<"2002";break;
case 2003:cout<<"2003";break;
case 2004:cout<<"2004";break;
case 2005:cout<<"2005";break;
}
switch(month){
case 1:cout<<'/'<<"Jan";break;
case 2:cout<<'/'<<"Feb";break;
case 3:cout<<'/'<<"Mar";break;
case 4:cout<<'/'<<"Apr";break;
case 5:cout<<'/'<<"May";break;
case 6:cout<<'/'<<"Jun";break;
case 7:cout<<'/'<<"Jul";break;
case 8:cout<<'/'<<"Aug";break;
case 9:cout<<'/'<<"Sep";break;
case 10:cout<<'/'<<"Oct";break;
case 11:cout<<'/'<<"Nov";break;
case 12:cout<<'/'<<"Dec";break;
}
cout<<'/'<<date<<endl;
cout<<"hour:minite:second :";
cout<<hh<<':'<<mm<<':'<<ss<<endl;
}
int main(){
Timedate A(2004,3,3),B;
A.list();
B.list();
B.putdate(2005,10,18);
B.puttime(17,30,00);
B.list();
return 0;
} 展开
1个回答
展开全部
#include <iostream>
#include <iomanip>
using namespace std;
/**********Program**********/
class Timedate{
public:
Timedate(int syear=2000,int smonth=1,int sdate=1)
{ //构造函数完成所有私有成员的初始化
year=syear;
month=smonth;
date=sdate;
hh=00;
mm=00;
ss=00;
}
void list(); //完成判断
void putdate(int syear,int smonth,int sdate)
{ //完成年月日的设置
year=syear;
month=smonth;
date=sdate;
}
void puttime(int hour,int minute,int second) //内联函数:完成时分秒的设置
{ hh=hour;
mm=minute;
ss=second;
}
private:
int year,month,date,hh,mm,ss;
};
/********** End **********/
void Timedate::list(){
cout<<"year/month/date :";
switch(year){
case 2000:cout<<"2000";break;
case 2001:cout<<"2001";break;
case 2002:cout<<"2002";break;
case 2003:cout<<"2003";break;
case 2004:cout<<"2004";break;
case 2005:cout<<"2005";break;
}
switch(month){
case 1:cout<<'/'<<"Jan";break;
case 2:cout<<'/'<<"Feb";break;
case 3:cout<<'/'<<"Mar";break;
case 4:cout<<'/'<<"Apr";break;
case 5:cout<<'/'<<"May";break;
case 6:cout<<'/'<<"Jun";break;
case 7:cout<<'/'<<"Jul";break;
case 8:cout<<'/'<<"Aug";break;
case 9:cout<<'/'<<"Sep";break;
case 10:cout<<'/'<<"Oct";break;
case 11:cout<<'/'<<"Nov";break;
case 12:cout<<'/'<<"Dec";break;
}
cout<<'/'<<date<<endl;
cout<<"hour:minite:second :";
cout<<hh<<':'<<mm<<':'<<ss<<endl;
}
int main(){
Timedate A(2004,3,3),B;
A.list();
B.list();
B.putdate(2005,10,18);
B.puttime(17,30,10);
B.list();
return 0;
}
#include <iomanip>
using namespace std;
/**********Program**********/
class Timedate{
public:
Timedate(int syear=2000,int smonth=1,int sdate=1)
{ //构造函数完成所有私有成员的初始化
year=syear;
month=smonth;
date=sdate;
hh=00;
mm=00;
ss=00;
}
void list(); //完成判断
void putdate(int syear,int smonth,int sdate)
{ //完成年月日的设置
year=syear;
month=smonth;
date=sdate;
}
void puttime(int hour,int minute,int second) //内联函数:完成时分秒的设置
{ hh=hour;
mm=minute;
ss=second;
}
private:
int year,month,date,hh,mm,ss;
};
/********** End **********/
void Timedate::list(){
cout<<"year/month/date :";
switch(year){
case 2000:cout<<"2000";break;
case 2001:cout<<"2001";break;
case 2002:cout<<"2002";break;
case 2003:cout<<"2003";break;
case 2004:cout<<"2004";break;
case 2005:cout<<"2005";break;
}
switch(month){
case 1:cout<<'/'<<"Jan";break;
case 2:cout<<'/'<<"Feb";break;
case 3:cout<<'/'<<"Mar";break;
case 4:cout<<'/'<<"Apr";break;
case 5:cout<<'/'<<"May";break;
case 6:cout<<'/'<<"Jun";break;
case 7:cout<<'/'<<"Jul";break;
case 8:cout<<'/'<<"Aug";break;
case 9:cout<<'/'<<"Sep";break;
case 10:cout<<'/'<<"Oct";break;
case 11:cout<<'/'<<"Nov";break;
case 12:cout<<'/'<<"Dec";break;
}
cout<<'/'<<date<<endl;
cout<<"hour:minite:second :";
cout<<hh<<':'<<mm<<':'<<ss<<endl;
}
int main(){
Timedate A(2004,3,3),B;
A.list();
B.list();
B.putdate(2005,10,18);
B.puttime(17,30,10);
B.list();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询