當前位置:編程學習大全網 - 編程軟體 - c++編程 制作壹個時鐘,可以顯示小時 分 秒

c++編程 制作壹個時鐘,可以顯示小時 分 秒

#include?<iostream>

#include?<vector>

class?Ctime?{

private:

std::vector<int>?_val;

const?static?int?_is60?=?60;

std::vector<int>&?calc_clock(?const?int&?v,?const?int?opt?=?0?)?{

int?res?=?v?+?opt;

_val.push_back(?res?%?_is60?);

_val.push_back(?(res/_is60)?%?_is60?);

_val.push_back(?(?res?-?_val[1]*_is60?-?_val[0]?)?/?(_is60*_is60)?);

return?_val;

}?

public:

Ctime?(?const?int&?v,?const?int?opt?=?0?)?{

calc_clock(?v,?opt?);

}

friend?std::ostream&?operator<<?(?std::ostream&?out,?const?Ctime&?clock?)?{

out?<<?clock._val[2]?<<?"?:?";

out?<<?clock._val[1]?<<?"?:?";

out?<<?clock._val[0];

return?out;

}

};

int?main(?)?{

Ctime?t1(?3661?);

Ctime?t2(?3661,?-8?);

Ctime?t3(?3661,?8?);

//

std::cout?<<?t1?<<?std::endl;

std::cout?<<?t2?<<?std::endl;

std::cout?<<?t3?<<?std::endl;

}

  • 上一篇:幼師資格證考試來面試的時候,妳會彈鋼琴。
  • 下一篇:企業,培訓機構調研優缺點
  • copyright 2024編程學習大全網