c++语言程序

[复制链接]
查看11 | 回复1 | 2009-9-4 16:17:47 | 显示全部楼层 |阅读模式
好假的clock类,顶多算time吧,都不会走的,呵呵
回复

使用道具 举报

千问 | 2009-9-4 16:17:47 | 显示全部楼层
程序:#include #include //包含需要头文件,time.h是用来更新时间的using namespace std;inline int absv(int a){return a>0?a:-a;}class Clocks{ private:
int hour,minute,second;
int clockfrom;
char p[10];
//私有成员保密,这样做是为了可以更新public:
Clocks(int h=0,int m=0,int s=0):hour(h),minute(m),second(s){clockfrom=clock();}
//构造函数,默认为00:00:00
char* toStr()
{
update();
p[0]=hour/10+'0';
p[1]=hour%10+'0';
p[2]=':';
p[3]=minute/10+'0';
p[4]=minute%10+'0';
p[5]=':';
p[6]=second/10+'0';
p[7]=second%10+'0';
p[8]='\0';
return p;
}//转换为字符串,这样是为了可以用不同方式输出
//例如:cout>ab;
if (ab=='a' || ab=='A')cout<<a.toStr()<<endl;
else if (ab=='b' || ab=='B')cout<<b.toStr()<<endl;
else if (ab=='e' || ab=='E')break;
else if (ab=='u' || ab=='U')a=b;
else if (ab=='i' || ab=='I')cout<<(a==b?"A=B":"A!=B")<<endl;
else cout<<"Wrong Input~"<<endl;}system("pause");return 0;}程序运行结果:a or b (e for exit , u for a=b , i for a==b? ) : a10:00:07a or b (e for exit , u for a=b , i for a==b? ) : b00:00:08a or b (e for exit , u for a=b , i for a==b? ) : a10:00:09a or b (e for exit , u for a=b , i for a==b? ) : b00:00:09a or b (e for exit , u for a=b , i for a==b? ) : ua or b (e for exit , u for a=b , i for a==b? ) : iA=Ba or b (e for exit , u for a=b , i for a==b? ) : a00:00:15a or b (e for exit , u for a=b , i for a==b? ) : b00:00:17a or b (e for exit , u for a=b , i for a==b? ) : a00:00:17a or b (e for exit , u for a=b , i for a==b? ) : b00:00:18a or b (e for exit , u for a=b , i for a==b? ) : a00:00:18a or b (e for exit , u for a=b , i for a==b? ) : b00:00:19a or b (e for exit , u for a=b , i for a==b? ) : e请按任意键继续. . .
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行