| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 624 人关注过本帖, 1 人收藏
标题:cin 函数在时间类中的 问题 。如何实现 时间设置后 的 显示连续性
只看楼主 加入收藏
haoyasen
Rank: 2
等 级:论坛游民
帖 子:90
专家分:20
注 册:2013-3-30
结帖率:91.67%
收藏(1)
 问题点数:0 回复次数:1 
cin 函数在时间类中的 问题 。如何实现 时间设置后 的 显示连续性
/*
【基本题】定义一个时间类,提供设定时间、显示时间和秒数增加1的功能,其中设定时间的方法需要校验数据的正确性,
并在main函数中验证。
*/
#include<iostream>
#include<iomanip>
#include<windows.h>
using namespace std;
class  CClock
{
    int hour,minute,second,status;
public:
    CClock (int myhour=0,int myminute=0,int myscend=0)
    :hour(myhour ),minute(myminute ),second (myscend ){};
    //void Sethour( int sethour):hour(sethour){};
    //void Setminute(int setminute):minute(setminute){};
    //void  Setsecond(int setsecond):second(setsecond){};
    CClock(CClock & a)
    {
        hour=a.hour ;
        minute=a.minute ;
        second =a.second ;
    };
    void Display();
};
void  CClock::Display ()
{
    second ++;
    if(second ==60)
    {
        second =0;
        minute ++;        
    }
    if(minute ==60)
    {
    minute =0;
    hour ++;
    }
    if(hour==24)
    {
    hour=0;
    }
    //说明时间如何设置
    cout<<"            the tips  about  the set  of the time :"<<endl;
    cout<<"             press the key 'h' for  reset the time "<<endl;
    cout<<"             press the key 'g' for  let  the time go on"<<endl;
    //时间输出
    cout<<"Hour:"<<setw (2)<<hour<<"Minute:"<<setw(2)<<minute
        <<"Second:"<<setw(2)<<second<<endl;                                    
    for(long  i=0;i<290000000;i++)
    {}
    system("cls");
}
void main()
{
    int sethour,setminute,setsecond,flag=1;
    CClock myclock;
    while(1)
    {
     myclock .Display ();
     if(cin.get ()=='h'&&flag==1)//想显示提示信息和设置时间
        {                                         //cin这里出现错误我想让他连续的显示
            cin.clear ();
            cout <<"input the hour"<<endl;cin>>sethour ;
            cout<<"input the minute "<<endl;cin>>setminute;
            cout<<"input the second"<<endl;cin>>setsecond;
        //    myclock .Sethour (sethour );myclock .Setminute (setminute );myclock .Setsecond (setsecond );
            CClock myclock1( sethour,setminute,setsecond);
            myclock =myclock1 ;
            if(cin.get()=='g')
                flag=0;
            cin.clear ();
        }
        flag=1;
    }
}
搜索更多相关主题的帖子: minute public 时间 include 
2013-05-27 20:56
haoyasen
Rank: 2
等 级:论坛游民
帖 子:90
专家分:20
注 册:2013-3-30
收藏
得分:0 
大家看看吧
2013-05-28 08:06
快速回复:cin 函数在时间类中的 问题 。如何实现 时间设置后 的 显示连续性
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020888 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved